Embed_in_Rd.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Siargey Kachanovich
4  *
5  * Copyright (C) 2019 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef FUNCTIONS_EMBED_IN_RD_H_
12 #define FUNCTIONS_EMBED_IN_RD_H_
13 
14 #include <cstdlib> // for std::size_t
15 
16 #include <Eigen/Dense>
17 
18 namespace Gudhi {
19 
20 namespace coxeter_triangulation {
21 
29 template <class Function_>
30 struct Embed_in_Rd {
35  Eigen::VectorXd operator()(const Eigen::VectorXd& p) const {
36  Eigen::VectorXd x = p;
37  Eigen::VectorXd x_k(fun_.amb_d()), x_rest(d_ - fun_.amb_d());
38  for (std::size_t i = 0; i < fun_.amb_d(); ++i) x_k(i) = x(i);
39  for (std::size_t i = fun_.amb_d(); i < d_; ++i) x_rest(i - fun_.amb_d()) = x(i);
40  Eigen::VectorXd result = fun_(x_k);
41  result.conservativeResize(this->cod_d());
42  for (std::size_t i = fun_.cod_d(); i < this->cod_d(); ++i) result(i) = x_rest(i - fun_.cod_d());
43  return result;
44  }
45 
47  std::size_t amb_d() const { return d_; }
48 
50  std::size_t cod_d() const { return d_ - (fun_.amb_d() - fun_.cod_d()); }
51 
53  Eigen::VectorXd seed() const {
54  Eigen::VectorXd result = fun_.seed();
55  result.conservativeResize(d_);
56  for (std::size_t l = fun_.amb_d(); l < d_; ++l) result(l) = 0;
57  return result;
58  }
59 
66  Embed_in_Rd(const Function_& function, std::size_t d) : fun_(function), d_(d) {}
67 
68  private:
69  Function_ fun_;
70  std::size_t d_;
71 };
72 
84 template <class Function_>
85 Embed_in_Rd<Function_> make_embedding(const Function_& function, std::size_t d) {
86  return Embed_in_Rd<Function_>(function, d);
87 }
88 
89 } // namespace coxeter_triangulation
90 
91 } // namespace Gudhi
92 
93 #endif
Embed_in_Rd< Function_ > make_embedding(const Function_ &function, std::size_t d)
Static constructor of an embedding function.
Definition: Embed_in_Rd.h:85
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Embedding of an implicit manifold in a higher dimension.
Definition: Embed_in_Rd.h:30
Eigen::VectorXd seed() const
Returns a point on the zero-set of the embedded function.
Definition: Embed_in_Rd.h:53
Embed_in_Rd(const Function_ &function, std::size_t d)
Constructor of the embedding function.
Definition: Embed_in_Rd.h:66
Eigen::VectorXd operator()(const Eigen::VectorXd &p) const
Value of the function at a specified point.
Definition: Embed_in_Rd.h:35
std::size_t amb_d() const
Returns the domain (ambient) dimension.
Definition: Embed_in_Rd.h:47
std::size_t cod_d() const
Returns the codomain dimension.
Definition: Embed_in_Rd.h:50