1 /* adjForATA.c */
2
3 #include "../InpMtx.h"
4
5 /*--------------------------------------------------------------------*/
6 /*
7 ----------------------------------
8 return an IVL object that contains
9 the adjacency structure of A^TA.
10
11 created -- 98jan28, cca
12 ----------------------------------
13 */
14 IVL *
InpMtx_adjForATA(InpMtx * inpmtxA)15 InpMtx_adjForATA (
16 InpMtx *inpmtxA
17 ) {
18 InpMtx *inpmtxATA ;
19 int firstcol, firstrow, irow, jvtx, lastcol, lastrow,
20 loc, ncol, nent, nrow, size ;
21 int *ind, *ivec1, *ivec2 ;
22 IVL *adjIVL ;
23 /*
24 ---------------
25 check the input
26 ---------------
27 */
28 if ( inpmtxA == NULL ) {
29 fprintf(stderr, "\n fatal error in InpMtx_adjForATA(%p)"
30 "\n NULL input\n", inpmtxA) ;
31 exit(-1) ;
32 }
33 /*
34 ----------------------------------------------------------
35 change the coordinate type and storage mode to row vectors
36 ----------------------------------------------------------
37 */
38 InpMtx_changeCoordType(inpmtxA, INPMTX_BY_ROWS) ;
39 InpMtx_changeStorageMode(inpmtxA, INPMTX_BY_VECTORS) ;
40 nent = InpMtx_nent(inpmtxA) ;
41 ivec1 = InpMtx_ivec1(inpmtxA) ;
42 ivec2 = InpMtx_ivec2(inpmtxA) ;
43 firstrow = IVmin(nent, ivec1, &loc) ;
44 lastrow = IVmax(nent, ivec1, &loc) ;
45 firstcol = IVmin(nent, ivec2, &loc) ;
46 lastcol = IVmax(nent, ivec2, &loc) ;
47 if ( firstrow < 0 || firstcol < 0 ) {
48 fprintf(stderr, "\n fatal error"
49 "\n firstrow = %d, firstcol = %d"
50 "\n lastrow = %d, lastcol = %d",
51 firstrow, firstcol, lastrow, lastcol) ;
52 exit(-1) ;
53 }
54 nrow = 1 + lastrow ;
55 ncol = 1 + lastcol ;
56 /*
57 -----------------------------------------------------------
58 create the new InpMtx object to hold the structure of A^TA
59 -----------------------------------------------------------
60 */
61 inpmtxATA = InpMtx_new() ;
62 InpMtx_init(inpmtxATA, INPMTX_BY_ROWS, INPMTX_INDICES_ONLY, 0, 0) ;
63 for ( irow = 0 ; irow < nrow ; irow++ ) {
64 InpMtx_vector(inpmtxA, irow, &size, &ind) ;
65 InpMtx_inputMatrix(inpmtxATA, size, size, 1, size, ind, ind) ;
66 }
67 for ( jvtx = 0 ; jvtx < nrow ; jvtx++ ) {
68 InpMtx_inputEntry(inpmtxATA, jvtx, jvtx) ;
69 }
70 InpMtx_changeStorageMode(inpmtxATA, INPMTX_BY_VECTORS) ;
71 /*
72 -------------------
73 fill the IVL object
74 -------------------
75 */
76 adjIVL = IVL_new() ;
77 IVL_init1(adjIVL, IVL_CHUNKED, nrow) ;
78 for ( jvtx = 0 ; jvtx < ncol ; jvtx++ ) {
79 InpMtx_vector(inpmtxATA, jvtx, &size, &ind) ;
80 IVL_setList(adjIVL, jvtx, size, ind) ;
81 }
82 /*
83 ------------------------------
84 free the working InpMtx object
85 ------------------------------
86 */
87 InpMtx_free(inpmtxATA) ;
88
89 return(adjIVL) ; }
90
91 /*--------------------------------------------------------------------*/
92