OpenKalman
arithmetic-operators.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 b recursive filters.
3  *
4  * Copyright (c) 2020-2025 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_VECTOR_SPACE_DESCRIPTORS_ARITHMETIC_OPERATORS_HPP
17 #define OPENKALMAN_VECTOR_SPACE_DESCRIPTORS_ARITHMETIC_OPERATORS_HPP
18 
24 #include "linear-algebra/coordinates/descriptors/DynamicDescriptor.hpp"
25 #include "linear-algebra/coordinates/descriptors/internal/Concatenate.hpp"
26 #include "linear-algebra/coordinates/descriptors/internal/Replicate.hpp"
27 
29 {
33 #ifdef __cpp_concepts
34  template<pattern T, pattern U>
35 #else
36  template<typename T, typename U, std::enable_if_t<pattern<T> and pattern<U>, int> = 0>
37 #endif
38  constexpr auto operator+(T&& t, U&& u)
39  {
40  if constexpr (euclidean_pattern<T> and euclidean_pattern<U>)
41  {
42  if constexpr (fixed_pattern<T> and fixed_pattern<U>)
43  return Dimensions<dimension_of_v<T> + dimension_of_v<U>>{};
44  else
45  return Dimensions {get_dimension(t) + get_dimension(u)};
46  }
47  else return coordinates::internal::Concatenate {std::forward<T>(t), std::forward<U>(u)};
48  }
49 
50 
54 #ifdef __cpp_concepts
55  template<pattern Arg, values::index N>
56 #else
57  template<typename Arg, typename N, std::enable_if_t<pattern<Arg> and values::index<N>, int> = 0>
58 #endif
59  constexpr auto operator*(Arg&& arg, const N& n)
60  {
61  if constexpr (euclidean_pattern<Arg>)
62  {
63  return coordinates::Dimensions {values::operation {std::multiplies{}, get_dimension(arg), n}};
64  }
65  else
66  {
67  return internal::Replicate {std::forward<Arg>(arg), n};
68  }
69  }
70 
71 
76 #ifdef __cpp_concepts
77  template<values::index N, pattern Arg>
78 #else
79  template<typename N, typename Arg, std::enable_if_t<pattern<Arg> and values::index<N>, int> = 0>
80 #endif
81  constexpr auto operator*(const N& n, Arg&& arg)
82  {
83  return operator*(std::forward<Arg>(arg), n);
84  }
85 
86 
87 } // namespace OpenKalman::coordinates
88 
89 
90 #endif //OPENKALMAN_VECTOR_SPACE_DESCRIPTORS_ARITHMETIC_OPERATORS_HPP
Definition for coordinates::euclidean_pattern.
An operation involving some number of values.
Definition: operation.hpp:69
Definition of the Dimensions class.
Definition for coordinates::fixed_pattern.
Definition for coordinates::pattern.
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:55
Definition: compares_with.hpp:28
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
Definition for coordinates::dimension_of.