Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f7de1c1af9 | |||
| abeb649386 | |||
| e4c2f1b950 |
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../onefileheader_test
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$#" -le 1 ] ; then
|
||||||
|
echo "Usage: $0 fileExec fileSrc"
|
||||||
|
echo "for example: $0 xtest tesTensor.c" >&2
|
||||||
|
else
|
||||||
|
gcc -o $1 $2 -W -I../link_repo_ytest
|
||||||
|
fi
|
||||||
@@ -15,15 +15,16 @@
|
|||||||
#include "fmock/fmock.h"
|
#include "fmock/fmock.h"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../linktest/y_test_h.h"
|
|
||||||
|
#include "../link_repo_ytest/y_test_h.h"
|
||||||
|
|
||||||
IMPLEMENTATION_FTEST()
|
IMPLEMENTATION_FTEST()
|
||||||
|
|
||||||
|
#include "y_tensor_h.h"
|
||||||
|
|
||||||
//#include "shapeutation_t/shapeutation_t.h"
|
//#include "shapeutation_t/shapeutation_t.h"
|
||||||
//#include "tensor_t/tensor_t.h"
|
//#include "tensor_t/tensor_t.h"
|
||||||
|
|
||||||
#include "y_tensor_h.h"
|
|
||||||
|
|
||||||
#ifndef _IMPLEMENTATION_DIMENSION
|
#ifndef _IMPLEMENTATION_DIMENSION
|
||||||
#define _IMPLEMENTATION_DIMENSION
|
#define _IMPLEMENTATION_DIMENSION
|
||||||
|
|||||||
+2
-358
@@ -1,364 +1,8 @@
|
|||||||
#ifndef __TOOLS_T_C_H__
|
|
||||||
#define __TOOLS_T_C_H__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
|
|
||||||
|
|
||||||
/* to define DEBUG in gcc cli do: gcc -D DEBUG=1 or 0 if need!*/
|
|
||||||
#ifndef DEBUG
|
|
||||||
#define DEBUG 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* F_OUT file (stream) to log*/
|
|
||||||
#ifndef F_OUT
|
|
||||||
#define F_OUT stdout
|
|
||||||
#endif
|
|
||||||
/* F_ERR file (stream) to log*/
|
|
||||||
#ifndef F_ERR
|
|
||||||
#define F_ERR stderr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
#ifndef SECOND
|
|
||||||
#define SECOND 0
|
|
||||||
#endif
|
|
||||||
#ifndef NANOSECOND
|
|
||||||
#define NANOSECOND 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
|
||||||
extern long int PRECISION_TYPE_FLOAT ;
|
|
||||||
extern long int PRECISION_TYPE_DOUBLE ;
|
|
||||||
extern long int PRECISION_TYPE_L_DOUBLE ;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*void get_cursor_position(int *col, int *rows);*/
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
|
|
||||||
#define debug_print(fmt, ...) \
|
|
||||||
do { /*if (DEBUG)*/ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
|
||||||
|
|
||||||
#define PRINT_DEBUG_(fmt, ...) \
|
|
||||||
do { /*if (DEBUG)*/ fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
|
||||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
|
||||||
|
|
||||||
#else
|
|
||||||
#define debug_print(fmt, ...) {}
|
|
||||||
|
|
||||||
#define PRINT_DEBUG_(fmt, ...) {}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define error_print(fmt, ...) \
|
|
||||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
|
||||||
__LINE__, __func__, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define PRINT_ERROR(fmt, ...) \
|
|
||||||
fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
|
||||||
__LINE__, __func__, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define PRINT_LOC_T(fmt, ...) \
|
|
||||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
|
||||||
__LINE__, __func__, __VA_ARGS__);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TYPE_CHAR char
|
|
||||||
#define TYPE_U_CHAR unsigned char
|
|
||||||
#define TYPE_INT int
|
|
||||||
#define TYPE_U_INT unsigned int
|
|
||||||
#define TYPE_L_INT long int
|
|
||||||
#define TYPE_U_L_INT unsigned long int
|
|
||||||
#define TYPE_SIZE_T size_t
|
|
||||||
#define TYPE_FLOAT float
|
|
||||||
#define TYPE_DOUBLE double
|
|
||||||
#define TYPE_L_DOUBLE long double
|
|
||||||
#define TYPE_STRING char*
|
|
||||||
|
|
||||||
#define FREE(x) { free((x)); (x) = NULL;}
|
|
||||||
|
|
||||||
#define FOREACH(array, array_size, function)\
|
|
||||||
for(size_t _ind = 0; _ind < array_size; ++_ind) function(array[_ind]);
|
|
||||||
|
|
||||||
#define MIN(X, Y) (((Y) < (X)) ? (Y) : (X))
|
|
||||||
#define MAX(X, Y) (((Y) > (X)) ? (Y) : (X))
|
|
||||||
|
|
||||||
#define GENERATE_ALL(type)\
|
|
||||||
int COMPARE_N_##type(const void *,const void*);\
|
|
||||||
void COPY_ARRAY_##type(type* dst, const type* src, size_t array_size);\
|
|
||||||
type MAX_ARRAY_##type(const type *array, size_t array_size);\
|
|
||||||
size_t ARG_MAX_ARRAY_##type(const type *array, size_t array_size);\
|
|
||||||
type MIN_ARRAY_##type(const type *array, size_t array_size);\
|
|
||||||
size_t ARG_MIN_ARRAY_##type(const type *array, size_t array_size);\
|
|
||||||
TYPE_STRING type##_TO_STR(type var);\
|
|
||||||
|
|
||||||
|
|
||||||
GENERATE_ALL(TYPE_CHAR)
|
|
||||||
GENERATE_ALL(TYPE_U_CHAR)
|
|
||||||
GENERATE_ALL(TYPE_INT)
|
|
||||||
GENERATE_ALL(TYPE_U_INT)
|
|
||||||
GENERATE_ALL(TYPE_L_INT)
|
|
||||||
GENERATE_ALL(TYPE_U_L_INT)
|
|
||||||
GENERATE_ALL(TYPE_SIZE_T)
|
|
||||||
GENERATE_ALL(TYPE_FLOAT)
|
|
||||||
GENERATE_ALL(TYPE_DOUBLE)
|
|
||||||
GENERATE_ALL(TYPE_L_DOUBLE)
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
|
|
||||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
|
|
||||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*__TOOLS_T_C_H__*/
|
|
||||||
|
|
||||||
/* implementations */
|
|
||||||
|
|
||||||
/* IMPLEMENTATION_TOOLS */
|
|
||||||
|
|
||||||
|
|
||||||
#define POW 17
|
|
||||||
#define MMOD ((1 << (POW)) - 1)
|
|
||||||
#define SUBA 5
|
|
||||||
#define SUBB 8
|
|
||||||
|
|
||||||
|
|
||||||
#define GEN_TO_STR_N(type,size,format) \
|
|
||||||
TYPE_STRING type##_TO_STR(type var){ \
|
|
||||||
char *ret = malloc(size); \
|
|
||||||
/*int szret = */sprintf(ret,format,var); \
|
|
||||||
/*ret[szret]='\0'*//*no need , already by default */; \
|
|
||||||
return ret; \
|
|
||||||
}\
|
|
||||||
|
|
||||||
|
|
||||||
#define GENERATE_FUNCTION_ALL(type)\
|
|
||||||
type MAX_ARRAY_##type(const type *array, size_t size){\
|
|
||||||
if(array == NULL) return 0;\
|
|
||||||
type mx =(type)array[0];\
|
|
||||||
for(size_t i = 0; i < size; ++i)\
|
|
||||||
if(COMPARE_N_##type(&mx,&array[i]) < 0) mx =(type)array[i];\
|
|
||||||
return mx;}\
|
|
||||||
\
|
|
||||||
size_t ARG_MAX_ARRAY_##type(const type *array, size_t size){\
|
|
||||||
if(array == NULL) return 0;\
|
|
||||||
size_t i_mx = 0;\
|
|
||||||
for(size_t i = 0; i < size; ++i)\
|
|
||||||
if(COMPARE_N_##type(&array[i_mx],&array[i]) < 0) i_mx = i;\
|
|
||||||
return i_mx;}\
|
|
||||||
\
|
|
||||||
type MIN_ARRAY_##type(const type *array, size_t size){\
|
|
||||||
if(array == NULL) return 0;\
|
|
||||||
type mn =(type)array[0];\
|
|
||||||
for(size_t i = 0; i < size; ++i)\
|
|
||||||
if(COMPARE_N_##type(&mn,&array[i]) > 0) mn =(type)array[i];\
|
|
||||||
return mn;}\
|
|
||||||
\
|
|
||||||
size_t ARG_MIN_ARRAY_##type(const type *array, size_t size){\
|
|
||||||
if(array == NULL) return 0;\
|
|
||||||
size_t i_mn = 0;\
|
|
||||||
for(size_t i = 0; i < size; ++i)\
|
|
||||||
if(COMPARE_N_##type(&array[i_mn],&array[i]) > 0) i_mn = i;\
|
|
||||||
return i_mn;}\
|
|
||||||
\
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define GENERATE_FUNCTION_NUMERIC(type)\
|
|
||||||
int COMPARE_N_##type(const void *a, const void *b){ \
|
|
||||||
type diff = 0;\
|
|
||||||
if((*(type*)a > *(type*)b)){ \
|
|
||||||
diff =(*(type*)a - *(type*)b) * PRECISION_##type; \
|
|
||||||
/*char *str_diff = type##_TO_STR(diff), *str_a = type##_TO_STR(*(type*)a), *str_b = type##_TO_STR(*(type*)b);\
|
|
||||||
PRINT_DEBUG_(" diff = %s a=%s b=%s PRECISION : %ld\n",str_diff, str_a, str_b, PRECISION_##type);\
|
|
||||||
free(str_diff); free(str_a); free(str_b);\
|
|
||||||
*/ \
|
|
||||||
if(diff >= 1) return 1;\
|
|
||||||
return 0;\
|
|
||||||
}else{\
|
|
||||||
diff =(*(type*)b - *(type*)a) * PRECISION_##type; \
|
|
||||||
/*char *str_diff = type##_TO_STR(diff), *str_a = type##_TO_STR(*(type*)a), *str_b = type##_TO_STR(*(type*)b);\
|
|
||||||
PRINT_DEBUG_(" diff = %s a=%s b=%s PRECISION : %ld\n",str_diff, str_a, str_b, PRECISION_##type);\
|
|
||||||
free(str_diff); free(str_a); free(str_b);\
|
|
||||||
*/\
|
|
||||||
if(diff >= 1) return -1;\
|
|
||||||
return 0;\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
/*if (diff <= -1) return -1; \
|
|
||||||
if (diff >= 1) return 1; \
|
|
||||||
return 0; \
|
|
||||||
*/\
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
void COPY_ARRAY_##type(type *dst, const type *src, size_t size){ \
|
|
||||||
for(size_t i = 0; i < size; ++i) dst[i]=src[i]; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef IMPLEMENTATION_TOOLS
|
|
||||||
#define IMPLEMENTATION_TOOLS()\
|
|
||||||
\
|
|
||||||
GEN_TO_STR_N(TYPE_CHAR,2,"%c")\
|
|
||||||
GEN_TO_STR_N(TYPE_U_CHAR,2,"%c")\
|
|
||||||
GEN_TO_STR_N(TYPE_INT,22,"%d")\
|
|
||||||
GEN_TO_STR_N(TYPE_U_INT,22,"%u")\
|
|
||||||
GEN_TO_STR_N(TYPE_L_INT,22,"%ld")\
|
|
||||||
GEN_TO_STR_N(TYPE_U_L_INT,22,"%lu")\
|
|
||||||
GEN_TO_STR_N(TYPE_SIZE_T,22,"%lu")\
|
|
||||||
GEN_TO_STR_N(TYPE_FLOAT,128,"%.10f")\
|
|
||||||
GEN_TO_STR_N(TYPE_DOUBLE,256,"%.30lf")\
|
|
||||||
GEN_TO_STR_N(TYPE_L_DOUBLE,256,"%.30Lf")\
|
|
||||||
\
|
|
||||||
TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){\
|
|
||||||
return var;\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
long int PRECISION_TYPE_CHAR = 1;\
|
|
||||||
long int PRECISION_TYPE_U_CHAR = 1;\
|
|
||||||
long int PRECISION_TYPE_INT = 1;\
|
|
||||||
long int PRECISION_TYPE_U_INT = 1;\
|
|
||||||
long int PRECISION_TYPE_L_INT = 1;\
|
|
||||||
long int PRECISION_TYPE_U_L_INT = 1;\
|
|
||||||
long int PRECISION_TYPE_SIZE_T = 1;\
|
|
||||||
\
|
|
||||||
long int PRECISION_TYPE_FLOAT = 100000000;\
|
|
||||||
/*long int PRECISION_TYPE_FLOAT = 100000;\
|
|
||||||
*/long int PRECISION_TYPE_DOUBLE = 100000000000;\
|
|
||||||
long int PRECISION_TYPE_L_DOUBLE = 100000000000000;\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
int \
|
|
||||||
COMPARE_N_TYPE_STRING(const void *a,const void* b)\
|
|
||||||
{\
|
|
||||||
char **aa=(char**)a;\
|
|
||||||
char **bb=(char**)b;\
|
|
||||||
PRINT_DEBUG_("a=%s, b=%s\n",*aa, *bb);\
|
|
||||||
return strcmp(*aa,*bb);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
void COPY_ARRAY_TYPE_STRING(char** dst, const char** src, size_t array_size)\
|
|
||||||
{\
|
|
||||||
for(size_t i = 0; i < array_size; ++i) strcpy(dst[i],src[i]);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_CHAR)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_CHAR)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_INT)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_INT)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_L_INT)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_L_INT)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_SIZE_T)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_FLOAT)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_DOUBLE)\
|
|
||||||
GENERATE_FUNCTION_NUMERIC(TYPE_L_DOUBLE)\
|
|
||||||
\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_CHAR)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_U_CHAR)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_INT)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_U_INT)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_L_INT)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_U_L_INT)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_SIZE_T)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_FLOAT)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_DOUBLE)\
|
|
||||||
GENERATE_FUNCTION_ALL(TYPE_L_DOUBLE)\
|
|
||||||
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\
|
|
||||||
*/\
|
|
||||||
\
|
|
||||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start){\
|
|
||||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
|
||||||
return (time_stop.tv_sec - time_start.tv_sec) + 1.0e-9 * (time_stop.tv_nsec - time_start.tv_nsec);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start){\
|
|
||||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
|
||||||
return 1.0e3 * (time_stop.tv_sec - time_start.tv_sec) + 1.0e-6 * (time_stop.tv_nsec - time_start.tv_nsec);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start){\
|
|
||||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
|
||||||
return 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
|
|
||||||
#endif /* IMPLEMENTATION_TOOLS */
|
|
||||||
|
|
||||||
#ifndef __DIMENSION_T_H__
|
#ifndef __DIMENSION_T_H__
|
||||||
#define __DIMENSION_T_H__
|
#define __DIMENSION_T_H__
|
||||||
|
|
||||||
|
#include "../link_repo_ytest/y_tool_c.h"
|
||||||
|
|
||||||
#include "../list_t/list_t.h"
|
#include "../list_t/list_t.h"
|
||||||
|
|
||||||
struct dimension{
|
struct dimension{
|
||||||
|
|||||||
Reference in New Issue
Block a user