utilfloat.h (1574B)
1 #include <stdlib.h> 2 3 void prntFlArr(float* a0, int a1){ 4 for(int i = 0; i < a1; i++){ 5 if(i < a1 - 1) printf("%f, ", a0[i]); 6 else printf("%f\n", a0[i]); 7 } 8 } 9 10 float* flArr(int a0){ 11 float* ret = malloc(sizeof(float)*a0); 12 for(int i = 0; i < a0; i++) ret[i] = 0; 13 return ret; 14 } 15 16 float* flRnd(int a0){ 17 float* ret = malloc(sizeof(float)*a0); 18 for(int i = 0; i < a0; i++) ret[i] = 2*((float)rand())/RAND_MAX - 1; 19 return ret; 20 } 21 22 float** wFlArr(int a0, int a1){ 23 float** ret = malloc(sizeof(float*)*a0); 24 for(int i = 0; i < a0; i++) ret[i] = flArr(a1); 25 return ret; 26 } 27 28 float** wFlRnd(int a0, int a1){ 29 float** ret = malloc(sizeof(float*)*a0); 30 for(int i = 0; i < a0; i++) ret[i] = flRnd(a1); 31 return ret; 32 } 33 34 float* cpFlArr(float* a0, int a1){ 35 float* ret = malloc(sizeof(float)*a1); 36 for(int i = 0; i < a1; i++) ret[i] = a0[i]; 37 return ret; 38 } 39 40 void pluseqFlArr(float* a0, float* a1, int a2){ 41 for(int i = 0; i < a2; i++) a0[i] = a0[i] + a1[i]; 42 } 43 44 float* uf_arith(float* aF0, float* aF1, int aI0, int aI1, int aI2){ 45 //array 0, array 1, n rows, n cols, operation 46 float* ret = malloc(sizeof(float)*aI0*aI1); 47 for(int it0 = 0; it0 < aI0*aI1; it0++){ 48 if(aI2 == 0) ret[it0] = aF0[it0] + aF1[it0]; 49 else if(aI2 == 1) ret[it0] = aF0[it0] - aF1[it0]; 50 else if(aI2 == 2) ret[it0] = aF0[it0]*aF1[it0]; 51 else ret[it0] = aF0[it0]/aF1[it0]; 52 } 53 return ret; 54 } 55 56 float* uf_mult(float* aF0, float* aF1, int aI0, int aI1, int aI2){ 57 //array 0, array 1, n row 0, n col 0 = n row 1, n col 1 58 float* ret = malloc(sizeof(float)*aI0*aI2); 59 return ret; 60 }