Files
ctensor/tensor.h

51 lines
1.4 KiB
C
Raw Normal View History

2023-09-03 10:12:41 +02:00
#ifndef _TENSOR_H_INCLUDED_
#define _TENSOR_H_INCLUDED_
#include "dtype.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
2023-09-03 10:12:41 +02:00
#include <string.h>
#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>
typedef struct _tensor {
dtype *elements;
2023-05-07 14:38:41 +02:00
uint8_t rank;
uint32_t *size;
uint32_t *stride;
2023-05-07 14:38:41 +02:00
uint32_t num_elem;
} *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-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-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-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-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);
bool tensor_mul_inplace(tensor t1, const tensor t2);
tensor tensor_add(const tensor t1, const tensor t2);
tensor tensor_sub(const tensor t1, const tensor t2);
tensor tensor_mul(const tensor t1, const tensor t2);
2023-02-27 14:45:21 +01:00
void tensor_print(const tensor t);
#endif