Added set function for iterators.
This commit is contained in:
@@ -44,6 +44,7 @@ void tensoriter_test_run_all(void)
|
||||
void (*test_func[NUM_TENSORITER_TEST_FUNC])(void) = {
|
||||
&tensoriter_test_scalar_next,
|
||||
&tensoriter_test_scalar_get,
|
||||
&tensoriter_test_scalar_set,
|
||||
&tensoriter_test_scalar_map,
|
||||
&tensoriter_test_scalar_map_add,
|
||||
&tensoriter_test_scalar_map_sub,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "tensoriter_test.h"
|
||||
|
||||
#define NUM_TENSOR_TEST_FUNC 18
|
||||
#define NUM_TENSORITER_TEST_FUNC 7
|
||||
#define NUM_TENSORITER_TEST_FUNC 8
|
||||
|
||||
|
||||
void tensor_test_run_all(void);
|
||||
|
||||
@@ -22,8 +22,8 @@ void tensoriter_test_scalar_next(void)
|
||||
void tensoriter_test_scalar_get(void)
|
||||
{
|
||||
/* Depends on tensor_init_one, tensor_set, tensoriter_scalar_next */
|
||||
uint32_t s[4] = {2, 4, 4};
|
||||
uint32_t index[4] = {0, 0, 0};
|
||||
uint32_t s[3] = {2, 4, 4};
|
||||
uint32_t index[3] = {0, 0, 0};
|
||||
tensor t = tensor_new();
|
||||
|
||||
tensor_init_one(t, s, 3);
|
||||
@@ -39,7 +39,7 @@ void tensoriter_test_scalar_get(void)
|
||||
uint32_t contained = 0;
|
||||
tensoriter_scalar iter = tensoriter_scalar_create(t);
|
||||
do {
|
||||
uint32_t value = (uint32_t) *tensoriter_scalar_get(iter);
|
||||
uint32_t value = (uint32_t) tensoriter_scalar_get(iter);
|
||||
tensor_assert(((1 << (value - 1)) & contained) == 0, "mute");
|
||||
contained |= 1 << (value - 1);
|
||||
} while (tensoriter_scalar_next(iter));
|
||||
@@ -48,6 +48,25 @@ void tensoriter_test_scalar_get(void)
|
||||
tensor_destroy(t);
|
||||
}
|
||||
|
||||
void tensoriter_test_scalar_set(void)
|
||||
{
|
||||
/* Depends on tensor_init_one, tensor_init_rand, tensoriter_scalar_next */
|
||||
uint32_t s[3] = {2, 4, 4};
|
||||
|
||||
tensor t1 = tensor_new();
|
||||
tensor t2 = tensor_new();
|
||||
|
||||
tensor_init_one(t1, s, 3);
|
||||
tensor_init_rand(t2, s, 3, (dtype) 30);
|
||||
|
||||
tensoriter_scalar iter = tensoriter_scalar_create(t2);
|
||||
do {
|
||||
tensoriter_scalar_set(iter, DTYPE_ONE);
|
||||
} while (tensoriter_scalar_next(iter));
|
||||
|
||||
tensor_assert_eq(t1, t2);
|
||||
}
|
||||
|
||||
dtype tensoriter_test_scalar_map_helper(dtype d) {
|
||||
static uint32_t contained = 0;
|
||||
if(((1 << ((uint32_t) d - 1)) & contained) == 0) {
|
||||
@@ -61,8 +80,8 @@ dtype tensoriter_test_scalar_map_helper(dtype d) {
|
||||
void tensoriter_test_scalar_map(void)
|
||||
{
|
||||
/* Depends on tensor_init_one, tensor_init_zero, tensor_set*/
|
||||
uint32_t s[4] = {2, 4, 4};
|
||||
uint32_t index[4] = {0, 0, 0};
|
||||
uint32_t s[3] = {2, 4, 4};
|
||||
uint32_t index[3] = {0, 0, 0};
|
||||
tensor t = tensor_new();
|
||||
tensor t0 = tensor_new();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
void tensoriter_test_scalar_next(void);
|
||||
void tensoriter_test_scalar_get(void);
|
||||
void tensoriter_test_scalar_set(void);
|
||||
void tensoriter_test_scalar_map(void);
|
||||
void tensoriter_test_scalar_map_add(void);
|
||||
void tensoriter_test_scalar_map_sub(void);
|
||||
|
||||
Reference in New Issue
Block a user