46 #ifndef _TB_NDARRAY_H_ 47 #define _TB_NDARRAY_H_ 52 #ifndef __FUNCTION_NAME__ 53 #ifdef WIN32 //WINDOWS 54 #define __FUNCTION_NAME__ __FUNCTION__ 56 #define __FUNCTION_NAME__ __func__ 62 #if defined(TB_ASSERT_STANDARD) 63 #define ASSERT(c ,msg, ...) assert(c) 64 #elif defined (TB_ASSERT_LOG) 65 #define ASSERT(c, msg, ...) nda_assert(c, #c, __FUNCTION_NAME__ , msg, ##__VA_ARGS__) 66 #elif defined (TB_ASSERT_NONE) 67 #define ASSERT(c, msg, ...) 69 #error Please define an assertion policy. 79 #define TB_TYPE TB_FLOAT 81 #if TB_TYPE == TB_FLOAT 82 typedef float tb_float;
84 typedef double tb_float;
uint8_t nda_shapeCanBroadCast(struct NDShape *shape1, struct NDShape *shape2)
Verifies if two shapes can be broadcasted Broadcast verifications follows numpy rules:
Tensor Shape DO NOT MANUALLY MODIFY ANY DATA ON THIS STRUCTURE. I will find you.
Definition: ndarray_std.h:55
uint64_t rank
Definition: ndarray_std.h:56
struct NDArray * nda_ones(struct NDShape *shape)
Creates an One initialized tensor.
Tensor data structure.
Definition: ndarray_std.h:73
Definition: ndarray.h:124
tb_float nda_get(struct NDArray *array, uint64_t *index)
Returns the value of an array.
struct NDShape * nda_newShapeFromArray(uint64_t rank, uint64_t *dims)
struct NDArray * nda_randomNormal(struct NDShape *shape, float mu, float sig)
Creates an array from a Guassian Distribution.
NDShape * shape
Definition: ndarray_std.h:75
Treats NDShape as a stack to pop elements, does not modify the original shape.
Definition: ndarray_std.h:65
void nda_ShapeStackInit(struct NDShapeStack *stack, struct NDShape *shape)
Unline other factory pattern object, the stack is usually allocated on the stack (in contrast to heap...
struct NDArray * nda_fill(struct NDShape *shape, tb_float value)
Creates an array initialized with one value.
char * nda_shapeToString(struct NDShape *shape)
Generate a string representation of the shape, which can be used for debugging or generating errors.
struct NDShape * nda_copyShape(struct NDShape *shape)
Creates and Allocates a shape with the same properties of the given one.
uint64_t nda_ShapeStackPop(struct NDShapeStack *stack)
Pops the next element in the stack, does not modify the shape but updates the index in the stack.
tb_float nda_vget1D(struct NDArray *array, uint64_t index)
Returns the value of array throughout a 1D index. If the index has a value higher than the original s...
void nda_reshape(struct NDArray *x, struct NDShape *shape)
reshape an ndarray, old shape is freed.
struct NDArray * nda_slice(struct NDArray *array, uint64_t *index)
Returns a slice of an array.
struct NDArray * nda_copy(struct NDArray *x)
copies an existent tensor, memory must be explicitly freed.
uint64_t nda_getTotalSize(struct NDShape *shape)
Calculate the total number of elements in a tensor shape.
void nda_free(struct NDArray *array)
frees an NDArray alongside its shape
NDArrayLocation
Definition: ndarray.h:122
NDShape * shape
Definition: ndarray_std.h:66
struct NDShape * nda_newShape(uint64_t rank,...)
Definition: ndarray.h:123
uint64_t * dims
Definition: ndarray_std.h:57
void nda_debugValue(struct NDArray *tensor)
Prints tensor value to stdout.
struct NDArray * nda_alloc(struct NDShape *shape)
Creates an empty zeroed tensor.
tb_float nda_vget(struct NDArray *array, uint64_t *index, struct NDShape *vshape)
Returns the value of array throughout a virtual shape. The virtual shape has the same size of the ori...
struct NDArray * nda_linspace(tb_float a, tb_float b, uint64_t n)
Return evenly spaced numbers over a specified interval.
uint8_t nda_ShapeStackCanPop(struct NDShapeStack *stack)
Checks if a shape stack can still popped further more.
void nda_debugShape(struct NDShape *shape)
Prints tensor shape to stdout.
struct NDShape * nda_newShapeFromArrayCopy(uint64_t rank, uint64_t *dims)
tb_float nda_get1D(struct NDArray *array, uint64_t index)
Returns the value of an array through 1d Inde.