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<std::decay_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  } // namespace detail
38 
39 
43 #ifdef __cpp_concepts
44  template<indexible Arg, values::scalar S> requires
45  requires(S s) { {values::to_number(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>>{},
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>>{},
71  std::forward<S>(s)}));
72  }
73  else if constexpr (values::fixed<S>)
74  {
75  if constexpr (values::to_number(S{}) == 1) return std::forward<Arg>(arg);
76  else return detail::scalar_quotient_impl(std::forward<Arg>(arg), std::forward<S>(s));
77  }
78  else
79  {
80  return detail::scalar_quotient_impl(std::forward<Arg>(arg), std::forward<S>(s));
81  }
82  }
83 
84 } // namespace OpenKalman
85 
86 
87 #endif //OPENKALMAN_SCALAR_QUOTIENT_HPP
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:319
Definition: tuple_reverse.hpp:103
decltype(auto) constexpr to_diagonal(Arg &&arg)
Convert an indexible object into a diagonal matrix.
Definition: to_diagonal.hpp:32
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
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:33
constexpr auto make_constant(C &&c, Descriptors &&descriptors)
Make a constant object based on a particular library object.
Definition: make_constant.hpp:37
operation(const Operation &, const Args &...) -> operation< Operation, Args... >
Deduction guide.
constant_diagonal_coefficient(T &&) -> constant_diagonal_coefficient< std::decay_t< T >>
Deduction guide for constant_diagonal_coefficient.
constant_coefficient(const T &) -> constant_coefficient< T >
Deduction guide for constant_coefficient.