16 #ifndef OPENKALMAN_CONSTANT_ADAPTER_HPP 17 #define OPENKALMAN_CONSTANT_ADAPTER_HPP 19 #include "coordinates/coordinates.hpp" 23 #include "linear-algebra/traits/internal/library_base.hpp" 48 template<values::value Value, indexible Shape> requires std::is_object_v<Value>
50 template<
typename Value,
typename Shape>
52 struct constant_adapter : internal::library_base_t<constant_adapter<Value, Shape>, Shape>
63 #ifdef __cpp_lib_ranges 64 template<values::value V, coordinates::pattern_collection P> requires
65 std::constructible_from<Value, V&&> and
66 std::constructible_from<Pattern, P&&>
68 template<
typename V,
typename P, std::enable_if_t<
69 values::value<V> and pattern_collection<P> and
70 stdex::constructible_from<Value, V&&> and stdex::constructible_from<Pattern, P&&>,
int> = 0>
73 : value_ {std::forward<V>(v)}, pattern_ {std::forward<P>(p)} {}
79 #ifdef __cpp_lib_ranges 80 template<values::value V, indexible S> requires
81 std::constructible_from<Value, V&&> and
82 std::constructible_from<Pattern, decltype(get_pattern_collection(std::declval<S&&>()))>
84 template<
typename V,
typename S, std::enable_if_t<values::value<V> and
85 stdex::constructible_from<Value, V&&> and
96 #ifdef __cpp_lib_ranges 97 template<values::value V> requires
98 std::constructible_from<Value, V&&> and
99 coordinates::fixed_pattern_collection<Pattern>
101 template<
typename V,
typename S, std::enable_if_t<values::value<V> and
102 stdex::constructible_from<Value, V&&> and coordinates::fixed_pattern_collection<Pattern>,
int> = 0>
105 : value_ {std::forward<V>(v)}, pattern_ {} {}
112 #ifdef __cpp_lib_ranges 114 requires values::fixed<Value> and coordinates::fixed_pattern_collection<Pattern>
116 template<
bool Enable, std::enable_if_t<Enable and values::fixed<Value> and coordinates::fixed_pattern_collection<Pattern>,
int> = 0>
119 : value_ {}, pattern_ {} {}
125 #ifdef __cpp_concepts 126 template<constant_
object Arg> requires
128 std::constructible_from<Value, constant_value<Arg>> and
129 std::constructible_from<Pattern, decltype(get_pattern_collection(std::declval<Arg&&>()))>
131 template<
typename Arg, std::enable_if_t<constant_object<Arg> and
133 stdex::constructible_from<Value, constant_value<Arg>> and
134 stdex::constructible_from<Pattern, decltype(get_pattern_collection(std::declval<Arg&&>()))>,
int> = 0>
144 #ifdef __cpp_concepts 145 template<constant_
object Arg> requires
147 std::assignable_from<Value&, constant_value<Arg>> and
148 std::assignable_from<Pattern&, decltype(get_pattern_collection(std::declval<Arg&&>()))>
150 template<
typename Arg, std::enable_if_t<constant_object<Arg> and
152 stdex::assignable_from<Value&, constant_value<Arg>> and
153 stdex::assignable_from<Pattern&, decltype(get_pattern_collection(std::declval<Arg&&>()))>,
int> = 0>
155 constexpr
auto&
operator=(
const Arg& arg)
167 #ifdef __cpp_lib_ranges 168 template<index_collection_for<Shape> Indices> requires (not empty_object<PatternMatrix>)
169 constexpr values::scalar
auto 171 template<
typename Indices, std::enable_if_t<
172 index_collection_for<Indices, Shape> and (not empty_object<PatternMatrix>),
int> = 0>
184 #ifdef __cpp_concepts 210 #ifdef __cpp_concepts 211 template<values::value C, indexible Arg>
213 template<
typename C,
typename Arg, std::enable_if_t<values::scalar<C> and indexible<Arg>,
int> = 0>
218 #ifdef __cpp_concepts 221 template<
typename Arg, std::enable_if_t<constant_
object<Arg> and (not is_constant_adapter<Arg>),
int> = 0>
235 #ifdef __cpp_concepts 236 template<indexible Shape, values::number N = element_type_of_t<Shape>>
238 template<
typename Shape,
typename N = element_type_of_t<Shape>>
249 template<
typename PatternMatrix,
typename Scalar,
auto...constant>
254 using XprType = constant_adapter<PatternMatrix, Scalar, constant...>;
258 using scalar_type =
typename XprType::MyScalarType;
259 using MyDims =
typename XprType::MyDimensions_t;
262 template<
typename Arg>
265 if constexpr (index_count_v<PatternMatrix> == stdex::dynamic_extent)
266 return std::forward<Arg>(arg).pattern_.size();
272 template<
typename Arg,
typename N>
275 if constexpr (index_count_v<PatternMatrix> == stdex::dynamic_extent)
277 return std::forward<Arg>(arg).pattern_[static_cast<typename MyDims::size_type>(n)];
279 else if constexpr (values::fixed<N>)
281 if constexpr (
N::value >= index_count_v<PatternMatrix>)
return Dimensions<1>{};
282 else return std::get<N::value>(std::forward<Arg>(arg).pattern_);
284 else if (n >= collections::size_of_v<MyDims>)
291 [](
auto&&...ds){
return std::array<std::size_t, collections::size_of_v<MyDims>> {std::forward<decltype(ds)>(ds)...}; },
292 std::forward<Arg>(arg).pattern_)[n];
300 template<
typename Arg>
301 static constexpr
auto get_constant(
const Arg& arg) {
return arg.value(); }
307 template<applicability b>
308 static constexpr
bool one_dimensional = OpenKalman::one_dimensional<PatternMatrix, b>;
311 template<applicability b>
312 static constexpr
bool is_square = OpenKalman::square_shaped<PatternMatrix, b>;
318 static constexpr
bool is_writable =
false;
326 template<
typename PatternMatrix,
typename Scalar,
auto...constant>
329 template<
typename Derived>
330 using library_base = internal::library_base_t<Derived, PatternMatrix>;
333 template<
typename Arg,
typename Indices>
334 static constexpr
auto 335 access(Arg&& arg,
const Indices&) {
return std::forward<Arg>(arg).
value(); }
341 template<
typename Arg>
342 static decltype(
auto)
343 to_native_matrix(Arg&& arg)
345 return OpenKalman::to_native_matrix<PatternMatrix>(std::forward<Arg>(arg));
349 template<data_layout layout,
typename S,
typename D>
353 return make_dense_object<PatternMatrix, layout, S>(std::forward<D>(d));
360 template<
typename C,
typename D>
361 static constexpr
auto 364 return OpenKalman::make_constant<PatternMatrix>(std::forward<C>(c), std::forward<D>(d));
368 template<
typename S,
typename D>
369 static constexpr
auto 370 make_identity_matrix(D&& d)
372 return make_identity_matrix_like<PatternMatrix, S>(std::forward<D>(d));
383 template<
typename...Ds,
typename Arg>
384 static decltype(
auto)
385 replicate(
const std::tuple<Ds...>& tup, Arg&& arg)
391 template<
typename...Ds,
typename Op,
typename...Args>
392 static constexpr decltype(
auto)
393 n_ary_operation(
const std::tuple<Ds...>& d_tup, Op&& op, Args&&...args)
399 template<std::size_t...indices,
typename BinaryFunction,
typename Arg>
400 static constexpr decltype(
auto)
401 reduce(BinaryFunction&& b, Arg&& arg)
417 template<
typename A,
typename B>
418 static constexpr
auto sum(
A&& a, B&& b)
424 template<
typename A,
typename B>
425 static constexpr
auto contract(
A&& a, B&& b)
436 template<HermitianAdapterType significant_triangle,
typename A,
typename U,
typename Alpha>
440 return Trait::template rank_update_hermitian<significant_triangle>(std::forward<A>(a), std::forward<U>(u), alpha);
constexpr auto n_ary_operation(const std::tuple< Ds... > &d_tup, Operation &&operation, Args &&...args)
Perform a component-wise n-ary operation, using broadcasting to match the size of a pattern matrix...
Definition: n_ary_operation.hpp:325
Definition for constant_value.
constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:56
decltype(auto) constexpr contract(A &&a, B &&b)
Matrix multiplication of A * B.
Definition: contract.hpp:54
Definition for constant_object.
decltype(auto) rank_update_hermitian(A &&a, U &&u, scalar_type_of_t< A > alpha=1)
Do a rank update on a hermitian matrix.
Definition: rank_update_hermitian.hpp:45
constexpr constant_adapter(V &&v)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: constant_adapter.hpp:104
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
Definition for index_collection_for.
constexpr constant_adapter(V &&v, P &&p)
Construct from value and a pattern_collection.
Definition: constant_adapter.hpp:72
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:59
decltype(auto) constexpr to_value_type(Arg &&arg)
Convert, if necessary, a fixed or dynamic value to its underlying base type.
Definition: to_value_type.hpp:28
The size of a sized object (including a collection).
Definition: size_of.hpp:33
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
decltype(auto) constexpr reduce(BinaryFunction &&b, Arg &&arg)
Perform a partial reduction based on an associative binary function, across one or more indices...
Definition: reduce.hpp:143
decltype(auto) constexpr apply(F &&f, T &&t)
A generalization of std::apply.
Definition: apply.hpp:49
constexpr detail::replicate_adaptor replicate
a std::ranges::range_adaptor_closure associated with replicate_view.
Definition: replicate.hpp:440
Definition for element_type_of.
constexpr constant_adapter()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: constant_adapter.hpp:117
The root namespace for OpenKalman.
Definition: basics.hpp:34
An interface to various routines from the linear algebra library associated with indexible object T...
Definition: library_interface.hpp:42
decltype(auto) constexpr access(Arg &&arg, const Indices &indices)
Access a component of an indexible object at a given set of indices.
Definition: access.hpp:74
Definition: object_traits.hpp:38
constexpr auto operator[](const Indices &indices) const
Access a component at a set of indices.
Definition: constant_adapter.hpp:175
constexpr auto value() const
Get the values::scalar associated with this object.
Definition: constant_adapter.hpp:189
decltype(auto) constexpr sum(Ts &&...ts)
Element-by-element sum of one or more objects.
Definition: sum.hpp:112
constexpr constant_adapter(V &&v, S &&s)
Construct from value and a reference to an indexible object.
Definition: constant_adapter.hpp:88
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
Definition of get_pattern_collection function.
Definition for indexible.
constexpr auto make_constant(C c, stdex::extents< IndexType, Extents... > extents)
Make an indexible object in which every element is a constant value.
Definition: make_constant.hpp:39
A matrix with typed rows and columns.
Definition: forward-class-declarations.hpp:292
constexpr constant_adapter(Arg &&arg)
Construct from another constant_object.
Definition: constant_adapter.hpp:136
A tensor or other matrix in which all elements are a constant value.
Definition: constant_adapter.hpp:52