Put dtype definition in separate file.

This commit is contained in:
2023-09-03 10:12:41 +02:00
parent 42546feae1
commit 5a4946c744
2 changed files with 28 additions and 20 deletions

23
dtype.h Normal file
View File

@@ -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_

View File

@@ -1,31 +1,16 @@
#ifndef TENSOR_H_INCLUDED
#define TENSOR_H_INCLUDED
#ifndef _TENSOR_H_INCLUDED_
#define _TENSOR_H_INCLUDED_
#include "dtype.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
/* 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;