SHOGUN
6.0.0
|
Namespaces | |
implementation | |
ocl | |
operations | |
special_purpose | |
util | |
Classes | |
struct | Block |
Generic class Block which wraps a matrix class and contains block specific information, providing a uniform way to deal with matrix blocks for all supported backend matrices. More... | |
struct | linalg_traits |
General purpose linalg_traits for compile time information about backends set per module (see below). This uses the backend from the modules. To get the backend set globally, use linalg_traits<ModuleName>::backend. More... | |
Enumerations | |
enum | Backend { EIGEN3, NATIVE, DEFAULT = 0 } |
All currently supported linear algebra backend libraries, with a default backend, which will be used for all the tasks if any particular backend is not set explicitly via cmake options. A Native backend is also defined to accommodate Shogun's native implementation of some operations. More... | |
Functions | |
template<class Matrix > | |
Block< Matrix > | block (Matrix matrix, index_t row_begin, index_t col_begin, index_t row_size, index_t col_size) |
template<class Operand , class UnaryOp > | |
auto | elementwise_compute (Operand operand, UnaryOp unary_op) -> typename Operand::template container_type< decltype(unary_op(operand.data()[0]))> |
template<class Operand , class UnaryOp > | |
void | elementwise_compute_inplace (Operand operand, UnaryOp unary_op) |
template<Backend backend, class Operand > | |
Operand::template container_type< typename operations::sin< typename Operand::Scalar >::return_type > | elementwise_sin (Operand operand) |
template<Backend backend, class Operand > | |
void | elementwise_sin_inplace (Operand operand) |
template<typename T , template< typename > class Container> | |
LinalgBackendBase * | infer_backend (const Container< T > &a) |
template<typename T , template< typename > class Container> | |
LinalgBackendBase * | infer_backend (const Container< T > &a, const Container< T > &b) |
template<typename T > | |
void | to_gpu (SGVector< T > &a, SGVector< T > &b) |
template<typename T > | |
void | to_gpu (SGMatrix< T > &a, SGMatrix< T > &b) |
template<typename T , template< typename > class Container> | |
void | to_gpu (Container< T > &a) |
template<typename T > | |
void | from_gpu (SGVector< T > &a, SGVector< T > &b) |
template<typename T > | |
void | from_gpu (SGMatrix< T > &a, SGMatrix< T > &b) |
template<typename T , template< typename > class Container> | |
void | from_gpu (Container< T > &a) |
template<typename T > | |
void | add (SGVector< T > &a, SGVector< T > &b, SGVector< T > &result, T alpha=1, T beta=1) |
template<typename T > | |
void | add (SGMatrix< T > &a, SGMatrix< T > &b, SGMatrix< T > &result, T alpha=1, T beta=1) |
template<typename T , template< typename > class Container> | |
Container< T > | add (Container< T > &a, Container< T > &b, T alpha=1, T beta=1) |
template<typename T > | |
SGMatrix< T > | cholesky_factor (const SGMatrix< T > &A, const bool lower=true) |
template<typename T > | |
SGVector< T > | cholesky_solver (const SGMatrix< T > &L, const SGVector< T > &b, const bool lower=true) |
template<typename T > | |
T | dot (const SGVector< T > &a, const SGVector< T > &b) |
template<typename T > | |
void | element_prod (Block< SGMatrix< T >> &a, Block< SGMatrix< T >> &b, SGMatrix< T > &result) |
template<typename T > | |
SGMatrix< T > | element_prod (Block< SGMatrix< T >> &a, Block< SGMatrix< T >> &b) |
template<typename T > | |
void | element_prod (SGMatrix< T > &a, SGMatrix< T > &b, SGMatrix< T > &result) |
template<typename T > | |
SGMatrix< T > | element_prod (SGMatrix< T > &a, SGMatrix< T > &b) |
template<typename T > | |
void | matrix_prod (SGMatrix< T > &A, SGVector< T > &b, SGVector< T > &result, bool transpose=false) |
template<typename T > | |
SGVector< T > | matrix_prod (SGMatrix< T > &A, SGVector< T > &b, bool transpose=false) |
template<typename T > | |
void | matrix_prod (SGMatrix< T > &A, SGMatrix< T > &B, SGMatrix< T > &result, bool transpose_A=false, bool transpose_B=false) |
template<typename T > | |
SGMatrix< T > | matrix_prod (SGMatrix< T > &A, SGMatrix< T > &B, bool transpose_A=false, bool transpose_B=false) |
template<typename T , template< typename > class Container> | |
T | max (const Container< T > &a) |
template<typename T , template< typename > class Container> | |
std::enable_if<!std::is_same< T, complex128_t >::value, float64_t >::type | mean (const Container< T > &a) |
template<template< typename > class Container> | |
complex128_t | mean (const Container< complex128_t > &a) |
template<typename T , template< typename > class Container> | |
void | range_fill (Container< T > &a, const T start=0) |
template<typename T > | |
void | scale (SGVector< T > &a, SGVector< T > &result, T alpha=1) |
template<typename T > | |
void | scale (SGMatrix< T > &A, SGMatrix< T > &result, T alpha=1) |
template<typename T , template< typename > class Container> | |
Container< T > | scale (Container< T > &a, T alpha=1) |
template<typename T , template< typename > class Container> | |
void | set_const (Container< T > &a, T value) |
template<typename T , template< typename > class Container> | |
T | sum (const Container< T > &a, bool no_diag=false) |
template<typename T > | |
T | sum (const Block< SGMatrix< T >> &a, bool no_diag=false) |
template<typename T > | |
T | sum_symmetric (const SGMatrix< T > &a, bool no_diag=false) |
template<typename T > | |
T | sum_symmetric (const Block< SGMatrix< T >> &a, bool no_diag=false) |
template<typename T > | |
SGVector< T > | colwise_sum (const SGMatrix< T > &mat, bool no_diag=false) |
template<typename T > | |
SGVector< T > | colwise_sum (const Block< SGMatrix< T >> &a, bool no_diag=false) |
template<typename T > | |
SGVector< T > | rowwise_sum (const SGMatrix< T > &mat, bool no_diag=false) |
template<typename T > | |
SGVector< T > | rowwise_sum (const Block< SGMatrix< T >> &a, bool no_diag=false) |
template<typename T > | |
void | logistic (SGMatrix< T > &a, SGMatrix< T > &result) |
This namespace contains all linear algebra specific modules and operations for which we (may) rely on multiple implementation, either native or making use of some supported third party external linear algebra libraries.
|
strong |
All currently supported linear algebra backend libraries, with a default backend, which will be used for all the tasks if any particular backend is not set explicitly via cmake options. A Native backend is also defined to accommodate Shogun's native implementation of some operations.
Developer's Note :
Note - Currently EIGEN3 is the default (if it is available).
Enumerator | |
---|---|
EIGEN3 | |
NATIVE | |
DEFAULT |
void shogun::linalg::add | ( | SGVector< T > & | a, |
SGVector< T > & | b, | ||
SGVector< T > & | result, | ||
T | alpha = 1 , |
||
T | beta = 1 |
||
) |
Performs the operation result = alpha * a + beta * b on vectors. This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result
a | First vector |
b | Second vector |
result | The vector that saves the result |
alpha | Constant to be multiplied by the first vector |
beta | Constant to be multiplied by the second vector |
Definition at line 284 of file LinalgNamespace.h.
void shogun::linalg::add | ( | SGMatrix< T > & | a, |
SGMatrix< T > & | b, | ||
SGMatrix< T > & | result, | ||
T | alpha = 1 , |
||
T | beta = 1 |
||
) |
Performs the operation result = alpha * a + beta * b on matrices. This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result
a | First matrix |
b | Second matrix |
result | The matrix that saves the result |
alpha | Constant to be multiplied by the first matrix |
beta | Constant to be multiplied by the second matrix |
Definition at line 315 of file LinalgNamespace.h.
Container<T> shogun::linalg::add | ( | Container< T > & | a, |
Container< T > & | b, | ||
T | alpha = 1 , |
||
T | beta = 1 |
||
) |
Performs the operation C = alpha * A + beta * B. This version returns the result in a newly created vector or matrix.
A | First vector or matrix |
B | Second vector or matrix |
alpha | Constant to be multiplied by the first vector or matrix |
beta | Constant to be multiplied by the second vector or matrix |
Definition at line 345 of file LinalgNamespace.h.
Block<Matrix> shogun::linalg::block | ( | Matrix | matrix, |
index_t | row_begin, | ||
index_t | col_begin, | ||
index_t | row_size, | ||
index_t | col_size | ||
) |
Method that returns a block object. Suited for Eigen3/SGMatrix
matrix | the matrix on which the block is defined |
row_begin | the row index at which the block starts |
col_begin | the col index at which the block starts |
row_size | the number of rows in the block |
col_size | the number of cols in the block |
Definition at line 105 of file mathematics/linalg/internal/Block.h.
Compute the cholesky decomposition \(A = L L^{*}\) or \(A = U^{*} U\) of a Hermitian positive definite matrix
A | The matrix whose cholesky decomposition is to be computed |
lower | Whether to compute the upper or lower triangular Cholesky factorization (default: lower) |
Definition at line 362 of file LinalgNamespace.h.
SGVector<T> shogun::linalg::cholesky_solver | ( | const SGMatrix< T > & | L, |
const SGVector< T > & | b, | ||
const bool | lower = true |
||
) |
Solve the linear equations \(Ax=b\), given the Cholesky factorization of A, where \(A\) is a Hermitian positive definite matrix
L | Triangular matrix, Cholesky factorization of A |
b | Right-hand side array |
lower | Whether to use L as the upper or lower triangular Cholesky factorization (default:lower) |
Definition at line 378 of file LinalgNamespace.h.
Method that computes colwise sum of co-efficients of a dense matrix
Mat | a matrix whose colwise sum has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 873 of file LinalgNamespace.h.
Method that computes the colwise sum of matrix blocks This operation works with CPU backends only.
a | the matrix-block whose colwise sum of co-efficients has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 887 of file LinalgNamespace.h.
Vector dot-product that works with generic vectors.
a | First vector |
b | Second vector |
Definition at line 393 of file LinalgNamespace.h.
void shogun::linalg::element_prod | ( | Block< SGMatrix< T >> & | a, |
Block< SGMatrix< T >> & | b, | ||
SGMatrix< T > & | result | ||
) |
Performs the operation C = A .* B where ".*" denotes elementwise multiplication on matrix blocks.
This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix.
This operation works with CPU backends only.
a | First matrix block |
b | Second matrix block |
c | Result matrix |
Definition at line 413 of file LinalgNamespace.h.
Performs the operation C = A .* B where ".*" denotes elementwise multiplication on matrix blocks.
This version returns the result in a newly created matrix.
A | First matrix block |
B | Second matrix block |
Definition at line 438 of file LinalgNamespace.h.
Performs the operation C = A .* B where ".*" denotes elementwise multiplication.
This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result
a | First matrix |
b | Second matrix |
result | Result matrix |
Definition at line 463 of file LinalgNamespace.h.
Performs the operation C = A .* B where ".*" denotes elementwise multiplication.
This version returns the result in a newly created matrix.
A | First matrix |
B | Second matrix |
Definition at line 491 of file LinalgNamespace.h.
auto shogun::linalg::elementwise_compute | ( | Operand | operand, |
UnaryOp | unary_op | ||
) | -> typename Operand::template container_type<decltype(unary_op(operand.data()[0]))> |
Template method for computing custom unary operations element-wise for matrices and vectors using NATIVE backend. Works for SGMatrix/SGVector.
This method returns the result in a newly allocated matrix/vector.
operand | The operand on which the element-wise operation has to be performed |
unary_op | The custom unary operator |
Definition at line 56 of file ElementwiseOperations.h.
void shogun::linalg::elementwise_compute_inplace | ( | Operand | operand, |
UnaryOp | unary_op | ||
) |
Template method for computing custom unary operations element-wise for matrices and vectors using NATIVE backend. Works for SGMatrix/SGVector.
This method computes the result in-place.
operand | The operand on which the element-wise operation has to be performed |
unary_op | The custom unary operator |
Definition at line 80 of file ElementwiseOperations.h.
Operand::template container_type<typename operations::sin<typename Operand::Scalar>::return_type> shogun::linalg::elementwise_sin | ( | Operand | operand | ) |
Template method for computing element-wise sin for matrices and vectors.
This method returns the result in a newly allocated matrix/vector.
operand | The operand on which the element-wise operation has to be performed |
Definition at line 141 of file ElementwiseOperations.h.
void shogun::linalg::elementwise_sin_inplace | ( | Operand | operand | ) |
Template method for computing element-wise sin for matrices and vectors.
This method computes the result in-place.
operand | The operand on which the element-wise operation has to be performed |
Definition at line 165 of file ElementwiseOperations.h.
Fetches data from GPU memory. Transfer vectors to CPU if GPU backend is still available.
Definition at line 193 of file LinalgNamespace.h.
Fetches data from GPU memory. Transfer matrices to CPU if GPU backend is still available.
Definition at line 230 of file LinalgNamespace.h.
void shogun::linalg::from_gpu | ( | Container< T > & | a | ) |
Fetches data from GPU memory. Transfer vector or matrix to CPU if GPU backend is still available.
Definition at line 266 of file LinalgNamespace.h.
LinalgBackendBase* shogun::linalg::infer_backend | ( | const Container< T > & | a | ) |
Infer the appropriate backend for linalg operations from the input SGVector or SGMatrix (Container).
Definition at line 52 of file LinalgNamespace.h.
LinalgBackendBase* shogun::linalg::infer_backend | ( | const Container< T > & | a, |
const Container< T > & | b | ||
) |
Infer the appropriate backend for linalg operations from the input SGVector or SGMatrix (Container). Raise error if the backends of the two Containers conflict.
a | The first SGVector/SGMatrix |
b | The second SGVector/SGMatrix |
Definition at line 79 of file LinalgNamespace.h.
Applies the elementwise logistic function f(x) = 1/(1+exp(-x)) to a matrix This method returns the result in-place.
a | The input matrix |
result | The output matrix |
Definition at line 51 of file LinalgSpecialPurposes.h.
void shogun::linalg::matrix_prod | ( | SGMatrix< T > & | A, |
SGVector< T > & | b, | ||
SGVector< T > & | result, | ||
bool | transpose = false |
||
) |
Performs the operation of a matrix multiplies a vector \(x = Ab\).
This version returns the result in-place. User should pass an appropriately allocated memory matrix.
A | The matrix |
b | The vector |
transpose | Whether to transpose the matrix. Default false |
result | Result vector |
Definition at line 516 of file LinalgNamespace.h.
SGVector<T> shogun::linalg::matrix_prod | ( | SGMatrix< T > & | A, |
SGVector< T > & | b, | ||
bool | transpose = false |
||
) |
Performs the operation of matrix multiply a vector \(x = Ab\). This version returns the result in a newly created vector.
A | The matrix |
b | The vector |
transpose | Whether to transpose a matrix. Default:false |
Definition at line 552 of file LinalgNamespace.h.
void shogun::linalg::matrix_prod | ( | SGMatrix< T > & | A, |
SGMatrix< T > & | B, | ||
SGMatrix< T > & | result, | ||
bool | transpose_A = false , |
||
bool | transpose_B = false |
||
) |
Performs the operation C = A * B where "*" denotes matrix multiplication.
This version returns the result in-place. User should pass an appropriately allocated memory matrix
A | First matrix |
B | Second matrix |
result | Result matrix |
transpose_A | whether to transpose matrix A |
transpose_B | whether to transpose matrix B |
Definition at line 587 of file LinalgNamespace.h.
SGMatrix<T> shogun::linalg::matrix_prod | ( | SGMatrix< T > & | A, |
SGMatrix< T > & | B, | ||
bool | transpose_A = false , |
||
bool | transpose_B = false |
||
) |
Performs the operation C = A * B where "*" denotes matrix multiplication.
This version returns the result in a newly created matrix.
A | First matrix |
B | Second matrix |
transpose_A | whether to transpose matrix A |
transpose_B | whether to transpose matrix B |
Definition at line 655 of file LinalgNamespace.h.
T shogun::linalg::max | ( | const Container< T > & | a | ) |
Returns the largest element in a vector or matrix
a | Input vector or matrix |
Definition at line 700 of file LinalgNamespace.h.
std::enable_if<!std::is_same<T, complex128_t>::value, float64_t>::type shogun::linalg::mean | ( | const Container< T > & | a | ) |
Method that computes the mean of vectors or matrices composed of real numbers.
Definition at line 713 of file LinalgNamespace.h.
complex128_t shogun::linalg::mean | ( | const Container< complex128_t > & | a | ) |
Method that computes the mean of vectors or matrices composed of complex numbers.
Definition at line 726 of file LinalgNamespace.h.
void shogun::linalg::range_fill | ( | Container< T > & | a, |
const T | start = 0 |
||
) |
Range fill a vector or matrix with start...start+len-1
a | The vector or matrix to be filled |
start | Value to be assigned to the first element of vector or matrix |
Definition at line 739 of file LinalgNamespace.h.
Method that computes rowwise sum of co-efficients of a dense matrix
mat | a matrix whose rowwise sum has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 900 of file LinalgNamespace.h.
Method that computes the rowwise sum of matrix blocks This operation works with CPU backends only.
a | the matrix-block whose rowwise sum of co-efficients has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 914 of file LinalgNamespace.h.
Performs the operation result = alpha * a on vectors This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass the operands argument a as a result
a | First vector |
alpha | Scale factor |
result | The vector of alpha * a |
Definition at line 755 of file LinalgNamespace.h.
Performs the operation result = alpha * A on matrices This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass the operands argument A as a result
A | First matrix |
alpha | Scale factor |
result | The matrix of alpha * A |
Definition at line 772 of file LinalgNamespace.h.
Container<T> shogun::linalg::scale | ( | Container< T > & | a, |
T | alpha = 1 |
||
) |
Performs the operation B = alpha * A on vectors or matrices This version returns the result in a newly created vector or matrix.
a | First vector/matrix |
alpha | Scale factor |
Definition at line 790 of file LinalgNamespace.h.
void shogun::linalg::set_const | ( | Container< T > & | a, |
T | value | ||
) |
Set const value to vectors or matrices
a | Vector or matrix to be set |
value | The value to set the vector or matrix |
Definition at line 804 of file LinalgNamespace.h.
T shogun::linalg::sum | ( | const Container< T > & | a, |
bool | no_diag = false |
||
) |
Method that computes the sum of vectors or matrices
a | The vector or matrix whose sum has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 817 of file LinalgNamespace.h.
Method that computes the sum of matrix blocks This operation works with CPU backends only.
a | The matrix-block whose sum of co-efficients has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 831 of file LinalgNamespace.h.
T shogun::linalg::sum_symmetric | ( | const SGMatrix< T > & | a, |
bool | no_diag = false |
||
) |
Method that computes the sum of symmetric matrices
a | The symmetric matrix whose sum has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 844 of file LinalgNamespace.h.
Method that computes the sum of symmetric matrix blocks This operation works with CPU backends only.
a | The symmetric matrix-block whose sum has to be computed |
no_diag | If true, diagonal entries are excluded from the sum. Default: false |
Definition at line 859 of file LinalgNamespace.h.
Transfers data to GPU memory. Shallow-copy of SGVector with vector on CPU if GPU backend not available
Definition at line 112 of file LinalgNamespace.h.
Transfers data to GPU memory. Does nothing if no GPU backend registered. Shallow-copy SGMatrix on CPU if GPU backend not available
Definition at line 147 of file LinalgNamespace.h.
void shogun::linalg::to_gpu | ( | Container< T > & | a | ) |
Transfers data to GPU memory in-place.
Definition at line 180 of file LinalgNamespace.h.