19 #ifndef KLU2_REFACTOR_HPP
20 #define KLU2_REFACTOR_HPP
22 #include "klu2_internal.h"
23 #include "klu2_memory.hpp"
24 #include "klu2_scale.hpp"
31 template <
typename Entry,
typename Int>
38 KLU_symbolic<Entry, Int> *Symbolic,
41 KLU_numeric<Entry, Int> *Numeric,
42 KLU_common<Entry, Int> *Common
46 Entry *Offx, *Lx, *Ux, *X, *Az, *Udiag ;
48 Int *P, *Q, *R, *Pnum, *Offp, *Offi, *Ui, *Li, *Pinv, *Lip, *Uip, *Llen,
52 Int k1, k2, nk, k, block, oldcol, pend, oldrow, n, p, newrow,
scale,
53 nblocks, poff, i, j, up, ulen, llen, maxblock, nzoff ;
63 Common->status = KLU_OK ;
68 Common->status = KLU_INVALID ;
72 Common->numerical_rank = AMESOS2_KLU2_EMPTY ;
73 Common->singular_col = AMESOS2_KLU2_EMPTY ;
85 nblocks = Symbolic->nblocks ;
86 maxblock = Symbolic->maxblock ;
92 Pnum = Numeric->Pnum ;
93 Offp = Numeric->Offp ;
94 Offi = Numeric->Offi ;
95 Offx = (Entry *) Numeric->Offx ;
97 LUbx = (Unit **) Numeric->LUbx ;
99 scale = Common->scale ;
103 if (Numeric->Rs == NULL)
105 Numeric->Rs = (
double *)KLU_malloc (n,
sizeof (
double), Common) ;
106 if (Common->status < KLU_OK)
108 Common->status = KLU_OUT_OF_MEMORY ;
117 Numeric->Rs = (
double *) KLU_free (Numeric->Rs, n, sizeof (
double), Common) ;
121 Pinv = Numeric->Pinv ;
122 X = (Entry *) Numeric->Xwork ;
123 Common->nrealloc = 0 ;
124 Udiag = (Entry *) Numeric->Udiag ;
125 nzoff = Symbolic->nzoff ;
135 if (!KLU_scale (scale, n,
Ap,
Ai, Ax, Rs, NULL, Common))
145 for (k = 0 ; k < maxblock ; k++)
164 for (block = 0 ; block < nblocks ; block++)
183 pend =
Ap [oldcol+1] ;
185 for (p =
Ap [oldcol] ; p < pend ; p++)
187 newrow = Pinv [
Ai [p]] - k1 ;
188 if (newrow < 0 && poff < nzoff)
191 Offx [poff] = Az [p] ;
210 Lip = Numeric->Lip + k1 ;
211 Llen = Numeric->Llen + k1 ;
212 Uip = Numeric->Uip + k1 ;
213 Ulen = Numeric->Ulen + k1 ;
216 for (k = 0 ; k < nk ; k++)
224 pend =
Ap [oldcol+1] ;
225 for (p =
Ap [oldcol] ; p < pend ; p++)
227 newrow = Pinv [
Ai [p]] - k1 ;
228 if (newrow < 0 && poff < nzoff)
231 Offx [poff] = Az [p] ;
237 X [newrow] = Az [p] ;
245 GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ;
246 for (up = 0 ; up < ulen ; up++)
253 GET_POINTER (LU, Lip, Llen, Li, Lx, j, llen) ;
254 for (p = 0 ; p < llen ; p++)
257 MULT_SUB (X [Li [p]], Lx [p], ujk) ;
268 Common->status = KLU_SINGULAR ;
269 if (Common->numerical_rank == AMESOS2_KLU2_EMPTY)
271 Common->numerical_rank = k+k1 ;
272 Common->singular_col = Q [k+k1] ;
274 if (Common->halt_if_singular)
282 GET_POINTER (LU, Lip, Llen, Li, Lx, k, llen) ;
283 for (p = 0 ; p < llen ; p++)
286 DIV (Lx [p], X [i], ukk) ;
302 for (block = 0 ; block < nblocks ; block++)
321 pend =
Ap [oldcol+1] ;
323 for (p =
Ap [oldcol] ; p < pend ; p++)
326 newrow = Pinv [oldrow] - k1 ;
327 if (newrow < 0 && poff < nzoff)
331 SCALE_DIV_ASSIGN (Offx [poff], Az [p], Rs [oldrow]) ;
338 SCALE_DIV_ASSIGN (s, Az [p], Rs [oldrow]) ;
351 Lip = Numeric->Lip + k1 ;
352 Llen = Numeric->Llen + k1 ;
353 Uip = Numeric->Uip + k1 ;
354 Ulen = Numeric->Ulen + k1 ;
357 for (k = 0 ; k < nk ; k++)
365 pend =
Ap [oldcol+1] ;
366 for (p =
Ap [oldcol] ; p < pend ; p++)
369 newrow = Pinv [oldrow] - k1 ;
370 if (newrow < 0 && poff < nzoff)
374 SCALE_DIV_ASSIGN (Offx [poff], Az [p], Rs [oldrow]);
381 SCALE_DIV_ASSIGN (X [newrow], Az [p], Rs [oldrow]) ;
389 GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ;
390 for (up = 0 ; up < ulen ; up++)
397 GET_POINTER (LU, Lip, Llen, Li, Lx, j, llen) ;
398 for (p = 0 ; p < llen ; p++)
401 MULT_SUB (X [Li [p]], Lx [p], ujk) ;
412 Common->status = KLU_SINGULAR ;
413 if (Common->numerical_rank == AMESOS2_KLU2_EMPTY)
415 Common->numerical_rank = k+k1 ;
416 Common->singular_col = Q [k+k1] ;
418 if (Common->halt_if_singular)
426 GET_POINTER (LU, Lip, Llen, Li, Lx, k, llen) ;
427 for (p = 0 ; p < llen ; p++)
430 DIV (Lx [p], X [i], ukk) ;
444 for (k = 0 ; k < n ; k++)
448 X [k] = Rs [Pnum [k]] ;
450 for (k = 0 ; k < n ; k++)
452 Rs [k] = REAL (X [k]) ;
457 ASSERT (Offp [n] == poff) ;
458 ASSERT (Symbolic->nzoff == poff) ;
459 PRINTF ((
"\n------------------- Off diagonal entries, new:\n")) ;
460 ASSERT (KLU_valid (n, Offp, Offi, Offx)) ;
461 if (Common->status == KLU_OK)
463 PRINTF ((
"\n ########### KLU_BTF_REFACTOR done, nblocks %d\n",nblocks));
464 for (block = 0 ; block < nblocks ; block++)
470 "\n================KLU_refactor output: k1 %d k2 %d nk %d\n",
474 PRINTF ((
"singleton ")) ;
475 PRINT_ENTRY (Udiag [k1]) ;
479 Lip = Numeric->Lip + k1 ;
480 Llen = Numeric->Llen + k1 ;
481 LU = (Unit *) Numeric->LUbx [block] ;
482 PRINTF ((
"\n---- L block %d\n", block)) ;
483 ASSERT (KLU_valid_LU (nk, TRUE, Lip, Llen, LU)) ;
484 Uip = Numeric->Uip + k1 ;
485 Ulen = Numeric->Ulen + k1 ;
486 PRINTF ((
"\n---- U block %d\n", block)) ;
487 ASSERT (KLU_valid_LU (nk, FALSE, Uip, Ulen, LU)) ;
void scale(ArrayView< Scalar1 > vals, size_t l, size_t ld, ArrayView< Scalar2 > s)
Scales a 1-D representation of a multivector.
int Ap[]
Column offsets.
Definition: klu2_simple.cpp:52
int Ai[]
Row values.
Definition: klu2_simple.cpp:54