OpenKalman
max_tensor_order.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) 2019-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 
16 #ifndef OPENKALMAN_MAX_TENSOR_ORDER_HPP
17 #define OPENKALMAN_MAX_TENSOR_ORDER_HPP
18 
19 
20 namespace OpenKalman
21 {
22  namespace detail
23  {
24  template<std::size_t i, typename T>
25  constexpr std::size_t max_tensor_order_impl(std::size_t result = 0)
26  {
27  if constexpr (i == 0) return result;
28  else if constexpr (dimension_size_of_index_is<T, i - 1, 1>) return max_tensor_order_impl<i - 1, T>(result);
29  else if constexpr (dimension_size_of_index_is<T, i - 1, 0>) return 0;
30  else return max_tensor_order_impl<i - 1, T>(result + 1);
31  }
32  } // namespace detail
33 
34 
42 #ifdef __cpp_concepts
43  template<typename T>
44 #else
45  template<typename T, typename = void>
46 #endif
48  : std::integral_constant<std::size_t, indexible<T> ? dynamic_size : 0> {};
49 
50 
51 #ifdef __cpp_concepts
52  template<typename T> requires (index_count_v<T> != dynamic_size)
53  struct max_tensor_order<T>
54 #else
55  template<typename T>
56  struct max_tensor_order<T, std::enable_if_t<index_count<T>::value != dynamic_size>>
57 #endif
58  : std::integral_constant<std::size_t, detail::max_tensor_order_impl<index_count_v<T>, T>()> {};
59 
60 
64  template<typename T>
65  static constexpr std::size_t max_tensor_order_v = max_tensor_order<T>::value;
66 
67 
68 } // namespace OpenKalman
69 
70 #endif //OPENKALMAN_MAX_TENSOR_ORDER_HPP
constexpr bool dimension_size_of_index_is
Specifies that a given index of T has a specified size.
Definition: dimension_size_of_index_is.hpp:44
Definition: tuple_reverse.hpp:103
The maximum number of indices of structure T of size other than 1 (including any dynamic indices)...
Definition: max_tensor_order.hpp:47
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33