From 5a4946c744dce9f9db26c93cad63cf6eafcbd1c5 Mon Sep 17 00:00:00 2001 From: Elias Kohout Date: Sun, 3 Sep 2023 10:12:41 +0200 Subject: [PATCH] Put dtype definition in separate file. --- dtype.h | 23 +++++++++++++++++++++++ tensor.h | 25 +++++-------------------- 2 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 dtype.h diff --git a/dtype.h b/dtype.h new file mode 100644 index 0000000..96848c1 --- /dev/null +++ b/dtype.h @@ -0,0 +1,23 @@ +#ifndef _DTYPE_H_INCLUDED_ +#define _DTYPE_H_INCLUDED_ + + +/* 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 pruint8_t function */ +#define DTYPE_RAND(max) ((float) rand() / RAND_MAX * (max)) +#define DTYPE_PRINT(a) (printf(" %4.1f ", (a))) + + +#endif // _DTYPE_H_INCLUDED_ diff --git a/tensor.h b/tensor.h index 25dcb1b..fe9827f 100644 --- a/tensor.h +++ b/tensor.h @@ -1,31 +1,16 @@ -#ifndef TENSOR_H_INCLUDED -#define TENSOR_H_INCLUDED +#ifndef _TENSOR_H_INCLUDED_ +#define _TENSOR_H_INCLUDED_ + +#include "dtype.h" #include #include -#include #include +#include #include #include #include -/* 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 pruint8_t function */ -#define DTYPE_RAND(max) ((float) rand() / RAND_MAX * (max)) -#define DTYPE_PRINT(a) (printf(" %4.1f ", (a))) - typedef struct _tensor { dtype *elements;