/[escript]/branches/diaplayground/cusplibrary/testing/csr_matrix.cu
ViewVC logotype

Annotation of /branches/diaplayground/cusplibrary/testing/csr_matrix.cu

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4955 - (hide annotations)
Tue May 20 04:33:15 2014 UTC (5 years, 5 months ago) by caltinay
File size: 4056 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 caltinay 4955 #include <unittest/unittest.h>
2     #include <cusp/csr_matrix.h>
3    
4     template <class Space>
5     void TestCsrMatrixBasicConstructor(void)
6     {
7     cusp::csr_matrix<int, float, Space> matrix(3, 2, 6);
8    
9     ASSERT_EQUAL(matrix.num_rows, 3);
10     ASSERT_EQUAL(matrix.num_cols, 2);
11     ASSERT_EQUAL(matrix.num_entries, 6);
12     ASSERT_EQUAL(matrix.row_offsets.size(), 4);
13     ASSERT_EQUAL(matrix.column_indices.size(), 6);
14     ASSERT_EQUAL(matrix.values.size(), 6);
15     }
16     DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixBasicConstructor);
17    
18     template <class Space>
19     void TestCsrMatrixCopyConstructor(void)
20     {
21     cusp::csr_matrix<int, float, Space> matrix(3, 2, 6);
22    
23     matrix.row_offsets[0] = 0;
24     matrix.row_offsets[1] = 2;
25     matrix.row_offsets[2] = 4;
26     matrix.row_offsets[3] = 6;
27    
28     matrix.column_indices[0] = 0; matrix.values[0] = 0;
29     matrix.column_indices[1] = 1; matrix.values[1] = 1;
30     matrix.column_indices[2] = 0; matrix.values[2] = 2;
31     matrix.column_indices[3] = 1; matrix.values[3] = 3;
32     matrix.column_indices[4] = 0; matrix.values[4] = 4;
33     matrix.column_indices[5] = 1; matrix.values[5] = 5;
34    
35     cusp::csr_matrix<int, float, Space> copy_of_matrix(matrix);
36    
37     ASSERT_EQUAL(copy_of_matrix.num_rows, 3);
38     ASSERT_EQUAL(copy_of_matrix.num_cols, 2);
39     ASSERT_EQUAL(copy_of_matrix.num_entries, 6);
40     ASSERT_EQUAL(copy_of_matrix.row_offsets.size(), 4);
41     ASSERT_EQUAL(copy_of_matrix.column_indices.size(), 6);
42     ASSERT_EQUAL(copy_of_matrix.values.size(), 6);
43    
44     ASSERT_EQUAL(copy_of_matrix.row_offsets, matrix.row_offsets);
45     ASSERT_EQUAL(copy_of_matrix.column_indices, matrix.column_indices);
46     ASSERT_EQUAL(copy_of_matrix.values, matrix.values);
47     }
48     DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixCopyConstructor);
49    
50     template <class Space>
51     void TestCsrMatrixResize(void)
52     {
53     cusp::csr_matrix<int, float, Space> matrix;
54    
55     matrix.resize(3, 2, 6);
56    
57     ASSERT_EQUAL(matrix.num_rows, 3);
58     ASSERT_EQUAL(matrix.num_cols, 2);
59     ASSERT_EQUAL(matrix.num_entries, 6);
60     ASSERT_EQUAL(matrix.row_offsets.size(), 4);
61     ASSERT_EQUAL(matrix.column_indices.size(), 6);
62     ASSERT_EQUAL(matrix.values.size(), 6);
63     }
64     DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixResize);
65    
66     template <class Space>
67     void TestCsrMatrixSwap(void)
68     {
69     cusp::csr_matrix<int, float, Space> A(1, 2, 2);
70     cusp::csr_matrix<int, float, Space> B(3, 1, 3);
71    
72     A.row_offsets[0] = 0;
73     A.row_offsets[1] = 2;
74    
75     A.column_indices[0] = 0; A.values[0] = 0;
76     A.column_indices[1] = 1; A.values[1] = 1;
77    
78     B.row_offsets[0] = 0;
79     B.row_offsets[1] = 1;
80     B.row_offsets[2] = 2;
81     B.row_offsets[3] = 3;
82    
83     B.column_indices[0] = 0; B.values[0] = 0;
84     B.column_indices[1] = 0; B.values[1] = 1;
85     B.column_indices[2] = 0; B.values[2] = 2;
86    
87     cusp::csr_matrix<int, float, Space> A_copy(A);
88     cusp::csr_matrix<int, float, Space> B_copy(B);
89    
90     A.swap(B);
91    
92     ASSERT_EQUAL(A.num_rows, 3);
93     ASSERT_EQUAL(A.num_cols, 1);
94     ASSERT_EQUAL(A.num_entries, 3);
95     ASSERT_EQUAL(A.row_offsets, B_copy.row_offsets);
96     ASSERT_EQUAL(A.column_indices, B_copy.column_indices);
97     ASSERT_EQUAL(A.values, B_copy.values);
98    
99     ASSERT_EQUAL(B.num_rows, 1);
100     ASSERT_EQUAL(B.num_cols, 2);
101     ASSERT_EQUAL(B.num_entries, 2);
102     ASSERT_EQUAL(B.row_offsets, A_copy.row_offsets);
103     ASSERT_EQUAL(B.column_indices, A_copy.column_indices);
104     ASSERT_EQUAL(B.values, A_copy.values);
105     }
106     DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixSwap);
107    
108     void TestCsrMatrixRebind(void)
109     {
110     typedef cusp::csr_matrix<int, float, cusp::host_memory> HostMatrix;
111     typedef HostMatrix::rebind<cusp::device_memory>::type DeviceMatrix;
112    
113     HostMatrix h_matrix(10,10,100);
114     DeviceMatrix d_matrix(h_matrix);
115    
116     ASSERT_EQUAL(h_matrix.num_entries, d_matrix.num_entries);
117     }
118     DECLARE_UNITTEST(TestCsrMatrixRebind);
119    

  ViewVC Help
Powered by ViewVC 1.1.26