Jive reference manual
|
Multiplies a series of matrices and vectors. More...
#include <jem/numeric/algebra/MatmulChain.h>
Public Member Functions | |
MatmulChain () | |
Creates a new matmul chain. More... | |
const Array< T, 2 > & | matmul (const Array< T > &v, const Array< T > &w) |
Computes the matrix product of two vectors. More... | |
const Array< T > & | matmul (const Array< T, 2 > &a, const Array< T > &v) |
Computes the product of a matrix and a vector. More... | |
const Array< T > & | matmul (const Array< T > &v, const Array< T, 2 > &a) |
Computes the product of a vector and a matrix. More... | |
const Array< T, 2 > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T > &w) |
Computes the product of two vectors and a matrix. More... | |
const Array< T, 2 > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b) |
Computes the product of two matrices. More... | |
const Array< T > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T > &v) |
Computes the product of two matrices and a vector. More... | |
const Array< T > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b) |
Computes the product of a vector and two matrices. More... | |
const Array< T, 2 > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T > &w) |
Computes the matrix product of two vectors and two matrices. More... | |
const Array< T, 2 > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c) |
Computes the product of three matrices. More... | |
const Array< T > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T > &v) |
Computes the product of three matrices and a vector. More... | |
const Array< T > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c) |
Computes the product of a vector and three matrices. More... | |
const Array< T, 2 > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T > &w) |
Computes the matrix product of two vectors and three matrices. More... | |
const Array< T, 2 > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T, 2 > &d) |
Computes the product of four matrices. More... | |
const Array< T > & | matmul (const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T, 2 > &d, const Array< T > &v) |
Computes the product of four matrices and a vector. More... | |
const Array< T > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T, 2 > &d) |
Computes the product of a vector and four matrices. More... | |
const Array< T, 2 > & | matmul (const Array< T > &v, const Array< T, 2 > &a, const Array< T, 2 > &b, const Array< T, 2 > &c, const Array< T, 2 > &d, const Array< T > &w) |
Computes the matrix product of two vectors and four matrices. More... | |
Static Public Attributes | |
static const int | LENGTH = N |
The length of the chain. More... | |
The template class MatmulChain
can be used to compute the product of N matrices containing elements of type T. It can also be used to compute the product of N matrices and a vector, and the product of a vector, N matrices and a vector. Since a MatmulChain
object stores any temporary matrices and vectors in private data members, it does not have to allocate and deallocate those temporary matrices and vectors for each product that it computes. As a consequence, a MatmuChain
can be considerably faster than an equivalent series of nested numeric::matmul()
calls, especially when the product of N matrices is computed repeatedly within a loop. This is illustrated in the example below:
When using the matmul()
function, the above loop could be coded as follows:
In this case, however, two temporary matrices will be allocated and destroyed in each iteration of the loop.
The first template argument, T, specifies the type of the matrix and vector elements. The second template argument, N, specifies the length of a MatmulChain
; that is, the number of matrices that are to be multiplied.
MatmulChain
class is not thread safe.N >= 0 && N <= 4
numeric::matmul()
jem::numeric::MatmulChain< T, N >::MatmulChain | ( | ) |
Creates a new MatmulChain
object that is ready for use.
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T > & | w | ||
) |
Returns a reference to a matrix containing the product of the vectors v and v. From a logical point of view, this function has the same effect as:
return numeric::matmul( v, w )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length zero.
v | - a (column) vector. |
w | - a (row) vector. |
LENGTH == 0
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T > & | v | ||
) |
Returns a reference to a vector containing the product of the matrix a and the vector v. From a logical point of view, this function has the same effect as:
return numeric::matmul( a, v )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length one.
a | - a matrix. |
v | - a (column) vector. |
LENGTH == 1 &&
a.size(1) == v.size()
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a | ||
) |
Returns a reference to a (row) vector containing the product of the vector v and the matrix a. From a logical point of view, this function has the same effect as:
return numeric::matmul( v, a )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length one.
v | - a (row) vector. |
a | - a matrix. |
LENGTH == 1 &&
v.size() == a.size(0)
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T > & | w | ||
) |
Returns a reference to a matrix containing the product of the vector v, the matrix a and the vector w. From a logical point of view, this function has the same effect as:
return numeric::matmul( v, numeric::matmul( a, w )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length one.
v | - a (row) vector. |
a | - a matrix. |
w | - a (column) vector. |
LENGTH == 1 &&
v.size() == a.size(0) &&
w.size() == a.size(1)
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b | ||
) |
Returns a reference to a matrix containing the product of the matrices a and b. From a logical point of view, this function has the same effect as:
return numeric::matmul( a, b )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length two.
a | - a matrix. |
b | - another matrix. |
LENGTH == 2 &&
a.size(1) == b.size(0)
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b, | ||
const Array< T > & | v | ||
) |
Returns a reference to a vector containing the product of the matrices a and b, and the vector v. From a logical point of view, this function has the same effect as:
return numeric::matmul( a, numeric::matmul( b, v ) )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length two.
a | - a matrix. |
b | - another matrix. |
v | - a (column) vector. |
LENGTH == 2 &&
a.size(1) == b.size(0) &&
b.size(1) == v.size()
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b | ||
) |
Returns a reference to a (row) vector containing the product of the vector v, and the matrices a and b. From a logical point of view, this function has the same effect as:
return numeric::matmul( numeric::matmul( v, a ), b )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length two.
v | - a (row) vector. |
a | - a matrix. |
b | - another matrix. |
LENGTH == 2 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0)
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b, | ||
const Array< T > & | w | ||
) |
Returns a reference to a matrix containing the product of the vector v, the matrices a and b, and the vector w. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length two.
v | - a (row) vector. |
a | - a matrix. |
b | - another matrix. |
w | - a (column) vector. |
LENGTH == 2 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0) &&
b.size(1) == w.size()
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c | ||
) |
Returns a reference to a matrix containing the product of the matrices a, b and c. From a logical point of view, this function has the same effect as:
return numeric::matmul( a, numeric::matmul( b, c ) )
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length three.
a | - a matrix. |
b | - a second matrix. |
c | - a third matrix. |
LENGTH == 3 &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0)
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T > & | v | ||
) |
Returns a reference to a vector containing the product of the matrices a, b and c, and the vector v. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length three.
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
v | - a (column) vector. |
LENGTH == 3 &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == v.size()
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c | ||
) |
Returns a reference to a (row) vector containing the product of the vector v, and the matrices a, b and c. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length three.
v | - a (row) vector. |
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
LENGTH == 3 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0)
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T > & | w | ||
) |
Returns a reference to a matrix containing the product of the vector v, the matrices a, b and c, and the vector w. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length three.
v | - a (row) vector. |
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
w | - a (column) vector. |
LENGTH == 3 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == w.size()
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T, 2 > & | d | ||
) |
Returns a reference to a matrix containing the product of the matrices a, b, c and d. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length four.
a | - a matrix. |
b | - a second matrix. |
c | - a third matrix. |
d | - a fourth matrix. |
LENGTH == 4 &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == d.size(0)
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T, 2 > & | a, |
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T, 2 > & | d, | ||
const Array< T > & | v | ||
) |
Returns a reference to a vector containing the product of the matrices a, b, c and d, and the vector v. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length four.
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
d | - a fourth matrix. |
v | - a (column) vector. |
LENGTH == 4 &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == d.size(0) &&
d.size(1) == v.size()
const Array<T>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T, 2 > & | d | ||
) |
Returns a reference to a (row) vector containing the product of the vector v and the matrices a, b, c and d. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length four.
v | - a (row) vector. |
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
d | - a fourth matrix. |
LENGTH == 4 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == d.size(0)
const Array<T,2>& jem::numeric::MatmulChain< T, N >::matmul | ( | const Array< T > & | v, |
const Array< T, 2 > & | a, | ||
const Array< T, 2 > & | b, | ||
const Array< T, 2 > & | c, | ||
const Array< T, 2 > & | d, | ||
const Array< T > & | w | ||
) |
Returns a reference to a matrix containing the product of the vector v, the matrices a, b, c and d, and the vector w. From a logical point of view, this function has the same effect as:
The returned reference is valid until this function is called again or until this MatmulChain
object is destroyed.
This function is only available if this matmul chain has length four.
v | - a (row) vector. |
a | - a matrix. |
b | - a second matrix |
c | - a third matrix. |
d | - a fourth matrix. |
w | - a (column) vector. |
LENGTH == 4 &&
v.size() == a.size(0) &&
a.size(1) == b.size(0) &&
b.size(1) == c.size(0) &&
c.size(1) == d.size(0) &&
d.size(1) == w.size()
|
static |
A constant integer representing the length of this chain. It is equal to the second template parameter.