C3E: Complex Compute Core Engine v1.0
An engine for handling complex computational tasks
|
Functions for tensor operations in the C3E library. More...
#include <c3e/commons.h>
Go to the source code of this file.
Functions | |
c3e_tensor * | c3e_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_tensor * | c3e_tensor_add (c3e_tensor *left, c3e_tensor *right) |
Adds two tensors element-wise. | |
c3e_tensor * | c3e_tensor_sub (c3e_tensor *left, c3e_tensor *right) |
Subtracts one tensor from another element-wise. | |
c3e_tensor * | c3e_tensor_mul (c3e_tensor *left, c3e_tensor *right) |
Multiplies two tensors element-wise. | |
c3e_tensor * | c3e_tensor_div (c3e_tensor *left, c3e_tensor *right) |
Divides one tensor by another element-wise. | |
c3e_tensor * | c3e_tensor_scale (c3e_tensor *tensor, int x) |
Scales the elements of a tensor by a scalar value. | |
c3e_tensor * | c3e_tensor_exp (c3e_tensor *tensor) |
Applies the exponential function to each element of a tensor. | |
c3e_tensor * | c3e_tensor_normalize (c3e_tensor *tensor) |
Normalizes the elements of a tensor. | |
c3e_tensor * | c3e_tensor_copy (c3e_tensor *tensor) |
Creates a copy of a tensor. | |
c3e_tensor * | c3e_tensor_zeros (size_t dsize, uint32_t dims, int rows, int cols) |
Creates a tensor filled with zeros. | |
c3e_tensor * | c3e_tensor_ones (size_t dsize, uint32_t dims, int rows, int cols) |
Creates a tensor filled with ones. | |
c3e_tensor * | c3e_tensor_fill (size_t dsize, uint32_t dims, int rows, int cols, c3e_number value) |
Creates a tensor filled with a specific value. | |
c3e_tensor * | c3e_tensor_random (size_t dsize, uint32_t dims, int rows, int cols, int seed) |
Creates a tensor with random values within a range. | |
c3e_tensor * | c3e_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. | |
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.
c3e_tensor * c3e_tensor_add | ( | c3e_tensor * | left, |
c3e_tensor * | right | ||
) |
This function performs element-wise addition of two tensors with the same dimensions.
left | Pointer to the first tensor. |
right | Pointer to the second tensor. |
c3e_tensor
structure containing the result of the addition. 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.
tensor | Pointer to the first tensor. |
subject | Pointer to the second tensor. |
true
if the tensors are element-wise close; false
otherwise. c3e_tensor * c3e_tensor_copy | ( | c3e_tensor * | tensor | ) |
This function duplicates the given tensor, creating a new tensor with the same data and dimensions.
tensor | Pointer to the tensor to be copied. |
c3e_tensor
structure that is a copy of the original tensor. c3e_tensor * c3e_tensor_div | ( | c3e_tensor * | left, |
c3e_tensor * | right | ||
) |
This function performs element-wise division of two tensors with the same dimensions.
left | Pointer to the tensor to be divided. |
right | Pointer to the tensor to divide by. |
c3e_tensor
structure containing the result of the division. bool c3e_tensor_equals | ( | c3e_tensor * | tensor, |
c3e_tensor * | subject | ||
) |
This function compares two tensors to determine if they are element-wise equal.
tensor | Pointer to the first tensor. |
subject | Pointer to the second tensor. |
true
if the tensors are equal; false
otherwise. c3e_tensor * c3e_tensor_exp | ( | c3e_tensor * | tensor | ) |
This function computes the exponential of every element in the tensor.
tensor | Pointer to the tensor to be transformed. |
c3e_tensor
structure containing the exponential-transformed tensor. 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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
rows | The number of rows in each matrix. |
cols | The number of columns in each matrix. |
value | The value to fill the tensor with. |
c3e_tensor
structure filled with the specified value. 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.
tensor | Pointer to the c3e_tensor structure to be freed. |
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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
matrices | Array of matrices representing the tensor data. |
data | Pointer to a vector containing the tensor data. |
c3e_tensor
structure. c3e_tensor * c3e_tensor_mul | ( | c3e_tensor * | left, |
c3e_tensor * | right | ||
) |
This function performs element-wise multiplication of two tensors with the same dimensions.
left | Pointer to the first tensor. |
right | Pointer to the second tensor. |
c3e_tensor
structure containing the result of the multiplication. c3e_tensor * c3e_tensor_normalize | ( | c3e_tensor * | tensor | ) |
This function normalizes the tensor elements, typically scaling them to a specific range or unit length.
tensor | Pointer to the tensor to be normalized. |
c3e_tensor
structure containing the normalized tensor. 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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
rows | The number of rows in each matrix. |
cols | The number of columns in each matrix. |
c3e_tensor
structure filled with ones. 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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
rows | The number of rows in each matrix. |
cols | The number of columns in each matrix. |
seed | The seed value for the random number generator. |
min | The minimum value of the random range. |
max | The maximum value of the random range. |
c3e_tensor
structure filled with random values. 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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
rows | The number of rows in each matrix. |
cols | The number of columns in each matrix. |
seed | The seed value for the random number generator. |
min | The minimum value of the random range. |
max | The maximum value of the random range. |
c3e_tensor
structure filled with random values within the specified range. c3e_tensor * c3e_tensor_scale | ( | c3e_tensor * | tensor, |
int | x | ||
) |
This function multiplies every element of the tensor by a specified scalar value.
tensor | Pointer to the tensor to be scaled. |
x | The scalar value by which to scale the tensor. |
c3e_tensor
structure containing the scaled tensor. c3e_tensor * c3e_tensor_sub | ( | c3e_tensor * | left, |
c3e_tensor * | right | ||
) |
This function performs element-wise subtraction of two tensors with the same dimensions.
left | Pointer to the tensor to be subtracted from. |
right | Pointer to the tensor to subtract. |
c3e_tensor
structure containing the result of the subtraction. 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.
dsize | The size of the data vector. |
dims | The number of dimensions in the tensor. |
rows | The number of rows in each matrix. |
cols | The number of columns in each matrix. |
c3e_tensor
structure filled with zeros.