openGPMP
Open Source Mathematics Package
Classes | Functions
gpmp::linalg Namespace Reference

Classes

class  DGEMM
 Class for performing matrix multiplication on double type arrays. More...
 
class  IGEMM
 Class for performing matrix multiplication on int type arrays. More...
 
class  SGEMM
 Class for performing matrix multiplication on float type arrays. More...
 
class  Eigen
 Class for computing eigenvalues of a matrix. More...
 
class  LinSys
 Class for solving linear systems and performing matrix operations. More...
 
class  Mtx
 Mtx class offers matrix arithmetic operations. Some methods are element-wise while others make use of grouping and unrolling. More...
 
class  Matrix
 Matrix and Scalar operations. More...
 
struct  mtx
 Matrix struct. More...
 
class  SVD
 
class  Tensor
 Represents a 3D tensor with basic operations. More...
 

Functions

template<typename T >
void vector_add_i8 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector addition for signed 8-bit integers. More...
 
template<typename T >
void vector_add_i16 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector addition for signed 16-bit integers. More...
 
template<typename T >
void vector_add_i32 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector addition for signed 32-bit integers. More...
 
template<typename T >
void vector_add_i64 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector addition for signed 64-bit integers. More...
 
void vector_add (const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2, std::vector< int8_t > &result)
 Performs vector addition for vectors of signed 8-bit integers. More...
 
void vector_add (const std::vector< uint8_t > &vec1, const std::vector< uint8_t > &vec2, std::vector< uint8_t > &result)
 Performs vector addition for vectors of unsigned 8-bit integers. More...
 
void vector_add (const std::vector< int16_t > &vec1, const std::vector< int16_t > &vec2, std::vector< int16_t > &result)
 Performs vector addition for vectors of signed 16-bit integers. More...
 
void vector_add (const std::vector< uint16_t > &vec1, const std::vector< uint16_t > &vec2, std::vector< uint16_t > &result)
 Performs vector addition for vectors of unsigned 16-bit integers. More...
 
void vector_add (const std::vector< int32_t > &vec1, const std::vector< int32_t > &vec2, std::vector< int32_t > &result)
 Performs vector addition for vectors of signed 32-bit integers. More...
 
void vector_add (const std::vector< uint32_t > &vec1, const std::vector< uint32_t > &vec2, std::vector< uint32_t > &result)
 Performs vector addition for vectors of unsigned 32-bit integers. More...
 
void vector_add (const std::vector< int64_t > &vec1, const std::vector< int64_t > &vec2, std::vector< int64_t > &result)
 Performs vector addition for vectors of signed 64-bit integers. More...
 
void vector_add (const std::vector< uint64_t > &vec1, const std::vector< uint64_t > &vec2, std::vector< uint64_t > &result)
 Performs vector addition for vectors of unsigned 64-bit integers. More...
 
template<typename T >
void vector_sub_i8 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector subtraction for signed 8-bit integers. More...
 
template<typename T >
void vector_sub_i16 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector subtraction for signed 16-bit integers. More...
 
template<typename T >
void vector_sub_i32 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector subtraction for signed 32-bit integers. More...
 
template<typename T >
void vector_sub_i64 (const T *data1, const T *data2, T *result_data, size_t size)
 Performs vector subtraction for signed 64-bit integers. More...
 
void vector_sub (const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2, std::vector< int8_t > &result)
 Performs vector subtraction for vectors of signed 8-bit integers. More...
 
void vector_sub (const std::vector< uint8_t > &vec1, const std::vector< uint8_t > &vec2, std::vector< uint8_t > &result)
 Performs vector subtraction for vectors of unsigned 8-bit integers. More...
 
void vector_sub (const std::vector< int16_t > &vec1, const std::vector< int16_t > &vec2, std::vector< int16_t > &result)
 Performs vector subtraction for vectors of signed 16-bit integers. More...
 
void vector_sub (const std::vector< uint16_t > &vec1, const std::vector< uint16_t > &vec2, std::vector< uint16_t > &result)
 Performs vector subtraction for vectors of unsigned 16-bit integers. More...
 
void vector_sub (const std::vector< int32_t > &vec1, const std::vector< int32_t > &vec2, std::vector< int32_t > &result)
 Performs vector subtraction for vectors of signed 32-bit integers. More...
 
void vector_sub (const std::vector< uint32_t > &vec1, const std::vector< uint32_t > &vec2, std::vector< uint32_t > &result)
 Performs vector subtraction for vectors of unsigned 32-bit integers. More...
 
void vector_sub (const std::vector< int64_t > &vec1, const std::vector< int64_t > &vec2, std::vector< int64_t > &result)
 Performs vector subtraction for vectors of signed 64-bit integers. More...
 
void vector_sub (const std::vector< uint64_t > &vec1, const std::vector< uint64_t > &vec2, std::vector< uint64_t > &result)
 Performs vector subtraction for vectors of unsigned 64-bit integers. More...
 
template<typename T >
void scalar_mult_i8 (const T *data, int scalar, T *result_data, size_t size)
 Performs scalar multiplication for signed 8-bit integers. More...
 
template<typename T >
void scalar_mult_i16 (const T *data, int scalar, T *result_data, size_t size)
 Performs scalar multiplication for signed 16-bit integers. More...
 
template<typename T >
void scalar_mult_i32 (const T *data, int scalar, T *result_data, size_t size)
 Performs scalar multiplication for signed 32-bit integers. More...
 
template<typename T >
void scalar_mult_i64 (const T *data, int scalar, T *result_data, size_t size)
 Performs scalar multiplication for signed 64-bit integers. More...
 
void scalar_mult (const std::vector< int8_t > &vec1, int scalar, std::vector< int8_t > &result)
 Performs scalar multiplication for vectors of signed 8-bit integers. More...
 
void scalar_mult (const std::vector< uint8_t > &vec1, int scalar, std::vector< uint8_t > &result)
 Performs scalar multiplication for vectors of unsigned 8-bit integers. More...
 
void scalar_mult (const std::vector< int16_t > &vec1, int scalar, std::vector< int16_t > &result)
 Performs scalar multiplication for vectors of signed 16-bit integers. More...
 
void scalar_mult (const std::vector< uint16_t > &vec1, int scalar, std::vector< uint16_t > &result)
 Performs scalar multiplication for vectors of unsigned 16-bit integers. More...
 
void scalar_mult (const std::vector< int32_t > &vec1, int scalar, std::vector< int32_t > &result)
 Performs scalar multiplication for vectors of signed 32-bit integers. More...
 
void scalar_mult (const std::vector< uint32_t > &vec1, int scalar, std::vector< uint32_t > &result)
 Performs scalar multiplication for vectors of unsigned 32-bit integers. More...
 
void scalar_mult (const std::vector< int64_t > &vec1, int scalar, std::vector< int64_t > &result)
 Performs scalar multiplication for vectors of signed 64-bit integers. More...
 
void scalar_mult (const std::vector< uint64_t > &vec1, int scalar, std::vector< uint64_t > &result)
 Performs scalar multiplication for vectors of unsigned 64-bit integers. More...
 
template<typename T >
dot_product_i8 (const T *vec1, const T *vec2, size_t size)
 Computes the dot product for signed 8-bit integer vectors. More...
 
template<typename T >
dot_product_i16 (const T *vec1, const T *vec2, size_t size)
 Computes the dot product for signed 16-bit integer vectors. More...
 
template<typename T >
dot_product_i32 (const T *vec1, const T *vec2, size_t size)
 Computes the dot product for signed 32-bit integer vectors. More...
 
template<typename T >
dot_product_i64 (const T *vec1, const T *vec2, size_t size)
 Computes the dot product for signed 64-bit integer vectors. More...
 
int dot_product (const std::vector< int8_t > &vec1, const std::vector< int8_t > &vec2)
 Computes the dot product for vectors of signed 8-bit integers. More...
 
int dot_product (const std::vector< uint8_t > &vec1, const std::vector< uint8_t > &vec2)
 Computes the dot product for vectors of unsigned 8-bit integers. More...
 
int dot_product (const std::vector< int16_t > &vec1, const std::vector< int16_t > &vec2)
 Computes the dot product for vectors of signed 16-bit integers. More...
 
int dot_product (const std::vector< uint16_t > &vec1, const std::vector< uint16_t > &vec2)
 Computes the dot product for vectors of unsigned 16-bit integers. More...
 
int dot_product (const std::vector< int32_t > &vec1, const std::vector< int32_t > &vec2)
 Computes the dot product for vectors of signed 32-bit integers. More...
 
int dot_product (const std::vector< uint32_t > &vec1, const std::vector< uint32_t > &vec2)
 Computes the dot product for vectors of unsigned 32-bit integers. More...
 
int dot_product (const std::vector< int64_t > &vec1, const std::vector< int64_t > &vec2)
 Computes the dot product for vectors of signed 64-bit integers. More...
 
int dot_product (const std::vector< uint64_t > &vec1, const std::vector< uint64_t > &vec2)
 Computes the dot product for vectors of unsigned 64-bit integers. More...
 
void vector_add (const std::vector< double > &vec1, const std::vector< double > &vec2, std::vector< double > &result)
 Performs vector addition for double vectors. More...
 
void vector_sub (const std::vector< double > &vec1, const std::vector< double > &vec2, std::vector< double > &result)
 Performs vector subtraction for double vectors. More...
 
void scalar_mult (const std::vector< double > &vec, double scalar, std::vector< double > &result)
 Performs scalar multiplication for double vectors. More...
 
double dot_product (const std::vector< double > &vec1, const std::vector< double > &vec2)
 Computes the dot product of two double vectors. More...
 
template<typename T >
void std_vector_add (const std::vector< T > &vec1, const std::vector< T > &vec2, std::vector< T > &result)
 Add two vectors element-wise. More...
 
template<typename T >
void std_vector_sub (const std::vector< T > &vec1, const std::vector< T > &vec2, std::vector< T > &result)
 Subtract one vector from another element-wise. More...
 
template<typename T >
void std_scalar_mult (const std::vector< T > &vec, int scalar, std::vector< T > &result)
 Multiply each element of a vector by a scalar. More...
 
template<typename T >
std_dot_product (const std::vector< T > &vec1, const std::vector< T > &vec2)
 Compute the dot product of two vectors. More...
 
void std_cross_product (const std::vector< double > &vec1, const std::vector< double > &vec2, std::vector< double > &result)
 Compute the cross product of two 3D vectors. More...
 
double std_vector_norm (const std::vector< double > &vec)
 Compute the Euclidean norm (magnitude) of a vector. More...
 
void std_vector_normalize (const std::vector< double > &vec, std::vector< double > &result)
 Normalize a vector to have unit length. More...
 
void std_vector_projection (const std::vector< double > &vec, const std::vector< double > &onto_vec, std::vector< double > &result)
 Compute the projection of one vector onto another. More...
 
void std_cross_product (const std::vector< int > &vec1, const std::vector< int > &vec2, std::vector< int > &result)
 Compute the cross product of two 3D vectors of integers. More...
 
double std_vector_norm (const std::vector< int > &vec)
 Compute the Euclidean norm (magnitude) of a vector of integers. More...
 
void std_vector_normalize (const std::vector< int > &vec, std::vector< double > &result)
 Normalize a vector of integers to have unit length. More...
 
void std_vector_projection (const std::vector< int > &vec, const std::vector< int > &onto_vec, std::vector< double > &result)
 Compute the projection of one vector of integers onto another. More...
 

Function Documentation

◆ dot_product() [1/9]

double gpmp::linalg::dot_product ( const std::vector< double > &  vec1,
const std::vector< double > &  vec2 
)

Computes the dot product of two double vectors.

This function computes the dot product of two double vectors

Parameters
vec1The first input vector
vec2The second input vector
Returns
The dot product of the two input vectors

◆ dot_product() [2/9]

int gpmp::linalg::dot_product ( const std::vector< int16_t > &  vec1,
const std::vector< int16_t > &  vec2 
)

Computes the dot product for vectors of signed 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [3/9]

int gpmp::linalg::dot_product ( const std::vector< int32_t > &  vec1,
const std::vector< int32_t > &  vec2 
)

Computes the dot product for vectors of signed 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [4/9]

int gpmp::linalg::dot_product ( const std::vector< int64_t > &  vec1,
const std::vector< int64_t > &  vec2 
)

Computes the dot product for vectors of signed 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [5/9]

int gpmp::linalg::dot_product ( const std::vector< int8_t > &  vec1,
const std::vector< int8_t > &  vec2 
)

Computes the dot product for vectors of signed 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

Referenced by gpmp::ml::SVC::kernel(), gpmp::optim::QuasiNewton::line_search(), and gpmp::optim::QuasiNewton::update_hessian_inverse().

◆ dot_product() [6/9]

int gpmp::linalg::dot_product ( const std::vector< uint16_t > &  vec1,
const std::vector< uint16_t > &  vec2 
)

Computes the dot product for vectors of unsigned 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [7/9]

int gpmp::linalg::dot_product ( const std::vector< uint32_t > &  vec1,
const std::vector< uint32_t > &  vec2 
)

Computes the dot product for vectors of unsigned 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [8/9]

int gpmp::linalg::dot_product ( const std::vector< uint64_t > &  vec1,
const std::vector< uint64_t > &  vec2 
)

Computes the dot product for vectors of unsigned 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product() [9/9]

int gpmp::linalg::dot_product ( const std::vector< uint8_t > &  vec1,
const std::vector< uint8_t > &  vec2 
)

Computes the dot product for vectors of unsigned 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
Returns
Dot product of the input vectors

◆ dot_product_i16()

template<typename T >
T gpmp::linalg::dot_product_i16 ( const T *  vec1,
const T *  vec2,
size_t  size 
)

Computes the dot product for signed 16-bit integer vectors.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
vec1Pointer to the first input vector
vec2Pointer to the second input vector
sizeSize of the input vectors
Returns
Dot product of the input vectors

◆ dot_product_i32()

template<typename T >
T gpmp::linalg::dot_product_i32 ( const T *  vec1,
const T *  vec2,
size_t  size 
)

Computes the dot product for signed 32-bit integer vectors.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
vec1Pointer to the first input vector
vec2Pointer to the second input vector
sizeSize of the input vectors
Returns
Dot product of the input vectors

◆ dot_product_i64()

template<typename T >
T gpmp::linalg::dot_product_i64 ( const T *  vec1,
const T *  vec2,
size_t  size 
)

Computes the dot product for signed 64-bit integer vectors.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
vec1Pointer to the first input vector
vec2Pointer to the second input vector
sizeSize of the input vectors
Returns
Dot product of the input vectors

◆ dot_product_i8()

template<typename T >
T gpmp::linalg::dot_product_i8 ( const T *  vec1,
const T *  vec2,
size_t  size 
)

Computes the dot product for signed 8-bit integer vectors.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
vec1Pointer to the first input vector
vec2Pointer to the second input vector
sizeSize of the input vectors
Returns
Dot product of the input vectors

◆ scalar_mult() [1/9]

void gpmp::linalg::scalar_mult ( const std::vector< double > &  vec,
double  scalar,
std::vector< double > &  result 
)

Performs scalar multiplication for double vectors.

This function multiplies each element of a double vector by a scalar value and stores the result in the provided result vector

Parameters
vecThe input vector
scalarThe scalar value to multiply each element by
resultThe vector where the result of the multiplication will be stored

◆ scalar_mult() [2/9]

void gpmp::linalg::scalar_mult ( const std::vector< int16_t > &  vec1,
int  scalar,
std::vector< int16_t > &  result 
)

Performs scalar multiplication for vectors of signed 16-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [3/9]

void gpmp::linalg::scalar_mult ( const std::vector< int32_t > &  vec1,
int  scalar,
std::vector< int32_t > &  result 
)

Performs scalar multiplication for vectors of signed 32-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [4/9]

void gpmp::linalg::scalar_mult ( const std::vector< int64_t > &  vec1,
int  scalar,
std::vector< int64_t > &  result 
)

Performs scalar multiplication for vectors of signed 64-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [5/9]

void gpmp::linalg::scalar_mult ( const std::vector< int8_t > &  vec1,
int  scalar,
std::vector< int8_t > &  result 
)

Performs scalar multiplication for vectors of signed 8-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [6/9]

void gpmp::linalg::scalar_mult ( const std::vector< uint16_t > &  vec1,
int  scalar,
std::vector< uint16_t > &  result 
)

Performs scalar multiplication for vectors of unsigned 16-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [7/9]

void gpmp::linalg::scalar_mult ( const std::vector< uint32_t > &  vec1,
int  scalar,
std::vector< uint32_t > &  result 
)

Performs scalar multiplication for vectors of unsigned 32-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [8/9]

void gpmp::linalg::scalar_mult ( const std::vector< uint64_t > &  vec1,
int  scalar,
std::vector< uint64_t > &  result 
)

Performs scalar multiplication for vectors of unsigned 64-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult() [9/9]

void gpmp::linalg::scalar_mult ( const std::vector< uint8_t > &  vec1,
int  scalar,
std::vector< uint8_t > &  result 
)

Performs scalar multiplication for vectors of unsigned 8-bit integers.

Parameters
vec1Input vector
scalarScalar value to multiply each element by
resultOutput vector containing the result of the multiplication

◆ scalar_mult_i16()

template<typename T >
void gpmp::linalg::scalar_mult_i16 ( const T *  data,
int  scalar,
T *  result_data,
size_t  size 
)

Performs scalar multiplication for signed 16-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
dataPointer to the input data array
scalarScalar value to multiply each element by
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ scalar_mult_i32()

template<typename T >
void gpmp::linalg::scalar_mult_i32 ( const T *  data,
int  scalar,
T *  result_data,
size_t  size 
)

Performs scalar multiplication for signed 32-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
dataPointer to the input data array
scalarScalar value to multiply each element by
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ scalar_mult_i64()

template<typename T >
void gpmp::linalg::scalar_mult_i64 ( const T *  data,
int  scalar,
T *  result_data,
size_t  size 
)

Performs scalar multiplication for signed 64-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
dataPointer to the input data array
scalarScalar value to multiply each element by
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ scalar_mult_i8()

template<typename T >
void gpmp::linalg::scalar_mult_i8 ( const T *  data,
int  scalar,
T *  result_data,
size_t  size 
)

Performs scalar multiplication for signed 8-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
dataPointer to the input data array
scalarScalar value to multiply each element by
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ std_cross_product() [1/2]

void gpmp::linalg::std_cross_product ( const std::vector< double > &  vec1,
const std::vector< double > &  vec2,
std::vector< double > &  result 
)

Compute the cross product of two 3D vectors.

This function computes the cross product of two 3D vectors and stores the result in the output vector

Parameters
vec1The first vector
vec2The second vector
resultThe output vector where the result will be stored

Definition at line 48 of file vector_naive.cpp.

50  {
51  result[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
52  result[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
53  result[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
54 }

◆ std_cross_product() [2/2]

void gpmp::linalg::std_cross_product ( const std::vector< int > &  vec1,
const std::vector< int > &  vec2,
std::vector< int > &  result 
)

Compute the cross product of two 3D vectors of integers.

This function computes the cross product of two 3D vectors of integers and stores the result in the output vector

Parameters
vec1The first vector of integers
vec2The second vector of integers
resultThe output vector where the result will be stored

Definition at line 88 of file vector_naive.cpp.

90  {
91  result.resize(3);
92  result[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
93  result[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
94  result[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
95 }

◆ std_dot_product()

template<typename T >
T gpmp::linalg::std_dot_product ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)

Compute the dot product of two vectors.

This function computes the dot product of two vectors

Parameters
vec1The first vector
vec2The second vector
Returns
The dot product of the two input vectors

Definition at line 681 of file vector.hpp.

681  {
682  T result = 0;
683  for (size_t i = 0; i < vec1.size(); ++i) {
684  result += vec1[i] * vec2[i];
685  }
686  return result;
687 }

Referenced by std_vector_projection().

◆ std_scalar_mult()

template<typename T >
void gpmp::linalg::std_scalar_mult ( const std::vector< T > &  vec,
int  scalar,
std::vector< T > &  result 
)

Multiply each element of a vector by a scalar.

This function multiplies each element of a vector by a scalar value and stores the result in the output vector

Parameters
vecThe input vector
scalarThe scalar value to multiply with
resultThe output vector where the result will be stored

Definition at line 662 of file vector.hpp.

664  {
665  result.resize(vec.size());
666  for (size_t i = 0; i < vec.size(); ++i) {
667  result[i] = vec[i] * scalar;
668  }
669 }

◆ std_vector_add()

template<typename T >
void gpmp::linalg::std_vector_add ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2,
std::vector< T > &  result 
)

Add two vectors element-wise.

This function calculates the element-wise addition of two vectors and stores the result in the output vector

Parameters
vec1The first vector
vec2The second vector
resultThe output vector where the result will be stored

Definition at line 622 of file vector.hpp.

624  {
625  result.resize(vec1.size());
626  for (size_t i = 0; i < vec1.size(); ++i) {
627  result[i] = vec1[i] + vec2[i];
628  }
629 }

◆ std_vector_norm() [1/2]

double gpmp::linalg::std_vector_norm ( const std::vector< double > &  vec)

Compute the Euclidean norm (magnitude) of a vector.

This function computes the Euclidean norm (magnitude) of a vector

Parameters
vecThe input vector
Returns
The Euclidean norm of the input vector

Definition at line 56 of file vector_naive.cpp.

56  {
57  double norm = 0.0;
58  for (double value : vec) {
59  norm += value * value;
60  }
61  return std::sqrt(norm);
62 }

Referenced by std_vector_normalize().

◆ std_vector_norm() [2/2]

double gpmp::linalg::std_vector_norm ( const std::vector< int > &  vec)

Compute the Euclidean norm (magnitude) of a vector of integers.

This function computes the Euclidean norm (magnitude) of a vector of integers

Parameters
vecThe input vector of integers
Returns
The Euclidean norm of the input vector

Definition at line 97 of file vector_naive.cpp.

97  {
98  double norm = 0.0;
99  for (int value : vec) {
100  norm += value * value;
101  }
102  return std::sqrt(norm);
103 }

◆ std_vector_normalize() [1/2]

void gpmp::linalg::std_vector_normalize ( const std::vector< double > &  vec,
std::vector< double > &  result 
)

Normalize a vector to have unit length.

This function normalizes a vector to have unit length

Parameters
vecThe input vector
resultThe output vector where the normalized vector will be stored

Definition at line 65 of file vector_naive.cpp.

66  {
67  double norm = gpmp::linalg::std_vector_norm(vec);
68  result.resize(vec.size());
69  for (size_t i = 0; i < vec.size(); ++i) {
70  result[i] = vec[i] / norm;
71  }
72 }
double std_vector_norm(const std::vector< double > &vec)
Compute the Euclidean norm (magnitude) of a vector.

References std_vector_norm().

◆ std_vector_normalize() [2/2]

void gpmp::linalg::std_vector_normalize ( const std::vector< int > &  vec,
std::vector< double > &  result 
)

Normalize a vector of integers to have unit length.

This function normalizes a vector of integers to have unit length

Parameters
vecThe input vector of integers
resultThe output vector where the normalized vector will be stored

Definition at line 106 of file vector_naive.cpp.

107  {
108  double norm = std_vector_norm(vec);
109  result.resize(vec.size());
110  for (size_t i = 0; i < vec.size(); ++i) {
111  result[i] = static_cast<double>(vec[i]) / norm;
112  }
113 }

References std_vector_norm().

◆ std_vector_projection() [1/2]

void gpmp::linalg::std_vector_projection ( const std::vector< double > &  vec,
const std::vector< double > &  onto_vec,
std::vector< double > &  result 
)

Compute the projection of one vector onto another.

This function computes the projection of one vector onto another and stores the result in the output vector

Parameters
vecThe vector to project
onto_vecThe vector onto which to project
resultThe output vector where the projected vector will be stored

Definition at line 75 of file vector_naive.cpp.

77  {
78  double dot = std_dot_product(vec, onto_vec);
79  double onto_vec_norm_sq = std_dot_product(onto_vec, onto_vec);
80 
81  result.resize(onto_vec.size());
82  for (size_t i = 0; i < onto_vec.size(); ++i) {
83  result[i] = (dot / onto_vec_norm_sq) * onto_vec[i];
84  }
85 }
T std_dot_product(const std::vector< T > &vec1, const std::vector< T > &vec2)
Compute the dot product of two vectors.
Definition: vector.hpp:681

References std_dot_product().

◆ std_vector_projection() [2/2]

void gpmp::linalg::std_vector_projection ( const std::vector< int > &  vec,
const std::vector< int > &  onto_vec,
std::vector< double > &  result 
)

Compute the projection of one vector of integers onto another.

This function computes the projection of one vector of integers onto another and stores the result in the output vector

Parameters
vecThe vector of integers to project
onto_vecThe vector of integers onto which to project
resultThe output vector where the projected vector will be stored

Definition at line 116 of file vector_naive.cpp.

118  {
119  double dot = std_dot_product(vec, onto_vec);
120  double onto_vec_norm_sq = std_dot_product(onto_vec, onto_vec);
121 
122  result.resize(onto_vec.size());
123  for (size_t i = 0; i < onto_vec.size(); ++i) {
124  result[i] = (dot / onto_vec_norm_sq) * onto_vec[i];
125  }
126 }

References std_dot_product().

◆ std_vector_sub()

template<typename T >
void gpmp::linalg::std_vector_sub ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2,
std::vector< T > &  result 
)

Subtract one vector from another element-wise.

This function calculates the element-wise subtraction of one vector from another and stores the result in the output vector

Parameters
vec1The vector to subtract from
vec2The vector to subtract
resultThe output vector where the result will be stored

Definition at line 642 of file vector.hpp.

644  {
645  result.resize(vec1.size());
646  for (size_t i = 0; i < vec1.size(); ++i) {
647  result[i] = vec1[i] - vec2[i];
648  }
649 }

◆ vector_add() [1/9]

void gpmp::linalg::vector_add ( const std::vector< double > &  vec1,
const std::vector< double > &  vec2,
std::vector< double > &  result 
)

Performs vector addition for double vectors.

This function adds corresponding elements of two double vectors and stores the result in the provided result vector

Parameters
vec1The first input vector
vec2The second input vector
resultThe vector where the result of the addition will be stored

◆ vector_add() [2/9]

void gpmp::linalg::vector_add ( const std::vector< int16_t > &  vec1,
const std::vector< int16_t > &  vec2,
std::vector< int16_t > &  result 
)

Performs vector addition for vectors of signed 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [3/9]

void gpmp::linalg::vector_add ( const std::vector< int32_t > &  vec1,
const std::vector< int32_t > &  vec2,
std::vector< int32_t > &  result 
)

Performs vector addition for vectors of signed 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [4/9]

void gpmp::linalg::vector_add ( const std::vector< int64_t > &  vec1,
const std::vector< int64_t > &  vec2,
std::vector< int64_t > &  result 
)

Performs vector addition for vectors of signed 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [5/9]

void gpmp::linalg::vector_add ( const std::vector< int8_t > &  vec1,
const std::vector< int8_t > &  vec2,
std::vector< int8_t > &  result 
)

Performs vector addition for vectors of signed 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [6/9]

void gpmp::linalg::vector_add ( const std::vector< uint16_t > &  vec1,
const std::vector< uint16_t > &  vec2,
std::vector< uint16_t > &  result 
)

Performs vector addition for vectors of unsigned 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [7/9]

void gpmp::linalg::vector_add ( const std::vector< uint32_t > &  vec1,
const std::vector< uint32_t > &  vec2,
std::vector< uint32_t > &  result 
)

Performs vector addition for vectors of unsigned 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [8/9]

void gpmp::linalg::vector_add ( const std::vector< uint64_t > &  vec1,
const std::vector< uint64_t > &  vec2,
std::vector< uint64_t > &  result 
)

Performs vector addition for vectors of unsigned 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add() [9/9]

void gpmp::linalg::vector_add ( const std::vector< uint8_t > &  vec1,
const std::vector< uint8_t > &  vec2,
std::vector< uint8_t > &  result 
)

Performs vector addition for vectors of unsigned 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the addition

◆ vector_add_i16()

template<typename T >
void gpmp::linalg::vector_add_i16 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector addition for signed 16-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_add_i32()

template<typename T >
void gpmp::linalg::vector_add_i32 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector addition for signed 32-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_add_i64()

template<typename T >
void gpmp::linalg::vector_add_i64 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector addition for signed 64-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_add_i8()

template<typename T >
void gpmp::linalg::vector_add_i8 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector addition for signed 8-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_sub() [1/9]

void gpmp::linalg::vector_sub ( const std::vector< double > &  vec1,
const std::vector< double > &  vec2,
std::vector< double > &  result 
)

Performs vector subtraction for double vectors.

This function subtracts corresponding elements of two double vectors and stores the result in the provided result vector

Parameters
vec1The first input vector
vec2The second input vector
resultThe vector where the result of the subtraction will be stored

◆ vector_sub() [2/9]

void gpmp::linalg::vector_sub ( const std::vector< int16_t > &  vec1,
const std::vector< int16_t > &  vec2,
std::vector< int16_t > &  result 
)

Performs vector subtraction for vectors of signed 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [3/9]

void gpmp::linalg::vector_sub ( const std::vector< int32_t > &  vec1,
const std::vector< int32_t > &  vec2,
std::vector< int32_t > &  result 
)

Performs vector subtraction for vectors of signed 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [4/9]

void gpmp::linalg::vector_sub ( const std::vector< int64_t > &  vec1,
const std::vector< int64_t > &  vec2,
std::vector< int64_t > &  result 
)

Performs vector subtraction for vectors of signed 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [5/9]

void gpmp::linalg::vector_sub ( const std::vector< int8_t > &  vec1,
const std::vector< int8_t > &  vec2,
std::vector< int8_t > &  result 
)

Performs vector subtraction for vectors of signed 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [6/9]

void gpmp::linalg::vector_sub ( const std::vector< uint16_t > &  vec1,
const std::vector< uint16_t > &  vec2,
std::vector< uint16_t > &  result 
)

Performs vector subtraction for vectors of unsigned 16-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [7/9]

void gpmp::linalg::vector_sub ( const std::vector< uint32_t > &  vec1,
const std::vector< uint32_t > &  vec2,
std::vector< uint32_t > &  result 
)

Performs vector subtraction for vectors of unsigned 32-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [8/9]

void gpmp::linalg::vector_sub ( const std::vector< uint64_t > &  vec1,
const std::vector< uint64_t > &  vec2,
std::vector< uint64_t > &  result 
)

Performs vector subtraction for vectors of unsigned 64-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub() [9/9]

void gpmp::linalg::vector_sub ( const std::vector< uint8_t > &  vec1,
const std::vector< uint8_t > &  vec2,
std::vector< uint8_t > &  result 
)

Performs vector subtraction for vectors of unsigned 8-bit integers.

Parameters
vec1First input vector
vec2Second input vector
resultOutput vector containing the result of the subtraction

◆ vector_sub_i16()

template<typename T >
void gpmp::linalg::vector_sub_i16 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector subtraction for signed 16-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_sub_i32()

template<typename T >
void gpmp::linalg::vector_sub_i32 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector subtraction for signed 32-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_sub_i64()

template<typename T >
void gpmp::linalg::vector_sub_i64 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector subtraction for signed 64-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays

◆ vector_sub_i8()

template<typename T >
void gpmp::linalg::vector_sub_i8 ( const T *  data1,
const T *  data2,
T *  result_data,
size_t  size 
)

Performs vector subtraction for signed 8-bit integers.

Template Parameters
TThe type of the data (int8_t, uint8_t, etc )
Parameters
data1Pointer to the first input data array
data2Pointer to the second input data array
result_dataPointer to the output data array
sizeSize of the input and output arrays