44 #include "Teuchos_UnitTestHarness.hpp" 45 #include "Teuchos_TestingHelpers.hpp" 46 #include "Teuchos_UnitTestRepository.hpp" 47 #include "Teuchos_GlobalMPISession.hpp" 58 typedef Teuchos::SerialDenseMatrix<ordinal_type,scalar_type>
SDM;
70 SDM B(m,m), C(n,n), S(m,n), T(m,n);
78 T.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, B, S, 0.0);
79 A.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, T, C, 0.0);
84 Teuchos::FancyOStream& out) {
90 Teuchos::Array<scalar_type> w(m, 1.0);
92 qr_func(k, A, w, Q, R);
94 TEUCHOS_TEST_EQUALITY(Q.numRows(), m, out, success);
95 TEUCHOS_TEST_EQUALITY(Q.numCols(), k, out, success);
96 TEUCHOS_TEST_EQUALITY(R.numRows(), k, out, success);
97 TEUCHOS_TEST_EQUALITY(R.numCols(), k, out, success);
101 QR.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, Q, R, 0.0);
102 SDM AA(Teuchos::View, A, m, k);
106 SDM eye(k,k), QTQ(k,k);
109 QTQ.multiply(Teuchos::TRANS, Teuchos::NO_TRANS, 1.0, Q, Q, 0.0);
117 Teuchos::FancyOStream& out) {
124 Teuchos::Array<ordinal_type> piv;
125 qr_func(A, Q, R, piv);
127 TEUCHOS_TEST_EQUALITY(Q.numRows(), m, out, success);
128 TEUCHOS_TEST_EQUALITY(Q.numCols(), k, out, success);
129 TEUCHOS_TEST_EQUALITY(R.numRows(), k, out, success);
130 TEUCHOS_TEST_EQUALITY(R.numCols(), n, out, success);
131 TEUCHOS_TEST_EQUALITY(piv.size(), n, out, success);
134 SDM AP(m,n), QR(m,n);
137 AP(i,
j) = A(i,piv[
j]);
138 QR.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, Q, R, 0.0);
142 SDM eye(k,k), QTQ(k,k);
145 QTQ.multiply(Teuchos::TRANS, Teuchos::NO_TRANS, 1.0, Q, Q, 0.0);
154 Teuchos::FancyOStream& out) {
160 Teuchos::Array<ordinal_type> piv(n);
163 Teuchos::Array<scalar_type> w(m, 1.0);
166 TEUCHOS_TEST_EQUALITY(rank, k, out, success);
167 TEUCHOS_TEST_EQUALITY(Q.numRows(), m, out, success);
168 TEUCHOS_TEST_EQUALITY(Q.numCols(), k, out, success);
169 TEUCHOS_TEST_EQUALITY(R.numRows(), k, out, success);
170 TEUCHOS_TEST_EQUALITY(R.numCols(), k, out, success);
171 TEUCHOS_TEST_EQUALITY(piv.size(), n, out, success);
174 SDM AP(m,k), QR(m,k);
177 AP(i,
j) = A(i,piv[
j]);
178 QR.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, Q, R, 0.0);
182 SDM eye(k,k), Qt(m,k), QTQ(k,k);
186 Qt(i,
j) = w[i]*Q(i,
j);
188 QTQ.multiply(Teuchos::TRANS, Teuchos::NO_TRANS, 1.0, Qt, Q, 0.0);
317 Teuchos::GlobalMPISession mpiSession(&argc, &
argv);
318 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc,
argv);
ordinal_type CPQR_MGS_threshold(const scalar_type &rank_threshold, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R, Teuchos::Array< ordinal_type > &piv)
Compute column-pivoted QR using modified Gram-Schmidt.
ordinal_type(* wcpqr_func_type)(const scalar_type &, const SDM &, const Teuchos::Array< scalar_type > &, SDM &, SDM &, Teuchos::Array< ordinal_type > &)
void(* cpqr_func_type)(const SDM &, SDM &, SDM &, Teuchos::Array< ordinal_type > &)
int main(int argc, char *argv[])
ordinal_type CPQR_Householder_threshold(const scalar_type &rank_threshold, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R, Teuchos::Array< ordinal_type > &piv)
Compute column-pivoted QR using Householder reflections.
void QR_CGS(ordinal_type k, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R)
Compute thin QR using classical Gram-Schmidt.
void QR_MGS(ordinal_type k, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R)
Compute thin QR using modified Gram-Schmidt.
void generateRandomMatrix(SDM &A, ordinal_type rank)
bool test_weighted_CPQR(wcpqr_func_type qr_func, ordinal_type m, ordinal_type n, ordinal_type k, scalar_type rtol, scalar_type atol, Teuchos::FancyOStream &out)
void CPQR_Householder3(const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R, Teuchos::Array< ordinal_type > &piv)
Compute column-pivoted QR using Householder reflections.
bool test_CPQR(cpqr_func_type qr_func, ordinal_type m, ordinal_type n, scalar_type rtol, scalar_type atol, Teuchos::FancyOStream &out)
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
bool compareSDM(const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &a1, const std::string &a1_name, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &a2, const std::string &a2_name, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
bool test_QR(qr_func_type qr_func, ordinal_type m, ordinal_type n, scalar_type rtol, scalar_type atol, Teuchos::FancyOStream &out)
void(* qr_func_type)(ordinal_type, const SDM &, const Teuchos::Array< scalar_type > &, SDM &, SDM &)
void CPQR_Householder(const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R, Teuchos::Array< ordinal_type > &piv)
Compute column-pivoted QR using Householder reflections.
void QR_MGS2(ordinal_type k, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R)
Compute thin QR using modified Gram-Schmidt with reorthogonalization.
Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > SDM
TEUCHOS_UNIT_TEST(Stokhos_SDMUtils, QR_CGS_TallSkinny)
void QR_Householder(ordinal_type k, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R)
Compute thin QR using Householder reflections.
ordinal_type CPQR_MGS_reorthog_threshold(const scalar_type &rank_threshold, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R, Teuchos::Array< ordinal_type > &piv)
Compute column-pivoted QR using modified Gram-Schmidt and reorthogonalization.