File: dia.cu

package info (click to toggle)
python-escript 5.6-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144,304 kB
  • sloc: python: 592,074; cpp: 136,909; ansic: 18,675; javascript: 9,411; xml: 3,384; sh: 738; makefile: 207
file content (45 lines) | stat: -rw-r--r-- 1,026 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
#include <cusp/dia_matrix.h>
#include <cusp/print.h>

int main(void)
{
    // allocate storage for (4,3) matrix with 6 nonzeros in 3 diagonals
    cusp::dia_matrix<int,float,cusp::host_memory> A(4,3,6,3);

    // initialize diagonal offsets
    A.diagonal_offsets[0] = -2;
    A.diagonal_offsets[1] =  0;
    A.diagonal_offsets[2] =  1;

    // initialize diagonal values

    // first diagonal
    A.values(0,2) =  0;  // outside matrix
    A.values(1,2) =  0;  // outside matrix
    A.values(2,0) = 40;
    A.values(3,0) = 60;
    
    // second diagonal
    A.values(0,1) = 10;
    A.values(1,1) =  0;
    A.values(2,1) = 50;
    A.values(3,1) = 50;  // outside matrix

    // third diagonal
    A.values(0,2) = 20;
    A.values(1,2) = 30;
    A.values(2,2) =  0;  // outside matrix
    A.values(3,2) =  0;  // outside matrix

    // A now represents the following matrix
    //    [10 20  0]
    //    [ 0  0 30]
    //    [40  0 50]
    //    [ 0 60  0]

    // print matrix entries
    cusp::print(A);

    return 0;
}