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

Vector operations and utilities for the C3E library. More...

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

Go to the source code of this file.

Functions

c3e_vectorc3e_vector_init (size_t size)
 Initializes a vector with a specified size.
 
c3e_vectorc3e_vector_create (size_t size, c3e_number *data)
 Creates a new c3e_vector instance with the specified size and data.
 
void c3e_vector_free (c3e_vector *vector)
 Frees the memory allocated for a vector.
 
c3e_number c3e_vector_length (c3e_matrix *matrix, int col)
 Computes the length of a column vector extracted from a matrix.
 
c3e_number c3e_vector_get (c3e_vector *vector, size_t index)
 Retrieves an element from the vector at a specified index.
 
void c3e_vector_set (c3e_vector *vector, size_t index, c3e_number value)
 Sets the value of an element in the vector at a specified index.
 
void c3e_vector_set_elements (c3e_vector *vector, c3e_number *values)
 Sets multiple elements in the vector with specified values.
 
c3e_vectorc3e_vector_add (c3e_vector *vector, c3e_vector *subject)
 Adds two vectors element-wise.
 
c3e_vectorc3e_vector_sub (c3e_vector *vector, c3e_vector *subject)
 Subtracts one vector from another element-wise.
 
c3e_vectorc3e_vector_mul (c3e_vector *vector, c3e_vector *subject)
 Multiplies two vectors element-wise.
 
c3e_vectorc3e_vector_div (c3e_vector *vector, c3e_vector *subject)
 Divides one vector by another element-wise.
 
c3e_vectorc3e_vector_exp (c3e_vector *vector)
 Computes the element-wise exponential of a vector.
 
c3e_vectorc3e_vector_scale (c3e_vector *vector, int x)
 Scales the elements of a vector by a specified factor.
 
c3e_number c3e_vector_sum (c3e_vector *vector)
 Computes the sum of all elements in a vector.
 
c3e_number c3e_vector_norm (c3e_vector *vector)
 Computes the Euclidean norm (magnitude) of a vector.
 
c3e_number c3e_vector_angle (c3e_vector *vector, c3e_vector *subject)
 Calculates the angle between two vectors.
 
c3e_number c3e_vector_cross (c3e_vector *vector, c3e_vector *subject)
 Computes the cross product of two vectors.
 
c3e_number c3e_vector_projection (c3e_vector *vector, c3e_vector *subject)
 Computes the projection of one vector onto another.
 
c3e_number c3e_vector_dot (c3e_vector *vector, c3e_vector *subject)
 Computes the dot product of two vectors.
 
c3e_number c3e_vector_dot_cols (c3e_matrix *matrix, int col1, c3e_matrix *subject, int col2)
 Computes the dot product of two columns in matrices.
 
c3e_vectorc3e_vector_normalize (c3e_vector *vector)
 Normalizes a vector to unit length.
 
c3e_vectorc3e_vector_transform (c3e_vector *vector, c3e_matrix *matrix)
 Transforms a vector by multiplying it with a matrix.
 
c3e_vectorc3e_vector_copy (c3e_vector *vector)
 Creates a copy of a vector.
 
c3e_vectorc3e_vector_zeros (size_t size)
 Creates a vector of zeros.
 
c3e_vectorc3e_vector_ones (size_t size)
 Creates a vector of ones.
 
c3e_vectorc3e_vector_fill (size_t size, c3e_number values)
 Creates a vector filled with a specific value.
 
c3e_vectorc3e_vector_random (size_t size, int seed)
 Creates a vector with random values.
 
c3e_vectorc3e_vector_random_bound (size_t size, int seed, c3e_number min, c3e_number max)
 Creates a vector with random values within a specified range.
 
bool c3e_vector_equals (c3e_vector *vector, c3e_vector *subject)
 Compares two vectors for equality.
 
bool c3e_vector_all_close (c3e_vector *vector, c3e_vector *subject)
 Checks if all elements of one vector are close to another vector's elements within a tolerance.
 
c3e_vectorc3e_vector_arc_sin (c3e_vector *vector)
 Computes the arc sine of each element in the vector.
 
c3e_vectorc3e_vector_arc_sinh (c3e_vector *vector)
 Computes the arc hyperbolic sine of each element in the vector.
 
c3e_vectorc3e_vector_sin (c3e_vector *vector)
 Computes the sine of each element in the vector.
 
c3e_vectorc3e_vector_sinh (c3e_vector *vector)
 Computes the hyperbolic sine of each element in the vector.
 
c3e_vectorc3e_vector_arc_cos (c3e_vector *vector)
 Computes the arc cosine of each element in the vector.
 
c3e_vectorc3e_vector_arc_cosh (c3e_vector *vector)
 Computes the arc hyperbolic cosine of each element in the vector.
 
c3e_vectorc3e_vector_cos (c3e_vector *vector)
 Computes the cosine of each element in the vector.
 
c3e_vectorc3e_vector_cosh (c3e_vector *vector)
 Computes the hyperbolic cosine of each element in the vector.
 
c3e_vectorc3e_vector_arc_tan (c3e_vector *vector)
 Computes the arc tangent of each element in the vector.
 
c3e_vectorc3e_vector_arc_tanh (c3e_vector *vector)
 Computes the arc hyperbolic tangent of each element in the vector.
 
c3e_vectorc3e_vector_tan (c3e_vector *vector)
 Computes the tangent of each element in the vector.
 
c3e_vectorc3e_vector_tanh (c3e_vector *vector)
 Computes the hyperbolic tangent of each element in the vector.
 
c3e_vectorc3e_vector_abs (c3e_vector *vector)
 Computes the absolute value of each element in the vector.
 
c3e_vectorc3e_vector_log (c3e_vector *vector)
 Computes the natural logarithm of each element in the vector.
 
c3e_vectorc3e_vector_log10 (c3e_vector *vector)
 Computes the base-10 logarithm of each element in the vector.
 
c3e_vectorc3e_vector_log2 (c3e_vector *vector)
 Computes the base-2 logarithm of each element in the vector.
 
c3e_vectorc3e_vector_log1p (c3e_vector *vector)
 Computes the natural logarithm of (1 + each element in the vector).
 
c3e_vectorc3e_vector_pow (c3e_vector *vector, c3e_number exp)
 Computes each element of the vector raised to the given power.
 
c3e_vectorc3e_vector_rsqrt (c3e_vector *vector)
 Computes the reciprocal square root of each element in the vector.
 
c3e_vectorc3e_vector_sqrt (c3e_vector *vector)
 Computes the square root of each element in the vector.
 

Detailed Description

Author
Nathanne Isip

This file provides functions for creating and manipulating vectors. Operations include initialization, modification, arithmetic operations, and various vector-specific calculations.

Function Documentation

◆ c3e_vector_abs()

c3e_vector * c3e_vector_abs ( c3e_vector vector)

This function applies the absolute value function to each element of the input vector. The resulting vector contains the absolute values of the original elements.

Parameters
vectorPointer to the input vector on which the absolute value function will be applied.
Returns
Pointer to a new vector containing the absolute values of the input vector elements.

◆ c3e_vector_add()

c3e_vector * c3e_vector_add ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
A pointer to the resulting vector after addition.

◆ c3e_vector_all_close()

bool c3e_vector_all_close ( c3e_vector vector,
c3e_vector subject 
)

Useful for comparing vectors in numerical computations where exact equality is not feasible.

Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
True if all elements are within tolerance, false otherwise.

◆ c3e_vector_angle()

c3e_number c3e_vector_angle ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
The angle between the two vectors in radians.

◆ c3e_vector_arc_cos()

c3e_vector * c3e_vector_arc_cos ( c3e_vector vector)

This function applies the arc cosine function (inverse of cosine) to each element of the input vector. The resulting vector contains the arc cosine values of the original elements.

Parameters
vectorPointer to the input vector on which the arc cosine function will be applied.
Returns
Pointer to a new vector containing the arc cosine values of the input vector elements.

◆ c3e_vector_arc_cosh()

c3e_vector * c3e_vector_arc_cosh ( c3e_vector vector)

This function applies the arc hyperbolic cosine function (inverse of hyperbolic cosine) to each element of the input vector. The resulting vector contains the arc hyperbolic cosine values of the original elements.

Parameters
vectorPointer to the input vector on which the arc hyperbolic cosine function will be applied.
Returns
Pointer to a new vector containing the arc hyperbolic cosine values of the input vector elements.

◆ c3e_vector_arc_sin()

c3e_vector * c3e_vector_arc_sin ( c3e_vector vector)

This function applies the arc sine function (inverse of sine) to each element of the input vector. The resulting vector contains the arc sine values of the original elements.

Parameters
vectorPointer to the input vector on which the arc sine function will be applied.
Returns
Pointer to a new vector containing the arc sine values of the input vector elements.

◆ c3e_vector_arc_sinh()

c3e_vector * c3e_vector_arc_sinh ( c3e_vector vector)

This function applies the arc hyperbolic sine function (inverse of hyperbolic sine) to each element of the input vector. The resulting vector contains the arc hyperbolic sine values of the original elements.

Parameters
vectorPointer to the input vector on which the arc hyperbolic sine function will be applied.
Returns
Pointer to a new vector containing the arc hyperbolic sine values of the input vector elements.

◆ c3e_vector_arc_tan()

c3e_vector * c3e_vector_arc_tan ( c3e_vector vector)

This function applies the arc tangent function (inverse of tangent) to each element of the input vector. The resulting vector contains the arc tangent values of the original elements.

Parameters
vectorPointer to the input vector on which the arc tangent function will be applied.
Returns
Pointer to a new vector containing the arc tangent values of the input vector elements.

◆ c3e_vector_arc_tanh()

c3e_vector * c3e_vector_arc_tanh ( c3e_vector vector)

This function applies the arc hyperbolic tangent function (inverse of hyperbolic tangent) to each element of the input vector. The resulting vector contains the arc hyperbolic tangent values of the original elements.

Parameters
vectorPointer to the input vector on which the arc hyperbolic tangent function will be applied.
Returns
Pointer to a new vector containing the arc hyperbolic tangent values of the input vector elements.

◆ c3e_vector_copy()

c3e_vector * c3e_vector_copy ( c3e_vector vector)
Parameters
vectorA pointer to the vector to be copied.
Returns
A pointer to the newly created copy of the vector.

◆ c3e_vector_cos()

c3e_vector * c3e_vector_cos ( c3e_vector vector)

This function applies the cosine function to each element of the input vector. The resulting vector contains the cosine values of the original elements.

Parameters
vectorPointer to the input vector on which the cosine function will be applied.
Returns
Pointer to a new vector containing the cosine values of the input vector elements.

◆ c3e_vector_cosh()

c3e_vector * c3e_vector_cosh ( c3e_vector vector)

This function applies the hyperbolic cosine function to each element of the input vector. The resulting vector contains the hyperbolic cosine values of the original elements.

Parameters
vectorPointer to the input vector on which the hyperbolic cosine function will be applied.
Returns
Pointer to a new vector containing the hyperbolic cosine values of the input vector elements.

◆ c3e_vector_create()

c3e_vector * c3e_vector_create ( size_t  size,
c3e_number data 
)

This function allocates memory for a new c3e_vector and initializes it with the provided size and data. The data array should contain size elements that are copied into the newly created vector's data array.

Parameters
sizeThe number of elements in the vector.
dataPointer to an array of c3e_number containing the initial values for the vector. The data is copied into the new vector.
Returns
Pointer to the newly created c3e_vector structure, or NULL if memory allocation fails.

◆ c3e_vector_cross()

c3e_number c3e_vector_cross ( c3e_vector vector,
c3e_vector subject 
)

Only valid for 3-dimensional vectors.

Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
The cross product of the two vectors.

◆ c3e_vector_div()

c3e_vector * c3e_vector_div ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the numerator vector.
subjectA pointer to the denominator vector.
Returns
A pointer to the resulting vector after division.

◆ c3e_vector_dot()

c3e_number c3e_vector_dot ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
The dot product of the two vectors.

◆ c3e_vector_dot_cols()

c3e_number c3e_vector_dot_cols ( c3e_matrix matrix,
int  col1,
c3e_matrix subject,
int  col2 
)
Parameters
matrixA pointer to the first matrix.
col1The index of the column in the first matrix.
subjectA pointer to the second matrix.
col2The index of the column in the second matrix.
Returns
The dot product of the two specified columns.

◆ c3e_vector_equals()

bool c3e_vector_equals ( c3e_vector vector,
c3e_vector subject 
)

Determines if two vectors have identical elements.

Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
True if the vectors are equal, false otherwise.

◆ c3e_vector_exp()

c3e_vector * c3e_vector_exp ( c3e_vector vector)
Parameters
vectorA pointer to the vector.
Returns
A pointer to the resulting vector with exponential values.

◆ c3e_vector_fill()

c3e_vector * c3e_vector_fill ( size_t  size,
c3e_number  values 
)
Parameters
sizeThe number of elements in the vector.
valuesThe value to fill each element of the vector.
Returns
A pointer to the newly created vector with all elements set to the specified value.

◆ c3e_vector_free()

void c3e_vector_free ( c3e_vector vector)

Releases the memory occupied by the vector and its elements.

Parameters
vectorA pointer to the vector to be freed.

◆ c3e_vector_get()

c3e_number c3e_vector_get ( c3e_vector vector,
size_t  index 
)
Parameters
vectorA pointer to the vector.
indexThe index of the element to retrieve.
Returns
The value of the element at the specified index.

◆ c3e_vector_init()

c3e_vector * c3e_vector_init ( size_t  size)

Allocates memory for a vector with the given size and initializes its elements to zero.

Parameters
sizeThe number of elements in the vector.
Returns
A pointer to the newly initialized vector.

◆ c3e_vector_length()

c3e_number c3e_vector_length ( c3e_matrix matrix,
int  col 
)

Calculates the Euclidean norm (length) of a column vector from a matrix.

Parameters
matrixThe matrix from which the column vector is extracted.
colThe index of the column to be used as the vector.
Returns
The length of the column vector.

◆ c3e_vector_log()

c3e_vector * c3e_vector_log ( c3e_vector vector)

This function applies the natural logarithm function to each element of the input vector. The resulting vector contains the natural logarithm values of the original elements.

Parameters
vectorPointer to the input vector on which the natural logarithm function will be applied.
Returns
Pointer to a new vector containing the natural logarithm values of the input vector elements.

◆ c3e_vector_log10()

c3e_vector * c3e_vector_log10 ( c3e_vector vector)

This function applies the base-10 logarithm function to each element of the input vector. The resulting vector contains the base-10 logarithm values of the original elements.

Parameters
vectorPointer to the input vector on which the base-10 logarithm function will be applied.
Returns
Pointer to a new vector containing the base-10 logarithm values of the input vector elements.

◆ c3e_vector_log1p()

c3e_vector * c3e_vector_log1p ( c3e_vector vector)

This function applies the natural logarithm function to (1 + each element) of the input vector. The resulting vector contains the natural logarithm values of the modified elements.

Parameters
vectorPointer to the input vector on which the natural logarithm of (1 + element) function will be applied.
Returns
Pointer to a new vector containing the natural logarithm values of the modified input vector elements.

◆ c3e_vector_log2()

c3e_vector * c3e_vector_log2 ( c3e_vector vector)

This function applies the base-2 logarithm function to each element of the input vector. The resulting vector contains the base-2 logarithm values of the original elements.

Parameters
vectorPointer to the input vector on which the base-2 logarithm function will be applied.
Returns
Pointer to a new vector containing the base-2 logarithm values of the input vector elements.

◆ c3e_vector_mul()

c3e_vector * c3e_vector_mul ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector.
Returns
A pointer to the resulting vector after multiplication.

◆ c3e_vector_norm()

c3e_number c3e_vector_norm ( c3e_vector vector)
Parameters
vectorA pointer to the vector.
Returns
The Euclidean norm of the vector.

◆ c3e_vector_normalize()

c3e_vector * c3e_vector_normalize ( c3e_vector vector)
Parameters
vectorA pointer to the vector to be normalized.
Returns
A pointer to the resulting unit vector.

◆ c3e_vector_ones()

c3e_vector * c3e_vector_ones ( size_t  size)
Parameters
sizeThe number of elements in the vector.
Returns
A pointer to the newly created vector with all elements set to one.

◆ c3e_vector_pow()

c3e_vector * c3e_vector_pow ( c3e_vector vector,
c3e_number  exp 
)

This function applies the power function to each element of the input vector, raising each element to the specified exponent.

Parameters
vectorPointer to the input vector on which the power function will be applied.
expThe exponent to which each element of the vector will be raised.
Returns
Pointer to a new vector containing the results of raising each element to the given power.

◆ c3e_vector_projection()

c3e_number c3e_vector_projection ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the vector to be projected.
subjectA pointer to the vector onto which projection is done.
Returns
The scalar projection of the vector onto the subject vector.

◆ c3e_vector_random()

c3e_vector * c3e_vector_random ( size_t  size,
int  seed 
)
Parameters
sizeThe number of elements in the vector.
seedThe seed value for the random number generator.
Returns
A pointer to the newly created vector with random values.

◆ c3e_vector_random_bound()

c3e_vector * c3e_vector_random_bound ( size_t  size,
int  seed,
c3e_number  min,
c3e_number  max 
)
Parameters
sizeThe number of elements in the vector.
seedThe seed value for the random number generator.
minThe minimum value in the range.
maxThe maximum value in the range.
Returns
A pointer to the newly created vector with random values within the specified range.

◆ c3e_vector_rsqrt()

c3e_vector * c3e_vector_rsqrt ( c3e_vector vector)

This function applies the reciprocal square root function (1 / sqrt(x)) to each element of the input vector. The resulting vector contains the reciprocal square root values of the original elements.

Parameters
vectorPointer to the input vector on which the reciprocal square root function will be applied.
Returns
Pointer to a new vector containing the reciprocal square root values of the input vector elements.

◆ c3e_vector_scale()

c3e_vector * c3e_vector_scale ( c3e_vector vector,
int  x 
)
Parameters
vectorA pointer to the vector.
xThe scaling factor.
Returns
A pointer to the resulting scaled vector.

◆ c3e_vector_set()

void c3e_vector_set ( c3e_vector vector,
size_t  index,
c3e_number  value 
)
Parameters
vectorA pointer to the vector.
indexThe index of the element to set.
valueThe value to be assigned to the element at the specified index.

◆ c3e_vector_set_elements()

void c3e_vector_set_elements ( c3e_vector vector,
c3e_number values 
)
Parameters
vectorA pointer to the vector.
valuesAn array of values to set in the vector.

◆ c3e_vector_sin()

c3e_vector * c3e_vector_sin ( c3e_vector vector)

This function applies the sine function to each element of the input vector. The resulting vector contains the sine values of the original elements.

Parameters
vectorPointer to the input vector on which the sine function will be applied.
Returns
Pointer to a new vector containing the sine values of the input vector elements.

◆ c3e_vector_sinh()

c3e_vector * c3e_vector_sinh ( c3e_vector vector)

This function applies the hyperbolic sine function to each element of the input vector. The resulting vector contains the hyperbolic sine values of the original elements.

Parameters
vectorPointer to the input vector on which the hyperbolic sine function will be applied.
Returns
Pointer to a new vector containing the hyperbolic sine values of the input vector elements.

◆ c3e_vector_sqrt()

c3e_vector * c3e_vector_sqrt ( c3e_vector vector)

This function applies the square root function to each element of the input vector. The resulting vector contains the square root values of the original elements.

Parameters
vectorPointer to the input vector on which the square root function will be applied.
Returns
Pointer to a new vector containing the square root values of the input vector elements.

◆ c3e_vector_sub()

c3e_vector * c3e_vector_sub ( c3e_vector vector,
c3e_vector subject 
)
Parameters
vectorA pointer to the first vector.
subjectA pointer to the second vector to be subtracted.
Returns
A pointer to the resulting vector after subtraction.

◆ c3e_vector_sum()

c3e_number c3e_vector_sum ( c3e_vector vector)
Parameters
vectorA pointer to the vector.
Returns
The sum of all elements in the vector.

◆ c3e_vector_tan()

c3e_vector * c3e_vector_tan ( c3e_vector vector)

This function applies the tangent function to each element of the input vector. The resulting vector contains the tangent values of the original elements.

Parameters
vectorPointer to the input vector on which the tangent function will be applied.
Returns
Pointer to a new vector containing the tangent values of the input vector elements.

◆ c3e_vector_tanh()

c3e_vector * c3e_vector_tanh ( c3e_vector vector)

This function applies the hyperbolic tangent function to each element of the input vector. The resulting vector contains the hyperbolic tangent values of the original elements.

Parameters
vectorPointer to the input vector on which the hyperbolic tangent function will be applied.
Returns
Pointer to a new vector containing the hyperbolic tangent values of the input vector elements.

◆ c3e_vector_transform()

c3e_vector * c3e_vector_transform ( c3e_vector vector,
c3e_matrix matrix 
)
Parameters
vectorA pointer to the vector.
matrixA pointer to the matrix used for transformation.
Returns
A pointer to the resulting transformed vector.

◆ c3e_vector_zeros()

c3e_vector * c3e_vector_zeros ( size_t  size)
Parameters
sizeThe number of elements in the vector.
Returns
A pointer to the newly created vector with all elements set to zero.