diff options
Diffstat (limited to 'modules/codec')
| -rw-r--r-- | modules/codec/c++/math.hpp | 20 | ||||
| -rw-r--r-- | modules/codec/tests/math.cpp | 13 |
2 files changed, 33 insertions, 0 deletions
diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index d110b64..7524265 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -3,7 +3,16 @@ #include "data_math.hpp" namespace saw { +template<uint64_t D> +class iterator final { +public: + template<typename Func + void apply(Func&& func){ + /// TODO !!!! + } +}; namespace math { + /* template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> data<typename T::InnerType,Encoding> norm_2(const data<T,Encoding>& d){ @@ -149,5 +158,16 @@ data<schema::Vector<T,D>,Encoding> scale( } return sc_vec; } + +template<typename T, uint64_t... Ds, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Tensor<T,Ds...>, Encoding> fill( + const data<T,Encoding>& filler){ + data<schema::Tensor<T,Ds...>, Encoding> tbf; + + iterator<sizeof...(Ds)>::apply([&](const auto& index){ + tbf.at(index) = filler; + }, {}, {{Ds...}}); + return tbf; +} } } diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp index 63b6d2b..5f4de92 100644 --- a/modules/codec/tests/math.cpp +++ b/modules/codec/tests/math.cpp @@ -28,6 +28,19 @@ SAW_TEST("Math/Tensor Construction"){ // data<sch::Vector<sch::Int32,3u>> b{{{1,3,5}}}; } +SAW_TEST("Math/Tensor Fill"){ + using namespace saw; + + auto tensor = math::fill<sch::Float64,2u,2u>({2.5}); + + bool cf{true}; + for(uint64_t i = 0u; i < 2u; ++i){ + for(uint64_t j = 0u; j < 2u; ++j){ + SAW_EXPECT((tensor.at({{i,j}}).get() == 2.5), "Wasn't filled with value 2.5"); + } + } +} + SAW_TEST("Math/Tensor"){ using namespace saw; |
