1 #include "BSprivate.h"
2
3 /*@ BScopy_nz - Copy the nonzero values from one matrix to another
4
5 Input Parameters:
6 . A - The source matrix
7
8 Output Parameters:
9 . newA - The destination matrix
10
11 Returns:
12 void
13
14 Notes: Recall that (in the incomplete Cholesky case)
15 A and another matrix are symmetric and generally
16 share the square dense matrices (with the assumption that
17 the diagonal of one matrix is either known or stored elsewhere)
18 associated with the cliques.
19
20 @*/
BScopy_nz(BSpar_mat * A,BSpar_mat * newA)21 void BScopy_nz(BSpar_mat *A, BSpar_mat *newA)
22 {
23 int i, j, k;
24 int size, len;
25 BSinode *inodes, *new_inodes;
26
27 /* first copy the clique blocks */
28 /* we now that both matrices point to the same blocks and */
29 /* that A is stored in the lower triangle and newA in the upper */
30 BScopy_cliques(A,newA); CHKERR(0);
31
32 /* now copy the inodes */
33 inodes = A->inodes->list;
34 len = A->inodes->length;
35 new_inodes = newA->inodes->list;
36 for (i=0;i<len;i++) {
37 size = inodes[i].length;
38 for (j=0;j<inodes[i].num_cols;j++) {
39 for (k=0;k<size;k++) {
40 new_inodes[i].nz[(j*size)+k] = inodes[i].nz[(j*size)+k];
41 }
42 }
43 }
44 }
45
46 /*+ BScopy_cliques - Copy the nonzero values from the cliques of
47 one matrix to another
48
49 Input Parameters:
50 . A - The source matrix
51
52 Output Parameters:
53 . newA - The destination matrix
54
55 Returns:
56 void
57
58 Notes: Recall that A and another matrix are symmetric and generally
59 share the square dense matrices (with the assumption that
60 the diagonal of one matrix is either known or stored elsewhere)
61 associated with the cliques. In the nonsymmetric case the dense
62 matrices are unique (storage not shared with another matrix).
63
64 +*/
BScopy_cliques(BSpar_mat * A,BSpar_mat * newA)65 void BScopy_cliques(BSpar_mat *A, BSpar_mat *newA)
66 {
67 int i, j, k;
68 int size;
69 BScl_2_inode *cl2i, *new_cl2i;
70 FLOAT *matrix, *new_matrix;
71
72
73 /* copy from the upper triangle to the lower triangle of the cliques */
74 /* that A is stored in the lower triangle and newA in the upper */
75 /* for the symmetric case. For the nonsymmetric case we have to */
76 /* copy everything. */
77 cl2i = A->clique2inode;
78 new_cl2i = newA->clique2inode;
79 for (i=0;i<cl2i->num_cols;i++) {
80 matrix = cl2i->d_mats[i].matrix;
81 new_matrix = new_cl2i->d_mats[i].matrix;
82 size = cl2i->d_mats[i].size;
83 for (j=0;j<size;j++) {
84 if(A->icc_storage) {
85 for (k=0;k<j;k++) {
86 matrix[(j*size)+k] = matrix[(k*size)+j];
87 }
88 } else {
89 for (k=0;k<size;k++) {
90 new_matrix[(j*size)+k] = matrix[(j*size)+k];
91 }
92 }
93 }
94 }
95 }
96