SCM

SCM Repository

[matrix] Diff of /pkg/Matrix/src/factorizations.c
ViewVC logotype

Diff of /pkg/Matrix/src/factorizations.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 649, Tue Mar 15 00:59:38 2005 UTC revision 652, Wed Mar 16 01:08:36 2005 UTC
# Line 32  Line 32 
32    
33  SEXP LU_expand(SEXP x)  SEXP LU_expand(SEXP x)
34  {  {
35      char *nms[] = {"L", "U", ""};      char *nms[] = {"L", "U", "P", ""};
36      SEXP L, U, val = PROTECT(Matrix_make_named(VECSXP, nms)),      SEXP L, U, P, val = PROTECT(Matrix_make_named(VECSXP, nms)),
37          lux = GET_SLOT(x, Matrix_xSym),          lux = GET_SLOT(x, Matrix_xSym),
38          dd = GET_SLOT(x, Matrix_DimSym);          dd = GET_SLOT(x, Matrix_DimSym);
39        int *perm, *pivot = INTEGER(GET_SLOT(x, Matrix_permSym)),
40            i, n = INTEGER(dd)[0];
41    
42      SET_VECTOR_ELT(val, 0, NEW_OBJECT(MAKE_CLASS("dtrMatrix")));      SET_VECTOR_ELT(val, 0, NEW_OBJECT(MAKE_CLASS("dtrMatrix")));
43      L = VECTOR_ELT(val, 0);      L = VECTOR_ELT(val, 0);
44      SET_VECTOR_ELT(val, 1, NEW_OBJECT(MAKE_CLASS("dtrMatrix")));      SET_VECTOR_ELT(val, 1, NEW_OBJECT(MAKE_CLASS("dtrMatrix")));
45      U = VECTOR_ELT(val, 1);      U = VECTOR_ELT(val, 1);
46        SET_VECTOR_ELT(val, 2, NEW_OBJECT(MAKE_CLASS("pMatrix")));
47        P = VECTOR_ELT(val, 2);
48      SET_SLOT(L, Matrix_xSym, duplicate(lux));      SET_SLOT(L, Matrix_xSym, duplicate(lux));
49      SET_SLOT(L, Matrix_DimSym, dd);      SET_SLOT(L, Matrix_DimSym, duplicate(dd));
50      SET_SLOT(L, Matrix_uploSym, mkString("L"));      SET_SLOT(L, Matrix_uploSym, mkString("L"));
51      SET_SLOT(L, Matrix_diagSym, mkString("U"));      SET_SLOT(L, Matrix_diagSym, mkString("U"));
52      make_array_triangular(REAL(GET_SLOT(L, Matrix_xSym)), L);      make_array_triangular(REAL(GET_SLOT(L, Matrix_xSym)), L);
53      SET_SLOT(U, Matrix_xSym, duplicate(lux));      SET_SLOT(U, Matrix_xSym, duplicate(lux));
54      SET_SLOT(U, Matrix_DimSym, dd);      SET_SLOT(U, Matrix_DimSym, duplicate(dd));
55      SET_SLOT(U, Matrix_uploSym, mkString("U"));      SET_SLOT(U, Matrix_uploSym, mkString("U"));
56      SET_SLOT(U, Matrix_diagSym, mkString("N"));      SET_SLOT(U, Matrix_diagSym, mkString("N"));
57      make_array_triangular(REAL(GET_SLOT(U, Matrix_xSym)), U);      make_array_triangular(REAL(GET_SLOT(U, Matrix_xSym)), U);
58        SET_SLOT(P, Matrix_DimSym, duplicate(dd));
59        perm = INTEGER(ALLOC_SLOT(P, Matrix_permSym, INTSXP, n));
60        for (i = 0; i < n; i++) perm[i] = i + 1;
61        for (i = 0; i < n; i++) {
62            int newpos = pivot[i] - 1;
63            if (newpos != i) {
64                int tmp = perm[i];
65    
66                perm[i] = newpos + 1;
67                perm[newpos] = tmp;
68            }
69        }
70      UNPROTECT(1);      UNPROTECT(1);
71      return val;      return val;
72  }  }

Legend:
Removed from v.649  
changed lines
  Added in v.652

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge