1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/* tests/test-transpose.C
*
* ------------------------------------
*
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*.
*/
/*! @file tests/test-transpose.C
* @ingroup tests
*
* @brief no doc
*
* @test no doc.
*/
#include "linbox/linbox-config.h"
#include <iostream>
#include <fstream>
#include "linbox/util/commentator.h"
#include "linbox/ring/modular.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/blackbox/scalar-matrix.h"
#include "linbox/blackbox/transpose.h"
#include "linbox/matrix/dense-matrix.h"
#include "linbox/matrix/sparse-matrix.h"
#include "test-common.h"
#include "test-blackbox.h"
using namespace LinBox;
#if 0
template <class Field2, class Blackbox>
static bool testBBrebind (const Field2 &F2, const Blackbox& B)
{
typedef typename Blackbox::template rebind<Field2>::other FBlackbox;
FBlackbox A(B, F2);
return testBlackbox(A);
}
#endif
/* Test Transpose:
* Check that Transpose<Blackbox> meets blackbox interface and behaves
* as transpose.
*
* Return true on success and false on failure
*/
template <class Blackbox>
static bool testTransposeBlackbox(Blackbox & A)
{
typedef typename Blackbox::Field Field;
commentator().start ("Testing Transpose", "testTranspose", 1);
Transpose<Blackbox> B(A);
bool ret = true, ret1;
size_t m = A.rowdim(), n = A.coldim();
const Field & F = A.field();
VectorDomain<Field> VD (F);
BlasVector<Field> x(F,n), y(F,m), z(F,n), w(F,m);
VD.random(x);
A.apply(y, x);
B.applyTranspose(w, x);
ret1 = VD.areEqual(y, w);
if (not ret1) commentator().report() << "A and B^T disagree, FAIL" << std::endl;
ret = ret and ret1;
VD.random(y);
A.applyTranspose(x, y);
B.apply(z, y);
ret1 = VD.areEqual(x, z);
if (not ret1) commentator().report() << "A^T and B disagree, FAIL" << std::endl;
ret = ret and ret1;
ret1 = testBlackboxNoRW(B);
if (not ret1) commentator().report() << "testBlackbox A^T FAIL" << std::endl;
ret = ret and ret1;
commentator().stop (MSG_STATUS (ret), (const char *) 0, "testTranspose");
return ret;
}
// ??? transpose.h does not attempt to define setEntry, getEntry ??? bds
/* Test getEntry and setEntry of a Transpose<BB>.
*
* this test template can be instantiated only if the underlying class BB
* has getEntry and setEntry (as dense and sparse matrix types should).
*
* For such matrices, A and A^T should share memory, so that results of
* setEntry on one are reflected by getEntry on the other.
*/
template <class Matrix>
bool testTransposeMatrix(Matrix& A) {
commentator().start ("Testing Transpose", "testTranspose", 1);
bool ret = true, ret1;
typedef typename Matrix::Field Field;
typename Field::Element x, y;
const Field & F = A.field();
F.init(x);
F.init(y);
Transpose<Matrix> B(A);
size_t m = A.rowdim(), n = A.coldim();
size_t i = (size_t)rand()%m, j = (size_t)rand()%n;
A.getEntry(x, i, j);
B.getEntry(y, j, i);
ret = ret and (ret1 = F.areEqual(x, y));
if (not ret1) commentator().report() << "A, A^T same getentry FAIL" << std::endl;
i = (size_t)rand()%m, j = (size_t)rand()%n;
A.setEntry(i, j, x);
B.getEntry(y, j, i);
ret = ret and (ret1 = F.areEqual(x, y));
if (not ret1) commentator().report() << "A set, A^T getEntry FAIL" << std::endl;
i = (size_t)rand()%m, j = (size_t)rand()%n;
B.setEntry(j, i, x);
A.getEntry(y, i, j);
ret = ret and (ret1 = F.areEqual(x, y));
if (not ret1) commentator().report() << "A^T set, A getEntry FAIL" << std::endl;
commentator().stop (MSG_STATUS (ret), (const char *) 0, "testTranspose");
return ret;
}
int main (int argc, char **argv)
{
bool pass = true;
static size_t m = 8;
static size_t n = 10;
static integer q = 101;
static Argument args[] = {
{ 'm', "-m M", "Set dimension of test matrices to NxN.", TYPE_INT, &m },
{ 'n', "-n N", "Set dimension of test matrices to NxN.", TYPE_INT, &n },
{ 'q', "-q Q", "Operate over the \"field\" GF(Q) [1].", TYPE_INTEGER, &q },
END_OF_ARGUMENTS
};
typedef Givaro::Modular<int32_t> Field ;
Field F(q);
// typedef vector<Field::Element> Vector;
parseArguments (argc, argv, args);
commentator().start("transpose black box test suite", "transpose");
// Make sure some more detailed messages get printed
commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDepth (2);
commentator().start("test on ScalarMatrix");
Field::Element s; F.init(s, 5);
ScalarMatrix<Field> A(F, n, n, s);
pass = pass and testTransposeBlackbox(A);
commentator().stop(MSG_STATUS (pass), (const char *) 0, "test on ScalarMatrix");
commentator().start("test on BlasMatrix");
BlasMatrix<Field> B(F, m, n);
for (size_t i = 0; i < m; ++i)
for (size_t j = 0; j < n; ++j)
B.setEntry(i, j, F.init(s, i*j));
pass = pass and testTransposeBlackbox(B);
// pass = pass and testTransposeMatrix(B);
commentator().stop(MSG_STATUS (pass), (const char *) 0, "test on BlasMatrix");
commentator().start("test on TriplesBB");
#if 0 /* fails because setEntry(?,?,0) fails. */
SparseMatrix<Field,SparseMatrixFormat::TPL> C(F, m, n);
for (size_t i = 0; i < min(m, n); ++i) C.setEntry(i, i, F.init(s, i+1));
pass = pass and testTransposeBlackbox(C);
pass = pass and testTransposeMatrix(C);
#endif
commentator().stop(MSG_STATUS (pass), (const char *) 0, "test on TriplesBB");
commentator().start("test on COO");
SparseMatrix<Field,SparseMatrixFormat::COO> C(F, m, n);
for (size_t i = 0; i < min(m, n); ++i) C.setEntry(i, i, F.init(s, i+1));
pass = pass and testTransposeBlackbox(C);
// pass = pass and testTransposeMatrix(C);
commentator().stop(MSG_STATUS (pass), (const char *) 0, "test on TriplesBB");
commentator().stop(MSG_STATUS (pass), (const char *) 0, "transpose black box test suite");
return pass ? 0 : -1;
}
// Local Variables:
// mode: C++
// tab-width: 4
// indent-tabs-mode: nil
// c-basic-offset: 4
// End:
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
|