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

Contents of /branches/diaplayground/cusplibrary/testing/ell_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: 9947 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 #include <unittest/unittest.h>
2
3 #include <cusp/ell_matrix.h>
4 #include <cusp/multiply.h>
5
6 template <typename MemorySpace>
7 void TestEllMatrixView(void)
8 {
9 typedef int IndexType;
10 typedef float ValueType;
11 typedef typename cusp::ell_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> IndexView1d;
15 typedef typename cusp::array1d_view<ValueIterator> ValueView1d;
16 typedef typename cusp::array2d_view<IndexView1d,cusp::column_major> IndexView2d;
17 typedef typename cusp::array2d_view<ValueView1d,cusp::column_major> ValueView2d;
18 typedef typename cusp::ell_matrix_view<IndexView2d,ValueView2d> View;
19
20 Matrix M(3, 2, 6, 2);
21
22 View V(3, 2, 6,
23 cusp::make_array2d_view(M.column_indices),
24 cusp::make_array2d_view(M.values));
25
26 ASSERT_EQUAL(V.num_rows, 3);
27 ASSERT_EQUAL(V.num_cols, 2);
28 ASSERT_EQUAL(V.num_entries, 6);
29
30 ASSERT_EQUAL_QUIET(V.column_indices.num_rows, M.column_indices.num_rows);
31 ASSERT_EQUAL_QUIET(V.column_indices.num_cols, M.column_indices.num_cols);
32 ASSERT_EQUAL_QUIET(V.column_indices.num_entries, M.column_indices.num_entries);
33 ASSERT_EQUAL_QUIET(V.column_indices.pitch, M.column_indices.pitch);
34 ASSERT_EQUAL_QUIET(V.column_indices.values.begin(), M.column_indices.values.begin());
35 ASSERT_EQUAL_QUIET(V.column_indices.values.end(), M.column_indices.values.end());
36 ASSERT_EQUAL_QUIET(V.values.num_rows, M.values.num_rows);
37 ASSERT_EQUAL_QUIET(V.values.num_cols, M.values.num_cols);
38 ASSERT_EQUAL_QUIET(V.values.num_entries, M.values.num_entries);
39 ASSERT_EQUAL_QUIET(V.values.pitch, M.values.pitch);
40 ASSERT_EQUAL_QUIET(V.values.values.begin(), M.values.values.begin());
41 ASSERT_EQUAL_QUIET(V.values.values.end(), M.values.values.end());
42
43 View W(M);
44
45 ASSERT_EQUAL(W.num_rows, 3);
46 ASSERT_EQUAL(W.num_cols, 2);
47 ASSERT_EQUAL(W.num_entries, 6);
48
49 ASSERT_EQUAL_QUIET(W.column_indices.num_rows, M.column_indices.num_rows);
50 ASSERT_EQUAL_QUIET(W.column_indices.num_cols, M.column_indices.num_cols);
51 ASSERT_EQUAL_QUIET(W.column_indices.num_entries, M.column_indices.num_entries);
52 ASSERT_EQUAL_QUIET(W.column_indices.pitch, M.column_indices.pitch);
53 ASSERT_EQUAL_QUIET(W.column_indices.values.begin(), M.column_indices.values.begin());
54 ASSERT_EQUAL_QUIET(W.column_indices.values.end(), M.column_indices.values.end());
55 ASSERT_EQUAL_QUIET(W.values.num_rows, M.values.num_rows);
56 ASSERT_EQUAL_QUIET(W.values.num_cols, M.values.num_cols);
57 ASSERT_EQUAL_QUIET(W.values.num_entries, M.values.num_entries);
58 ASSERT_EQUAL_QUIET(W.values.pitch, M.values.pitch);
59 ASSERT_EQUAL_QUIET(W.values.values.begin(), M.values.values.begin());
60 ASSERT_EQUAL_QUIET(W.values.values.end(), M.values.values.end());
61 }
62 DECLARE_HOST_DEVICE_UNITTEST(TestEllMatrixView);
63
64
65 template <typename MemorySpace>
66 void TestEllMatrixViewAssignment(void)
67 {
68 typedef int IndexType;
69 typedef float ValueType;
70 typedef typename cusp::ell_matrix<IndexType,ValueType,MemorySpace> Matrix;
71 typedef typename cusp::array1d<IndexType,MemorySpace>::iterator IndexIterator;
72 typedef typename cusp::array1d<ValueType,MemorySpace>::iterator ValueIterator;
73 typedef typename cusp::array1d_view<IndexIterator> IndexView1d;
74 typedef typename cusp::array1d_view<ValueIterator> ValueView1d;
75 typedef typename cusp::array2d_view<IndexView1d,cusp::column_major> IndexView2d;
76 typedef typename cusp::array2d_view<ValueView1d,cusp::column_major> ValueView2d;
77 typedef typename cusp::ell_matrix_view<IndexView2d,ValueView2d> View;
78
79 Matrix M(3, 2, 6, 2);
80
81 View V = M;
82
83 ASSERT_EQUAL(V.num_rows, 3);
84 ASSERT_EQUAL(V.num_cols, 2);
85 ASSERT_EQUAL(V.num_entries, 6);
86
87 ASSERT_EQUAL_QUIET(V.column_indices.num_rows, M.column_indices.num_rows);
88 ASSERT_EQUAL_QUIET(V.column_indices.num_cols, M.column_indices.num_cols);
89 ASSERT_EQUAL_QUIET(V.column_indices.num_entries, M.column_indices.num_entries);
90 ASSERT_EQUAL_QUIET(V.column_indices.pitch, M.column_indices.pitch);
91 ASSERT_EQUAL_QUIET(V.column_indices.values.begin(), M.column_indices.values.begin());
92 ASSERT_EQUAL_QUIET(V.column_indices.values.end(), M.column_indices.values.end());
93 ASSERT_EQUAL_QUIET(V.values.num_rows, M.values.num_rows);
94 ASSERT_EQUAL_QUIET(V.values.num_cols, M.values.num_cols);
95 ASSERT_EQUAL_QUIET(V.values.num_entries, M.values.num_entries);
96 ASSERT_EQUAL_QUIET(V.values.pitch, M.values.pitch);
97 ASSERT_EQUAL_QUIET(V.values.values.begin(), M.values.values.begin());
98 ASSERT_EQUAL_QUIET(V.values.values.end(), M.values.values.end());
99
100 View W = V;
101
102 ASSERT_EQUAL(W.num_rows, 3);
103 ASSERT_EQUAL(W.num_cols, 2);
104 ASSERT_EQUAL(W.num_entries, 6);
105
106 ASSERT_EQUAL_QUIET(W.column_indices.num_rows, M.column_indices.num_rows);
107 ASSERT_EQUAL_QUIET(W.column_indices.num_cols, M.column_indices.num_cols);
108 ASSERT_EQUAL_QUIET(W.column_indices.num_entries, M.column_indices.num_entries);
109 ASSERT_EQUAL_QUIET(W.column_indices.pitch, M.column_indices.pitch);
110 ASSERT_EQUAL_QUIET(W.column_indices.values.begin(), M.column_indices.values.begin());
111 ASSERT_EQUAL_QUIET(W.column_indices.values.end(), M.column_indices.values.end());
112 ASSERT_EQUAL_QUIET(W.values.num_rows, M.values.num_rows);
113 ASSERT_EQUAL_QUIET(W.values.num_cols, M.values.num_cols);
114 ASSERT_EQUAL_QUIET(W.values.num_entries, M.values.num_entries);
115 ASSERT_EQUAL_QUIET(W.values.pitch, M.values.pitch);
116 ASSERT_EQUAL_QUIET(W.values.values.begin(), M.values.values.begin());
117 ASSERT_EQUAL_QUIET(W.values.values.end(), M.values.values.end());
118
119 }
120 DECLARE_HOST_DEVICE_UNITTEST(TestEllMatrixViewAssignment);
121
122
123 template <typename MemorySpace>
124 void TestMakeEllMatrixView(void)
125 {
126 typedef int IndexType;
127 typedef float ValueType;
128 typedef typename cusp::ell_matrix<IndexType,ValueType,MemorySpace> Matrix;
129 typedef typename cusp::array1d<IndexType,MemorySpace>::iterator IndexIterator;
130 typedef typename cusp::array1d<ValueType,MemorySpace>::iterator ValueIterator;
131 typedef typename cusp::array1d_view<IndexIterator> IndexView1d;
132 typedef typename cusp::array1d_view<ValueIterator> ValueView1d;
133 typedef typename cusp::array2d_view<IndexView1d,cusp::column_major> IndexView2d;
134 typedef typename cusp::array2d_view<ValueView1d,cusp::column_major> ValueView2d;
135 typedef typename cusp::ell_matrix_view<IndexView2d,ValueView2d> View;
136 typedef typename cusp::array1d<IndexType,MemorySpace>::const_iterator ConstIndexIterator;
137 typedef typename cusp::array1d<ValueType,MemorySpace>::const_iterator ConstValueIterator;
138 typedef typename cusp::array1d_view<ConstIndexIterator> ConstIndexView1d;
139 typedef typename cusp::array1d_view<ConstValueIterator> ConstValueView1d;
140 typedef typename cusp::array2d_view<ConstIndexView1d,cusp::column_major> ConstIndexView2d;
141 typedef typename cusp::array2d_view<ConstValueView1d,cusp::column_major> ConstValueView2d;
142 typedef typename cusp::ell_matrix_view<ConstIndexView2d,ConstValueView2d> ConstView;
143
144 // construct view from parts
145 {
146 Matrix M(3, 2, 6, 2);
147
148 View V =
149 cusp::make_ell_matrix_view(3, 2, 6,
150 cusp::make_array2d_view(M.column_indices),
151 cusp::make_array2d_view(M.values));
152
153 ASSERT_EQUAL(V.num_rows, 3);
154 ASSERT_EQUAL(V.num_cols, 2);
155 ASSERT_EQUAL(V.num_entries, 6);
156
157 V.column_indices(0,0) = 10;
158 V.values(0,0) = 20;
159
160 ASSERT_EQUAL_QUIET(V.column_indices, M.column_indices);
161 ASSERT_EQUAL_QUIET(V.values, M.values);
162 }
163
164 // construct view from matrix
165 {
166 Matrix M(3, 2, 6, 2);
167
168 View V = cusp::make_ell_matrix_view(M);
169
170 ASSERT_EQUAL(V.num_rows, 3);
171 ASSERT_EQUAL(V.num_cols, 2);
172 ASSERT_EQUAL(V.num_entries, 6);
173
174 V.column_indices(0,0) = 10;
175 V.values(0,0) = 20;
176
177 ASSERT_EQUAL_QUIET(V.column_indices, M.column_indices);
178 ASSERT_EQUAL_QUIET(V.values, M.values);
179 }
180
181 // construct view from view
182 {
183 Matrix M(3, 2, 6, 2);
184
185 View X = cusp::make_ell_matrix_view(M);
186 View V = cusp::make_ell_matrix_view(X);
187
188 ASSERT_EQUAL(V.num_rows, 3);
189 ASSERT_EQUAL(V.num_cols, 2);
190 ASSERT_EQUAL(V.num_entries, 6);
191
192 V.column_indices(0,0) = 10;
193 V.values(0,0) = 20;
194
195 ASSERT_EQUAL_QUIET(V.column_indices, M.column_indices);
196 ASSERT_EQUAL_QUIET(V.values, M.values);
197
198 }
199
200 // construct view from const matrix
201 {
202 const Matrix M(3, 2, 6, 2);
203
204 ConstView V = cusp::make_ell_matrix_view(M);
205
206 ASSERT_EQUAL(cusp::make_ell_matrix_view(M).num_rows, 3);
207 ASSERT_EQUAL(cusp::make_ell_matrix_view(M).num_cols, 2);
208 ASSERT_EQUAL(cusp::make_ell_matrix_view(M).num_entries, 6);
209
210 ASSERT_EQUAL_QUIET(V.column_indices, M.column_indices);
211 ASSERT_EQUAL_QUIET(V.values, M.values);
212 }
213 }
214 DECLARE_HOST_DEVICE_UNITTEST(TestMakeEllMatrixView);
215

  ViewVC Help
Powered by ViewVC 1.1.26