OpenKalman
scalar_quotient.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) 2024 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_SCALAR_QUOTIENT_HPP
17 #define OPENKALMAN_SCALAR_QUOTIENT_HPP
18 
19 
20 namespace OpenKalman
21 {
22  namespace detail
23  {
24  template<typename Arg, typename S>
25  static constexpr auto
26  scalar_quotient_impl(Arg&& arg, S&& s)
27  {
28  if constexpr (interface::scalar_quotient_defined_for<Arg, Arg&&, S&&>)
29  {
30  return interface::library_interface<stdex::remove_cvref_t<Arg>>::scalar_quotient(std::forward<Arg>(arg), std::forward<S>(s));
31  }
32  else
33  {
34  return n_ary_operation(std::divides<scalar_type_of_t<Arg>>{}, std::forward<Arg>(arg), make_constant(arg, s));
35  }
36  }
37  }
38 
39 
43 #ifdef __cpp_concepts
44  template<indexible Arg, values::scalar S> requires
45  requires(S s) { {values::to_value_type(s)} -> std::convertible_to<scalar_type_of_t<Arg>>; }
46  static constexpr vector_space_descriptors_may_match_with<Arg> auto
47 #else
48  template<typename Arg, typename S>
49  static constexpr auto
50 #endif
51  scalar_quotient(Arg&& arg, S&& s)
52  {
53  if constexpr (zero<Arg>)
54  {
55  return std::forward<Arg>(arg);
56  }
57  else if constexpr (constant_matrix<Arg>)
58  {
59  return make_constant(std::forward<Arg>(arg),
61  std::divides<scalar_type_of_t<Arg>>{},
62  constant_value{arg},
63  std::forward<S>(s)));
64  }
65  else if constexpr (constant_diagonal_matrix<Arg>)
66  {
67  return to_diagonal(make_constant(diagonal_of(std::forward<Arg>(arg)),
69  std::divides<scalar_type_of_t<Arg>>{},
70  constant_diagonal_value{arg},
71  std::forward<S>(s))));
72  }
73  else if constexpr (values::fixed_value_compares_with<S, 1>)
74  {
75  return std::forward<Arg>(arg);
76  }
77  else
78  {
79  return detail::scalar_quotient_impl(std::forward<Arg>(arg), std::forward<S>(s));
80  }
81  }
82 
83 }
84 
85 
86 #endif
constexpr auto n_ary_operation(const std::tuple< Ds... > &d_tup, Operation &&operation, Args &&...args)
Perform a component-wise n-ary operation, using broadcasting to match the size of a pattern matrix...
Definition: n_ary_operation.hpp:325
decltype(auto) constexpr to_value_type(Arg &&arg)
Convert, if necessary, a fixed or dynamic value to its underlying base type.
Definition: to_value_type.hpp:28
decltype(auto) constexpr to_diagonal(Arg &&arg)
Convert an indexible object into a diagonal matrix.
Definition: to_diagonal.hpp:33
The root namespace for OpenKalman.
Definition: basics.hpp:34
decltype(auto) constexpr diagonal_of(Arg &&arg)
Extract a column vector (or column slice for rank>2 tensors) comprising the diagonal elements...
Definition: diagonal_of.hpp:36
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
constexpr auto make_constant(C c, stdex::extents< IndexType, Extents... > extents)
Make an indexible object in which every element is a constant value.
Definition: make_constant.hpp:39
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98