C3E: Complex Compute Core Engine v1.0
An engine for handling complex computational tasks
Loading...
Searching...
No Matches
tensor.h File Reference

Functions for tensor operations in the C3E library. More...

#include <c3e/commons.h>
Include dependency graph for tensor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

c3e_tensorc3e_tensor_init (size_t dsize, uint32_t dims, c3e_matrix **matrices, c3e_vector *data)
 Initializes a tensor with given data and dimensions.
 
void c3e_tensor_free (c3e_tensor *tensor)
 Frees the resources associated with a tensor.
 
c3e_tensorc3e_tensor_add (c3e_tensor *left, c3e_tensor *right)
 Adds two tensors element-wise.
 
c3e_tensorc3e_tensor_sub (c3e_tensor *left, c3e_tensor *right)
 Subtracts one tensor from another element-wise.
 
c3e_tensorc3e_tensor_mul (c3e_tensor *left, c3e_tensor *right)
 Multiplies two tensors element-wise.
 
c3e_tensorc3e_tensor_div (c3e_tensor *left, c3e_tensor *right)
 Divides one tensor by another element-wise.
 
c3e_tensorc3e_tensor_scale (c3e_tensor *tensor, int x)
 Scales the elements of a tensor by a scalar value.
 
c3e_tensorc3e_tensor_exp (c3e_tensor *tensor)
 Applies the exponential function to each element of a tensor.
 
c3e_tensorc3e_tensor_normalize (c3e_tensor *tensor)
 Normalizes the elements of a tensor.
 
c3e_tensorc3e_tensor_copy (c3e_tensor *tensor)
 Creates a copy of a tensor.
 
c3e_tensorc3e_tensor_zeros (size_t dsize, uint32_t dims, int rows, int cols)
 Creates a tensor filled with zeros.
 
c3e_tensorc3e_tensor_ones (size_t dsize, uint32_t dims, int rows, int cols)
 Creates a tensor filled with ones.
 
c3e_tensorc3e_tensor_fill (size_t dsize, uint32_t dims, int rows, int cols, c3e_number value)
 Creates a tensor filled with a specific value.
 
c3e_tensorc3e_tensor_random (size_t dsize, uint32_t dims, int rows, int cols, int seed)
 Creates a tensor with random values within a range.
 
c3e_tensorc3e_tensor_random_bound (size_t dsize, uint32_t dims, int rows, int cols, int seed, c3e_number min, c3e_number max)
 Creates a tensor with random values within a specified range.
 
bool c3e_tensor_equals (c3e_tensor *tensor, c3e_tensor *subject)
 Checks if two tensors are equal.
 
bool c3e_tensor_all_close (c3e_tensor *tensor, c3e_tensor *subject)
 Checks if two tensors are element-wise close within a tolerance.
 

Detailed Description

Author
Nathanne Isip

This file provides functions for creating, manipulating, and performing operations on tensors. Tensors are multi-dimensional arrays of numerical values, generalizing vectors and matrices. The provided functions include tensor initialization, arithmetic operations, and utilities.

Function Documentation

◆ c3e_tensor_add()

c3e_tensor * c3e_tensor_add ( c3e_tensor left,
c3e_tensor right 
)

This function performs element-wise addition of two tensors with the same dimensions.

Parameters
leftPointer to the first tensor.
rightPointer to the second tensor.
Returns
A pointer to a new c3e_tensor structure containing the result of the addition.

◆ c3e_tensor_all_close()

bool c3e_tensor_all_close ( c3e_tensor tensor,
c3e_tensor subject 
)

This function compares two tensors to determine if they are element-wise close within a specified tolerance.

Parameters
tensorPointer to the first tensor.
subjectPointer to the second tensor.
Returns
true if the tensors are element-wise close; false otherwise.

◆ c3e_tensor_copy()

c3e_tensor * c3e_tensor_copy ( c3e_tensor tensor)

This function duplicates the given tensor, creating a new tensor with the same data and dimensions.

Parameters
tensorPointer to the tensor to be copied.
Returns
A pointer to a new c3e_tensor structure that is a copy of the original tensor.

◆ c3e_tensor_div()

c3e_tensor * c3e_tensor_div ( c3e_tensor left,
c3e_tensor right 
)

This function performs element-wise division of two tensors with the same dimensions.

Parameters
leftPointer to the tensor to be divided.
rightPointer to the tensor to divide by.
Returns
A pointer to a new c3e_tensor structure containing the result of the division.

◆ c3e_tensor_equals()

bool c3e_tensor_equals ( c3e_tensor tensor,
c3e_tensor subject 
)

This function compares two tensors to determine if they are element-wise equal.

Parameters
tensorPointer to the first tensor.
subjectPointer to the second tensor.
Returns
true if the tensors are equal; false otherwise.

◆ c3e_tensor_exp()

c3e_tensor * c3e_tensor_exp ( c3e_tensor tensor)

This function computes the exponential of every element in the tensor.

Parameters
tensorPointer to the tensor to be transformed.
Returns
A pointer to a new c3e_tensor structure containing the exponential-transformed tensor.

◆ c3e_tensor_fill()

c3e_tensor * c3e_tensor_fill ( size_t  dsize,
uint32_t  dims,
int  rows,
int  cols,
c3e_number  value 
)

This function creates a tensor of specified dimensions and size, initialized with a given value.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
rowsThe number of rows in each matrix.
colsThe number of columns in each matrix.
valueThe value to fill the tensor with.
Returns
A pointer to the newly created c3e_tensor structure filled with the specified value.

◆ c3e_tensor_free()

void c3e_tensor_free ( c3e_tensor tensor)

This function deallocates memory used by the c3e_tensor structure, including memory for the matrices and vector data.

Parameters
tensorPointer to the c3e_tensor structure to be freed.

◆ c3e_tensor_init()

c3e_tensor * c3e_tensor_init ( size_t  dsize,
uint32_t  dims,
c3e_matrix **  matrices,
c3e_vector data 
)

This function creates a new tensor with the specified number of dimensions and size, initializing it with provided matrices and vector data.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
matricesArray of matrices representing the tensor data.
dataPointer to a vector containing the tensor data.
Returns
A pointer to the newly created c3e_tensor structure.

◆ c3e_tensor_mul()

c3e_tensor * c3e_tensor_mul ( c3e_tensor left,
c3e_tensor right 
)

This function performs element-wise multiplication of two tensors with the same dimensions.

Parameters
leftPointer to the first tensor.
rightPointer to the second tensor.
Returns
A pointer to a new c3e_tensor structure containing the result of the multiplication.

◆ c3e_tensor_normalize()

c3e_tensor * c3e_tensor_normalize ( c3e_tensor tensor)

This function normalizes the tensor elements, typically scaling them to a specific range or unit length.

Parameters
tensorPointer to the tensor to be normalized.
Returns
A pointer to a new c3e_tensor structure containing the normalized tensor.

◆ c3e_tensor_ones()

c3e_tensor * c3e_tensor_ones ( size_t  dsize,
uint32_t  dims,
int  rows,
int  cols 
)

This function creates a tensor of specified dimensions and size, initialized with ones.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
rowsThe number of rows in each matrix.
colsThe number of columns in each matrix.
Returns
A pointer to the newly created c3e_tensor structure filled with ones.

◆ c3e_tensor_random()

c3e_tensor * c3e_tensor_random ( size_t  dsize,
uint32_t  dims,
int  rows,
int  cols,
int  seed 
)

This function generates a tensor with random values within a specified range, using a given seed for randomness.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
rowsThe number of rows in each matrix.
colsThe number of columns in each matrix.
seedThe seed value for the random number generator.
minThe minimum value of the random range.
maxThe maximum value of the random range.
Returns
A pointer to the newly created c3e_tensor structure filled with random values.

◆ c3e_tensor_random_bound()

c3e_tensor * c3e_tensor_random_bound ( size_t  dsize,
uint32_t  dims,
int  rows,
int  cols,
int  seed,
c3e_number  min,
c3e_number  max 
)

This function generates a tensor with random values within a specified range, using a given seed for randomness.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
rowsThe number of rows in each matrix.
colsThe number of columns in each matrix.
seedThe seed value for the random number generator.
minThe minimum value of the random range.
maxThe maximum value of the random range.
Returns
A pointer to the newly created c3e_tensor structure filled with random values within the specified range.

◆ c3e_tensor_scale()

c3e_tensor * c3e_tensor_scale ( c3e_tensor tensor,
int  x 
)

This function multiplies every element of the tensor by a specified scalar value.

Parameters
tensorPointer to the tensor to be scaled.
xThe scalar value by which to scale the tensor.
Returns
A pointer to a new c3e_tensor structure containing the scaled tensor.

◆ c3e_tensor_sub()

c3e_tensor * c3e_tensor_sub ( c3e_tensor left,
c3e_tensor right 
)

This function performs element-wise subtraction of two tensors with the same dimensions.

Parameters
leftPointer to the tensor to be subtracted from.
rightPointer to the tensor to subtract.
Returns
A pointer to a new c3e_tensor structure containing the result of the subtraction.

◆ c3e_tensor_zeros()

c3e_tensor * c3e_tensor_zeros ( size_t  dsize,
uint32_t  dims,
int  rows,
int  cols 
)

This function creates a tensor of specified dimensions and size, initialized with zeros.

Parameters
dsizeThe size of the data vector.
dimsThe number of dimensions in the tensor.
rowsThe number of rows in each matrix.
colsThe number of columns in each matrix.
Returns
A pointer to the newly created c3e_tensor structure filled with zeros.