File: print.cu

package info (click to toggle)
python-escript 5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 87,772 kB
  • ctags: 49,550
  • sloc: python: 585,488; cpp: 133,173; ansic: 18,675; xml: 3,283; sh: 690; makefile: 215
file content (37 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (4)
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
#include <unittest/unittest.h>

#include <cusp/print.h>

#include <cusp/array1d.h>
#include <cusp/array2d.h>
#include <cusp/coo_matrix.h>
#include <cusp/csr_matrix.h>
#include <cusp/dia_matrix.h>
#include <cusp/ell_matrix.h>
#include <cusp/hyb_matrix.h>

#include <sstream>

template <typename Matrix>
void TestPrintMatrix(void)
{
    // initialize a 2x3 matrix
    cusp::array2d<float, cusp::host_memory> A(2,3);
    A(0,0) = 42;  A(0,1) =  0;  A(0,2) = 53;
    A(1,0) =  0;  A(1,1) = 71;  A(1,2) =  0;
    
    Matrix M(A);

    std::ostringstream oss;
    
    cusp::print(M, oss);

    // ensure certain substrings are present in the output
    ASSERT_EQUAL(oss.str().length() > 0, true);
    ASSERT_EQUAL(oss.str().find("<2, 3>") != std::string::npos, true);
    ASSERT_EQUAL(oss.str().find("42") != std::string::npos, true);
    ASSERT_EQUAL(oss.str().find("53") != std::string::npos, true);
    ASSERT_EQUAL(oss.str().find("71") != std::string::npos, true);
}
DECLARE_MATRIX_UNITTEST(TestPrintMatrix);