add macro MIN MAX in toom_t, and add copy tensor and weight_in neurons

This commit is contained in:
2024-06-11 21:40:39 +02:00
parent b3de7fb171
commit 99e87a7b5b
11 changed files with 110 additions and 1 deletions
+7
View File
@@ -129,6 +129,13 @@ tensor_##type* CLONE_TENSOR_##type(tensor_##type *tens){\
}\
return NULL;\
}\
\
void copy_tensor_##type(tensor_##type * dst, tensor_##type * src){\
if(dst!=NULL && src!=NULL && dst->dim->rank == src->dim->rank){ \
for(size_t i=0; i<(dst->dim)->rank;++i)\
dst->x[i]=src->x[i];\
}\
}\
\
void free_tensor_##type(tensor_##type * tens){\
if(tens){\
+1
View File
@@ -20,6 +20,7 @@ tensor_##type* CREATE_TENSOR_FROM_CPY_DIM_##type(dimension *dim);\
void _RECREATE_TENSOR_IF_NOT_THE_SAME_DIM_OR_NULL_##type(tensor_##type **M, dimension *dd);\
tensor_##type* CLONE_TENSOR_##type(tensor_##type *tens);\
void free_tensor_##type(tensor_##type * tens); \
void copy_tensor_##type(tensor_##type * dst, tensor_##type * src);\
tensor_##type * sub_minus_tensor_head_##type(tensor_##type *rootens, size_t minuSubdim, size_t rankInDim); \
tensor_##type * sub_minus_tensor_tail_##type(tensor_##type *rootens, size_t minuSubdim, size_t rankInDim); \
tensor_##type * sub_tensor_head_##type(tensor_##type *rootens, size_t subdim, size_t rankInDim); \
+29
View File
@@ -1676,6 +1676,35 @@ TEST(rec_in_file_tensor){
free_tensor_TYPE_FLOAT(M0);
}
TEST(copy_tensor){
dimension *d0=create_dim(3);
d0->perm[0]=2;
d0->perm[1]=3;
d0->perm[2]=4;
updateRankDim(d0);
tensor_TYPE_FLOAT *M0 = CREATE_TENSOR_TYPE_FLOAT(d0);
tensor_TYPE_FLOAT *M1 = CREATE_TENSOR_FROM_CPY_DIM_TYPE_FLOAT(d0);
LOG("M0->dim->rank = %ld\n",M0->dim->rank);
init_random_x_TYPE_FLOAT(M0,2.7,5.4,50001);
init_random_x_TYPE_FLOAT(M1,2.7,5.4,50001);
print_tensor_float(M0, "init M0 random");
copy_tensor_TYPE_FLOAT(M1, M0);
print_tensor_float(M1, "M1 copy of M0");
free_tensor_TYPE_FLOAT(M0);
free_tensor_TYPE_FLOAT(M1);
}