43 #ifndef KLU2_REFACTOR_HPP 
   44 #define KLU2_REFACTOR_HPP 
   46 #include "klu2_internal.h" 
   47 #include "klu2_memory.hpp" 
   48 #include "klu2_scale.hpp" 
   55 template <
typename Entry, 
typename Int>
 
   62     KLU_symbolic<Entry, Int> *Symbolic,
 
   65     KLU_numeric<Entry, Int> *Numeric,
 
   66     KLU_common<Entry, Int>  *Common
 
   70     Entry *Offx, *Lx, *Ux, *X, *Az, *Udiag ;
 
   72     Int *P, *Q, *R, *Pnum, *Offp, *Offi, *Ui, *Li, *Pinv, *Lip, *Uip, *Llen,
 
   76     Int k1, k2, nk, k, block, oldcol, pend, oldrow, n, p, newrow, 
scale,
 
   77         nblocks, poff, i, j, up, ulen, llen, maxblock, nzoff ;
 
   87     Common->status = KLU_OK ;
 
   92         Common->status = KLU_INVALID ;
 
   96     Common->numerical_rank = EMPTY ;
 
   97     Common->singular_col = EMPTY ;
 
  109     nblocks = Symbolic->nblocks ;
 
  110     maxblock = Symbolic->maxblock ;
 
  116     Pnum = Numeric->Pnum ;
 
  117     Offp = Numeric->Offp ;
 
  118     Offi = Numeric->Offi ;
 
  119     Offx = (Entry *) Numeric->Offx ;
 
  121     LUbx = (Unit **) Numeric->LUbx ;
 
  123     scale = Common->scale ;
 
  127         if (Numeric->Rs == NULL)
 
  129             Numeric->Rs = (
double *)KLU_malloc (n, 
sizeof (
double), Common) ;
 
  130             if (Common->status < KLU_OK)
 
  132                 Common->status = KLU_OUT_OF_MEMORY ;
 
  141         Numeric->Rs = (
double *) KLU_free (Numeric->Rs, n, sizeof (
double), Common) ;
 
  145     Pinv = Numeric->Pinv ;
 
  146     X = (Entry *) Numeric->Xwork ;
 
  147     Common->nrealloc = 0 ;
 
  148     Udiag = (Entry *) Numeric->Udiag ;
 
  149     nzoff = Symbolic->nzoff ;
 
  159         if (!KLU_scale (scale, n, Ap, Ai, Ax, Rs, NULL, Common))
 
  169     for (k = 0 ; k < maxblock ; k++)
 
  188         for (block = 0 ; block < nblocks ; block++)
 
  207                 pend = Ap [oldcol+1] ;
 
  209                 for (p = Ap [oldcol] ; p < pend ; p++)
 
  211                     newrow = Pinv [Ai [p]] - k1 ;
 
  212                     if (newrow < 0 && poff < nzoff)
 
  215                         Offx [poff] = Az [p] ;
 
  234                 Lip  = Numeric->Lip  + k1 ;
 
  235                 Llen = Numeric->Llen + k1 ;
 
  236                 Uip  = Numeric->Uip  + k1 ;
 
  237                 Ulen = Numeric->Ulen + k1 ;
 
  240                 for (k = 0 ; k < nk ; k++)
 
  248                     pend = Ap [oldcol+1] ;
 
  249                     for (p = Ap [oldcol] ; p < pend ; p++)
 
  251                         newrow = Pinv [Ai [p]] - k1 ;
 
  252                         if (newrow < 0 && poff < nzoff)
 
  255                             Offx [poff] = Az [p] ;
 
  261                             X [newrow] = Az [p] ;
 
  269                     GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ;
 
  270                     for (up = 0 ; up < ulen ; up++)
 
  277                         GET_POINTER (LU, Lip, Llen, Li, Lx, j, llen) ;
 
  278                         for (p = 0 ; p < llen ; p++)
 
  281                             MULT_SUB (X [Li [p]], Lx [p], ujk) ;
 
  292                         Common->status = KLU_SINGULAR ;
 
  293                         if (Common->numerical_rank == EMPTY)
 
  295                             Common->numerical_rank = k+k1 ;
 
  296                             Common->singular_col = Q [k+k1] ;
 
  298                         if (Common->halt_if_singular)
 
  306                     GET_POINTER (LU, Lip, Llen, Li, Lx, k, llen) ;
 
  307                     for (p = 0 ; p < llen ; p++)
 
  310                         DIV (Lx [p], X [i], ukk) ;
 
  326         for (block = 0 ; block < nblocks ; block++)
 
  345                 pend = Ap [oldcol+1] ;
 
  347                 for (p = Ap [oldcol] ; p < pend ; p++)
 
  350                     newrow = Pinv [oldrow] - k1 ;
 
  351                     if (newrow < 0 && poff < nzoff)
 
  355                         SCALE_DIV_ASSIGN (Offx [poff], Az [p], Rs [oldrow]) ;
 
  362                         SCALE_DIV_ASSIGN (s, Az [p], Rs [oldrow]) ;
 
  375                 Lip  = Numeric->Lip  + k1 ;
 
  376                 Llen = Numeric->Llen + k1 ;
 
  377                 Uip  = Numeric->Uip  + k1 ;
 
  378                 Ulen = Numeric->Ulen + k1 ;
 
  381                 for (k = 0 ; k < nk ; k++)
 
  389                     pend = Ap [oldcol+1] ;
 
  390                     for (p = Ap [oldcol] ; p < pend ; p++)
 
  393                         newrow = Pinv [oldrow] - k1 ;
 
  394                         if (newrow < 0 && poff < nzoff)
 
  398                             SCALE_DIV_ASSIGN (Offx [poff], Az [p], Rs [oldrow]);
 
  405                             SCALE_DIV_ASSIGN (X [newrow], Az [p], Rs [oldrow]) ;
 
  413                     GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ;
 
  414                     for (up = 0 ; up < ulen ; up++)
 
  421                         GET_POINTER (LU, Lip, Llen, Li, Lx, j, llen) ;
 
  422                         for (p = 0 ; p < llen ; p++)
 
  425                             MULT_SUB (X [Li [p]], Lx [p], ujk) ;
 
  436                         Common->status = KLU_SINGULAR ;
 
  437                         if (Common->numerical_rank == EMPTY)
 
  439                             Common->numerical_rank = k+k1 ;
 
  440                             Common->singular_col = Q [k+k1] ;
 
  442                         if (Common->halt_if_singular)
 
  450                     GET_POINTER (LU, Lip, Llen, Li, Lx, k, llen) ;
 
  451                     for (p = 0 ; p < llen ; p++)
 
  454                         DIV (Lx [p], X [i], ukk) ;
 
  468         for (k = 0 ; k < n ; k++)
 
  472             X [k] = Rs [Pnum [k]] ;
 
  474         for (k = 0 ; k < n ; k++)
 
  476             Rs [k] = REAL (X [k]) ;
 
  481     ASSERT (Offp [n] == poff) ;
 
  482     ASSERT (Symbolic->nzoff == poff) ;
 
  483     PRINTF ((
"\n------------------- Off diagonal entries, new:\n")) ;
 
  484     ASSERT (KLU_valid (n, Offp, Offi, Offx)) ;
 
  485     if (Common->status == KLU_OK)
 
  487         PRINTF ((
"\n ########### KLU_BTF_REFACTOR done, nblocks %d\n",nblocks));
 
  488         for (block = 0 ; block < nblocks ; block++)
 
  494                 "\n================KLU_refactor output: k1 %d k2 %d nk %d\n",
 
  498                 PRINTF ((
"singleton  ")) ;
 
  499                 PRINT_ENTRY (Udiag [k1]) ;
 
  503                 Lip = Numeric->Lip + k1 ;
 
  504                 Llen = Numeric->Llen + k1 ;
 
  505                 LU = (Unit *) Numeric->LUbx [block] ;
 
  506                 PRINTF ((
"\n---- L block %d\n", block)) ;
 
  507                 ASSERT (KLU_valid_LU (nk, TRUE, Lip, Llen, LU)) ;
 
  508                 Uip = Numeric->Uip + k1 ;
 
  509                 Ulen = Numeric->Ulen + k1 ;
 
  510                 PRINTF ((
"\n---- U block %d\n", block)) ;
 
  511                 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.