41 #ifndef KLU2_ANALYZE_GIVEN_HPP
42 #define KLU2_ANALYZE_GIVEN_HPP
44 #include "klu2_internal.h"
45 #include "klu2_memory.hpp"
53 template <
typename Entry,
typename Int>
54 KLU_symbolic<Entry, Int> *KLU_alloc_symbolic
59 KLU_common<Entry, Int> *Common
62 KLU_symbolic<Entry, Int> *Symbolic ;
65 Int nz, i, j, p, pend ;
71 Common->status = KLU_OK ;
79 if (n <= 0 || Ap == NULL || Ai == NULL)
82 Common->status = KLU_INVALID ;
87 if (Ap [0] != 0 || nz < 0)
90 Common->status = KLU_INVALID ;
94 for (j = 0 ; j < n ; j++)
96 if (Ap [j] > Ap [j+1])
99 Common->status = KLU_INVALID ;
103 P = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
104 if (Common->status < KLU_OK)
107 Common->status = KLU_OUT_OF_MEMORY ;
110 for (i = 0 ; i < n ; i++)
114 for (j = 0 ; j < n ; j++)
117 for (p = Ap [j] ; p < pend ; p++)
120 if (i < 0 || i >= n || P [i] == j)
123 KLU_free (P, n,
sizeof (Int), Common) ;
124 Common->status = KLU_INVALID ;
136 Symbolic = (KLU_symbolic<Entry, Int> *) KLU_malloc (
sizeof (KLU_symbolic<Entry, Int>), 1, Common) ;
137 if (Common->status < KLU_OK)
140 KLU_free (P, n,
sizeof (Int), Common) ;
141 Common->status = KLU_OUT_OF_MEMORY ;
145 Q = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
146 R = (Int *) KLU_malloc (n+1,
sizeof (Int), Common) ;
147 Lnz = (
double *) KLU_malloc (n,
sizeof (
double), Common) ;
154 Symbolic->Lnz = Lnz ;
156 if (Common->status < KLU_OK)
159 KLU_free_symbolic (&Symbolic, Common) ;
160 Common->status = KLU_OUT_OF_MEMORY ;
172 template <
typename Entry,
typename Int>
173 KLU_symbolic<Entry, Int> *KLU_analyze_given
183 KLU_common<Entry, Int> *Common
186 KLU_symbolic<Entry, Int> *Symbolic ;
188 Int nblocks, nz, block, maxblock, *P, *Q, *R, nzoff, p, pend, do_btf, k ;
194 Symbolic = KLU_alloc_symbolic (n, Ap, Ai, Common) ;
195 if (Symbolic == NULL)
202 Lnz = Symbolic->Lnz ;
209 if (Quser == (Int *) NULL)
211 for (k = 0 ; k < n ; k++)
218 for (k = 0 ; k < n ; k++)
228 do_btf = Common->btf ;
229 do_btf = (do_btf) ? TRUE : FALSE ;
230 Symbolic->ordering = 2 ;
231 Symbolic->do_btf = do_btf ;
244 Int *Pinv, *Work, *Bi, k1, k2, nk, oldcol ;
246 Work = (Int *) KLU_malloc (4*n,
sizeof (Int), Common) ;
247 Pinv = (Int *) KLU_malloc (n,
sizeof (Int), Common) ;
248 if (Puser != (Int *) NULL)
250 Bi = (Int *) KLU_malloc (nz+1,
sizeof (Int), Common) ;
257 if (Common->status < KLU_OK)
260 KLU_free (Work, 4*n,
sizeof (Int), Common) ;
261 KLU_free (Pinv, n,
sizeof (Int), Common) ;
262 if (Puser != (Int *) NULL)
264 KLU_free (Bi, nz+1,
sizeof (Int), Common) ;
266 KLU_free_symbolic (&Symbolic, Common) ;
267 Common->status = KLU_OUT_OF_MEMORY ;
275 if (Puser != (Int *) NULL)
277 for (k = 0 ; k < n ; k++)
279 Pinv [Puser [k]] = k ;
281 for (p = 0 ; p < nz ; p++)
283 Bi [p] = Pinv [Ai [p]] ;
294 nblocks = KLU_OrdinalTraits<Int>::btf_strongcomp (n, Ap, Bi, Q, P, R,
301 if (Puser != (Int *) NULL)
303 for (k = 0 ; k < n ; k++)
305 Work [k] = Puser [P [k]] ;
307 for (k = 0 ; k < n ; k++)
317 for (k = 0 ; k < n ; k++)
329 for (block = 0 ; block < nblocks ; block++)
339 PRINTF ((
"BLOCK %d, k1 %d k2-1 %d nk %d\n", block, k1, k2-1, nk)) ;
340 maxblock = MAX (maxblock, nk) ;
346 for (k = k1 ; k < k2 ; k++)
349 pend = Ap [oldcol+1] ;
350 for (p = Ap [oldcol] ; p < pend ; p++)
352 if (Pinv [Ai [p]] < k1)
360 Lnz [block] = EMPTY ;
367 KLU_free (Work, 4*n,
sizeof (Int), Common) ;
368 KLU_free (Pinv, n,
sizeof (Int), Common) ;
369 if (Puser != (Int *) NULL)
371 KLU_free (Bi, nz+1,
sizeof (Int), Common) ;
393 for (k = 0 ; k < n ; k++)
395 P [k] = (Puser == NULL) ? k : Puser [k] ;
403 Symbolic->nblocks = nblocks ;
404 Symbolic->maxblock = maxblock ;
405 Symbolic->lnz = EMPTY ;
406 Symbolic->unz = EMPTY ;
407 Symbolic->nzoff = nzoff ;