OpenKalman
to_dense_object.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2022-2024 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_TO_DENSE_OBJECT_HPP
17 #define OPENKALMAN_TO_DENSE_OBJECT_HPP
18 
19 namespace OpenKalman
20 {
28 #ifdef __cpp_concepts
29  template<indexible T, Layout layout = Layout::none, values::number Scalar = scalar_type_of_t<T>, indexible Arg> requires
30  (layout != Layout::stride)
31  constexpr writable decltype(auto)
32 #else
33  template<typename T, Layout layout = Layout::none, typename Scalar = scalar_type_of_t<T>, typename Arg, std::enable_if_t<
34  indexible<T> and (layout != Layout::stride) and values::number<Scalar> and indexible<Arg>, int> = 0>
35  constexpr decltype(auto)
36 #endif
37  to_dense_object(Arg&& arg)
38  {
39  if constexpr (writable<Arg>)
40  {
41  return std::forward<Arg>(arg);
42  }
43  else if constexpr (writable<decltype(to_native_matrix<T>(std::declval<Arg&&>()))>)
44  {
45  return to_native_matrix<T>(std::forward<Arg>(arg));
46  }
47  else
48  {
49  auto m {make_dense_object<T, layout, Scalar>(all_vector_space_descriptors(arg))};
50  assign(m, std::forward<Arg>(arg));
51  return m;
52  }
53  }
54 
55 
62 #ifdef __cpp_concepts
63  template<Layout layout, values::number Scalar, indexible Arg> requires (layout != Layout::stride)
64  constexpr writable decltype(auto)
65 #else
66  template<Layout layout, typename Scalar, typename Arg, std::enable_if_t<values::number<Scalar> and indexible<Arg> and
67  (layout != Layout::stride), int> = 0>
68  constexpr decltype(auto)
69 #endif
70  to_dense_object(Arg&& arg)
71  {
72  if constexpr (writable<Arg> and std::is_same_v<Scalar, scalar_type_of_t<Arg>>)
73  return std::forward<Arg>(arg);
74  else
75  return to_dense_object<std::decay_t<Arg>, layout, Scalar>(std::forward<Arg>(arg));
76  }
77 
78 
86 #ifdef __cpp_concepts
87  template<Layout layout = Layout::none, indexible Arg> requires (layout != Layout::stride)
88  constexpr writable decltype(auto)
89 #else
90  template<Layout layout = Layout::none, typename Arg, std::enable_if_t<indexible<Arg> and (layout != Layout::stride), int> = 0>
91  constexpr decltype(auto)
92 #endif
93  to_dense_object(Arg&& arg)
94  {
95  if constexpr (writable<Arg>)
96  return std::forward<Arg>(arg);
97  else
98  return to_dense_object<std::decay_t<Arg>, layout, scalar_type_of_t<Arg>>(std::forward<Arg>(arg));
99  }
100 
101 
102 } // namespace OpenKalman
103 
104 #endif //OPENKALMAN_TO_DENSE_OBJECT_HPP
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
decltype(auto) constexpr to_dense_object(Arg &&arg)
Convert the argument to a dense, writable matrix of a particular scalar type.
Definition: to_dense_object.hpp:37
decltype(auto) constexpr all_vector_space_descriptors(const T &t)
Return a collection of coordinates::pattern objects associated with T.
Definition: all_vector_space_descriptors.hpp:52
The root namespace for OpenKalman.
Definition: basics.hpp:34
A generalization of the above: a custom stride is specified for each index.
constexpr To && assign(To &&a, From &&b)
Assign a writable object from an indexible object.
Definition: assign.hpp:51