16 #ifndef OPENKALMAN_TO_DIAGONAL_HPP 17 #define OPENKALMAN_TO_DIAGONAL_HPP 19 #include "patterns/patterns.hpp" 27 #include "linear-algebra/functions/internal/make_wrapped_mdspan.hpp" 38 template<indexible Arg, patterns::pattern_collection P> requires
39 pattern_collection_for<decltype(patterns::views::diagonal_of(patterns::to_extents(std::declval<P>()))), Arg>
42 template<
typename Arg,
typename P, std::enable_if_t<
43 pattern_collection_for<decltype(patterns::views::diagonal_of(patterns::to_extents(std::declval<P>()))), Arg>,
int> = 0>
44 constexpr decltype(
auto)
49 if constexpr (one_dimensional<Arg> and
54 else if constexpr (zero<Arg>)
56 return make_zero<values::value_type_of_t<element_type_of_t<Arg>>>(std::forward<P>(p));
61 using N = std::decay_t<decltype(n)>;
62 using nested_extents_type =
typename N::extents_type;
63 using nested_layout =
typename N::layout_type;
64 using nested_accessor =
typename N::accessor_type;
65 auto nested_m = n.mapping();
68 using mapping_type =
typename layout_type::template mapping<extents_type>;
69 std::size_t off_diag_index = nested_m.required_span_size();
73 using data_handle_type =
typename accessor_type::data_handle_type;
74 auto a = accessor_type {n.accessor()};
76 return internal::make_wrapped_mdspan(
77 std::forward<Arg>(arg),
78 [off_diag_index](
auto&& h) {
return data_handle_type {std::forward<decltype(h)>(h), off_diag_index}; },
93 template<indexible Arg>
96 template<
typename Arg, std::enable_if_t<indexible<Arg>,
int> = 0>
97 constexpr decltype(
auto)
103 return std::forward<Arg>(arg);
105 else if constexpr (interface::to_diagonal_defined_for<Arg&&>)
112 std::forward<Arg>(arg),
constexpr bool diagonal_matrix
Specifies that a type is a diagonal matrix or tensor.
Definition: diagonal_matrix.hpp:32
Definitions for attach_patterns.
decltype(auto) constexpr attach_patterns(Arg &&arg, P &&p)
Attach a pattern_collection to an indexible object.
Definition: attach_patterns.hpp:74
Definition: to_diagonal_mdspan_policies.hpp:29
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the patterns::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:36
constexpr bool collection_compares_with
Compares two pattern_collection objects.
Definition: collection_compares_with.hpp:132
Definition for diagonal_matrix.
constexpr detail::to_diagonal_adapter to_diagonal
A RangeAdapterObject that converts one pattern_collection to another that is equivalent to duplicatin...
Definition: to_diagonal.hpp:81
constexpr bool compares_with_pattern_collection
Compares the associated pattern collection of indexible T with pattern_collection D...
Definition: compares_with_pattern_collection.hpp:50
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
Definition of get_mdspan function.
Definition for pattern_collection_for.
Definitions for make_zero.
Definition: to_diagonal_mdspan_policies.hpp:177
Definition for indexible.
Definition for compares_with_pattern_collection.
decltype(auto) constexpr to_diagonal(Arg &&arg, P &&p)
Convert a column vector (or any other array with a 1D second index) into a diagonal_matrix.
Definition: to_diagonal.hpp:46
constexpr auto to_extents(P &&p)
Convert a pattern_collection to std::extents.
Definition: to_extents.hpp:78
Definition: extents.hpp:372
decltype(auto) constexpr get_mdspan(T &&t)
Get the mdspan associated with indexible object T.
Definition: get_mdspan.hpp:35