/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/stats_tests.cpp
70 строк
3 KB
kolkir
Refactor simd algos to use map reduce
16 мар 2025, 23:09
16 мар 2025, 23:09
5f536e1
Код
Авторство
О чём код?
#include <adept/tensor.hpp> #include <vector> #include "adept/types.hpp" #include "catch.hpp" using namespace adept; TEMPLATE_TEST_CASE("Tensors max less lane", "[stats]", float32_t, float64_t, int32_t) { std::vector<TestType> dx = {1, 2, 3, 4}; auto x = Tensor::from_blob( dx.data(), {.shape = {1, 4}, .device = device_t::CPU, .dtype = to_dtype<TestType>()}); Tensor s = x.max(); REQUIRE_THAT(s.at<TestType>({0, 0}), Catch::WithinRel(4.0f, 0.001f)); } TEMPLATE_TEST_CASE("Tensors max", "[stats]", float32_t, float64_t, int32_t) { std::vector<TestType> dx = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto x = Tensor::from_blob( dx.data(), {.shape = {3, 3}, .device = device_t::CPU, .dtype = to_dtype<TestType>()}); Tensor s = x.max(); REQUIRE_THAT(s.at<TestType>({0, 0}), Catch::WithinRel(9.0f, 0.001f)); } TEMPLATE_TEST_CASE("Tensors sum less lane", "[stats]", float32_t, float64_t, int32_t) { std::vector<TestType> dx = {1, 2, 3, 4}; auto x = Tensor::from_blob( dx.data(), {.shape = {1, 4}, .device = device_t::CPU, .dtype = to_dtype<TestType>()}); Tensor s = x.sum(); REQUIRE_THAT(s.at<TestType>({0, 0}), Catch::WithinRel(10.0f, 0.001f)); } TEMPLATE_TEST_CASE("Tensors sum", "[stats]", float32_t, float64_t, int32_t) { std::vector<TestType> dx = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto x = Tensor::from_blob( dx.data(), {.shape = {3, 3}, .device = device_t::CPU, .dtype = to_dtype<TestType>()}); Tensor s = x.sum(); REQUIRE_THAT(s.at<TestType>({0, 0}), Catch::WithinRel(45.0f, 0.001f)); } TEMPLATE_TEST_CASE("Tensors mean", "[stats]", float32_t, float64_t, int32_t) { std::vector<TestType> dx = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto x = Tensor::from_blob( dx.data(), {.shape = {3, 3}, .device = device_t::CPU, .dtype = to_dtype<TestType>()}); Tensor s = x.mean(); REQUIRE_THAT(s.at<TestType>({0, 0}), Catch::WithinRel(5.0f, 0.001f)); } TEST_CASE("Tensors sum with zero", "[stats]") { std::vector<float32_t> dx = {0.f, .2f, .3f, 0.4f, 0.1f}; auto x = Tensor::from_blob(dx.data(), {.shape = {1, 5}, .device = device_t::CPU, .dtype = dtype_t::Float32}); Tensor s = x.sum(); REQUIRE_THAT(s.at<float32_t>({0, 0}), Catch::WithinRel(1.0f, 0.001f)); } TEST_CASE("Tensors mean with zero", "[stats]") { std::vector<float32_t> dx = {0.f, .2f, .3f, 0.4f, 0.1f}; auto x = Tensor::from_blob(dx.data(), {.shape = {1, 5}, .device = device_t::CPU, .dtype = dtype_t::Float32}); Tensor s = x.mean(); REQUIRE_THAT(s.at<float32_t>({0, 0}), Catch::WithinRel(0.2f, 0.001f)); }