25 template<
typename Architecture_t>
27 ->
typename Architecture_t::Scalar_t
30 using Scalar_t =
typename Architecture_t::Scalar_t;
31 using Matrix_t =
typename Architecture_t::Matrix_t;
33 Scalar_t maximumError = 0.0;
35 for (
size_t t = 0; t < ntests; t++) {
41 TMatrixT<Scalar_t> ARef(m,k), A2Ref(m,k), ATRef(k,m) , BRef(k,n), BTRef(n,k), CRef(m,n);
47 Matrix_t
A(ARef), A2(A2Ref), AT(ATRef),
B(BRef), BT(BTRef),
C(CRef);
51 Architecture_t::Multiply(C,
A,
B);
53 maximumError = std::max(error, maximumError);
56 CRef.
TMult(ATRef,BRef);
57 Architecture_t::TransposeMultiply(C, AT,
B);
59 maximumError = std::max(error, maximumError);
62 CRef.
MultT(ARef,BTRef);
63 Architecture_t::MultiplyTranspose(C,
A, BT);
65 maximumError = std::max(error, maximumError);
68 for (
size_t i = 0; i < (size_t) ARef.GetNrows(); i++) {
69 for (
size_t j = 0; j < (size_t) ARef.GetNcols(); j++) {
70 ARef(i,j) *= A2Ref(i,j);
73 Architecture_t::Hadamard(
A, A2);
75 maximumError = std::max(error, maximumError);
85 template<
typename Architecture_t>
87 ->
typename Architecture_t::Scalar_t
90 using Scalar_t =
typename Architecture_t::Scalar_t;
91 using Matrix_t =
typename Architecture_t::Matrix_t;
93 Scalar_t maximumError = 0.0;
94 for (
size_t t = 0; t < ntests; t++) {
100 n = rand() % 100 + 1;
104 for (
size_t i = 0; i < (size_t) ARef.GetNrows(); i++) {
105 for (
size_t j = 0; j < (size_t) ARef.GetNcols(); j++) {
107 if (i == 0) BRef(j, 0) = m * j;
111 Matrix_t
A(ARef),
B(n, 1);
112 Architecture_t::SumColumns(B,
A);
115 maximumError = std::max(error, maximumError);
auto maximumRelativeError(const Matrix1 &X, const Matrix2 &Y) -> decltype(X(0, 0))
Compute the maximum, element-wise relative error of the matrices X and Y normalized by the element of...
void randomMatrix(AMatrix &X)
Fill matrix with random, Gaussian-distributed values.
auto testSumColumns(size_t ntests) -> typename Architecture_t::Scalar_t
Test the summing over columns by summing by the sums obtained from a matrix filled with column indice...
auto testMultiplication(size_t ntests) -> typename Architecture_t::Scalar_t
Test multiplication (standard, transposed, hadamard) operation on architecture specific matrix types ...
void MultT(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B^T.
void TMult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
Create a matrix C such that C = A' * B.
void Mult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B.