Init, Implementation of Create, Destroy, Init and basic get and set functions.

This commit is contained in:
2023-02-24 19:10:32 +01:00
commit 7cce34a3e1
2 changed files with 266 additions and 0 deletions

40
tensor.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef TENSOR_H_INCLUDED
#define TENSOR_H_INCLUDED
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define PRINT_STRING " %4.1f "
typedef float t_type;
typedef struct _tensor {
t_type *elements;
int dimension;
int *size;
int num_elem;
} *tensor;
tensor tensor_new(void);
void tensor_destroy(tensor t);
int tensor_is_empty(tensor t);
int _tensor_check_size(const int *size, int dim);
int _tensor_set_size(tensor t, const int *size, int dim);
int tensor_set(tensor t, const int *index, t_type val);
t_type tensor_get(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);
void tensor_for_each_elem(tensor t, t_type (*func)(t_type));
void tensor_print(tensor t);
#endif