8#include <Eigen/Geometry>
17#include "wuzp/core/internal/operator_traits.hpp"
22template <
typename ValueT_,
int RowsV_,
int ColsV_>
25template <
int RowsV_,
int ColsV_>
27template <
int RowsV_,
int ColsV_>
29template <
int RowsV_,
int ColsV_>
32template <
typename ValueT_,
int RowsV_>
42template <
typename ValueT_>
50template <
typename UnitT_>
52template <
typename UnitT_>
54template <
typename UnitT_>
61concept EigenArray = std::is_base_of_v<Eigen::ArrayBase<T>, T>;
69 static void run(ImplementationT_& ) {}
73struct Initialize<ImplementationT_, std::tuple<Arg0T_, ArgsT_...>> {
74 static void run(ImplementationT_& impl, Arg0T_&& arg0, ArgsT_&&... args) {
75 applyCommas((impl << std::forward<Arg0T_>(arg0)), std::forward<ArgsT_>(args)...);
82template <wuzp_eigen::EigenArray ImplementationT_,
typename ValueT_,
int RowsV_,
int ColsV_>
84 using type = Eigen::Array<ValueT_, RowsV_, ColsV_>;
89template <wuzp_eigen::EigenArray ImplementationT_>
91 static auto get(
const ImplementationT_& impl,
const int row,
const int col) {
return impl(row, col); }
92 static void set(ImplementationT_& impl,
const int row,
const int col,
const typename ImplementationT_::Scalar value) {
93 impl(row, col) = value;
97template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
99 static bool equal(
const ImplementationLhsT_& lhs,
const ImplementationRhsT_& rhs) {
return lhs.matrix() == rhs.matrix(); }
100 static bool approxEqual(
const ImplementationLhsT_& lhs,
const ImplementationRhsT_& rhs,
101 const typename ImplementationLhsT_::Scalar tolerance) {
102 return lhs.matrix().isApprox(rhs.matrix(), tolerance);
106template <wuzp_eigen::EigenArray ImplementationT_>
108 static auto value(
const ImplementationT_& impl) {
return impl.transpose(); }
110 using type =
decltype(
value(std::declval<const ImplementationT_>()));
113template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
115 : internal::OperatorSum<ImplementationLhsT_, ImplementationRhsT_> {};
117template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
119 : internal::OperatorDifference<ImplementationLhsT_, ImplementationRhsT_> {};
121template <wuzp_eigen::EigenArray ImplementationT_>
124template <wuzp_eigen::EigenArray ImplementationLhsT_, ArithmeticValue ValueRhsT_>
125struct Product<
AccessImplementation<ImplementationLhsT_>, ValueRhsT_> : internal::OperatorProduct<ImplementationLhsT_, ValueRhsT_> {};
126template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
128 : internal::OperatorProduct<ImplementationLhsT_, ImplementationRhsT_> {};
130template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
132 static auto value(
const ImplementationLhsT_& implLhs,
const ImplementationRhsT_& implRhs) {
133 return (implLhs.matrix() * implRhs.matrix()).array();
136 using type =
decltype(
value(std::declval<const ImplementationLhsT_>(), std::declval<const ImplementationRhsT_>()));
139template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
141 static auto value(
const ImplementationLhsT_& implLhs,
const ImplementationRhsT_& implRhs) {
142 if constexpr (ImplementationLhsT_::RowsAtCompileTime == 1 && ImplementationLhsT_::ColsAtCompileTime == 1) {
143 return implLhs(0, 0) * implRhs;
144 }
else if constexpr (ImplementationRhsT_::RowsAtCompileTime == 1 && ImplementationRhsT_::ColsAtCompileTime == 1) {
145 return implLhs * implRhs(0, 0);
146 }
else if constexpr (ImplementationLhsT_::RowsAtCompileTime == 1) {
147 return (implRhs.matrix() * implLhs.matrix()).array();
149 return (implLhs.matrix() * implRhs.matrix()).array();
153 using type =
decltype(
value(std::declval<const ImplementationLhsT_>(), std::declval<const ImplementationRhsT_>()));
156template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
158 static auto value(
const ImplementationLhsT_& implLhs,
const ImplementationRhsT_& implRhs) {
160 return (implLhs.matrix().cross(implRhs.matrix())).array().eval();
163 using type =
decltype(
value(std::declval<const ImplementationLhsT_>(), std::declval<const ImplementationRhsT_>()));
166template <wuzp_eigen::EigenArray ImplementationLhsT_, wuzp_eigen::EigenArray ImplementationRhsT_>
168 : internal::OperatorDivision<ImplementationLhsT_, ImplementationRhsT_> {};
169template <wuzp_eigen::EigenArray ImplementationLhsT_, ArithmeticValue ValueRhsT_>
170struct Division<
AccessImplementation<ImplementationLhsT_>, ValueRhsT_> : internal::OperatorDivision<ImplementationLhsT_, ValueRhsT_> {};
172template <wuzp_eigen::EigenArray ImplementationT_>
174 static auto value(
const ImplementationT_& impl) {
return impl.matrix().norm(); }
176 using type =
decltype(
value(std::declval<const ImplementationT_>()));
179template <wuzp_eigen::EigenArray ImplementationT_>
181 static auto value(
const ImplementationT_& impl) {
return impl.matrix().squaredNorm(); }
183 using type =
decltype(
value(std::declval<const ImplementationT_>()));
186template <wuzp_eigen::EigenArray ImplementationT_>
188 static auto value(
const ImplementationT_& impl) {
return impl.matrix().determinant(); }
190 using type =
decltype(
value(std::declval<const ImplementationT_>()));
194template <wuzp_eigen::EigenArray ImplementationT_>
196 static auto value(
const ImplementationT_& impl) {
return impl.matrix().inverse().array(); }
198 using type =
decltype(
value(std::declval<const ImplementationT_>()));
201template <wuzp_eigen::EigenArray ImplementationT_>
203 static auto value(
const ImplementationT_& impl) {
return impl.inverse(); }
205 using type =
decltype(
value(std::declval<const ImplementationT_>()));
210template <wuzp_eigen::EigenArray ImplementationT_,
typename FunctionT_>
212 static auto value(
const ImplementationT_& impl,
const FunctionT_& function) {
return impl.unaryExpr(function); }
214 using type =
decltype(
value(std::declval<const ImplementationT_>(), std::declval<const FunctionT_>()));
217template <wuzp_eigen::EigenArray ImplementationT_,
int BlockRowIdV_,
int BlockColIdV_,
int BlockRowsV_,
int BlockColsV_>
219 static auto value(
const ImplementationT_& impl) {
return impl.template block<BlockRowsV_, BlockColsV_>(BlockRowIdV_, BlockColIdV_); }
221 using type =
decltype(
value(std::declval<const ImplementationT_>()));
224template <wuzp_eigen::EigenArray ImplementationT_>
226 static void run(ImplementationT_& impl) { impl.setZero(); }
229template <wuzp_eigen::EigenArray ImplementationT_>
232 static void run(ImplementationT_& impl) { impl.setRandom(); }
237template <wuzp_eigen::EigenArray ImplementationT_>
239 static ImplementationT_
value(
const ImplementationT_& impl) {
return impl; }
242template <wuzp_eigen::EigenArray ImplementationT_>
244 static ImplementationT_
construct(ImplementationT_& source) {
return std::move(source); }
245 static void assign(ImplementationT_& target, ImplementationT_& source) { target = std::move(source); }
250template <wuzp_eigen::EigenArray ImplementationT_>
253 ImplementationT_::RowsAtCompileTime, ImplementationT_::ColsAtCompileTime>
::type;
Wrapper for the actual implementation of a value container.
The implementation types of the backend: Eigen's arrays and the expressions of arrays,...
ValueMatrix< int, RowsV_, ColsV_ > ValueMatrixI
ValueVector< float, RowsV_ > ValueVectorF
ValueVector< int, RowsV_ > ValueVectorI
wuzp::Quantity< ValueD, UnitT_ > QuantityD
wuzp::Quantity< ValueI, UnitT_ > QuantityI
A quantity with a value of this backend, e.g. QuantityD<wuzp_units::Length>.
ValueVector< double, RowsV_ > ValueVectorD
ValueMatrix< double, RowsV_, ColsV_ > ValueMatrixD
ValueMatrix< float, RowsV_, ColsV_ > ValueMatrixF
ValueMatrix< ValueT_, RowsV_, 1 > ValueVector
ValueMatrix< ValueT_, 1, 1 > Value
wuzp::ValuesWrapper< wuzp::MatrixSize< RowsV_, ColsV_ >, ValueT_, Eigen::Array< ValueT_, RowsV_, ColsV_ > > ValueMatrix
wuzp::Quantity< ValueF, UnitT_ > QuantityF
Quantities< ValueT_, TypeMatrixImpl< MatrixSize< 1, 1 >, std::tuple< UnitT_ > > > Quantity
Container to store a single quantity.
void applyCommas(First &&first, Rest &&... rest)
Applies the comma operator from left to right: applyCommas(a, b, c) evaluates ((a,...
Type wrapper which is used to access traits partially specialized in the implementation header files.
decltype(value(std::declval< const ImplementationT_ >())) type
static auto value(const ImplementationT_ &impl)
static auto get(const ImplementationT_ &impl, const int row, const int col)
static void set(ImplementationT_ &impl, const int row, const int col, const typename ImplementationT_::Scalar value)
Element access of a matrix of a value matrix backend: get(impl, row, col) returns an element,...
static bool equal(const ImplementationLhsT_ &lhs, const ImplementationRhsT_ &rhs)
static bool approxEqual(const ImplementationLhsT_ &lhs, const ImplementationRhsT_ &rhs, const typename ImplementationLhsT_::Scalar tolerance)
static ImplementationT_ value(const ImplementationT_ &impl)
Copies a matrix of a value matrix backend: value returns the copy, which must not share its values wi...
static auto value(const ImplementationLhsT_ &implLhs, const ImplementationRhsT_ &implRhs)
decltype(value(std::declval< const ImplementationLhsT_ >(), std::declval< const ImplementationRhsT_ >())) type
static auto value(const ImplementationT_ &impl, const FunctionT_ &function)
decltype(value(std::declval< const ImplementationT_ >(), std::declval< const FunctionT_ >())) type
A function applied to every element of a matrix, like Eigen's DenseBase::unaryExpr(): value(impl,...
static auto value(const ImplementationT_ &impl)
decltype(value(std::declval< const ImplementationT_ >())) type
The elementwise reciprocal of a matrix, like Eigen's ArrayBase::inverse() or cwiseInverse().
static auto value(const ImplementationT_ &impl)
decltype(value(std::declval< const ImplementationT_ >())) type
typename Rebind< AccessImplementation< ImplementationT_ >, typename ImplementationT_::Scalar, ImplementationT_::RowsAtCompileTime, ImplementationT_::ColsAtCompileTime >::type type
static type value(const ImplementationT_ &impl)
static void run(ImplementationT_ &impl, Arg0T_ &&arg0, ArgsT_ &&... args)
Initializes an allocated matrix of a value matrix backend with its elements, row by row: run(impl,...
decltype(value(std::declval< const ImplementationLhsT_ >(), std::declval< const ImplementationRhsT_ >())) type
static auto value(const ImplementationLhsT_ &implLhs, const ImplementationRhsT_ &implRhs)
static auto value(const ImplementationT_ &impl)
decltype(value(std::declval< const ImplementationT_ >())) type
The inverse: the matrix inverse of a matrix, like Eigen's MatrixBase::inverse(), and the reciprocal o...
static void assign(ImplementationT_ &target, ImplementationT_ &source)
static ImplementationT_ construct(ImplementationT_ &source)
Moves a matrix of a value matrix backend: construct returns the moved matrix, assign moves it into an...
The negation is performed elementwise.
static auto value(const ImplementationT_ &impl)
decltype(value(std::declval< const ImplementationT_ >())) type
static auto value(const ImplementationLhsT_ &implLhs, const ImplementationRhsT_ &implRhs)
decltype(value(std::declval< const ImplementationLhsT_ >(), std::declval< const ImplementationRhsT_ >())) type
static void run(ImplementationT_ &impl)
Eigen::Array< ValueT_, RowsV_, ColsV_ > type
The evaluated type of another value type and size, of the same backend as T: e.g. the 1x1 values of a...
static void run(ImplementationT_ &)
Allocates a default constructed matrix of a value matrix backend for the size MatrixSizeT_: run(impl)...
static auto value(const ImplementationT_ &impl)
decltype(value(std::declval< const ImplementationT_ >())) type
decltype(value(std::declval< const ImplementationT_ >())) type
static auto value(const ImplementationT_ &impl)
static void run(ImplementationT_ &impl)