Added custom data types and modified print function vor higher ranks.

This commit is contained in:
2023-04-11 17:51:01 +02:00
parent 0ef0eeb047
commit 7fa02795a3
2 changed files with 44 additions and 24 deletions

View File

@@ -7,9 +7,23 @@
#include <time.h>
#include <assert.h>
#define PRINT_STRING " %4.1f "
/* Defining the datatype of the tensor */
typedef float dtype;
/* dtype needs to implement add, sub, mul and div, */
#define DTYPE_ADD(a, b) ((a) + (b))
#define DTYPE_SUB(a, b) ((a) - (b))
#define DTYPE_MUL(a, b) ((a) * (b))
#define DTYPE_DIV(a, b) ((a) / (b))
/* equal and not equal,*/
#define DTYPE_EQ(a, b) ((a) == (b))
#define DTYPE_NE(a, b) ((a) != (b))
/* one and zero, */
#define DTYPE_ONE 1.0
#define DTYPE_ZERO 0.0
/* and a random and print function */
#define DTYPE_RAND(max) ((float) rand() / RAND_MAX * (max))
#define DTYPE_PRINT(a) (printf(" %4.1f ", (a)))
typedef struct _tensor {
dtype *elements;
@@ -34,7 +48,7 @@ dtype tensor_get(const tensor t, const int *index, int *success);
int tensor_init_one(tensor t, int dimension, const int *size);
int tensor_init_zero(tensor t, int dimension, const int *size);
int tensor_init_rand(tensor t, int dimension, const int *size, int max);
int tensor_init_rand(tensor t, int dimension, const int *size, dtype max);
int tensor_cpy(tensor t1, const tensor t2);
void tensor_add_scalar(tensor t, dtype n);