From 7c61fb5cedca75058f0cac35badf517fc9e2d539 Mon Sep 17 00:00:00 2001 From: David Bellot Date: Mon, 5 Jul 2010 18:20:58 +0000 Subject: [PATCH] whoops another file missing. Now it's correct, kdiff3 gives 100% between trunk and release [SVN r63670] --- test/sparse_view_test.cpp | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 test/sparse_view_test.cpp diff --git a/test/sparse_view_test.cpp b/test/sparse_view_test.cpp new file mode 100644 index 00000000..ce4602c6 --- /dev/null +++ b/test/sparse_view_test.cpp @@ -0,0 +1,107 @@ + +/* Test program to test find functions of triagular matrices + * + * author: Gunter Winkler ( guwi17 at gmx dot de ) + */ + + +// ublas headers + +#include + +#include +#include +#include + +#include + +// other boost headers + +// headers for testcase + +#define BOOST_TEST_MODULE SparseMatrixErasureTest +#include + +// standard and system headers + +#include +#include + +namespace ublas = boost::numeric::ublas; + + /* + sparse input matrix: + + 1 2 0 0 + 0 3 9 0 + 0 1 4 0 + */ + + static const std::string inputMatrix = "[3,4]((1,2,0,0),(0,3,9,0),(0,1,4,0))\n"; + + const unsigned int NNZ = 6; + const unsigned int IB = 1; + const double VA[] = { 1.0, 2.0, 3.0, 9.0, 1.0, 4.0 }; + const unsigned int IA[] = { 1, 3, 5, 7 }; + const unsigned int JA[] = { 1, 2, 2, 3, 2, 3 }; + +BOOST_AUTO_TEST_CASE( test_construction_and_basic_operations ) +{ + + typedef ublas::matrix DENSE_MATRIX; + + // prepare data + + DENSE_MATRIX A; + + std::istringstream iss(inputMatrix); + iss >> A; + + std::cout << A << std::endl; + + std::cout << ( ublas::make_compressed_matrix_view(3,4,NNZ,IA,JA,VA) ) << std::endl; + + typedef ublas::compressed_matrix_view COMPMATVIEW; + + COMPMATVIEW viewA(3,4,NNZ,IA,JA,VA); + + std::cout << viewA << std::endl; + +} + + + +BOOST_AUTO_TEST_CASE( test_construction_from_pointers ) +{ + + std::cout << ( ublas::make_compressed_matrix_view(4,3,NNZ + , ublas::c_array_view(4,&(IA[0])) + , ublas::c_array_view(6,&(JA[0])) + , ublas::c_array_view(6,&(VA[0]))) ) << std::endl; + + unsigned int * ia = new unsigned int[4](); + unsigned int * ja = new unsigned int[6](); + double * va = new double[6](); + + std::copy(&(IA[0]),&(IA[4]),ia); + std::copy(&(JA[0]),&(JA[6]),ja); + std::copy(&(VA[0]),&(VA[6]),va); + + typedef ublas::compressed_matrix_view + , ublas::c_array_view + , ublas::c_array_view > COMPMATVIEW; + + COMPMATVIEW viewA(4,3,NNZ + , ublas::c_array_view(4,ia) + , ublas::c_array_view(6,ja) + , ublas::c_array_view(6,va)); + + std::cout << viewA << std::endl; + + delete[] va; + delete[] ja; + delete[] ia; + +}