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

Contents of /branches/diaplayground/cusplibrary/testing/csr_matrix_view.cu

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #include <unittest/unittest.h>
2
3 #include <cusp/csr_matrix.h>
4 #include <cusp/multiply.h>
5
6 template <typename MemorySpace>
7 void TestCsrMatrixView(void)
8 {
9 typedef int IndexType;
10 typedef float ValueType;
11 typedef typename cusp::csr_matrix<IndexType,ValueType,MemorySpace> Matrix;
12 typedef typename cusp::array1d<IndexType,MemorySpace>::iterator IndexIterator;
13 typedef typename cusp::array1d<ValueType,MemorySpace>::iterator ValueIterator;
14 typedef typename cusp::array1d_view<IndexIterator> IndexView;
15 typedef typename cusp::array1d_view<ValueIterator> ValueView;
16 typedef typename cusp::csr_matrix_view<IndexView,IndexView,ValueView> View;
17
18 Matrix M(3, 2, 6);
19
20 View V(3, 2, 6,
21 cusp::make_array1d_view(M.row_offsets.begin(), M.row_offsets.end()),
22 cusp::make_array1d_view(M.column_indices.begin(), M.column_indices.end()),
23 cusp::make_array1d_view(M.values.begin(), M.values.end()));
24
25 ASSERT_EQUAL(V.num_rows, 3);
26 ASSERT_EQUAL(V.num_cols, 2);
27 ASSERT_EQUAL(V.num_entries, 6);
28
29 ASSERT_EQUAL_QUIET(V.row_offsets.begin(), M.row_offsets.begin());
30 ASSERT_EQUAL_QUIET(V.row_offsets.end(), M.row_offsets.end());
31 ASSERT_EQUAL_QUIET(V.column_indices.begin(), M.column_indices.begin());
32 ASSERT_EQUAL_QUIET(V.column_indices.end(), M.column_indices.end());
33 ASSERT_EQUAL_QUIET(V.values.begin(), M.values.begin());
34 ASSERT_EQUAL_QUIET(V.values.end(), M.values.end());
35
36 View W(M);
37
38 ASSERT_EQUAL(W.num_rows, 3);
39 ASSERT_EQUAL(W.num_cols, 2);
40 ASSERT_EQUAL(W.num_entries, 6);
41
42 ASSERT_EQUAL_QUIET(W.row_offsets.begin(), M.row_offsets.begin());
43 ASSERT_EQUAL_QUIET(W.row_offsets.end(), M.row_offsets.end());
44 ASSERT_EQUAL_QUIET(W.column_indices.begin(), M.column_indices.begin());
45 ASSERT_EQUAL_QUIET(W.column_indices.end(), M.column_indices.end());
46 ASSERT_EQUAL_QUIET(W.values.begin(), M.values.begin());
47 ASSERT_EQUAL_QUIET(W.values.end(), M.values.end());
48 }
49 DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixView);
50
51
52 template <typename MemorySpace>
53 void TestCsrMatrixViewAssignment(void)
54 {
55 typedef int IndexType;
56 typedef float ValueType;
57 typedef typename cusp::csr_matrix<IndexType,ValueType,MemorySpace> Matrix;
58 typedef typename cusp::array1d<IndexType,MemorySpace>::iterator IndexIterator;
59 typedef typename cusp::array1d<ValueType,MemorySpace>::iterator ValueIterator;
60 typedef typename cusp::array1d_view<IndexIterator> IndexView;
61 typedef typename cusp::array1d_view<ValueIterator> ValueView;
62 typedef typename cusp::csr_matrix_view<IndexView,IndexView,ValueView> View;
63
64 Matrix M(3, 2, 6);
65
66 View V = M;
67
68 ASSERT_EQUAL(V.num_rows, 3);
69 ASSERT_EQUAL(V.num_cols, 2);
70 ASSERT_EQUAL(V.num_entries, 6);
71
72 ASSERT_EQUAL_QUIET(V.row_offsets.begin(), M.row_offsets.begin());
73 ASSERT_EQUAL_QUIET(V.row_offsets.end(), M.row_offsets.end());
74 ASSERT_EQUAL_QUIET(V.column_indices.begin(), M.column_indices.begin());
75 ASSERT_EQUAL_QUIET(V.column_indices.end(), M.column_indices.end());
76 ASSERT_EQUAL_QUIET(V.values.begin(), M.values.begin());
77 ASSERT_EQUAL_QUIET(V.values.end(), M.values.end());
78
79 View W = V;
80
81 ASSERT_EQUAL(W.num_rows, 3);
82 ASSERT_EQUAL(W.num_cols, 2);
83 ASSERT_EQUAL(W.num_entries, 6);
84
85 ASSERT_EQUAL_QUIET(W.row_offsets.begin(), M.row_offsets.begin());
86 ASSERT_EQUAL_QUIET(W.row_offsets.end(), M.row_offsets.end());
87 ASSERT_EQUAL_QUIET(W.column_indices.begin(), M.column_indices.begin());
88 ASSERT_EQUAL_QUIET(W.column_indices.end(), M.column_indices.end());
89 ASSERT_EQUAL_QUIET(W.values.begin(), M.values.begin());
90 ASSERT_EQUAL_QUIET(W.values.end(), M.values.end());
91 }
92 DECLARE_HOST_DEVICE_UNITTEST(TestCsrMatrixViewAssignment);
93
94
95 template <typename MemorySpace>
96 void TestMakeCsrMatrixView(void)
97 {
98 typedef int IndexType;
99 typedef float ValueType;
100 typedef typename cusp::csr_matrix<IndexType,ValueType,MemorySpace> Matrix;
101 typedef typename cusp::array1d<IndexType,MemorySpace>::iterator IndexIterator;
102 typedef typename cusp::array1d<ValueType,MemorySpace>::iterator ValueIterator;
103 typedef typename cusp::array1d_view<IndexIterator> IndexView;
104 typedef typename cusp::array1d_view<ValueIterator> ValueView;
105 typedef typename cusp::csr_matrix_view<IndexView,IndexView,ValueView> View;
106
107 // construct view from parts
108 {
109 Matrix M(3, 2, 6);
110
111 View V =
112 cusp::make_csr_matrix_view(3, 2, 6,
113 cusp::make_array1d_view(M.row_offsets),
114 cusp::make_array1d_view(M.column_indices),
115 cusp::make_array1d_view(M.values));
116
117 ASSERT_EQUAL(V.num_rows, 3);
118 ASSERT_EQUAL(V.num_cols, 2);
119 ASSERT_EQUAL(V.num_entries, 6);
120
121 V.row_offsets[0] = 0; V.column_indices[0] = 1; V.values[0] = 2;
122
123 ASSERT_EQUAL_QUIET(V.row_offsets.begin(), M.row_offsets.begin());
124 ASSERT_EQUAL_QUIET(V.row_offsets.end(), M.row_offsets.end());
125 ASSERT_EQUAL_QUIET(V.column_indices.begin(), M.column_indices.begin());
126 ASSERT_EQUAL_QUIET(V.column_indices.end(), M.column_indices.end());
127 ASSERT_EQUAL_QUIET(V.values.begin(), M.values.begin());
128 ASSERT_EQUAL_QUIET(V.values.end(), M.values.end());
129 }
130
131 // construct view from matrix
132 {
133 Matrix M(3, 2, 6);
134
135 View V = cusp::make_csr_matrix_view(M);
136
137 ASSERT_EQUAL(V.num_rows, 3);
138 ASSERT_EQUAL(V.num_cols, 2);
139 ASSERT_EQUAL(V.num_entries, 6);
140
141 V.row_offsets[0] = 0; V.column_indices[0] = 1; V.values[0] = 2;
142
143 ASSERT_EQUAL_QUIET(V.row_offsets.begin(), M.row_offsets.begin());
144 ASSERT_EQUAL_QUIET(V.row_offsets.end(), M.row_offsets.end());
145 ASSERT_EQUAL_QUIET(V.column_indices.begin(), M.column_indices.begin());
146 ASSERT_EQUAL_QUIET(V.column_indices.end(), M.column_indices.end());
147 ASSERT_EQUAL_QUIET(V.values.begin(), M.values.begin());
148 ASSERT_EQUAL_QUIET(V.values.end(), M.values.end());
149 }
150
151 // construct view from view
152 {
153 Matrix M(3, 2, 6);
154
155 View X = cusp::make_csr_matrix_view(M);
156 View V = cusp::make_csr_matrix_view(X);
157
158 ASSERT_EQUAL(V.num_rows, 3);
159 ASSERT_EQUAL(V.num_cols, 2);
160 ASSERT_EQUAL(V.num_entries, 6);
161
162 V.row_offsets[0] = 0; V.column_indices[0] = 1; V.values[0] = 2;
163
164 ASSERT_EQUAL_QUIET(V.row_offsets.begin(), M.row_offsets.begin());
165 ASSERT_EQUAL_QUIET(V.row_offsets.end(), M.row_offsets.end());
166 ASSERT_EQUAL_QUIET(V.column_indices.begin(), M.column_indices.begin());
167 ASSERT_EQUAL_QUIET(V.column_indices.end(), M.column_indices.end());
168 ASSERT_EQUAL_QUIET(V.values.begin(), M.values.begin());
169 ASSERT_EQUAL_QUIET(V.values.end(), M.values.end());
170 }
171
172 // construct view from const matrix
173 {
174 const Matrix M(3, 2, 6);
175
176 ASSERT_EQUAL(cusp::make_csr_matrix_view(M).num_rows, 3);
177 ASSERT_EQUAL(cusp::make_csr_matrix_view(M).num_cols, 2);
178 ASSERT_EQUAL(cusp::make_csr_matrix_view(M).num_entries, 6);
179
180 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).row_offsets.begin(), M.row_offsets.begin());
181 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).row_offsets.end(), M.row_offsets.end());
182 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).column_indices.begin(), M.column_indices.begin());
183 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).column_indices.end(), M.column_indices.end());
184 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).values.begin(), M.values.begin());
185 ASSERT_EQUAL_QUIET(cusp::make_csr_matrix_view(M).values.end(), M.values.end());
186 }
187 }
188 DECLARE_HOST_DEVICE_UNITTEST(TestMakeCsrMatrixView);
189

  ViewVC Help
Powered by ViewVC 1.1.26