14#include <lagrange/common.h>
15#include <lagrange/experimental/Array.h>
18namespace experimental {
27template <
typename Derived>
28std::unique_ptr<ArrayBase> create_array(
const Eigen::MatrixBase<Derived>& matrix)
30 using EvalType = std::decay_t<
decltype(matrix.eval())>;
31 return std::make_unique<EigenArray<EvalType>>(matrix);
34template <
typename Derived>
35std::unique_ptr<ArrayBase> create_array(
const Eigen::ArrayBase<Derived>& array)
37 return create_array(array.matrix());
40template <
typename Derived>
41std::unique_ptr<ArrayBase> create_array(Eigen::PlainObjectBase<Derived>&& matrix)
43 static_assert(!std::is_const<Derived>::value,
"Derived should not be const!");
45 const void* ptr = matrix.data();
47 auto r = std::make_unique<EigenArray<Derived>>(std::move(matrix.derived()));
49 const void* ptr2 = r->data();
55template <
typename Scalar,
typename Index,
int Options = Eigen::RowMajor>
56std::unique_ptr<ArrayBase> create_array(Scalar* values, Index rows, Index cols)
58 using EigenType = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options>;
59 return std::make_unique<EigenArray<EigenType>>(Eigen::Map<EigenType>(values, rows, cols));
62static inline std::shared_ptr<ArrayBase> create_array(std::shared_ptr<ArrayBase> array_ptr)
67template <
typename Derived>
68std::unique_ptr<ArrayBase> wrap_with_array(Eigen::PlainObjectBase<Derived>& matrix)
70 static_assert(!std::is_const<Derived>::value,
"Derived should not be const!");
71 return std::make_unique<EigenArrayRef<Derived>>(matrix);
74template <
typename Derived>
75std::unique_ptr<const ArrayBase> wrap_with_array(
const Eigen::PlainObjectBase<Derived>& matrix)
77 static_assert(!std::is_const<Derived>::value,
"Derived should not be const!");
78 return std::make_unique<EigenArrayRef<const Derived>>(matrix);
81template <
typename Derived>
82std::unique_ptr<ArrayBase> wrap_with_array(
const Eigen::PlainObjectBase<Derived>&& )
85 StaticAssertableBool<Derived>::False,
86 "Lagrange Array cannot wrap around r-value Eigen matrix "
87 "because its memory may be invalid after the creation.");
91template <
typename Derived,
int Options,
typename Str
ideType>
92std::enable_if_t<!std::is_const<Derived>::value, std::unique_ptr<ArrayBase>> wrap_with_array(
93 Eigen::Map<Derived, Options, StrideType>& matrix)
95 static_assert(!std::is_const<Derived>::value,
"Derived should not be const!");
96 return std::make_unique<RawArray<
97 typename Derived::Scalar,
98 Derived::RowsAtCompileTime,
99 Derived::ColsAtCompileTime,
100 Derived::Options>>(matrix.data(), matrix.rows(), matrix.cols());
103template <
typename Derived,
int Options,
typename Str
ideType>
104std::enable_if_t<std::is_const<Derived>::value, std::unique_ptr<const ArrayBase>> wrap_with_array(
105 const Eigen::Map<Derived, Options, StrideType>& matrix)
107 return std::make_unique<
const RawArray<
108 const typename Derived::Scalar,
109 Derived::RowsAtCompileTime,
110 Derived::ColsAtCompileTime,
111 Derived::Options>>(matrix.data(), matrix.rows(), matrix.cols());
114template <
typename Derived,
int Options,
typename Str
ideType>
115std::enable_if_t<!std::is_const<Derived>::value, std::unique_ptr<ArrayBase>> wrap_with_array(
116 Eigen::Map<Derived, Options, StrideType>&& matrix)
118 return std::make_unique<RawArray<
119 typename Derived::Scalar,
120 Derived::RowsAtCompileTime,
121 Derived::ColsAtCompileTime,
122 Derived::Options>>(matrix.data(), matrix.rows(), matrix.cols());
125template <
typename Derived,
int Options,
typename Str
ideType>
126std::enable_if_t<std::is_const<Derived>::value, std::unique_ptr<const ArrayBase>> wrap_with_array(
127 const Eigen::Map<Derived, Options, StrideType>&& matrix)
129 return std::make_unique<
const RawArray<
130 const typename Derived::Scalar,
131 Derived::RowsAtCompileTime,
132 Derived::ColsAtCompileTime,
133 Derived::Options>>(matrix.data(), matrix.rows(), matrix.cols());
139 int Rows = Eigen::Dynamic,
140 int Cols = Eigen::Dynamic,
141 int Options = Eigen::RowMajor>
142std::unique_ptr<ArrayBase> wrap_with_array(Scalar* values, Index rows, Index cols)
144 return std::make_unique<RawArray<Scalar, Rows, Cols, Options>>(values, rows, cols);
150 int Rows = Eigen::Dynamic,
151 int Cols = Eigen::Dynamic,
152 int Options = Eigen::RowMajor>
153std::unique_ptr<const ArrayBase> wrap_with_array(
const Scalar* values, Index rows, Index cols)
155 return std::make_unique<const RawArray<const Scalar, Rows, Cols, Options>>(values, rows, cols);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Main namespace for Lagrange.
Definition: AABBIGL.h:30