OpenKalman
get_chip.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 
16 #ifndef OPENKALMAN_GET_CHIP_HPP
17 #define OPENKALMAN_GET_CHIP_HPP
18 
19 namespace OpenKalman
20 {
35 #ifdef __cpp_concepts
36  template<std::size_t...indices, indexible Arg, values::index...Ixs> requires (sizeof...(indices) == sizeof...(Ixs))
37 #else
38  template<std::size_t...indices, typename Arg, typename...Ixs, std::enable_if_t<
39  indexible<Arg> and (values::index<Ixs> and ...) and (sizeof...(indices) == sizeof...(Ixs)), int> = 0>
40 #endif
41  constexpr decltype(auto)
42  get_chip(Arg&& arg, Ixs...ixs)
43  {
44  (... , []{
45  if constexpr (values::fixed<Ixs> and not dynamic_dimension<Arg, indices>)
46  static_assert(std::decay_t<Ixs>::value < index_dimension_of_v<Arg, indices>, "get_chip: indices must be in range");
47  }());
48 
49  if constexpr (sizeof...(indices) == 0) return std::forward<Arg>(arg);
50  else return get_slice<indices...>(
51  std::forward<Arg>(arg),
52  std::tuple{ixs...}, // begin points
53  std::tuple{(std::integral_constant<decltype(indices), 1> {})...}); // block sizes (always 1 in each collapsed dimension)
54  }
55 
56 
57 } // namespace OpenKalman
58 
59 #endif //OPENKALMAN_GET_CHIP_HPP
decltype(auto) constexpr get_slice(Arg &&arg, const std::tuple< Offset... > &offsets, const std::tuple< Extent... > &extents)
Extract a slice from a matrix or tensor.
Definition: get_slice.hpp:101
decltype(auto) constexpr get_chip(Arg &&arg, Ixs...ixs)
Extract a sub-array having rank less than the rank of the input object.
Definition: get_chip.hpp:42
constexpr bool indexible
T is a generalized tensor type.
Definition: indexible.hpp:32
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool index
T is an index value.
Definition: index.hpp:56