7 #ifndef LIN_GENERATORS_CONSTANTS_HPP_ 8 #define LIN_GENERATORS_CONSTANTS_HPP_ 11 #include "../core.hpp" 14 #include <type_traits> 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) {
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);
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) {
87 static_assert(std::numeric_limits<T>::has_quiet_NaN,
"Quiet NaN must be supported!");
89 return consts<T, R, C, MR, MC>(std::numeric_limits<T>::quiet_NaN(), r, c);
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);
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);
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);
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);
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);
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