OpenKalman
check_block_limits.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_CHECK_BLOCK_LIMITS_HPP
18 #define OPENKALMAN_CHECK_BLOCK_LIMITS_HPP
19 
20 namespace OpenKalman::internal
21 {
22 
23  namespace detail
24  {
25  template<std::size_t limit_ix, std::size_t index, typename Arg, typename...Limits>
26  constexpr void check_block_limit(const Arg& arg, const Limits&...)
27  {
28  if constexpr (((limit_ix >= std::tuple_size_v<Limits>) or ...)) return;
29  else if constexpr (((values::fixed<std::tuple_element_t<limit_ix, Limits>>) and ...) and not dynamic_dimension<Arg, index>)
30  {
31  constexpr std::size_t block_limit = (static_cast<std::size_t>(std::decay_t<std::tuple_element_t<limit_ix, Limits>>::value) + ... + 0_uz);
32  static_assert(block_limit <= index_dimension_of_v<Arg, index>, "Block limits must be in range");
33  }
34  /*else // Not necessary: the matrix/tensor library should check runtime limits.
35  {
36  auto lim = (std::get<limit_ix>(limits) + ... + 0);
37  auto max = get_index_dimension_of<index>(arg);
38  if (lim < 0 or lim > max) throw std::out_of_range {"Block function limits are out of range for index " + std::to_string(index)};
39  }*/
40  }
41 
42  } // namespace detail
43 
44 
49  template<std::size_t...limit_ix, std::size_t...indices, typename Arg, typename...Limits>
50  constexpr void check_block_limits(
51  std::index_sequence<limit_ix...>, std::index_sequence<indices...>, const Arg& arg, const Limits&...limits)
52  {
53  (detail::check_block_limit<limit_ix, indices>(arg, limits...), ...);
54  }
55 
56 } // namespace OpenKalman::internal
57 
58 #endif //OPENKALMAN_CHECK_BLOCK_LIMITS_HPP
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
Definition: basics.hpp:48
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75