Jive reference manual
|
A collection of functions for computing dense matrix/vector-matrix/vector products. More...
Functions | |
template<class T > | |
void | jem::numeric::matmul (const Array< T, 1 > &r, const Array< T, 2 > &a, const Array< T, 1 > &b) |
Computes the product of a matrix and a column vector. More... | |
template<class T > | |
Array< T, 1 > | jem::numeric::matmul (const Array< T, 2 > &a, const Array< T, 1 > &b) |
Returns the product of a matrix and a column vector. More... | |
template<class T > | |
void | jem::numeric::matmul (const Array< T, 1 > &r, const Array< T, 1 > &a, const Array< T, 2 > &b) |
Computes the product of a row vector and a matrix. More... | |
template<class T > | |
Array< T, 1 > | jem::numeric::matmul (const Array< T, 1 > &a, const Array< T, 2 > &b) |
Returns the product of a row vector and a matrix. More... | |
template<class T > | |
void | jem::numeric::matmul (const Array< T, 2 > &r, const Array< T, 1 > &a, const Array< T, 1 > &b) |
Computes the product of a column vector and a row vector. More... | |
template<class T > | |
Array< T, 2 > | jem::numeric::matmul (const Array< T, 1 > &a, const Array< T, 1 > &b) |
Returns the product of a column vector and a row vector. More... | |
template<class T > | |
void | jem::numeric::matmul (const Array< T, 2 > &r, const Array< T, 2 > &a, const Array< T, 2 > &b) |
Computes the product of two matrices. More... | |
template<class T , int M, int N, int P> | |
void | jem::numeric::matmul (Tuple< T, M, P > &r, const Tuple< T, M, N > &a, const Tuple< T, N, P > &b) |
Computes the product of two matrices. More... | |
template<class T , int M, int P> | |
void | jem::numeric::matmul (Tuple< T, M, P > &r, const Array< T, 2 > &a, const Array< T, 2 > &b) |
Computes the product of two matrices. More... | |
template<class T , int M, int N> | |
void | jem::numeric::matmul (const Array< T, 2 > &r, const Tuple< T, M, N > &a, const Array< T, 2 > &b) |
Computes the product of two matrices. More... | |
template<class T , int N, int P> | |
void | jem::numeric::matmul (const Array< T, 2 > &r, const Array< T, 2 > &a, const Tuple< T, N, P > &b) |
Computes the product of two matrices. More... | |
template<class T > | |
Array< T, 2 > | jem::numeric::matmul (const Array< T, 2 > &a, const Array< T, 2 > &b) |
Returns the product of two matrices. More... | |
template<class T , int M, int N, int P> | |
Tuple< T, M, P > | jem::numeric::matmul (const Tuple< T, M, N > &a, const Tuple< T, N, P > &b) |
Returns the product of two matrices. More... | |
template<class T , int M, int N> | |
Array< T, 2 > | jem::numeric::matmul (const Tuple< T, M, N > &a, const Array< T, 2 > &b) |
Returns the product of two matrices. More... | |
template<class T , int N, int P> | |
Array< T, 2 > | jem::numeric::matmul (const Array< T, 2 > &a, const Tuple< T, N, P > &b) |
Returns the product of two matrices. More... | |
#include <jem/numeric/algebra/matmul.h>
This header file exports a set of template functions – all named matmul
– that compute the following types of matrix-vector products: the product of a matrix and a column vector; the product of a row vector and a matrix; the product of a column vector and a row vector; and the product of two matrices.
Both column and row vectors are represented by one-dimensional Array
objects. Matrices are represented by two-dimensional Array
objects and by Tuple
objects.
The matmul
functions come in two flavors: one with three parameters and one with two parameters. The matmul
functions with three parameters store their results in their first argument. The matmul
functions with two parameter, on the other hand, return a new Array
or Tuple
object containing the computed results. The three-parameter versions of matmul
are faster because they do not have to allocate memory. The two-parameter versions are sometimes more convenient to use because they can be easily embedded into an array expression.
MatmulChain
void jem::numeric::matmul | ( | const Array< T, 1 > & | r, |
const Array< T, 2 > & | a, | ||
const Array< T, 1 > & | b | ||
) |
Computes the product of the matrix a and the column vector b. The result is stored in the column vector r.
This function is equivalent with:
However, if the template parameter T
is of type bool
, then the matrix-vector product is computed as follows:
Note that the actual implementation of this is function is much more efficient than the code shown above because it takes advantage of the particular way in which the Array
class stores its data.
r | - a column vector that is set to the matrix-vector product of a and b. |
a | - a matrix. |
b | - a column vector. |
r.size() == a.size(0) &&
b.size() == a.size(1)
Array<T,1> jem::numeric::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 1 > & | b | ||
) |
Returns a column vector containing the product of the matrix a and the column vector b.
This function simply executes:
a | - a matrix. |
b | - a column vector. |
void jem::numeric::matmul | ( | const Array< T, 1 > & | r, |
const Array< T, 1 > & | a, | ||
const Array< T, 2 > & | b | ||
) |
Computes the product of the row vector a and the matrix b. The result is stored in the row vector r.
This function essentially executes the following algorithm:
If the template argument T
equals the type bool
, however, the vector-matrix product is computed as follows:
Note that the actual implementation of this is function is much more efficient than the code shown above because it takes advantage of the particular way in which the Array
class stores its data.
r | - a row vector that is set to the vector-matrix product of a and b. |
a | - a row vector. |
b | - a matrix. |
r.size() == b.size(1) &&
a.size() == a.size(0)
Array<T,1> jem::numeric::matmul | ( | const Array< T, 1 > & | a, |
const Array< T, 2 > & | b | ||
) |
Returns a row vector containing the product of the row vector a and the matrix b.
This function simply executes:
a | - a row vector. |
b | - a matrix. |
void jem::numeric::matmul | ( | const Array< T, 2 > & | r, |
const Array< T, 1 > & | a, | ||
const Array< T, 1 > & | b | ||
) |
Computes the product of the column vector a and the row vector b. The result is stored in the matrix r.
The vector-vector product is computed as follows:
If the template arguments T
is of type bool
, however, then the product is computed as follows:
Note that the actual implementation of this is function is much more efficient than the code shown above because it takes advantage of the particular way in which the Array
class stores its data.
r | - a matrix that is set to the vector-vector product of a and b. |
a | - a column vector. |
b | - a row vector. |
r.size(0) == a.size() &&
r.size(1) == b.size()
Array<T,2> jem::numeric::matmul | ( | const Array< T, 1 > & | a, |
const Array< T, 1 > & | b | ||
) |
Returns a matrix containing the product of the column vector a and the row vector b.
This function simply executes:
a | - a column vector. |
b | - a row vector. |
void jem::numeric::matmul | ( | const Array< T, 2 > & | r, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b | ||
) |
Computes the product of the matrices a and b. The resulting matrix is stored in r.
The matrix-matrix product is computed as follows:
If the template arguments T
is of type bool
, then the product is computes as follows:
Note that the actual implementation of this is function is much more efficient than the code shown above because it takes advantage of the particular way in which the Array
class stores its data.
r | - a matrix that is set to the matrix-matrix product of a and b. |
a | - a matrix. |
b | - another matrix. |
r.size(0) == a.size(0) &&
r.size(1) == b.size(1) &&
a.size(1) == b.size(0)
void jem::numeric::matmul | ( | Tuple< T, M, P > & | r, |
const Tuple< T, M, N > & | a, | ||
const Tuple< T, N, P > & | b | ||
) |
Computes the matrix-matrix product of the tuples a and b. The resulting matrix is stored in the tuple r. This function has the same semantics as the equivalent matmul
function with three array arguments.
r | - a tuple that is set to the matrix-matrix product of a and b. |
a | - a tuple representing a matrix. |
b | - a tuple representing another matrix. |
void jem::numeric::matmul | ( | Tuple< T, M, P > & | r, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b | ||
) |
Computes the matrix-matrix product of the two-dimensional arrays a and b. The resulting matrix is stored in the tuple r. This function has the same semantics as the equivalent matmul
function with three array arguments.
r | - a tuple that is set to the matrix-matrix product of a and b. |
a | - an array representing a matrix. |
b | - another array. |
a.size(0) == M &&
a.size(1) == b.size(0) &&
b.size(1) == P
void jem::numeric::matmul | ( | const Array< T, 2 > & | r, |
const Tuple< T, M, N > & | a, | ||
const Array< T, 2 > & | b | ||
) |
Computes the matrix-matrix product of the tuple a and the two-dimensional array b. The resulting matrix is stored in the two-dimensional array r. This function has the same semantics as the equivalent matmul
function with three array arguments.
r | - an array that is set to the matrix-matrix product of a and b. |
a | - a tuple representing a matrix. |
b | - an array representing another matrix. |
r.size(0) == M &&
r.size(1) == b.size(1) &&
b.size(0) == N
void jem::numeric::matmul | ( | const Array< T, 2 > & | r, |
const Array< T, 2 > & | a, | ||
const Tuple< T, N, P > & | b | ||
) |
Computes the matrix-matrix product of the two-dimensional array a and the tuple b. The resulting matrix is stored in the two-dimensional array r. This function has the same semantics as the equivalent matmul
function with three array arguments.
r | - an array that is set to the matrix-matrix product of a and b. |
a | - an array representing a matrix. |
b | - a tuple representing another matrix. |
r.size(0) == a.size(0) &&
r.size(1) == P &&
a.size(1) == N
Array<T,2> jem::numeric::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b | ||
) |
Returns a matrix containing the product of the matrices a and b.
This function simply executes:
a | - a matrix. |
b | - another matrix. |
a.size(1) == b.size(0)
Tuple<T,M,P> jem::numeric::matmul | ( | const Tuple< T, M, N > & | a, |
const Tuple< T, N, P > & | b | ||
) |
Returns a tuple containing the product of the tuples a and b.
This function simply executes:
a | - a tuple representing a matrix. |
b | - a tuple representing another matrix. |
Array<T,2> jem::numeric::matmul | ( | const Tuple< T, M, N > & | a, |
const Array< T, 2 > & | b | ||
) |
Returns a two-dimensional array containing the product of the tuple a and the two-dimensional array b.
This function simply executes:
a | - a tuple representing a matrix. |
b | - an array representing another matrix. |
b.size(0) == N
Array<T,2> jem::numeric::matmul | ( | const Array< T, 2 > & | a, |
const Tuple< T, N, P > & | b | ||
) |
Returns a two-dimensional array containing the product of the two-dimensional array a and the tuple b.
This function simply executes:
a | - an array representing a matrix. |
b | - a tuple representing another matrix. |
a.size(1) == N