lin
constants.hpp
Go to the documentation of this file.
1 // vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab
2 
7 #ifndef LIN_GENERATORS_CONSTANTS_HPP_
8 #define LIN_GENERATORS_CONSTANTS_HPP_
9 
10 #include "stream_constants.hpp"
11 #include "../core.hpp"
12 
13 #include <limits>
14 #include <type_traits>
15 
16 namespace lin {
17 
39 template <typename T, size_t R, size_t C, size_t MR = R, size_t MC = C>
40 constexpr auto consts(T t, size_t r = MR, size_t c = MC) {
42 }
43 
61 template <class C, std::enable_if_t<internal::has_traits<C>::value, size_t> = 0>
62 constexpr auto consts(typename C::Traits::elem_t t, size_t r = C::Traits::max_rows, size_t c = C::Traits::max_cols) {
63  return consts<typename C::Traits::elem_t, C::Traits::rows, C::Traits::cols, C::Traits::max_rows, C::Traits::max_cols>(t, r, c);
64 }
65 
84 template <typename T, size_t R, size_t C, size_t MR = R, size_t MC = C>
85 constexpr auto nans(size_t r = MR, size_t c = MC) {
86  // Ensure quiet NaN values are supported
87  static_assert(std::numeric_limits<T>::has_quiet_NaN, "Quiet NaN must be supported!");
88 
89  return consts<T, R, C, MR, MC>(std::numeric_limits<T>::quiet_NaN(), r, c);
90 }
91 
106 template <class C, std::enable_if_t<internal::has_traits<C>::value, size_t> = 0>
107 constexpr auto nans(size_t r = C::Traits::max_rows, size_t c = C::Traits::max_cols) {
108  return nans<typename C::Traits::elem_t, C::Traits::rows, C::Traits::cols, C::Traits::max_rows, C::Traits::max_cols>(r, c);
109 }
110 
129 template <typename T, size_t R, size_t C, size_t MR = R, size_t MC = C>
130 constexpr auto ones(size_t r = MR, size_t c = MC) {
131  return consts<T, R, C, MR, MC>(T(1), r, c);
132 }
133 
148 template <class C, std::enable_if_t<internal::has_traits<C>::value, size_t> = 0>
149 constexpr auto ones(size_t r = C::Traits::max_rows, size_t c = C::Traits::max_cols) {
150  return ones<typename C::Traits::elem_t, C::Traits::rows, C::Traits::cols, C::Traits::max_rows, C::Traits::max_cols>(r, c);
151 }
152 
171 template <typename T, size_t R, size_t C, size_t MR = R, size_t MC = C>
172 constexpr auto zeros(size_t r = MR, size_t c = MC) {
173  return consts<T, R, C, MR, MC>(T(0), r, c);
174 }
175 
190 template <class C, std::enable_if_t<internal::has_traits<C>::value, size_t> = 0>
191 constexpr auto zeros(size_t r = C::Traits::max_rows, size_t c = C::Traits::max_cols) {
192  return zeros<typename C::Traits::elem_t, C::Traits::rows, C::Traits::cols, C::Traits::max_rows, C::Traits::max_cols>(r, c);
193 }
194 } // namespace lin
195 
196 #endif
constexpr auto consts(typename C::Traits::elem_t t, size_t r=C::Traits::max_rows, size_t c=C::Traits::max_cols)
Creates a constants stream.
Definition: constants.hpp:62
Tensor stream where all element accesses return the same constant value.
Definition: stream_constants.hpp:35
constexpr auto nans(size_t r=C::Traits::max_rows, size_t c=C::Traits::max_cols)
Creates a stream of not-a-number values.
Definition: constants.hpp:107
constexpr auto ones(size_t r=C::Traits::max_rows, size_t c=C::Traits::max_cols)
Creates a ones stream.
Definition: constants.hpp:149
Definition: config.hpp:27
constexpr auto zeros(size_t r=C::Traits::max_rows, size_t c=C::Traits::max_cols)
Creates a zeros stream.
Definition: constants.hpp:191