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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #include <unittest/unittest.h>
2
3 #include <cusp/array2d.h>
4 #include <cusp/coo_matrix.h>
5 #include <cusp/csr_matrix.h>
6 #include <cusp/dia_matrix.h>
7 #include <cusp/ell_matrix.h>
8 #include <cusp/hyb_matrix.h>
9
10 #include <cusp/detail/format_utils.h>
11
12 template <class Space>
13 void TestOffsetsToIndices(void)
14 {
15 cusp::array1d<int, Space> offsets(8);
16 offsets[0] = 0;
17 offsets[1] = 0;
18 offsets[2] = 0;
19 offsets[3] = 1;
20 offsets[4] = 1;
21 offsets[5] = 2;
22 offsets[6] = 5;
23 offsets[7] = 10;
24
25 cusp::array1d<int, Space> expected(10);
26 expected[0] = 2;
27 expected[1] = 4;
28 expected[2] = 5;
29 expected[3] = 5;
30 expected[4] = 5;
31 expected[5] = 6;
32 expected[6] = 6;
33 expected[7] = 6;
34 expected[8] = 6;
35 expected[9] = 6;
36
37 cusp::array1d<int, Space> indices(10);
38 cusp::detail::offsets_to_indices(offsets, indices);
39
40 ASSERT_EQUAL(indices, expected);
41 }
42 DECLARE_HOST_DEVICE_UNITTEST(TestOffsetsToIndices);
43
44
45 template <class Space>
46 void TestIndicesToOffsets(void)
47 {
48 cusp::array1d<int, Space> indices(10);
49 indices[0] = 2;
50 indices[1] = 4;
51 indices[2] = 5;
52 indices[3] = 5;
53 indices[4] = 5;
54 indices[5] = 6;
55 indices[6] = 6;
56 indices[7] = 6;
57 indices[8] = 6;
58 indices[9] = 6;
59
60 cusp::array1d<int, Space> expected(8);
61 expected[0] = 0;
62 expected[1] = 0;
63 expected[2] = 0;
64 expected[3] = 1;
65 expected[4] = 1;
66 expected[5] = 2;
67 expected[6] = 5;
68 expected[7] = 10;
69
70 cusp::array1d<int, Space> offsets(8);
71 cusp::detail::indices_to_offsets(indices, offsets);
72
73 ASSERT_EQUAL(offsets, expected);
74 }
75 DECLARE_HOST_DEVICE_UNITTEST(TestIndicesToOffsets);
76
77 template <class Matrix>
78 void TestExtractDiagonal(void)
79 {
80 typedef typename Matrix::index_type IndexType;
81 typedef typename Matrix::value_type ValueType;
82 typedef typename Matrix::memory_space Space;
83
84 {
85 cusp::array2d<float, Space> A(2,2);
86 A(0,0) = 1.0; A(0,1) = 2.0;
87 A(1,0) = 3.0; A(1,1) = 4.0;
88
89 cusp::array1d<float, Space> expected(2);
90 expected[0] = 1.0;
91 expected[1] = 4.0;
92
93 cusp::array1d<float, Space> output;
94
95 cusp::detail::extract_diagonal(Matrix(A), output);
96
97 ASSERT_EQUAL(output, expected);
98 }
99
100 {
101 cusp::array2d<float, Space> A(3,4);
102 A(0,0) = 0.0; A(0,1) = 0.0; A(0,2) = 4.0; A(0,3) = 0.0;
103 A(1,0) = 1.0; A(1,1) = 2.0; A(1,2) = 0.0; A(1,3) = 6.0;
104 A(2,0) = 0.0; A(2,1) = 3.0; A(2,2) = 5.0; A(2,3) = 0.0;
105
106 cusp::array1d<float, Space> expected(3);
107 expected[0] = 0.0;
108 expected[1] = 2.0;
109 expected[2] = 5.0;
110
111 cusp::array1d<float, Space> output;
112
113 cusp::detail::extract_diagonal(Matrix(A), output);
114
115 ASSERT_EQUAL(output, expected);
116 }
117
118 {
119 cusp::array2d<float, Space> A(5,5);
120 A(0,0) = 1.0; A(0,1) = 1.0; A(0,2) = 2.0; A(0,3) = 0.0; A(0,4) = 0.0;
121 A(1,0) = 3.0; A(1,1) = 4.0; A(1,2) = 0.0; A(1,3) = 0.0; A(1,4) = 0.0;
122 A(2,0) = 0.0; A(2,1) = 6.0; A(2,2) = 0.0; A(2,3) = 0.0; A(2,4) = 0.0;
123 A(3,0) = 0.0; A(3,1) = 0.0; A(3,2) = 7.0; A(3,3) = 8.0; A(3,4) = 0.0;
124 A(4,0) = 0.0; A(4,1) = 0.0; A(4,2) = 0.0; A(4,3) = 0.0; A(4,4) = 9.0;
125
126 cusp::array1d<float, Space> expected(5);
127 expected[0] = 1.0;
128 expected[1] = 4.0;
129 expected[2] = 0.0;
130 expected[3] = 8.0;
131 expected[4] = 9.0;
132
133 cusp::array1d<float, Space> output;
134
135 cusp::detail::extract_diagonal(Matrix(A), output);
136
137 ASSERT_EQUAL(output, expected);
138 }
139 }
140 DECLARE_SPARSE_MATRIX_UNITTEST(TestExtractDiagonal);
141

  ViewVC Help
Powered by ViewVC 1.1.26