SCM

SCM Repository

[matrix] Diff of /pkg/R/AllClass.R
ViewVC logotype

Diff of /pkg/R/AllClass.R

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

revision 476, Wed Feb 2 11:51:24 2005 UTC revision 477, Wed Feb 2 14:14:59 2005 UTC
# Line 4  Line 4 
4  }  }
5    
6  # Virtual class of all Matrix objects  # Virtual class of all Matrix objects
7  setClass("Matrix")  setClass("Matrix", representation(Dim = "integer"),
8             validity = function(object) {
9                 Dim <- object@Dim
10                 if (length(Dim) != 2)
11                     return("Dim slot must be of length 2")
12                 if (any(Dim < 0))
13                     return("Dim slot must contain non-negative values")
14                 TRUE
15             })
16    
17  # general double-precision matrices  # Virtual class of numeric matrices
18  setClass("geMatrix",  setClass("dMatrix",
19           representation(x = "numeric", Dim = "integer",           representation(x = "numeric"),
20                          rcond = "numeric", factors = "list"),           contains = "Matrix")
21           prototype = prototype(x = numeric(0), Dim = as.integer(c(0,0)),  
22                                 rcond = numeric(0),  # Virtual class of integer matrices
23                                 factors = list()),  setClass("iMatrix",
24           contains = "Matrix",           representation(x = "integer"),
25             contains = "Matrix")
26    
27    # Virtual class of logical matrices
28    setClass("lMatrix",
29             representation(x = "logical"),
30             contains = "Matrix")
31    
32    # Virtual class of complex matrices
33    setClass("zMatrix", # letter 'z' is as in the names of Lapack subroutines
34             representation(x = "complex"),
35             contains = "Matrix")
36    
37    # Virtual class of dense, numeric matrices
38    setClass("ddenseMatrix",
39             representation(rcond = "numeric", factors = "list"),
40             contains = "dMatrix")
41    
42    # numeric, dense, general matrices
43    setClass("dgeMatrix", contains = "ddenseMatrix",
44             validity = function(object) { ## dgeMatrix checks the length of x is prod(Dim)
45                 .Call("dgeMatrix_validate", object)
46             })
47    
48    # numeric, dense, non-packed, triangular matrices
49    setClass("dtrMatrix",
50             representation(uplo = "character", diag = "character"),
51             contains = "dgeMatrix",
52             prototype = prototype(uplo = "U", diag = "N"),
53           validity = function(object) {           validity = function(object) {
54               .Call("geMatrix_validate", object)               .Call("dtrMatrix_validate", object)
55           })           })
56    
57  # Dense, non-packed, triangular matrices  # numeric, dense, packed, triangular matrices
58  setClass("trMatrix",  setClass("dtpMatrix",
59           representation(uplo = "character", diag = "character"),           representation(uplo = "character", diag = "character"),
60           contains = "geMatrix",           contains = "ddenseMatrix",
61           prototype = prototype(uplo = "U", diag = "N"),           prototype = prototype(uplo = "U", diag = "N"),
62           validity = function(object) {           validity = function(object) {
63               .Call("trMatrix_validate", object)               .Call("dtpMatrix_validate", object)
64           })           })
65    
66  # Dense, packed, triangular matrices  # numeric, dense, non-packed symmetric matrices
67  # setClass("tpMatrix", representation(...))  setClass("dsyMatrix",
68             representation(uplo = "character"),
69             prototype = prototype(uplo = "U"),
70             contains = "dgeMatrix",
71             validity = function(object) .Call("dsyMatrix_validate", object)
72             )
73    
74  # Dense, non-packed symmetric matrices  # numeric, dense, non-packed symmetric matrices
75  setClass("syMatrix",  setClass("dspMatrix",
76           representation(uplo = "character"),           representation(uplo = "character"),
77           prototype = prototype(uplo = "U",           prototype = prototype(uplo = "U"),
78             x = numeric(0), Dim = as.integer(c(0,0)),           contains = "dgeMatrix",
79             rcond = numeric(0), factors = list()),           validity = function(object) .Call("dspMatrix_validate", object)
80           contains = "geMatrix",           )
          validity = function(object) {  
              .Call("syMatrix_validate", object)  
          })  
81    
82  # Dense, packed, symmetric matrices  # numeric, dense, non-packed, postive-definite, symmetric matrices
83  # setClass("spMatrix", representation(...))  setClass("dpoMatrix", contains = "dsyMatrix",
84             validity = function(object) .Call("dpoMatrix_validate", object)
85             )
86    
87  # Dense, non-packed, postive-definite, symmetric matrices  # numeric, dense, packed, postive-definite, symmetric matrices
88  setClass("poMatrix", contains = "syMatrix",  setClass("dpoMatrix", contains = "dspMatrix",
89           prototype = prototype(uplo = "U",           validity = function(object) .Call("dppMatrix_validate", object)
            x = numeric(0), Dim = as.integer(c(0,0)),  
            rcond = numeric(0), factors = list())  
          )  
   
 # Sparse general matrix in sorted compressed sparse column format  
 setClass("cscMatrix",  
          representation(p = "integer", i = "integer", x = "numeric",  
                         Dim = "integer", factors = "list"),  
          prototype = prototype(p = as.integer(0), i = integer(0),  
                         x = numeric(0), Dim = as.integer(c(0, 0))),  
          validity = function(object)  
                     .Call("csc_validate", object)  
90           )           )
91    
92  # Sparse triangular matrix in sorted compressed sparse column format  # numeric, sparse, triplet general matrices
93  setClass("tscMatrix",  setClass("dgTMatrix",
94             representation(i = "integer", j = "integer", factors = "list"),
95             contains = "dMatrix",
96             validity = function(object) .Call("dgTMatrix_validate", object)
97             )
98    
99    # numeric, sparse, triplet triangular matrices
100    setClass("dtTMatrix",
101           representation(uplo = "character", diag = "character"),           representation(uplo = "character", diag = "character"),
102           prototype = prototype(p = as.integer(0), i = integer(0),           contains = "dgTMatrix",
103                          x = numeric(0), Dim = as.integer(c(0, 0)),           validity = function(object) .Call("dtTMatrix_validate", object)
104                          uplo = 'L', diag = 'N'),           )
          contains = "cscMatrix",  
          validity = function(object)  
                     .Call("tsc_validate", object))  
105    
106  # Sparse symmetric matrix in compressed sparse column format.  # numeric, sparse, triplet symmetric matrices
107  # Only one triangle is stored, uplo indicates if it is the lower or upper  setClass("dtTMatrix",
108  setClass("sscMatrix",           representation(uplo = "character"),
109           representation = representation(uplo = "character"),           contains = "dsTMatrix",
110           prototype = prototype(p = as.integer(0), i = integer(0),           validity = function(object) .Call("dsTMatrix_validate", object)
111                          x = numeric(0), Dim = as.integer(c(0, 0)),           )
                         uplo = 'L'),  
          contains = "cscMatrix",  
          validity = function(object)  
                     .Call("sscMatrix_validate", object))  
112    
113  # Sparse general matrix in triplet format  # numeric, sparse, sorted compressed sparse column-oriented general matrices
114  setClass("tripletMatrix",  setClass("dgCMatrix",
115           representation(i = "integer", j = "integer", x = "numeric",           representation(i = "integer", p = "integer", factors = "list"),
116                          Dim = "integer"),           contains = "dMatrix",
117           prototype = prototype(i = integer(0), j = integer(0),           validity = function(object) .Call("dgCMatrix_validate", object)
118           x = numeric(0), Dim = as.integer(c(0,0))),           )
119           validity = function(object)  
120                      .Call("triplet_validate", object))  # numeric, sparse, sorted compressed sparse column-oriented triangular matrices
121    setClass("dtCMatrix",
122             representation(uplo = "character", diag = "character"),
123             contains = "dgCMatrix",
124             validity = function(object) .Call("dtCMatrix_validate", object)
125             )
126    
127    # numeric, sparse, sorted compressed sparse column-oriented symmetric matrices
128    setClass("dsCMatrix",
129             representation(uplo = "character"),
130             contains = "dgCMatrix",
131             validity = function(object) .Call("dsCMatrix_validate", object)
132             )
133    
134    # numeric, sparse, sorted compressed sparse row-oriented general matrices
135    setClass("dgRMatrix",
136             representation(j = "integer", p = "integer", factors = "list"),
137             contains = "dMatrix",
138             validity = function(object) .Call("dgRMatrix_validate", object)
139             )
140    
141    # numeric, sparse, sorted compressed sparse row-oriented triangular matrices
142    setClass("dtRMatrix",
143             representation(uplo = "character", diag = "character"),
144             contains = "dgRMatrix",
145             validity = function(object) .Call("dtRMatrix_validate", object)
146             )
147    
148    # numeric, sparse, sorted compressed sparse row-oriented symmetric matrices
149    setClass("dsRMatrix",
150             representation(uplo = "character"),
151             contains = "dgRMatrix",
152             validity = function(object) .Call("dsRMatrix_validate", object)
153             )
154    
155    ## Compressed sparse column matrix in blocks
156    setClass("dgBCMatrix", representation(p = "integer", i = "integer", x = "array"))
157    
158  setClass("determinant",  setClass("determinant",
159           representation(modulus ="numeric",           representation(modulus ="numeric",
# Line 97  Line 161 
161                          sign = "integer",                          sign = "integer",
162                          call = "call"))                          call = "call"))
163    
164  setClass("LU", representation(x = "numeric", Dim = "integer",  setClass("LU", representation(x = "numeric",
165                                pivot = "integer"),                                pivot = "integer"),
166           validity = function(object)           validity = function(object)
167                      .Call("LU_validate", object))                      .Call("LU_validate", object))
168    
169  setClass("Cholesky", contains = "trMatrix")  setClass("Cholesky", contains = "dtrMatrix")
170    
171  setClass("sscChol",  setClass("dCholCMatrix",
172           representation = representation(perm = "integer", Parent = "integer",           representation = representation(perm = "integer", Parent = "integer",
173           D = "numeric"),           D = "numeric"),
174           contains = "tscMatrix",           contains = "dtCMatrix",
          prototype = prototype(p = as.integer(0), i = integer(0),  
                         x = numeric(0), Dim = as.integer(c(0, 0)),  
                         uplo = 'L', perm = integer(0), Parent = integer(0),  
                         D = numeric(0)),  
175           validity = function(object)           validity = function(object)
176             .Call("sscChol_validate", object))             .Call("dCholCMatrix_validate", object))
177    
178  setClass("sscCrosstab", representation =  setClass("sscCrosstab", representation =
179           representation(Gp = "integer", perm = "integer"),           representation(Gp = "integer", perm = "integer"),
180           contains = "sscMatrix",           contains = "dsCMatrix",
181           validity = function(object)           validity = function(object)
182             .Call("sscCrosstab_validate", object))             .Call("sscCrosstab_validate", object))
183    
# Line 157  Line 217 
217                         # correlation matrices and standard deviations                         # correlation matrices and standard deviations
218  setClass("corrmatrix", representation("matrix", stdDev = "numeric"))  setClass("corrmatrix", representation("matrix", stdDev = "numeric"))
219    
 ## Compressed sparse column matrix in blocks  
 setClass("cscBlocked", representation(p = "integer", i = "integer", x = "array"))  
   
 ## Block/block sparse symmetric matrices  
 setClass("bbSparseSy", representation(x = "list", uplo = "character"),  
          validity = function(object) {  
              ul <- object@uplo  
              if (length(ul) != 1 || nchar(ul[1]) != 1 ||  
                  !toupper(ul[1]) %in% c('L', 'U'))  
                  return("uplo slot must be 'U' or 'L'")  
              xl <- object@x  
              nf <- as.integer((-1 + sqrt(1 + 8 * length(xl))) / 2)  
              if (length(xl) != ((nf * (nf + 1))/2))  
                  return("x slot has incorrect length")  
              if (any(unlist(lapply(xl, class)) != "cscBlocked"))  
                  return("x slot must be a list of cscBlocked objects")  
              TRUE  
          })  
   
 ## Block/block cross tabulation  
 #setClass("bbCrosstab", contains = "bbSparseSy")  
   
 ## Block/block sparse triangular matrices  
 setClass("bbSparseTr", representation(x = "list", uplo = "character",  
                                       diag = "character"),  
          validity = function(object) {  
              ul <- object@uplo  
              if (length(ul) != 1 || nchar(ul[1]) != 1 ||  
                  !toupper(ul[1]) %in% c('L', 'U'))  
                  return("uplo slot must be 'U' or 'L'")  
              dd <- object@diag  
              if (length(dd) != 1 || nchar(dd[1]) != 1 ||  
                  !toupper(dd[1]) %in% c('N', 'U'))  
                  return("diag slot must be 'N' or 'U'")  
              xl <- object@x  
              nf <- as.integer((-1 + sqrt(1 + 8 * length(xl))) / 2)  
              if (length(xl) != ((nf * (nf + 1))/2))  
                  return("x slot has incorrect length")  
              if (any(unlist(lapply(xl, class)) != "cscBlocked"))  
                  return("x slot must be a list of cscBlocked objects")  
              TRUE  
          })  
   
   
 ## Block/block L matrix  
 setClass("bbLmat", representation(Linv = "list"), contains = "bbSparseTr",  
          validity = function(object) {  
              linv <- object@linv  
              xl <- object@x  
              nf <- as.integer((-1 + sqrt(1 + 8 * length(xl))) / 2)  
              if (length(linv) != nf)  
                  return("x and Linv slots have inconsistent length")  
              if (any(unlist(lapply(xl, class)) != "cscBlocked"))  
                  return("x slot must be a list of cscBlocked objects")  
              TRUE  
          })  
   
220    
221    

Legend:
Removed from v.476  
changed lines
  Added in v.477

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