OpenKalman
make_writable_square_matrix.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-2023 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 
17 #ifndef OPENKALMAN_MAKE_WRITABLE_SQUARE_MATRIX_HPP
18 #define OPENKALMAN_MAKE_WRITABLE_SQUARE_MATRIX_HPP
19 
20 
21 namespace OpenKalman::internal
22 {
27  template<typename U, typename A>
28  constexpr decltype(auto)
29  make_writable_square_matrix(A&& a)
30  {
31  constexpr auto dim = not dynamic_dimension<A, 0> ? index_dimension_of_v<A, 0> :
32  not dynamic_dimension<A, 1> ? index_dimension_of_v<A, 1> : index_dimension_of_v<U, 0>;
33  if constexpr (writable<A>)
34  {
35  return std::forward<A>(a);
36  }
37  else if constexpr (not has_dynamic_dimensions<A> or dim == dynamic_size)
38  {
39  return to_dense_object(std::forward<A>(a));
40  }
41  else
42  {
43  constexpr auto d = std::integral_constant<std::size_t, dim>{};
44  auto ret {make_dense_object<A>(d, d)};
45  ret = std::forward<A>(a);
46  return ret;
47  }
48  }
49 
50 } // namespace OpenKalman::internal
51 
52 #endif //OPENKALMAN_MAKE_WRITABLE_SQUARE_MATRIX_HPP
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
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition: basics.hpp:48