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

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

1 #include <unittest/unittest.h>
2
3 #include <cusp/precond/diagonal.h>
4
5 #include <cusp/array2d.h>
6 #include <cusp/coo_matrix.h>
7 #include <cusp/csr_matrix.h>
8 #include <cusp/dia_matrix.h>
9 #include <cusp/ell_matrix.h>
10 #include <cusp/hyb_matrix.h>
11
12 #include <cusp/multiply.h>
13
14 template <class MatrixType>
15 void _TestDiagonalPreconditioner(void)
16 {
17 typedef typename MatrixType::memory_space Space;
18
19 cusp::array2d<float, Space> A(5,5);
20 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;
21 A(1,0) = 3.0; A(1,1) = 2.0; A(1,2) = 0.0; A(1,3) = 0.0; A(1,4) = 5.0;
22 A(2,0) = 0.0; A(2,1) = 0.0; A(2,2) = 0.5; A(2,3) = 0.0; A(2,4) = 0.0;
23 A(3,0) = 0.0; A(3,1) = 6.0; A(3,2) = 7.0; A(3,3) = 4.0; A(3,4) = 0.0;
24 A(4,0) = 0.0; A(4,1) = 8.0; A(4,2) = 0.0; A(4,3) = 0.0; A(4,4) = 0.25;
25
26 cusp::array1d<float, Space> input(5, 1.0);
27 cusp::array1d<float, Space> expected(5);
28 expected[0] = 1.00;
29 expected[1] = 0.50;
30 expected[2] = 2.00;
31 expected[3] = 0.25;
32 expected[4] = 4.00;
33
34 cusp::array1d<float, Space> output(5, 0.0f);
35
36 MatrixType M(A);
37 cusp::precond::diagonal<float, Space> D(M);
38
39 ASSERT_EQUAL(D.num_rows, 5);
40 ASSERT_EQUAL(D.num_cols, 5);
41 ASSERT_EQUAL(D.num_entries, 5);
42
43 D(input, output);
44
45 ASSERT_EQUAL(output, expected);
46
47 cusp::multiply(D, input, output);
48
49 ASSERT_EQUAL(output, expected);
50 }
51
52 template <class SparseMatrix>
53 void TestDiagonalPreconditioner(void)
54 {
55 _TestDiagonalPreconditioner<SparseMatrix>();
56 }
57 DECLARE_SPARSE_MATRIX_UNITTEST(TestDiagonalPreconditioner);
58

  ViewVC Help
Powered by ViewVC 1.1.26