Changed int type to uint_8/uint_32

This commit is contained in:
2023-05-07 14:38:41 +02:00
parent c251786cd4
commit 78623d2e9d
3 changed files with 75 additions and 69 deletions

View File

@@ -1,12 +1,15 @@
#ifndef TENSOR_H_INCLUDED
#define TENSOR_H_INCLUDED
#include <_types/_uint32_t.h>
#include <_types/_uint8_t.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
/* Defining the datatype of the tensor */
typedef float dtype;
@@ -21,43 +24,43 @@ typedef float dtype;
/* one and zero, */
#define DTYPE_ONE 1.0
#define DTYPE_ZERO 0.0
/* and a random and print function */
/* 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;
int rank;
int *size;
int *index_offsets;
int num_elem;
uint8_t rank;
uint32_t *size;
uint32_t *index_offsets;
uint32_t num_elem;
} *tensor;
tensor tensor_new(void);
void tensor_destroy(tensor t);
int tensor_is_empty(const tensor t);
int tensor_is_equal(const tensor t1, const tensor t2);
uint8_t tensor_is_empty(const tensor t);
uint8_t tensor_is_equal(const tensor t1, const tensor t2);
int _tensor_check_size(const int *size, int dim);
int _tensor_set_size(tensor t, const int *size, int dim);
uint8_t _tensor_check_size(const uint32_t *size, uint8_t rank);
uint8_t _tensor_set_size(tensor t, const uint32_t *size, uint8_t rank);
int tensor_set(tensor t, const int *index, dtype val);
dtype tensor_get(const tensor t, const int *index, int *success);
uint8_t tensor_set(tensor t, const uint32_t *index, dtype val);
dtype tensor_get(const tensor t, const uint32_t *index, uint8_t *success);
int tensor_init_one(tensor t, int rank, const int *size);
int tensor_init_zero(tensor t, int rank, const int *size);
int tensor_init_rand(tensor t, int rank, const int *size, dtype max);
int tensor_cpy(tensor t1, const tensor t2);
uint8_t tensor_init_one(tensor t, uint8_t rank, const uint32_t *size);
uint8_t tensor_init_zero(tensor t, uint8_t rank, const uint32_t *size);
uint8_t tensor_init_rand(tensor t, uint8_t rank, const uint32_t *size, dtype max);
uint8_t tensor_cpy(tensor t1, const tensor t2);
void tensor_add_scalar(tensor t, dtype n);
void tensor_sub_scalar(tensor t, dtype n);
void tensor_mul_scalar(tensor t, dtype n);
void tensor_div_scalar(tensor t, dtype n);
int tensor_add_inplace(tensor t1, const tensor t2);
int tensor_sub_inplace(tensor t1, const tensor t2);
uint8_t tensor_add_inplace(tensor t1, const tensor t2);
uint8_t tensor_sub_inplace(tensor t1, const tensor t2);
tensor tensor_add(const tensor t1, const tensor t2);
tensor tensor_sub(const tensor t1, const tensor t2);