add some functions to convert input char to dimension and tensor
This commit is contained in:
@@ -143,7 +143,14 @@ void split_dim_part(dimension *root, dimension **part_1, dimension **part_2, siz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void increment_dim_var(dimension *d){
|
||||||
|
if(endian){
|
||||||
|
(d->perm[0])++;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
(d->perm[d->size - 1])++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void add_dimension(dimension **d, dimension *d0, dimension *d1) {
|
void add_dimension(dimension **d, dimension *d0, dimension *d1) {
|
||||||
(*d) = create_dim(d0->size + d1->size);
|
(*d) = create_dim(d0->size + d1->size);
|
||||||
@@ -170,9 +177,11 @@ void min_dimension(dimension **d, dimension *d0, dimension *d1) {
|
|||||||
|
|
||||||
void printDebug_dimension(dimension *d,char *msg){
|
void printDebug_dimension(dimension *d,char *msg){
|
||||||
|
|
||||||
printf("(%s)->size = %ld | (%s)->rank = %ld \n",msg,d->size,msg,d->rank);
|
printf("(%s)->size = %ld | (%s)->rank = %ld \n[",msg,d->size,msg,d->rank);
|
||||||
for(size_t i=0; i<d->size; ++i)
|
for(size_t i=0; i<d->size; ++i)
|
||||||
printf("[%ld: %ld] |", i,d->perm[i]);
|
printf(" %ld,", d->perm[i]);
|
||||||
|
printf("] \n");
|
||||||
|
//printf("[%ld: %ld] |", i,d->perm[i]);
|
||||||
/* if(endian)
|
/* if(endian)
|
||||||
printf("\nendian (true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index\n");
|
printf("\nendian (true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index\n");
|
||||||
else
|
else
|
||||||
@@ -287,3 +296,46 @@ size_t* CoordFromLin(size_t line, dimension *dim){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void append_in_list_perm(list_perm_in_dim **list_p, size_t perm){
|
||||||
|
list_perm_in_dim *lis=malloc(sizeof(list_perm_in_dim));
|
||||||
|
lis->perm=perm;
|
||||||
|
lis->next=NULL;
|
||||||
|
if(*list_p == NULL){
|
||||||
|
lis->index=0;
|
||||||
|
*list_p = lis;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
list_perm_in_dim *tmp =*list_p;
|
||||||
|
while(tmp->next) tmp=tmp->next;
|
||||||
|
lis->index = tmp->index +1;
|
||||||
|
tmp->next=lis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dimension * create_dim_from_list_perm( list_perm_in_dim *l_p){
|
||||||
|
|
||||||
|
if(l_p){
|
||||||
|
list_perm_in_dim *tmp =l_p;
|
||||||
|
while(tmp->next) tmp=tmp->next;
|
||||||
|
dimension *dim=create_dim(tmp->index + 1);
|
||||||
|
(dim)->size = tmp->index + 1;
|
||||||
|
tmp=l_p;
|
||||||
|
while(tmp){
|
||||||
|
(dim)->perm[tmp->index]=tmp->perm;
|
||||||
|
tmp=tmp->next;
|
||||||
|
}
|
||||||
|
updateRankDim(dim);
|
||||||
|
return dim;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_list_perm_in_dim(list_perm_in_dim *l_p){
|
||||||
|
list_perm_in_dim *tmp=l_p, *ttmp;
|
||||||
|
while(tmp){
|
||||||
|
ttmp = tmp;
|
||||||
|
tmp = ttmp->next;
|
||||||
|
free(ttmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,20 @@ size_t LineFromCoord(size_t *coo, dimension *dim);
|
|||||||
size_t* CoordFromLin(size_t line, dimension *dim);
|
size_t* CoordFromLin(size_t line, dimension *dim);
|
||||||
void vCoordFromLin(size_t *ret, size_t line, dimension *dim );
|
void vCoordFromLin(size_t *ret, size_t line, dimension *dim );
|
||||||
|
|
||||||
|
void increment_dim_var(dimension *d);
|
||||||
|
|
||||||
|
struct list_perm_in_dim{
|
||||||
|
size_t index;
|
||||||
|
size_t perm;
|
||||||
|
struct list_perm_in_dim *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct list_perm_in_dim list_perm_in_dim;
|
||||||
|
|
||||||
|
void append_in_list_perm(list_perm_in_dim **list_p, size_t perm);
|
||||||
|
dimension * create_dim_from_list_perm( list_perm_in_dim *l_p);
|
||||||
|
|
||||||
|
void free_list_perm_in_dim(list_perm_in_dim *l_p);
|
||||||
|
|
||||||
#endif /* __DIMENSION_T__H__ */
|
#endif /* __DIMENSION_T__H__ */
|
||||||
//int compare_dimension(dimension *d1, dimension *d2);
|
//int compare_dimension(dimension *d1, dimension *d2);
|
||||||
|
|||||||
@@ -179,6 +179,44 @@ TEST(sprint_dim){
|
|||||||
free(dimSTR);
|
free(dimSTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(incrment_dim){
|
||||||
|
endian=false;
|
||||||
|
dimension *D=create_dim(4);
|
||||||
|
D->perm[0]=2;
|
||||||
|
D->perm[1]=3;
|
||||||
|
D->perm[2]=5;
|
||||||
|
D->perm[3]=6;
|
||||||
|
|
||||||
|
updateRankDim(D);
|
||||||
|
|
||||||
|
char *dimSTR =NULL;
|
||||||
|
size_t nb=sprint_dimension(&dimSTR, D);
|
||||||
|
|
||||||
|
LOG(" nb char : %ld\n, dim print:\n%s\n",nb, dimSTR);
|
||||||
|
|
||||||
|
increment_dim_var(D);
|
||||||
|
|
||||||
|
nb=sprint_dimension(&dimSTR, D);
|
||||||
|
|
||||||
|
LOG(" nb char : %ld\n, dim print increment:\n%s\n",nb, dimSTR);
|
||||||
|
|
||||||
|
free_dimension(D);
|
||||||
|
free(dimSTR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(list_perm_in_dim){
|
||||||
|
list_perm_in_dim *l_p=NULL;
|
||||||
|
|
||||||
|
for(size_t i=1;i<5; ++i){
|
||||||
|
append_in_list_perm(&l_p, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
dimension *dim=create_dim_from_list_perm(l_p);
|
||||||
|
|
||||||
|
printDebug_dimension(dim, "from l_p");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
|||||||
@@ -7,39 +7,51 @@
|
|||||||
#define GEN_NEURONS_F_(type)\
|
#define GEN_NEURONS_F_(type)\
|
||||||
\
|
\
|
||||||
void calc_net_neurons_##type(neurons_##type *nr){\
|
void calc_net_neurons_##type(neurons_##type *nr){\
|
||||||
size_t contractNB= ((nr->input)->dim)->size - ((nr->net)->dim)->size ;\
|
size_t contractNB= ((nr->weight_in)->dim)->size - ((nr->input)->dim)->size ;\
|
||||||
nr->TensorContraction_##type(&(nr->net), nr->weight_in,nr->input, contractNB, nr->nb_thread );\
|
/*print_tensor_msg_##type((nr->weight_in)," weight_in calc");*/\
|
||||||
|
/*print_tensor_msg_##type((nr->input)," input calc");*/\
|
||||||
|
nr->TensorContraction(&(nr->net), nr->input, nr->weight_in, contractNB, nr->nb_thread );\
|
||||||
|
/*print_tensor_msg_##type((nr->net)," net calc");*/\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void calc_out_neurons_##type(neurons_##type *nr, type (*f)(type x) ){\
|
void calc_out_neurons_##type(neurons_##type *nr){\
|
||||||
calc_net_neurons_##type(nr);\
|
calc_net_neurons_##type(nr);\
|
||||||
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
||||||
(nr->output)->x[i]=f((nr->net)->x[i]);\
|
(nr->output)->x[i]=(nr->f_act)((nr->net)->x[i]);\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
void calc_delta_neurons_##type(neurons_##type *nr, type (*df)(type x)){\
|
void calc_delta_neurons_##type(neurons_##type *nr){\
|
||||||
if(nr->next_layer == NULL){\
|
if(nr->next_layer == NULL){\
|
||||||
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
||||||
(nr->delta_out)->x[i]=df((nr->net)->x[i])*(nr->dL)((nr->target)->x[i],(nr->output)->x[i]);\
|
(nr->delta_out)->x[i]=(nr->d_f_act)((nr->net)->x[i])*(nr->dL)((nr->target)->x[i],(nr->output)->x[i]);\
|
||||||
}\
|
}\
|
||||||
|
/*print_tensor_msg_##type(nr->delta_out," nr delta_out calc delta_out last layer");*/\
|
||||||
}else{\
|
}else{\
|
||||||
tensor_##type *temp_w_d;\
|
tensor_##type *temp_w_d;\
|
||||||
size_t cntrctnb=(((nr->next_layer)->weight_in)->dim)->size-(((nr->next_layer)->delta_out)->dim)->size ;\
|
size_t cntrctnb=(((nr->next_layer)->weight_in)->dim)->size-(((nr->next_layer)->delta_out)->dim)->size ;\
|
||||||
nr->TensorContraction_##type(&temp_w_d, ((nr->next_layer)->weight_in), (nr->next_layer)->delta_out,cntrctnb,nr->nb_thread);\
|
/*print_tensor_msg_##type((nr->next_layer)->weight_in," nxt weight_in calc delta_out");*/\
|
||||||
|
/*print_tensor_msg_##type((nr->next_layer)->delta_out," nxt delta_out calc delta_out");*/\
|
||||||
|
nr->TensorContraction(&temp_w_d, ((nr->next_layer)->weight_in), (nr->next_layer)->delta_out,cntrctnb,nr->nb_thread);\
|
||||||
|
/*print_tensor_msg_##type(temp_w_d," nxt tmp calc delta_out");*/\
|
||||||
\
|
\
|
||||||
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
for(size_t i = 0; i<(nr->net)->dim->rank; ++i){\
|
||||||
(nr->delta_out)->x[i]=df((nr->net)->x[i]) * temp_w_d->x[i] ;\
|
(nr->delta_out)->x[i]=(nr->d_f_act)((nr->net)->x[i]) * temp_w_d->x[i] ;\
|
||||||
}\
|
}\
|
||||||
|
/*print_tensor_msg_##type(nr->delta_out," nr delta_out calc delta_out");*/\
|
||||||
free_tensor_##type(temp_w_d);\
|
free_tensor_##type(temp_w_d);\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
void update_weight_neurons_##type(neurons_##type *nr){\
|
void update_weight_neurons_##type(neurons_##type *nr){\
|
||||||
tensor_##type *tmp_e_w;\
|
tensor_##type *tmp_e_w;\
|
||||||
nr->TensorProduct_##type(&(tmp_e_w), nr->delta_out, nr->input, nr->nb_thread);\
|
nr->TensorProduct(&(tmp_e_w), nr->input, nr->delta_out, nr->nb_thread);\
|
||||||
|
/*print_tensor_msg_##type(nr->input," nr input update wei");*/\
|
||||||
|
/*print_tensor_msg_##type(nr->delta_out," nr delta_out update wei");*/\
|
||||||
|
/*print_tensor_msg_##type(tmp_e_w," tmp_e_w update wei");*/\
|
||||||
\
|
\
|
||||||
for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
for(size_t i = 0; i<(nr->weight_in)->dim->rank; ++i){\
|
||||||
(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
(nr->weight_in)->x[i]= (nr->weight_in)->x[i] - nr->learning_rate *tmp_e_w->x[i] ;\
|
||||||
}\
|
}\
|
||||||
|
/*print_tensor_msg_##type(nr->weight_in," weight_in updated ");*/\
|
||||||
free_tensor_##type(tmp_e_w);\
|
free_tensor_##type(tmp_e_w);\
|
||||||
}\
|
}\
|
||||||
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out){\
|
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out){\
|
||||||
@@ -71,100 +83,107 @@ void link_layers_##type(neurons_##type *nPrev, neurons_##type *nNext ){\
|
|||||||
for(size_t i=0;i<((nNext->bias)->dim)->rank;++i) (nNext->bias)->x[i]=1;\
|
for(size_t i=0;i<((nNext->bias)->dim)->rank;++i) (nNext->bias)->x[i]=1;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void setup_networks_all_dim_inputs_##type(neurons_##type **base_nr, dimension **dim_in_layers, size_t nb_layers){\
|
\
|
||||||
neurons_##type *tmp_l, *ttmp_l=NULL;\
|
\
|
||||||
|
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **tab_in_layers, size_t *sz_layers, size_t nb_layers){\
|
||||||
|
neurons_##type *tmp_l=NULL, *ttmp_l=NULL;\
|
||||||
for(size_t l=0; l<nb_layers; ++l){\
|
for(size_t l=0; l<nb_layers; ++l){\
|
||||||
|
tmp_l = malloc(sizeof(neurons_##type)); \
|
||||||
if(l==0){\
|
if(l==0){\
|
||||||
*base_nr=malloc(sizeof(neurons_##type)); \
|
*base_nr = tmp_l ;\
|
||||||
tmp_l = *base_nr;\
|
|
||||||
}else{\
|
}else{\
|
||||||
ttmp_l->next_layer = malloc(sizeof(neurons_##type));\
|
ttmp_l->next_layer = tmp_l ;\
|
||||||
tmp_l = ttmp_l->next_layer;\
|
|
||||||
}\
|
}\
|
||||||
/*dimension *dim=init_copy_dim(tab_in_layers[l],sz_layers[l]);\
|
tmp_l->id_layer= l;\
|
||||||
tensor_##type *input=CREATE_TENSOR_##type(dim);*/\
|
tmp_l->input = NULL; \
|
||||||
tensor_##type *input=CREATE_TENSOR_##type(dim_in_layers[l]);\
|
tmp_l->net = NULL; \
|
||||||
tmp_l->input = input;\
|
|
||||||
\
|
|
||||||
tmp_l->net = NULL; /* output tensor_prodContract */\
|
|
||||||
tmp_l->output = NULL; \
|
tmp_l->output = NULL; \
|
||||||
tmp_l->target = NULL; \
|
tmp_l->target = NULL; \
|
||||||
tmp_l->weight_in = NULL; /* weight link in */\
|
tmp_l->weight_in = NULL; \
|
||||||
tmp_l->bias = NULL; /* bias */\
|
tmp_l->weight_out = NULL; \
|
||||||
tmp_l->weight_out = NULL; /* weight link out */\
|
tmp_l->delta_out = NULL; \
|
||||||
|
tmp_l->bias = NULL; \
|
||||||
tmp_l->prev_layer = ttmp_l;\
|
tmp_l->prev_layer = ttmp_l;\
|
||||||
tmp_l->next_layer = NULL;\
|
tmp_l->next_layer = NULL;\
|
||||||
\
|
\
|
||||||
if(ttmp_l != NULL){\
|
if(ttmp_l != NULL){\
|
||||||
|
dimension *dim=init_copy_dim(tab_in_layers[l-1],sz_layers[l-1]);\
|
||||||
|
increment_dim_var(dim);\
|
||||||
|
tmp_l->input = CREATE_TENSOR_##type(dim);\
|
||||||
|
for(size_t i=0;i<((tmp_l->input)->dim)->rank;++i) (tmp_l->input)->x[i]=(type)l;\
|
||||||
|
\
|
||||||
link_layers_##type(ttmp_l,tmp_l);\
|
link_layers_##type(ttmp_l,tmp_l);\
|
||||||
|
if(l>1 ){\
|
||||||
dimension *dim_out = (ttmp_l->output)->dim;\
|
dimension *dim_out = (ttmp_l->output)->dim;\
|
||||||
|
for(size_t i=0;i<dim_out->rank; ++i) (ttmp_l->output)->x[i]=(type)(l-1);\
|
||||||
ttmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
ttmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
if(l == nb_layers - 1) ttmp_l->target = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
for(size_t i=0;i<dim_out->rank; ++i) (ttmp_l->net)->x[i]=(type)(l-1);\
|
||||||
ttmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); /* NULL; */ /* delta */\
|
ttmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); \
|
||||||
|
for(size_t i=0;i< dim_out->rank; ++i) (ttmp_l->delta_out)->x[i]=(type)(l-1);\
|
||||||
dimension *d_w_in; \
|
dimension *d_w_in; \
|
||||||
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
||||||
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
init_random_x_##type(ttmp_l->weight_in,0,1,5000);\
|
init_random_x_##type(ttmp_l->weight_in,0,1,5000);\
|
||||||
}\
|
}\
|
||||||
\
|
if(l==nb_layers-1) {\
|
||||||
ttmp_l = tmp_l;\
|
dimension *dim_out=init_copy_dim(tab_in_layers[l],sz_layers[l]);\
|
||||||
\
|
tmp_l->output = CREATE_TENSOR_##type(dim_out);\
|
||||||
}\
|
for(size_t i=0;i<((tmp_l->output)->dim)->rank;++i) (tmp_l->output)->x[i]=(type)l;\
|
||||||
}\
|
tmp_l->target = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
\
|
for(size_t i=0;i<((tmp_l->target)->dim)->rank;++i) (tmp_l->target)->x[i]=(type)(l);\
|
||||||
\
|
tmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
||||||
void setup_networks_allinputs_##type(neurons_##type **base_nr, size_t **tab_in_layers, size_t *sz_layers, size_t nb_layers){\
|
for(size_t i=0;i<((tmp_l->net)->dim)->rank;++i) (tmp_l->net)->x[i]=(type)(l);\
|
||||||
neurons_##type *tmp_l, *ttmp_l=NULL;\
|
tmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); \
|
||||||
for(size_t l=0; l<nb_layers-1; ++l){\
|
for(size_t i=0;i<((tmp_l->delta_out)->dim)->rank;++i) (tmp_l->delta_out)->x[i]=(type)(l);\
|
||||||
if(l==0){\
|
|
||||||
*base_nr=malloc(sizeof(neurons_##type)); \
|
|
||||||
tmp_l = *base_nr;\
|
|
||||||
}else{\
|
|
||||||
ttmp_l->next_layer = malloc(sizeof(neurons_##type));\
|
|
||||||
tmp_l = ttmp_l->next_layer;\
|
|
||||||
}\
|
|
||||||
dimension *dim=init_copy_dim(tab_in_layers[l],sz_layers[l]);\
|
|
||||||
tensor_##type *input=CREATE_TENSOR_##type(dim);\
|
|
||||||
tmp_l->input = input;\
|
|
||||||
\
|
|
||||||
tmp_l->net = NULL; /* output tensor_prodContract */\
|
|
||||||
tmp_l->output = NULL; \
|
|
||||||
tmp_l->target = NULL; \
|
|
||||||
tmp_l->weight_in = NULL; /* weight link in */\
|
|
||||||
tmp_l->bias = NULL; /* bias */\
|
|
||||||
tmp_l->weight_out = NULL; /* weight link out */\
|
|
||||||
tmp_l->prev_layer = ttmp_l;\
|
|
||||||
tmp_l->next_layer = NULL;\
|
|
||||||
\
|
|
||||||
if(ttmp_l != NULL){\
|
|
||||||
link_layers_##type(ttmp_l,tmp_l);\
|
|
||||||
dimension *dim_out = (ttmp_l->output)->dim;\
|
|
||||||
ttmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out);\
|
|
||||||
ttmp_l->delta_out = CREATE_TENSOR_FROM_CPY_DIM_##type(dim_out); /* NULL; */ /* delta */\
|
|
||||||
dimension *d_w_in; \
|
|
||||||
add_dimension(&d_w_in, (ttmp_l->input)->dim, ((ttmp_l->output)->dim)); \
|
|
||||||
ttmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
|
||||||
init_random_x_##type(ttmp_l->weight_in,0,1,5000);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
ttmp_l = tmp_l;\
|
|
||||||
\
|
|
||||||
if(l == nb_layers - 2) {\
|
|
||||||
dimension *dim=init_copy_dim(tab_in_layers[l+1],sz_layers[l+1]);\
|
|
||||||
tensor_##type *input=CREATE_TENSOR_##type(dim);\
|
|
||||||
tmp_l->output= CREATE_TENSOR_FROM_CPY_DIM_##type(dim);\
|
|
||||||
tmp_l->net = CREATE_TENSOR_FROM_CPY_DIM_##type(dim);\
|
|
||||||
tmp_l->target = CREATE_TENSOR_FROM_CPY_DIM_##type(dim);\
|
|
||||||
dimension *d_w_in; \
|
dimension *d_w_in; \
|
||||||
add_dimension(&d_w_in, (tmp_l->input)->dim, ((tmp_l->output)->dim)); \
|
add_dimension(&d_w_in, (tmp_l->input)->dim, ((tmp_l->output)->dim)); \
|
||||||
tmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
tmp_l->weight_in = CREATE_TENSOR_##type(d_w_in);\
|
||||||
init_random_x_##type(tmp_l->weight_in,0,1,5000);\
|
init_random_x_##type(tmp_l->weight_in,0,1,5000);\
|
||||||
|
\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
ttmp_l = tmp_l;\
|
||||||
|
\
|
||||||
|
\
|
||||||
\
|
\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
void setup_all_layers_functions_##type(neurons_##type *base, \
|
||||||
|
void (*TensorContraction)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread),/* nbthread is ignored if not required ! */\
|
||||||
|
void (*TensorProduct)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t nbthread),/* nbthread is ignored if not required ! */\
|
||||||
|
type (*dL)(type t, type o),\
|
||||||
|
type (*L)(type t, type o),\
|
||||||
|
type (*f_act)(type x),\
|
||||||
|
type (*d_f_act)(type x)\
|
||||||
|
){\
|
||||||
|
neurons_##type *temp = base;\
|
||||||
|
while(temp){\
|
||||||
|
temp->TensorContraction = TensorContraction;\
|
||||||
|
temp->TensorProduct= TensorProduct;\
|
||||||
|
temp->L=L;\
|
||||||
|
temp->dL=dL;\
|
||||||
|
temp->f_act=f_act;\
|
||||||
|
temp->d_f_act=d_f_act;\
|
||||||
|
temp=temp->next_layer;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
void setup_all_layers_params_##type(neurons_##type *base,\
|
||||||
|
size_t nb_thread,\
|
||||||
|
type learning_rate){\
|
||||||
|
\
|
||||||
|
neurons_##type *temp = base;\
|
||||||
|
while(temp){\
|
||||||
|
temp->nb_thread=nb_thread;\
|
||||||
|
temp->learning_rate=learning_rate;\
|
||||||
|
temp=temp->next_layer;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
\
|
||||||
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers, size_t nb_layers){\
|
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers, size_t nb_layers){\
|
||||||
size_t *sz_layers=malloc(nb_layers*sizeof(size_t));\
|
size_t *sz_layers=malloc(nb_layers*sizeof(size_t));\
|
||||||
for(size_t i=0; i<nb_layers;++i) sz_layers[i]=1;\
|
for(size_t i=0; i<nb_layers;++i) sz_layers[i]=1;\
|
||||||
@@ -173,7 +192,7 @@ void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers,
|
|||||||
ttab_in_layers[i]=malloc(sizeof(size_t));\
|
ttab_in_layers[i]=malloc(sizeof(size_t));\
|
||||||
ttab_in_layers[i][0]=tab_in_layers[i];\
|
ttab_in_layers[i][0]=tab_in_layers[i];\
|
||||||
}\
|
}\
|
||||||
setup_networks_allinputs_##type(base_nr, ttab_in_layers, sz_layers, nb_layers);\
|
setup_networks_alloutputs_##type(base_nr, ttab_in_layers, sz_layers, nb_layers);\
|
||||||
\
|
\
|
||||||
for(size_t i=0; i<nb_layers;++i) {\
|
for(size_t i=0; i<nb_layers;++i) {\
|
||||||
free(ttab_in_layers[i]);\
|
free(ttab_in_layers[i]);\
|
||||||
@@ -182,8 +201,8 @@ void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers,
|
|||||||
free(sz_layers);\
|
free(sz_layers);\
|
||||||
}\
|
}\
|
||||||
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out){\
|
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out){\
|
||||||
if(((nr->input)->dim)->rank == sz_in){\
|
if(((nr->output)->dim)->rank == sz_in){\
|
||||||
for(size_t i=0;i<sz_in;++i) (nr->input)->x[i]=in[i];\
|
for(size_t i=0;i<sz_in;++i) (nr->output)->x[i]=in[i];\
|
||||||
}\
|
}\
|
||||||
neurons_##type *tmp=nr;\
|
neurons_##type *tmp=nr;\
|
||||||
while(tmp->next_layer) tmp=tmp->next_layer;\
|
while(tmp->next_layer) tmp=tmp->next_layer;\
|
||||||
@@ -195,13 +214,14 @@ void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t s
|
|||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
void print_neurons_msg_##type(neurons_##type *nr, char *msg){\
|
void print_neurons_msg_##type(neurons_##type *nr, char *msg){\
|
||||||
size_t l=0;\
|
|
||||||
while(nr){\
|
while(nr){\
|
||||||
printf("%s, layer %ld\n",msg,l++); \
|
printf("%s, layer %ld\n",msg,nr->id_layer); \
|
||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
if(nr->input) print_tensor_msg_##type(nr->input," input "); else printf(" input NULL\n");\
|
if(nr->input) print_tensor_msg_##type(nr->input," input "); else printf(" input NULL\n");\
|
||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
if(nr->output) print_tensor_msg_##type(nr->input," input "); else printf(" output NULL\n");\
|
if(nr->bias) print_tensor_msg_##type(nr->bias," bias "); else printf(" bias NULL\n");\
|
||||||
|
PR_LINE;\
|
||||||
|
if(nr->output) print_tensor_msg_##type(nr->output," output "); else printf(" output NULL\n");\
|
||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
if(nr->net) print_tensor_msg_##type(nr->net," net "); else printf(" net NULL\n");\
|
if(nr->net) print_tensor_msg_##type(nr->net," net "); else printf(" net NULL\n");\
|
||||||
PR_LINE;\
|
PR_LINE;\
|
||||||
@@ -217,6 +237,33 @@ void print_neurons_msg_##type(neurons_##type *nr, char *msg){\
|
|||||||
nr=nr->next_layer;\
|
nr=nr->next_layer;\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
|
\
|
||||||
|
void free_neurons_##type(neurons_##type *base){\
|
||||||
|
neurons_##type *temp = base, *ttemp;\
|
||||||
|
while(temp){\
|
||||||
|
if(temp->input) free_tensor_##type(temp->input);\
|
||||||
|
if(temp->output) {\
|
||||||
|
if(temp->next_layer == NULL) free((temp->output)->x);\
|
||||||
|
free_dimension((temp->output)->dim);free(temp->output);\
|
||||||
|
}\
|
||||||
|
if(temp->bias) {free_dimension((temp->bias)->dim);free(temp->bias);}\
|
||||||
|
if(temp->net) free_tensor_##type(temp->net);\
|
||||||
|
if(temp->weight_in) free_tensor_##type(temp->weight_in);\
|
||||||
|
if(temp->weight_out) free_tensor_##type(temp->weight_out);\
|
||||||
|
if(temp->delta_out) free_tensor_##type(temp->delta_out);\
|
||||||
|
if(temp->target) free_tensor_##type(temp->target);\
|
||||||
|
ttemp = temp;\
|
||||||
|
temp = ttemp->next_layer;\
|
||||||
|
free(ttemp);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
type error_out_##type(neurons_##type *base){\
|
||||||
|
while(base->next_layer) base=base->next_layer;\
|
||||||
|
type sum=0;\
|
||||||
|
for(size_t i=0; i< ((base->target)->dim)->rank; ++i) sum += base->L((base->target)->x[i], (base->output)->x[i]);\
|
||||||
|
return sum / (((base->target)->dim)->rank);\
|
||||||
|
}\
|
||||||
|
|
||||||
|
|
||||||
GEN_NEURONS_F_(TYPE_FLOAT)
|
GEN_NEURONS_F_(TYPE_FLOAT)
|
||||||
GEN_NEURONS_F_(TYPE_DOUBLE)
|
GEN_NEURONS_F_(TYPE_DOUBLE)
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ struct neurons_##type {/* layer */\
|
|||||||
tensor_##type *delta_out; /* delta */\
|
tensor_##type *delta_out; /* delta */\
|
||||||
struct neurons_##type *prev_layer;\
|
struct neurons_##type *prev_layer;\
|
||||||
struct neurons_##type *next_layer;\
|
struct neurons_##type *next_layer;\
|
||||||
void (*TensorContraction_##type)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread);/* nbthread is ignored if not required ! */\
|
void (*TensorContraction)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread);/* nbthread is ignored if not required ! */\
|
||||||
void (*TensorProduct_##type)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t nbthread);/* nbthread is ignored if not required ! */\
|
void (*TensorProduct)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t nbthread);/* nbthread is ignored if not required ! */\
|
||||||
type (*dL)(type t, type o);\
|
type (*dL)(type t, type o);\
|
||||||
|
type (*L)(type t, type o);\
|
||||||
|
type (*f_act)(type x);\
|
||||||
|
type (*d_f_act)(type x);\
|
||||||
};\
|
};\
|
||||||
typedef struct neurons_##type neurons_##type;\
|
typedef struct neurons_##type neurons_##type;\
|
||||||
\
|
\
|
||||||
@@ -33,15 +36,31 @@ struct func_act_##type {\
|
|||||||
type (*deriv_func_act)(type x); /* derivate func act */\
|
type (*deriv_func_act)(type x); /* derivate func act */\
|
||||||
};\
|
};\
|
||||||
/*void calc_net_neurons_##type(neurons_##type *nr);*/\
|
/*void calc_net_neurons_##type(neurons_##type *nr);*/\
|
||||||
void calc_out_neurons_##type(neurons_##type *nr, type (*f)(type x) );\
|
void calc_out_neurons_##type(neurons_##type *nr);\
|
||||||
void calc_delta_neurons_##type(neurons_##type *nr, type (*df)(type x));\
|
void calc_delta_neurons_##type(neurons_##type *nr);\
|
||||||
void update_weight_neurons_##type(neurons_##type *nr);\
|
void update_weight_neurons_##type(neurons_##type *nr);\
|
||||||
void setup_networks_##type(neurons_##type **base_nr, size_t **tab_in_layers, size_t *tab_sz_layers, size_t nb_layers);\
|
/*void setup_networks_##type(neurons_##type **base_nr, size_t **tab_in_layers, size_t *tab_sz_layers, size_t nb_layers);*/\
|
||||||
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out);\
|
void init_in_out_all_networks_##type(neurons_##type *nr, tensor_##type *in, tensor_##type *out);\
|
||||||
\
|
void setup_networks_alloutputs_##type(neurons_##type **base_nr, size_t **tab_in_layers, size_t *sz_layers, size_t nb_layers);\
|
||||||
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers, size_t nb_layers);\
|
void setup_networks_OneD_##type(neurons_##type **base_nr, size_t *tab_in_layers, size_t nb_layers);\
|
||||||
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out);\
|
void init_in_out_all_networks_OneD_##type(neurons_##type *nr, type *in, size_t sz_in, type *out, size_t sz_out);\
|
||||||
void print_neurons_msg_##type(neurons_##type *nr, char * msg);\
|
void print_neurons_msg_##type(neurons_##type *nr, char * msg);\
|
||||||
|
\
|
||||||
|
void free_neurons_##type(neurons_##type *base);\
|
||||||
|
\
|
||||||
|
void setup_all_layers_functions_##type(neurons_##type *base, \
|
||||||
|
void (*TensorContraction)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread),/* nbthread is ignored if not required ! */\
|
||||||
|
void (*TensorProduct)(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t nbthread),/* nbthread is ignored if not required ! */\
|
||||||
|
type (*dL)(type t, type o),\
|
||||||
|
type (*L)(type t, type o),\
|
||||||
|
type (*f_act)(type x),\
|
||||||
|
type (*d_f_act)(type x)\
|
||||||
|
);\
|
||||||
|
void setup_all_layers_params_##type(neurons_##type *base,\
|
||||||
|
size_t nb_thread,\
|
||||||
|
type learning_rate);\
|
||||||
|
type error_out_##type(neurons_##type *base);\
|
||||||
|
|
||||||
|
|
||||||
GEN_NEURON_(TYPE_FLOAT)
|
GEN_NEURON_(TYPE_FLOAT)
|
||||||
GEN_NEURON_(TYPE_DOUBLE)
|
GEN_NEURON_(TYPE_DOUBLE)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ NEURODIR=$(PWD)/..
|
|||||||
DIMDIR=$(PWD)/../../dimension_t
|
DIMDIR=$(PWD)/../../dimension_t
|
||||||
INCLUDE_DIR=$(PWD)/../src
|
INCLUDE_DIR=$(PWD)/../src
|
||||||
CFLAGS=-I$(INCLUDE_DIR) -I$(YPERMDIR)/src -I$(YTESTDIR)/include_ytest/include -I$(DIMDIR)/src -I$(TENSDIR)/src #"-D DEBUG=1"
|
CFLAGS=-I$(INCLUDE_DIR) -I$(YPERMDIR)/src -I$(YTESTDIR)/include_ytest/include -I$(DIMDIR)/src -I$(TENSDIR)/src #"-D DEBUG=1"
|
||||||
LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL
|
LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL -lm
|
||||||
|
|
||||||
#SRC_DIR=$(ROOT_DIR)/src
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
#SRC=$(wildcard */*/*.c)
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
|||||||
+55
-4
@@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
// for sleep !
|
// for sleep !
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -19,16 +21,65 @@
|
|||||||
|
|
||||||
#define VALGRIND_ 1
|
#define VALGRIND_ 1
|
||||||
|
|
||||||
TEST(init_One){
|
float L(float t, float o){
|
||||||
|
return (o - t) * (o - t)/2;
|
||||||
|
}
|
||||||
|
float DL(float t, float o){
|
||||||
|
return (o - t);
|
||||||
|
}
|
||||||
|
|
||||||
neurons_TYPE_FLOAT *bn=NULL;
|
float f(float x){
|
||||||
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){3,4,2},3);
|
return 1/(1+exp((double)(-x)));
|
||||||
print_neurons_msg_TYPE_FLOAT(bn,"bn");
|
}
|
||||||
|
|
||||||
|
float df(float x){
|
||||||
|
return exp(-x)/ ((1+exp(-x)) * (1+exp(-x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(init_One){
|
||||||
|
//endian=false;
|
||||||
|
neurons_TYPE_FLOAT *bn=NULL, *tmp=NULL, *ttmp=NULL;
|
||||||
|
setup_networks_OneD_TYPE_FLOAT(&bn, (size_t[]){3,5,2},3);
|
||||||
init_in_out_all_networks_OneD_TYPE_FLOAT(bn,(float[]){1.2,0.5,1.3},3,(float[]){0.1,0.8},2);
|
init_in_out_all_networks_OneD_TYPE_FLOAT(bn,(float[]){1.2,0.5,1.3},3,(float[]){0.1,0.8},2);
|
||||||
|
|
||||||
|
|
||||||
|
setup_all_layers_functions_TYPE_FLOAT(bn,
|
||||||
|
tensorContractnProdThread_TYPE_FLOAT,
|
||||||
|
tensorProdThread_TYPE_FLOAT,
|
||||||
|
DL,
|
||||||
|
L,
|
||||||
|
f,
|
||||||
|
df);
|
||||||
|
|
||||||
|
setup_all_layers_params_TYPE_FLOAT(bn, 2, 0.7);
|
||||||
|
|
||||||
|
//print_neurons_msg_TYPE_FLOAT(bn,"bn");
|
||||||
|
|
||||||
|
tmp=bn->next_layer;
|
||||||
|
while(tmp){
|
||||||
|
calc_out_neurons_TYPE_FLOAT(tmp);
|
||||||
|
ttmp = tmp;
|
||||||
|
tmp = tmp->next_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while(ttmp != bn){
|
||||||
|
calc_delta_neurons_TYPE_FLOAT(ttmp);
|
||||||
|
update_weight_neurons_TYPE_FLOAT(ttmp);
|
||||||
|
ttmp = ttmp->prev_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print_neurons_msg_TYPE_FLOAT(bn,"bn");
|
||||||
|
|
||||||
|
LOG(" error : %f\n", error_out_TYPE_FLOAT(bn));
|
||||||
|
|
||||||
|
free_neurons_TYPE_FLOAT(bn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -343,11 +343,11 @@ void print_tensor_msg_##type(tensor_##type *T,char *msg) {\
|
|||||||
if (endian ) {\
|
if (endian ) {\
|
||||||
begin = (T->dim->size) - 1; end = 0;\
|
begin = (T->dim->size) - 1; end = 0;\
|
||||||
iter = decr; cond = isGreatEqThan; \
|
iter = decr; cond = isGreatEqThan; \
|
||||||
printf("endian(=true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index \n");\
|
/*printf("endian(=true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index \n");*/\
|
||||||
}else{\
|
}else{\
|
||||||
begin = 0 ; end = (T->dim->size) - 1; \
|
begin = 0 ; end = (T->dim->size) - 1; \
|
||||||
iter = incr; cond = isLessEqThan; \
|
iter = incr; cond = isLessEqThan; \
|
||||||
printf("endian(=false): the lowest index varies first, e.g: [x0,x1,x2,...,xn] x0 is the lowest index \n");\
|
/*printf("endian(=false): the lowest index varies first, e.g: [x0,x1,x2,...,xn] x0 is the lowest index \n");*/\
|
||||||
}\
|
}\
|
||||||
for(long int i=0;i<(T->dim)->rank;++i){\
|
for(long int i=0;i<(T->dim)->rank;++i){\
|
||||||
vCoordFromLin(coord,i,T->dim);\
|
vCoordFromLin(coord,i,T->dim);\
|
||||||
@@ -357,10 +357,10 @@ void print_tensor_msg_##type(tensor_##type *T,char *msg) {\
|
|||||||
else break;\
|
else break;\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
printf(" [{");\
|
printf(" [");\
|
||||||
for(size_t k=0; k<(T->dim)->size;++k) printf(" %ld,",coord[k]);\
|
for(size_t k=0; k<(T->dim)->size;++k) printf(" %ld,",coord[k]);\
|
||||||
val=type##_TO_STR(T->x[i]);\
|
val=type##_TO_STR(T->x[i]);\
|
||||||
printf("}#%ld] %s, ",i,val);\
|
printf(" |#%ld]: %s, ",i,val);\
|
||||||
free(val); val=NULL;\
|
free(val); val=NULL;\
|
||||||
if(coord[begin]==(T->dim)->perm[begin]-1){\
|
if(coord[begin]==(T->dim)->perm[begin]-1){\
|
||||||
for(long int j=begin; cond(j,end); j = iter(j)){\
|
for(long int j=begin; cond(j,end); j = iter(j)){\
|
||||||
@@ -617,7 +617,7 @@ void* runProd_thread_##type(void *arg){\
|
|||||||
a0_id=i % arg_t->MRank;\
|
a0_id=i % arg_t->MRank;\
|
||||||
a1_id=i / arg_t->MRank;\
|
a1_id=i / arg_t->MRank;\
|
||||||
}\
|
}\
|
||||||
arg_t->Mx[i] += arg_t->M0x[a0_id] * arg_t->M1x[a1_id];\
|
arg_t->Mx[i] = arg_t->M0x[a0_id] * arg_t->M1x[a1_id];\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
@@ -984,6 +984,128 @@ void tensorContractnProdNotOpt_##type(tensor_##type** MM, tensor_##type *M0, ten
|
|||||||
FREE_dM_S_ ; \
|
FREE_dM_S_ ; \
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
|
\
|
||||||
|
/*format_file: [dim]((x,x,a)(a,x,a)) | example:[2,3,4](((a0,b0,c0,d0)(a1,b1,c1,d1)(a2,b2,c2,d2))((e0,f0,g0,h0)(e1,f1,g1,h1)(e2,f2,g2,h2)))*/\
|
||||||
|
tensor_##type * parseInput_withDim_to_tensor_##type(char *input){\
|
||||||
|
tensor_##type *tens ;\
|
||||||
|
size_t len = strlen(input);\
|
||||||
|
list_perm_in_dim *l_p=NULL;\
|
||||||
|
size_t ss;\
|
||||||
|
char *ttmp=input;\
|
||||||
|
char *ppEnd="[";\
|
||||||
|
bool size_unknown=false; \
|
||||||
|
for(size_t i=0; i<len ; ++i){\
|
||||||
|
if(input[i]==']') break;\
|
||||||
|
if((input[i]=='*') ||(input[i]=='_')){ size_unknown =true; break;}\
|
||||||
|
}\
|
||||||
|
while(ppEnd && (ppEnd[0] !=']') ){\
|
||||||
|
ss = strtoul(ttmp, &ppEnd, 10);\
|
||||||
|
while(ttmp == ppEnd && ppEnd[0] !=']'){\
|
||||||
|
ttmp++;\
|
||||||
|
ss = strtoul(ttmp, &ppEnd, 10);\
|
||||||
|
}\
|
||||||
|
if(ppEnd !=ttmp )\
|
||||||
|
append_in_list_perm(&l_p,ss);\
|
||||||
|
/*printf("ss: %ld\n",ss);*/\
|
||||||
|
ttmp=ppEnd;\
|
||||||
|
}\
|
||||||
|
dimension *dim=create_dim_from_list_perm(l_p);\
|
||||||
|
/*printf("ppEnd = %s\n",ppEnd);*/\
|
||||||
|
\
|
||||||
|
ttmp++; ppEnd++;\
|
||||||
|
\
|
||||||
|
if(size_unknown == false){\
|
||||||
|
tens = CREATE_TENSOR_##type(dim);\
|
||||||
|
\
|
||||||
|
size_t i=0;\
|
||||||
|
type x;\
|
||||||
|
while(ppEnd && (ppEnd[0] !='\0') && i<dim->rank){\
|
||||||
|
x = strto_##type(ttmp, &ppEnd);\
|
||||||
|
while(ttmp == ppEnd && ppEnd[0] !='\0'){\
|
||||||
|
ttmp++;\
|
||||||
|
x = strto_##type(ttmp, &ppEnd);\
|
||||||
|
}\
|
||||||
|
if(ppEnd[0]!='\0')\
|
||||||
|
(tens)->x[i] = x;\
|
||||||
|
/*printf("d: %lf\n",d);*/\
|
||||||
|
ttmp=ppEnd;\
|
||||||
|
++i;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
else{\
|
||||||
|
array_chainlist_##type *l_a=NULL;\
|
||||||
|
type x;\
|
||||||
|
while(ppEnd && (ppEnd[0] !='\0')){\
|
||||||
|
x = strto_##type(ttmp, &ppEnd);\
|
||||||
|
while(ttmp == ppEnd && ppEnd[0] !='\0'){\
|
||||||
|
ttmp++;\
|
||||||
|
x = strto_##type(ttmp, &ppEnd);\
|
||||||
|
}\
|
||||||
|
/*if(ppEnd[0]!='\0')*/ \
|
||||||
|
if(ppEnd != ttmp)\
|
||||||
|
append_array_chainlist_##type(&l_a, x);\
|
||||||
|
/*printf("-- x: %f\n",x);*/\
|
||||||
|
ttmp=ppEnd;\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
tens = create_tensor_from_list_array_##type(l_a,dim);\
|
||||||
|
}\
|
||||||
|
return tens;\
|
||||||
|
}\
|
||||||
|
void append_array_chainlist_##type(array_chainlist_##type **list_a, type x){\
|
||||||
|
array_chainlist_##type *lis=malloc(sizeof(array_chainlist_##type));\
|
||||||
|
lis->x=x;\
|
||||||
|
lis->next=NULL;\
|
||||||
|
if(*list_a == NULL){\
|
||||||
|
lis->index=0;\
|
||||||
|
*list_a = lis;\
|
||||||
|
}\
|
||||||
|
else{\
|
||||||
|
array_chainlist_##type *tmp =*list_a;\
|
||||||
|
while(tmp->next) tmp=tmp->next;\
|
||||||
|
lis->index = tmp->index +1;\
|
||||||
|
tmp->next=lis;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
tensor_##type * create_tensor_from_list_array_##type( array_chainlist_##type *l_a, dimension *part_dim){\
|
||||||
|
if(l_a){\
|
||||||
|
array_chainlist_##type *tmp =l_a;\
|
||||||
|
while(tmp->next) tmp=tmp->next;\
|
||||||
|
size_t miss_part_d=(tmp->index + 1)/part_dim->rank;\
|
||||||
|
dimension *dim=create_dim(part_dim->size + 1);\
|
||||||
|
if(endian){\
|
||||||
|
dim->perm[0]=miss_part_d;\
|
||||||
|
for(size_t i=0; i<part_dim->size;++i) dim->perm[i+1]=part_dim->perm[i];\
|
||||||
|
}else{\
|
||||||
|
size_t i=0;\
|
||||||
|
for(i=0; i<part_dim->size;++i) dim->perm[i]=part_dim->perm[i];\
|
||||||
|
dim->perm[i]=miss_part_d;\
|
||||||
|
\
|
||||||
|
}\
|
||||||
|
updateRankDim(dim);\
|
||||||
|
tensor_##type *tens= CREATE_TENSOR_##type(dim);\
|
||||||
|
tmp=l_a;\
|
||||||
|
while(tmp){\
|
||||||
|
(tens)->x[tmp->index]=tmp->x;\
|
||||||
|
tmp=tmp->next;\
|
||||||
|
}\
|
||||||
|
return tens;\
|
||||||
|
}\
|
||||||
|
return NULL;\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
void free_array_chainlist_##type(array_chainlist_##type *l_a){\
|
||||||
|
array_chainlist_##type *tmp=l_a, *ttmp;\
|
||||||
|
while(tmp){\
|
||||||
|
ttmp = tmp;\
|
||||||
|
tmp = ttmp->next;\
|
||||||
|
free(ttmp);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GEN_FUNC_TENSOR(TYPE_FLOAT);
|
GEN_FUNC_TENSOR(TYPE_FLOAT);
|
||||||
GEN_FUNC_TENSOR(TYPE_DOUBLE);
|
GEN_FUNC_TENSOR(TYPE_DOUBLE);
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ void tensorContractnProdThread_##type(tensor_##type **MM, tensor_##type *M0, ten
|
|||||||
void tensorContractnPro2dThread_##type(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread); \
|
void tensorContractnPro2dThread_##type(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber, size_t nbthread); \
|
||||||
void tensorContractnProdNotOpt_##type(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber); \
|
void tensorContractnProdNotOpt_##type(tensor_##type **MM, tensor_##type *M0, tensor_##type *M1, size_t contractionNumber); \
|
||||||
void init_random_x_##type(tensor_##type *M, type minR, type maxR, int randomRange);\
|
void init_random_x_##type(tensor_##type *M, type minR, type maxR, int randomRange);\
|
||||||
|
tensor_##type * parseInput_withDim_to_tensor_##type(char *input);\
|
||||||
|
struct array_chainlist_##type{\
|
||||||
|
size_t index;\
|
||||||
|
type x;\
|
||||||
|
struct array_chainlist_##type *next;\
|
||||||
|
};\
|
||||||
|
typedef struct array_chainlist_##type array_chainlist_##type;\
|
||||||
|
void append_array_chainlist_##type(array_chainlist_##type **list_a, type x);\
|
||||||
|
tensor_##type * create_tensor_from_list_array_##type( array_chainlist_##type *l_a, dimension *part_dim);\
|
||||||
|
void free_array_chainlist_##type(array_chainlist_##type *l_a);\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GENERATE_TENSOR_TYPE(TYPE_FLOAT);
|
GENERATE_TENSOR_TYPE(TYPE_FLOAT);
|
||||||
|
|||||||
+162
-3
@@ -423,7 +423,7 @@ TEST(Split_randomInit){
|
|||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
TEST(Split_randomInit){
|
TEST(Split_randomInit){
|
||||||
endian=false;
|
//endian=false;
|
||||||
dimension *d0=create_dim(3);
|
dimension *d0=create_dim(3);
|
||||||
|
|
||||||
d0->perm[0]=4;
|
d0->perm[0]=4;
|
||||||
@@ -444,8 +444,8 @@ TEST(Split_randomInit){
|
|||||||
|
|
||||||
tensor_TYPE_FLOAT *Tpart1=NULL, *Tpart2=NULL;
|
tensor_TYPE_FLOAT *Tpart1=NULL, *Tpart2=NULL;
|
||||||
|
|
||||||
split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 2, 4);
|
//split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 2, 4);
|
||||||
//split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 0, 1);
|
split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 0, 1);
|
||||||
//split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 2, 1);
|
//split_tensor_TYPE_FLOAT(M0,&Tpart1,&Tpart2, 2, 1);
|
||||||
|
|
||||||
print_tensor_float(Tpart1, " Tpart1 1");
|
print_tensor_float(Tpart1, " Tpart1 1");
|
||||||
@@ -685,6 +685,118 @@ TEST(tensorContractnProd_TYPE_FLOAT2 ){
|
|||||||
free_tensor_TYPE_FLOAT(M1);
|
free_tensor_TYPE_FLOAT(M1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
TEST(tensorContractnProd_TYPE_DOUBLE_2_1 ){
|
||||||
|
dimension *d0=create_dim(2);
|
||||||
|
dimension *d1=create_dim(1);
|
||||||
|
#if VALGRIND_
|
||||||
|
d0->perm[0]=4;
|
||||||
|
d0->perm[1]=2; //3;
|
||||||
|
|
||||||
|
d1->perm[0]=2;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
d0->perm[0]=125;
|
||||||
|
d0->perm[1]=52; //3;
|
||||||
|
|
||||||
|
d1->perm[0]=52;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
updateRankDim(d0);
|
||||||
|
updateRankDim(d1);
|
||||||
|
|
||||||
|
|
||||||
|
tensor_TYPE_DOUBLE *M0 = CREATE_TENSOR_TYPE_DOUBLE(d0);
|
||||||
|
tensor_TYPE_DOUBLE *M1 = CREATE_TENSOR_TYPE_DOUBLE(d1);
|
||||||
|
|
||||||
|
LOG("M0->dim->rank = %ld\n",M0->dim->rank);
|
||||||
|
LOG("M1->dim->rank = %ld\n",M1->dim->rank);
|
||||||
|
for(size_t i=0; i<M0->dim->rank;++i) M0->x[i]=i*0.1 +1;
|
||||||
|
for(size_t i=0; i<M1->dim->rank;++i) M1->x[i]=i*0.003 + 2;
|
||||||
|
|
||||||
|
print_tensor_double(M0,"M0");
|
||||||
|
print_tensor_double(M1,"M1");
|
||||||
|
|
||||||
|
tensor_TYPE_DOUBLE *M;
|
||||||
|
tensor_TYPE_DOUBLE *MnO;
|
||||||
|
|
||||||
|
tensorContractnProd_TYPE_DOUBLE(&M, M0,M1,1);
|
||||||
|
//print_tensor_double(M,"M");
|
||||||
|
//cl_tensorContractnProd_TYPE_DOUBLE(&MnO, M0,M1,2);
|
||||||
|
tensorContractnProdNotOpt_TYPE_DOUBLE(&MnO, M0,M1,1);
|
||||||
|
|
||||||
|
print_tensor_double(MnO,"MnO");
|
||||||
|
|
||||||
|
// for(size_t i=0;i<M->dim->rank;++i)
|
||||||
|
// EXPECT_EQ_TYPE_DOUBLE(M->x[i],MnO->x[i]);
|
||||||
|
|
||||||
|
EXPECT_ARRAY_EQ_TYPE_DOUBLE(M->x,M->dim->rank,MnO->x,MnO->dim->rank);
|
||||||
|
|
||||||
|
free_tensor_TYPE_DOUBLE(M);
|
||||||
|
free_tensor_TYPE_DOUBLE(MnO);
|
||||||
|
free_tensor_TYPE_DOUBLE(M0);
|
||||||
|
free_tensor_TYPE_DOUBLE(M1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(tensorContractnProd_TYPE_DOUBLE_2_2 ){
|
||||||
|
dimension *d0=create_dim(2);
|
||||||
|
dimension *d1=create_dim(2);
|
||||||
|
#if VALGRIND_
|
||||||
|
d0->perm[0]=4;
|
||||||
|
d0->perm[1]=2; //3;
|
||||||
|
|
||||||
|
d1->perm[0]=2;
|
||||||
|
d1->perm[1]=1;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
d0->perm[0]=125;
|
||||||
|
d0->perm[1]=52; //3;
|
||||||
|
|
||||||
|
d1->perm[0]=52;
|
||||||
|
d1->perm[1]=1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
updateRankDim(d0);
|
||||||
|
updateRankDim(d1);
|
||||||
|
|
||||||
|
|
||||||
|
tensor_TYPE_DOUBLE *M0 = CREATE_TENSOR_TYPE_DOUBLE(d0);
|
||||||
|
tensor_TYPE_DOUBLE *M1 = CREATE_TENSOR_TYPE_DOUBLE(d1);
|
||||||
|
|
||||||
|
LOG("M0->dim->rank = %ld\n",M0->dim->rank);
|
||||||
|
LOG("M1->dim->rank = %ld\n",M1->dim->rank);
|
||||||
|
for(size_t i=0; i<M0->dim->rank;++i) M0->x[i]=i*0.1 +1;
|
||||||
|
for(size_t i=0; i<M1->dim->rank;++i) M1->x[i]=i*0.003 + 2;
|
||||||
|
|
||||||
|
print_tensor_double(M0,"M0");
|
||||||
|
print_tensor_double(M1,"M1");
|
||||||
|
|
||||||
|
tensor_TYPE_DOUBLE *M;
|
||||||
|
tensor_TYPE_DOUBLE *MnO;
|
||||||
|
|
||||||
|
tensorContractnProd_TYPE_DOUBLE(&M, M0,M1,1);
|
||||||
|
//print_tensor_double(M,"M");
|
||||||
|
//cl_tensorContractnProd_TYPE_DOUBLE(&MnO, M0,M1,2);
|
||||||
|
tensorContractnProdNotOpt_TYPE_DOUBLE(&MnO, M0,M1,1);
|
||||||
|
|
||||||
|
print_tensor_double(MnO,"MnO");
|
||||||
|
|
||||||
|
// for(size_t i=0;i<M->dim->rank;++i)
|
||||||
|
// EXPECT_EQ_TYPE_DOUBLE(M->x[i],MnO->x[i]);
|
||||||
|
|
||||||
|
EXPECT_ARRAY_EQ_TYPE_DOUBLE(M->x,M->dim->rank,MnO->x,MnO->dim->rank);
|
||||||
|
|
||||||
|
free_tensor_TYPE_DOUBLE(M);
|
||||||
|
free_tensor_TYPE_DOUBLE(MnO);
|
||||||
|
free_tensor_TYPE_DOUBLE(M0);
|
||||||
|
free_tensor_TYPE_DOUBLE(M1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(tensorContractnProd_TYPE_DOUBLE2 ){
|
TEST(tensorContractnProd_TYPE_DOUBLE2 ){
|
||||||
dimension *d0=create_dim(3);
|
dimension *d0=create_dim(3);
|
||||||
@@ -1166,6 +1278,53 @@ TEST(tensorProd_vsThread2d ){
|
|||||||
free_tensor_TYPE_FLOAT(M1);
|
free_tensor_TYPE_FLOAT(M1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(parseInput_withDim_to_tensor){
|
||||||
|
endian=true;
|
||||||
|
char *input="[2,3]"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"(.56,124,22.5)) ";
|
||||||
|
|
||||||
|
tensor_TYPE_FLOAT *t=parseInput_withDim_to_tensor_TYPE_FLOAT(input);
|
||||||
|
|
||||||
|
print_tensor_msg_TYPE_FLOAT(t," tensor from input" );
|
||||||
|
|
||||||
|
free_tensor_TYPE_FLOAT(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parseInput_unknownpart_to_tensor){
|
||||||
|
//endian=true;
|
||||||
|
endian=true;
|
||||||
|
char *input="[*,3]"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"((1.21,10,0.23)"\
|
||||||
|
"(.56,124,22.5)) ";
|
||||||
|
|
||||||
|
tensor_TYPE_FLOAT *t=parseInput_withDim_to_tensor_TYPE_FLOAT(input);
|
||||||
|
|
||||||
|
print_tensor_msg_TYPE_FLOAT(t," tensor from input" );
|
||||||
|
|
||||||
|
free_tensor_TYPE_FLOAT(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parseInput_unknownpart_to_tensorendfalse){
|
||||||
|
endian=false;
|
||||||
|
char *input="[3,_]"\
|
||||||
|
"((1.21,10,0.23,21)"\
|
||||||
|
"((1.21,10,0.23,.1)"\
|
||||||
|
"(.56,124,22.5,1.44))";
|
||||||
|
|
||||||
|
tensor_TYPE_FLOAT *t=parseInput_withDim_to_tensor_TYPE_FLOAT(input);
|
||||||
|
|
||||||
|
print_tensor_msg_TYPE_FLOAT(t," tensor from input" );
|
||||||
|
|
||||||
|
free_tensor_TYPE_FLOAT(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "ftest/ftest.h"
|
#include "ftest/ftest.h"
|
||||||
#include "tools_t/tools_t.h"
|
#include "tools_t/tools_t.h"
|
||||||
|
|
||||||
#define INFINITY -8
|
#define ININITY_REPS -8
|
||||||
#define INITSTATE -1
|
#define INITSTATE -1
|
||||||
#define DONOTHING 0
|
#define DONOTHING 0
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ struct func_mock_info_struct{
|
|||||||
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
|
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
|
||||||
long call;/* increment when call (try to executed) and 0 if not : init value */
|
long call;/* increment when call (try to executed) and 0 if not : init value */
|
||||||
long failed_call;/* increment when condition not fill and 0 if not : init value */
|
long failed_call;/* increment when condition not fill and 0 if not : init value */
|
||||||
long init_times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
long init_times_left;/* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */
|
||||||
long times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
long times_left;/* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */
|
||||||
struct func_mock_info_struct *next;
|
struct func_mock_info_struct *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ extern struct list_base_fmock *g_list_base_fmock;
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int expect_call; /* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */\
|
int expect_call; /* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */\
|
||||||
long init_times_left; /* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */\
|
long init_times_left; /* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */\
|
||||||
long times_left; /* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */\
|
long times_left; /* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */\
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ extern struct list_base_fmock *g_list_base_fmock;
|
|||||||
PRINT_HK_C(RED_K,tab_hk_f[hk_TR]," 1 argument check failed from %s \n",__func__); \
|
PRINT_HK_C(RED_K,tab_hk_f[hk_TR]," 1 argument check failed from %s \n",__func__); \
|
||||||
}*/\
|
}*/\
|
||||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
||||||
if (((tmp_mock->info_mock)->times_left <= INFINITY) || ((tmp_mock->info_mock)->times_left > 0)){\
|
if (((tmp_mock->info_mock)->times_left <= ININITY_REPS) || ((tmp_mock->info_mock)->times_left > 0)){\
|
||||||
--((tmp_mock->info_mock)->times_left);\
|
--((tmp_mock->info_mock)->times_left);\
|
||||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'v',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'v',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
||||||
if(1 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
if(1 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
||||||
|
|||||||
@@ -118,6 +118,16 @@ GENERATE_ALL(TYPE_DOUBLE)
|
|||||||
GENERATE_ALL(TYPE_L_DOUBLE)
|
GENERATE_ALL(TYPE_L_DOUBLE)
|
||||||
GENERATE_ALL(TYPE_STRING)
|
GENERATE_ALL(TYPE_STRING)
|
||||||
|
|
||||||
|
/* strto_type */
|
||||||
|
|
||||||
|
int strto_TYPE_INT(char *str, char **endptr);
|
||||||
|
unsigned int strto_TYPE_U_INT(char *str, char **endptr);
|
||||||
|
long int strto_TYPE_L_INT(char *str, char **endptr);
|
||||||
|
unsigned long int strto_TYPE_U_L_INT(char *str, char **endptr);
|
||||||
|
size_t strto_TYPE_SIZE_T(char *str, char **endptr);
|
||||||
|
float strto_TYPE_FLOAT(char *str, char **endptr);
|
||||||
|
double strto_TYPE_DOUBLE(char *str, char **endptr);
|
||||||
|
long double strto_TYPE_L_DOUBLE(char *str, char **endptr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* time calucl
|
* time calucl
|
||||||
|
|||||||
Binary file not shown.
@@ -169,7 +169,7 @@ EXPECT_MOCK_CALL(int,f_mock, (),false, 2) {
|
|||||||
EXPECT_MOCK_CALL(int,f_mock, (),1, 1) { EXPECT_EQ_IN_MOCKF(23,21,f_mock);return 10;}
|
EXPECT_MOCK_CALL(int,f_mock, (),1, 1) { EXPECT_EQ_IN_MOCKF(23,21,f_mock);return 10;}
|
||||||
|
|
||||||
EXPECT_MOCK_CALL(int,f_mock, (),1==2||2<1, 1) {return 18;}
|
EXPECT_MOCK_CALL(int,f_mock, (),1==2||2<1, 1) {return 18;}
|
||||||
EXPECT_MOCK_CALL(int,f_mock, (),1, INFINITY) {return -18;}
|
EXPECT_MOCK_CALL(int,f_mock, (),1, ININITY_REPS) {return -18;}
|
||||||
|
|
||||||
|
|
||||||
TEST(mockf1){
|
TEST(mockf1){
|
||||||
@@ -238,7 +238,7 @@ EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a==b), 1){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (1), INFINITY){
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (1), ININITY_REPS){
|
||||||
return a*b;
|
return a*b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "ftest/ftest.h"
|
#include "ftest/ftest.h"
|
||||||
#include "tools_t/tools_t.h"
|
#include "tools_t/tools_t.h"
|
||||||
|
|
||||||
#define INFINITY -8
|
#define ININITY_REPS -8
|
||||||
#define INITSTATE -1
|
#define INITSTATE -1
|
||||||
#define DONOTHING 0
|
#define DONOTHING 0
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ struct func_mock_info_struct{
|
|||||||
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
|
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
|
||||||
long call;/* increment when call (try to executed) and 0 if not : init value */
|
long call;/* increment when call (try to executed) and 0 if not : init value */
|
||||||
long failed_call;/* increment when condition not fill and 0 if not : init value */
|
long failed_call;/* increment when condition not fill and 0 if not : init value */
|
||||||
long init_times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
long init_times_left;/* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */
|
||||||
long times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
long times_left;/* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */
|
||||||
struct func_mock_info_struct *next;
|
struct func_mock_info_struct *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ extern struct list_base_fmock *g_list_base_fmock;
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int expect_call; /* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */\
|
int expect_call; /* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */\
|
||||||
long init_times_left; /* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */\
|
long init_times_left; /* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */\
|
||||||
long times_left; /* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */\
|
long times_left; /* DONOTHING do nothing (pass to -> next), ININITY_REPS every time; INITSTATE init; > 0 execute and decrement */\
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ extern struct list_base_fmock *g_list_base_fmock;
|
|||||||
PRINT_HK_C(RED_K,tab_hk_f[hk_TR]," 1 argument check failed from %s \n",__func__); \
|
PRINT_HK_C(RED_K,tab_hk_f[hk_TR]," 1 argument check failed from %s \n",__func__); \
|
||||||
}*/\
|
}*/\
|
||||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
||||||
if (((tmp_mock->info_mock)->times_left <= INFINITY) || ((tmp_mock->info_mock)->times_left > 0)){\
|
if (((tmp_mock->info_mock)->times_left <= ININITY_REPS) || ((tmp_mock->info_mock)->times_left > 0)){\
|
||||||
--((tmp_mock->info_mock)->times_left);\
|
--((tmp_mock->info_mock)->times_left);\
|
||||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'v',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'v',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
|
||||||
if(1 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
if(1 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ char * number_call_translate(long nb){
|
|||||||
if(nb>1) sprintf(ret," be called %ld times",nb);
|
if(nb>1) sprintf(ret," be called %ld times",nb);
|
||||||
else if(nb == 1) sprintf(ret," be called once");
|
else if(nb == 1) sprintf(ret," be called once");
|
||||||
else if(nb == 0 ) sprintf(ret," not to be executed");
|
else if(nb == 0 ) sprintf(ret," not to be executed");
|
||||||
else if(nb==INFINITY) sprintf(ret," be called forever");
|
else if(nb==ININITY_REPS) sprintf(ret," be called forever");
|
||||||
else if(nb==INITSTATE) sprintf(ret," not expected");
|
else if(nb==INITSTATE) sprintf(ret," not expected");
|
||||||
else sprintf(ret," nothing! it's negative:%ld", nb);
|
else sprintf(ret," nothing! it's negative:%ld", nb);
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,16 @@ GENERATE_ALL(TYPE_DOUBLE)
|
|||||||
GENERATE_ALL(TYPE_L_DOUBLE)
|
GENERATE_ALL(TYPE_L_DOUBLE)
|
||||||
GENERATE_ALL(TYPE_STRING)
|
GENERATE_ALL(TYPE_STRING)
|
||||||
|
|
||||||
|
/* strto_type */
|
||||||
|
|
||||||
|
int strto_TYPE_INT(char *str, char **endptr);
|
||||||
|
unsigned int strto_TYPE_U_INT(char *str, char **endptr);
|
||||||
|
long int strto_TYPE_L_INT(char *str, char **endptr);
|
||||||
|
unsigned long int strto_TYPE_U_L_INT(char *str, char **endptr);
|
||||||
|
size_t strto_TYPE_SIZE_T(char *str, char **endptr);
|
||||||
|
float strto_TYPE_FLOAT(char *str, char **endptr);
|
||||||
|
double strto_TYPE_DOUBLE(char *str, char **endptr);
|
||||||
|
long double strto_TYPE_L_DOUBLE(char *str, char **endptr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* time calucl
|
* time calucl
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_s
|
|||||||
#define GEN_TO_STR_N(type,size,format) \
|
#define GEN_TO_STR_N(type,size,format) \
|
||||||
TYPE_STRING type##_TO_STR(type var){ \
|
TYPE_STRING type##_TO_STR(type var){ \
|
||||||
char *ret = malloc(size); \
|
char *ret = malloc(size); \
|
||||||
int szret = sprintf(ret,format,var); \
|
/*int szret = */sprintf(ret,format,var); \
|
||||||
ret[szret]='\0'; \
|
/*ret[szret]='\0'*//*no need , already by default */; \
|
||||||
return ret; \
|
return ret; \
|
||||||
}\
|
}\
|
||||||
|
|
||||||
@@ -197,6 +197,33 @@ GENERATE_FUNCTION_ALL(TYPE_DOUBLE)
|
|||||||
GENERATE_FUNCTION_ALL(TYPE_L_DOUBLE)
|
GENERATE_FUNCTION_ALL(TYPE_L_DOUBLE)
|
||||||
GENERATE_FUNCTION_ALL(TYPE_STRING)
|
GENERATE_FUNCTION_ALL(TYPE_STRING)
|
||||||
|
|
||||||
|
/* strto_type */
|
||||||
|
|
||||||
|
int strto_TYPE_INT(char *str, char **endptr){
|
||||||
|
return (int)strtol(str,endptr,10);
|
||||||
|
}
|
||||||
|
unsigned int strto_TYPE_U_INT(char *str, char **endptr){
|
||||||
|
return (unsigned int)strtoul(str,endptr,10);
|
||||||
|
}
|
||||||
|
long int strto_TYPE_L_INT(char *str, char **endptr){
|
||||||
|
return strtol(str,endptr,10);
|
||||||
|
}
|
||||||
|
unsigned long int strto_TYPE_U_L_INT(char *str, char **endptr){
|
||||||
|
return strtoul(str,endptr,10);
|
||||||
|
}
|
||||||
|
size_t strto_TYPE_SIZE_T(char *str, char **endptr){
|
||||||
|
return strtoul(str,endptr,10);
|
||||||
|
}
|
||||||
|
float strto_TYPE_FLOAT(char *str, char **endptr){
|
||||||
|
return strtof(str,endptr);
|
||||||
|
}
|
||||||
|
double strto_TYPE_DOUBLE(char *str, char **endptr){
|
||||||
|
return strtod(str,endptr);
|
||||||
|
}
|
||||||
|
long double strto_TYPE_L_DOUBLE(char *str, char **endptr){
|
||||||
|
return strtold(str,endptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* time section
|
* time section
|
||||||
|
|||||||
Reference in New Issue
Block a user