2023-09-03 10:12:41 +02:00
|
|
|
#ifndef _TENSOR_H_INCLUDED_
|
|
|
|
|
#define _TENSOR_H_INCLUDED_
|
|
|
|
|
|
|
|
|
|
#include "dtype.h"
|
2023-02-24 19:10:32 +01:00
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
2023-09-03 10:12:41 +02:00
|
|
|
#include <string.h>
|
2023-03-13 15:45:30 +01:00
|
|
|
#include <assert.h>
|
2023-05-07 14:38:41 +02:00
|
|
|
#include <stdint.h>
|
2023-05-08 17:06:49 +02:00
|
|
|
#include <stdbool.h>
|
2023-02-24 19:10:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _tensor {
|
2023-02-24 20:53:00 +01:00
|
|
|
dtype *elements;
|
2023-05-07 14:38:41 +02:00
|
|
|
uint8_t rank;
|
|
|
|
|
uint32_t *size;
|
2023-09-07 11:54:55 +02:00
|
|
|
uint32_t *stride;
|
2023-05-07 14:38:41 +02:00
|
|
|
uint32_t num_elem;
|
2023-02-24 19:10:32 +01:00
|
|
|
} *tensor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tensor tensor_new(void);
|
|
|
|
|
void tensor_destroy(tensor t);
|
|
|
|
|
|
2023-05-08 17:06:49 +02:00
|
|
|
bool tensor_is_empty(const tensor t);
|
|
|
|
|
bool tensor_is_equal(const tensor t1, const tensor t2);
|
2023-02-24 19:10:32 +01:00
|
|
|
|
2023-09-03 09:45:20 +02:00
|
|
|
bool _tensor_check_size(const uint32_t *size, uint8_t rank);
|
|
|
|
|
bool _tensor_set_size(tensor t, const uint32_t *size, uint8_t rank);
|
2023-02-24 19:10:32 +01:00
|
|
|
|
2023-09-03 09:45:20 +02:00
|
|
|
bool tensor_set(tensor t, const uint32_t *index, dtype val);
|
|
|
|
|
dtype tensor_get(const tensor t, const uint32_t *index, bool *success);
|
2023-02-24 19:10:32 +01:00
|
|
|
|
2023-09-03 09:45:20 +02:00
|
|
|
bool tensor_init_one(tensor t, const uint32_t *size, uint8_t rank);
|
|
|
|
|
bool tensor_init_zero(tensor t, const uint32_t *size, uint8_t rank);
|
|
|
|
|
bool tensor_init_rand(tensor t, const uint32_t *size, uint8_t rank, dtype max);
|
|
|
|
|
bool tensor_cpy(tensor t1, const tensor t2);
|
2023-02-24 19:10:32 +01:00
|
|
|
|
2023-09-03 09:45:20 +02:00
|
|
|
bool tensor_add_inplace(tensor t1, const tensor t2);
|
|
|
|
|
bool tensor_sub_inplace(tensor t1, const tensor t2);
|
2023-09-07 13:45:04 +02:00
|
|
|
bool tensor_mul_inplace(tensor t1, const tensor t2);
|
2023-04-11 20:39:14 +02:00
|
|
|
tensor tensor_add(const tensor t1, const tensor t2);
|
|
|
|
|
tensor tensor_sub(const tensor t1, const tensor t2);
|
2023-09-07 13:45:04 +02:00
|
|
|
tensor tensor_mul(const tensor t1, const tensor t2);
|
2023-02-27 14:45:21 +01:00
|
|
|
|
2023-02-24 19:17:31 +01:00
|
|
|
void tensor_print(const tensor t);
|
2023-02-24 19:10:32 +01:00
|
|
|
|
|
|
|
|
#endif
|