File: diagonal.cu

package info (click to toggle)
python-escript 5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 87,772 kB
  • ctags: 49,550
  • sloc: python: 585,488; cpp: 133,173; ansic: 18,675; xml: 3,283; sh: 690; makefile: 215
file content (58 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <unittest/unittest.h>

#include <cusp/precond/diagonal.h>

#include <cusp/array2d.h>
#include <cusp/coo_matrix.h>
#include <cusp/csr_matrix.h>
#include <cusp/dia_matrix.h>
#include <cusp/ell_matrix.h>
#include <cusp/hyb_matrix.h>

#include <cusp/multiply.h>

template <class MatrixType>
void _TestDiagonalPreconditioner(void)
{
    typedef typename MatrixType::memory_space Space;

    cusp::array2d<float, Space> A(5,5);
    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; 
    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;
    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;
    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;
    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;

    cusp::array1d<float, Space> input(5, 1.0);
    cusp::array1d<float, Space> expected(5);
    expected[0] = 1.00;
    expected[1] = 0.50;
    expected[2] = 2.00;
    expected[3] = 0.25;
    expected[4] = 4.00;

    cusp::array1d<float, Space> output(5, 0.0f);

    MatrixType M(A);
    cusp::precond::diagonal<float, Space> D(M);

    ASSERT_EQUAL(D.num_rows,    5);
    ASSERT_EQUAL(D.num_cols,    5);
    ASSERT_EQUAL(D.num_entries, 5);

    D(input, output);

    ASSERT_EQUAL(output, expected);
    
    cusp::multiply(D, input, output);

    ASSERT_EQUAL(output, expected);
}

template <class SparseMatrix>
void TestDiagonalPreconditioner(void)
{
    _TestDiagonalPreconditioner<SparseMatrix>();
}
DECLARE_SPARSE_MATRIX_UNITTEST(TestDiagonalPreconditioner);