Files
ctensor/tests/tensoriter_test.c

72 lines
1.5 KiB
C
Raw Normal View History

2023-09-04 16:41:07 +02:00
#include "tensoriter_test.h"
void tensoriter_test_scalar_next(void)
{
2023-09-05 13:35:07 +02:00
/* Depends on tensor_init_one */
uint32_t s[4] = {2, 5, 3, 7};
tensor t = tensor_new();
tensor_init_one(t, s, 4);
tensoriter_scalar iter = tensoriter_scalar_create(t);
uint32_t i = 0;
do {
i++;
} while (tensoriter_scalar_next(iter));
tensor_assert(i == t->num_elem, "(not the rigth number of values)");
2023-09-04 16:41:07 +02:00
}
void tensoriter_test_scalar_get(void)
{
2023-09-05 13:35:07 +02:00
/* Depends on tensor_init_one, tensor_set, tensoriter_scalar_next */
uint32_t s[4] = {2, 4, 4};
uint32_t index[4] = {0, 0, 0};
tensor t = tensor_new();
tensor_init_one(t, s, 3);
float i = 1;
for (index[0] = 0; index[0] < s[0]; ++index[0]) {
for (index[1] = 0; index[1] < s[1]; ++index[1]) {
for (index[2] = 0; index[2] < s[2]; ++index[2]) {
tensor_set(t, index, i++);
}
}
}
uint32_t contained = 0;
tensoriter_scalar iter = tensoriter_scalar_create(t);
do {
uint32_t x = 1;
uint32_t value = (uint32_t) *tensoriter_scalar_get(iter);
tensor_assert(((x << (value - 1)) & contained) == 0, "mute");
contained |= (x << (value - 1));
} while (tensoriter_scalar_next(iter));
tensor_assert((contained & 0) == 0, "(missed a value)");
2023-09-04 16:41:07 +02:00
}
void tensoriter_test_scalar_map(void)
{
//TODO
}
void tensoriter_test_scalar_map_add(void)
{
//TODO
}
void tensoriter_test_scalar_map_sub(void)
{
//TODO
}
void tensoriter_test_scalar_map_mul(void)
{
//TODO
}
void tensoriter_test_scalar_map_div(void)
{
//TODO
}