11 #ifndef OPENKALMAN_LINEARTRANSFORMATION_HPP 12 #define OPENKALMAN_LINEARTRANSFORMATION_HPP 33 (index_dimension_of_v<TransformationMatrix, 0> == coordinates::dimension_of_v<OutputCoefficients>) and
34 (index_dimension_of_v<TransformationMatrix, 1> == coordinates::dimension_of_v<InputCoefficients>) and
35 ((index_dimension_of_v<PerturbationTransformationMatrices, 0> == coordinates::dimension_of_v<OutputCoefficients>) and ...) and
36 (square_shaped<PerturbationTransformationMatrices> and ...)
38 template<
typename InputCoefficients,
typename OutputCoefficients,
typename TransformationMatrix,
39 typename ... PerturbationTransformationMatrices>
47 template<
typename In,
typename Out,
typename Tm,
typename...Pm, std::size_t order> requires (order <= 1)
50 template<
typename In,
typename Out,
typename Tm,
typename...Pm, std::size_t order>
56 #ifndef __cpp_concepts 59 template<
typename T,
typename R,
typename C,
typename =
void>
60 struct is_linear_transformation_input : std::false_type {};
62 template<
typename T,
typename R,
typename C>
63 struct is_linear_transformation_input<T, R, C, std::enable_if_t<
64 typed_matrix<T> and compares_with<vector_space_descriptor_of_t<T, 0>, R>and
65 compares_with<vector_space_descriptor_of_t<T, 1>, C>>>: std::true_type {};
67 template<
typename T,
typename R,
typename C>
68 struct is_linear_transformation_input<T, R, C, std::enable_if_t<
69 typed_matrix_nestable<T> and (index_dimension_of<T, 0>::value == coordinates::dimension_of_v<R>) and
70 (index_dimension_of<T, 1>::value == coordinates::dimension_of_v<C>)>> : std::true_type {};
83 template<
typename T,
typename RowCoefficients,
typename ColumnCoefficients = RowCoefficients>
84 concept linear_transformation_input =
85 (typed_matrix<T> or typed_matrix_nestable<T>) and
86 fixed_pattern<RowCoefficients> and fixed_pattern<ColumnCoefficients> and
89 (not typed_matrix_nestable<T> or (index_dimension_of_v<T, 0> == coordinates::dimension_of_v<RowCoefficients> and
90 index_dimension_of_v<T, 1> == coordinates::dimension_of_v<ColumnCoefficients>));
92 template<
typename T,
typename RowCoefficients,
typename ColumnCoefficients = RowCoefficients>
93 constexpr
bool linear_transformation_input =
94 fixed_pattern<RowCoefficients> and fixed_pattern<ColumnCoefficients> and
101 #ifdef __cpp_concepts 102 template<fixed_pattern InputCoefficients, fixed_pattern OutputCoefficients,
typed_matrix_nestable TransformationMatrix,
104 (index_dimension_of_v<TransformationMatrix, 0> == coordinates::dimension_of_v<OutputCoefficients>) and
105 (index_dimension_of_v<TransformationMatrix, 1> == coordinates::dimension_of_v<InputCoefficients>) and
106 ((index_dimension_of_v<PerturbationTransformationMatrices, 0> == coordinates::dimension_of_v<OutputCoefficients>) and ...) and
107 (square_shaped<PerturbationTransformationMatrices> and ...)
109 template<
typename InputCoefficients,
typename OutputCoefficients,
typename TransformationMatrix,
110 typename ... PerturbationTransformationMatrices>
115 #ifndef __cpp_concepts 116 static_assert(fixed_pattern<InputCoefficients>);
117 static_assert(fixed_pattern<OutputCoefficients>);
118 static_assert(typed_matrix_nestable<TransformationMatrix>);
119 static_assert((typed_matrix_nestable<PerturbationTransformationMatrices> and ...));
120 static_assert(index_dimension_of_v<TransformationMatrix, 0> == coordinates::dimension_of_v<OutputCoefficients>);
121 static_assert(index_dimension_of_v<TransformationMatrix, 1> == coordinates::dimension_of_v<InputCoefficients>);
122 static_assert(((index_dimension_of_v<PerturbationTransformationMatrices, 0> == coordinates::dimension_of_v<OutputCoefficients>) and ...));
123 static_assert((square_shaped<PerturbationTransformationMatrices> and ...));
128 template<
typename Jacobians,
typename InputTuple, std::size_t...ints>
129 constexpr
auto sumprod(Jacobians&& js, InputTuple&& inputs, std::index_sequence<ints...>)
const 131 return make_self_contained(
132 ((std::get<ints>(std::forward<Jacobians>(js)) * std::get<ints>(std::forward<InputTuple>(inputs))) + ...));
136 using TransformationMatricesTuple = std::tuple<
140 const TransformationMatricesTuple transformation_matrices;
148 : transformation_matrices {mat, p_mats...} {}
156 #ifdef __cpp_concepts 157 template<oin::linear_transformation_input<OutputCoefficients, InputCoefficients> T,
158 oin::linear_transformation_input<OutputCoefficients> ... Ps>
160 template<
typename T,
typename ... Ps, std::enable_if_t<
161 oin::linear_transformation_input<T, OutputCoefficients, InputCoefficients> and
162 (oin::linear_transformation_input<Ps, OutputCoefficients> and ...),
int> = 0>
165 : transformation_matrices {std::forward<T>(mat), std::forward<Ps>(p_mats)...} {}
169 #ifdef __cpp_concepts 170 template<transformation_input<InputCoefficients> In, perturbation<OutputCoefficients> ... Perturbations>
172 template<
typename In,
typename ... Perturbations, std::enable_if_t<transformation_input<In, InputCoefficients> and
173 (perturbation<Perturbations, OutputCoefficients> and ...),
int> = 0>
179 std::forward_as_tuple(std::forward<In>(in), oin::get_perturbation(std::forward<Perturbations>(ps))...),
180 std::make_index_sequence<
sizeof...(Perturbations) + 1> {});
185 #ifdef __cpp_concepts 186 template<transformation_input<InputCoefficients> In, perturbation<OutputCoefficients> ... Perturbations>
188 template<
typename In,
typename ... Perturbations, std::enable_if_t<transformation_input<In, InputCoefficients> and
189 (perturbation<Perturbations, OutputCoefficients> and ...),
int> = 0>
191 auto jacobian(
const In&,
const Perturbations& ...)
const 193 constexpr
auto mat_count = std::tuple_size_v<TransformationMatricesTuple>;
196 if constexpr(
sizeof...(Perturbations) + 1 > mat_count)
198 constexpr
auto pad_size =
sizeof...(Perturbations) + 1 - mat_count;
199 auto id =
make_vector_space_adapter(make_identity_matrix_like<TransformationMatrix>(), OutputCoefficients{}, OutputCoefficients{});
204 return oin::tuple_slice<0,
sizeof...(Perturbations) + 1>(transformation_matrices);
215 #ifdef __cpp_concepts 216 template<typed_matrix T, oin::linear_transformation_input<vector_space_descriptor_of_t<T, 0>> ... Ps>
218 template<
typename T,
typename ... Ps, std::enable_if_t<
219 (typed_matrix<T> and ... and oin::linear_transformation_input<Ps, vector_space_descriptor_of_t<T, 0>>),
226 equivalent_self_contained_t<nested_object_of_t<T>>,
230 #ifdef __cpp_concepts 231 template<typed_matrix_nestable T, oin::linear_transformation_input<Dimensions<index_dimension_of_v<T, 0>>> ... Ps>
233 template<
typename T,
typename ... Ps, std::enable_if_t<
238 Dimensions<index_dimension_of_v<T, 1>>,
239 Dimensions<index_dimension_of_v<T, 0>>,
240 equivalent_self_contained_t<T>,
241 equivalent_self_contained_t<Ps>...>;
250 template<
typename InC,
typename OutC,
typename T,
typename ... Ps>
253 template<
typename InC,
typename OutC,
typename T,
typename ... Ps>
261 #endif //OPENKALMAN_LINEARTRANSFORMATION_HPP typename nested_object_of< T >::type nested_object_of_t
Helper type for nested_object_of.
Definition: nested_object_of.hpp:66
auto make_vector_space_adapter(Arg &&arg, Descriptors &&descriptors)
If necessary, wrap an object in a wrapper that adds vector space descriptors for each index...
Definition: make_vector_space_adapter.hpp:37
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr bool typed_matrix_nestable
Specifies a type that is nestable in a general typed matrix (e.g., matrix, mean, or euclidean_mean) ...
Definition: object-types.hpp:253
The root namespace for OpenKalman.
Definition: basics.hpp:34
typename vector_space_descriptor_of< T, N >::type vector_space_descriptor_of_t
helper template for vector_space_descriptor_of.
Definition: vector_space_descriptor_of.hpp:56
Definition: tuple_fill_view.hpp:32
constexpr auto tuple_slice(Arg &&arg)
Takes a slice of a tuple, given an index range.
Definition: tuple_slice.hpp:132
constexpr bool fixed_pattern
A coordinates::pattern for which the size is fixed at compile time.
Definition: fixed_pattern.hpp:47
Definition: TransformationTraits.hpp:39
Definition: basics.hpp:48
A matrix with typed rows and columns.
Definition: forward-class-declarations.hpp:448