SCM

SCM Repository

[matrix] Annotation of /pkg/Matrix/R/AllClass.R
ViewVC logotype

Annotation of /pkg/Matrix/R/AllClass.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3203 - (view) (download)

1 : maechler 1548 ## --- New "logic" class -- currently using "raw" instead of "logical"
2 :     ## LOGIC setClass("logic", contains = "raw")
3 :    
4 : mmaechler 3123 ##' To be used in initialize method or other Matrix constructors
5 :     ##'
6 :     ##' TODO: via .Call(..)
7 :     .fixupDimnames <- function(dnms) {
8 :     N.N <- list(NULL, NULL)
9 :     if(is.null(dnms) || identical(dnms, N.N)) return(N.N)
10 :     ## else
11 :     if(any(i0 <- lengths(dnms) == 0) && !all(vapply(dnms[i0], is.null, NA)))
12 :     ## replace character(0) etc, by NULL :
13 :     dnms[i0] <- list(NULL)
14 :     ## coerce, e.g. integer dimnames to character: -- as R's matrix(..):
15 :     if(any(i0 <- vapply(dnms, function(d) !is.null(d) && !is.character(d), NA)))
16 :     dnms[i0] <- lapply(dnms[i0], as.character)
17 :     dnms
18 :     }
19 :    
20 :    
21 : maechler 513 ## ------------- Virtual Classes ----------------------------------------
22 :    
23 : maechler 946 ## Mother class of all Matrix objects
24 : mmaechler 3165 setClass("Matrix", contains = "VIRTUAL",
25 :     slots = c(Dim = "integer", Dimnames = "list"),
26 : maechler 898 prototype = prototype(Dim = integer(2), Dimnames = list(NULL,NULL)),
27 :     validity = function(object) {
28 : mmaechler 3114 if(!isTRUE(r <- .Call(Dim_validate, object, "Matrix")))
29 :     r
30 :     else .Call(dimNames_validate, object)
31 : maechler 898 })
32 : bates 10
33 : mmaechler 3203 if(FALSE)## Allowing 'Dimnames' to define 'Dim' --> would require changes in
34 :     ## ../src/Mutils.c dimNames_validate() and how it is used in validity above
35 :     setMethod("initialize", "Matrix", function(.Object, ...)
36 :     {
37 :     .Object <- callNextMethod()
38 :     if(length(args <- list(...)) && any(nzchar(snames <- names(args))) && "Dimnames" %in% snames)
39 :     {
40 :     .Object@Dimnames <- DN <- .fixupDimnames(.Object@Dimnames)
41 :     if(is.na(match("Dim", snames)) && !any(vapply(DN, is.null, NA)))
42 :     ## take 'Dim' from 'Dimnames' dimensions
43 :     .Object@Dim <- lengths(DN, use.names=FALSE)
44 :     }
45 :     .Object
46 :     })
47 :    
48 : mmaechler 3114 if(getRversion() >= "3.2.0") {
49 :     setMethod("initialize", "Matrix", function(.Object, ...)
50 :     {
51 :     .Object <- callNextMethod()
52 : mmaechler 3123 if(length(args <- list(...)) && any(nzchar(snames <- names(args))) && "Dimnames" %in% snames)
53 :     .Object@Dimnames <- .fixupDimnames(.Object@Dimnames)
54 :     .Object
55 : mmaechler 3114 })
56 :     } else { ## R < 3.2.0
57 :     setMethod("initialize", "Matrix", function(.Object, ...)
58 :     {
59 : mmaechler 3123 .Object <- callNextMethod(.Object, ...)
60 :     if(length(args <- list(...)) && any(nzchar(snames <- names(args))) && "Dimnames" %in% snames)
61 :     .Object@Dimnames <- .fixupDimnames(.Object@Dimnames)
62 :     .Object
63 : mmaechler 3114 })
64 :     }
65 :    
66 : bates 1156 ## The class of composite matrices - i.e. those for which it makes sense to
67 :     ## create a factorization
68 : mmaechler 3165 setClass("compMatrix", contains = c("Matrix", "VIRTUAL"),
69 :     slots = c(factors = "list"))
70 : bates 1156
71 : bates 1160 ## Virtual classes of Matrices determined by above/below diagonal relationships
72 :    
73 : mmaechler 3165 setClass("generalMatrix", contains = c("compMatrix", "VIRTUAL"))
74 : bates 1160
75 : mmaechler 3165 setClass("symmetricMatrix", contains = c("compMatrix", "VIRTUAL"),
76 :     slots = c(uplo = "character"),
77 : maechler 1751 prototype = prototype(uplo = "U"),
78 : maechler 1575 validity = function(object) .Call(symmetricMatrix_validate, object))
79 : maechler 886
80 : mmaechler 3165 setClass("triangularMatrix", contains = c("Matrix", "VIRTUAL"),
81 :     slots = c(uplo = "character", diag = "character"),
82 : maechler 1751 prototype = prototype(uplo = "U", diag = "N"),
83 : maechler 1575 validity = function(object) .Call(triangularMatrix_validate, object))
84 : maechler 887
85 : bates 1160
86 : maechler 946 ## Virtual class of numeric matrices
87 : mmaechler 3165 setClass("dMatrix", contains = c("Matrix", "VIRTUAL"), slots = c(x = "numeric"),
88 : mmaechler 2996 validity = function(object) .Call(dMatrix_validate, object))
89 : bates 477
90 : maechler 946 ## Virtual class of integer matrices
91 : mmaechler 3165 setClass("iMatrix", contains = c("Matrix", "VIRTUAL"), slots = c(x = "integer"))
92 : bates 477
93 : maechler 946 ## Virtual class of logical matrices
94 : mmaechler 3165 setClass("lMatrix", contains = c("Matrix", "VIRTUAL"), slots = c(x = "logical"))
95 : bates 477
96 : maechler 1548 ## Virtual class of nonzero pattern matrices
97 : mmaechler 3165 setClass("nMatrix", contains = c("Matrix", "VIRTUAL"))
98 : maechler 1548 ## aka 'pattern' matrices -- have no x slot
99 :    
100 : mmaechler 3165 ## Virtual class of complex matrices - 'z' as in the names of Lapack routines
101 :     setClass("zMatrix", contains = c("Matrix", "VIRTUAL"), slots = c(x = "complex"))
102 : bates 477
103 : maechler 1109 ## Virtual class of dense matrices (including "packed")
104 : mmaechler 3165 setClass("denseMatrix", contains = c("Matrix", "VIRTUAL"))
105 : maechler 848
106 : maechler 946 ## Virtual class of dense, numeric matrices
107 : mmaechler 3165 setClass("ddenseMatrix", contains = c("dMatrix", "denseMatrix", "VIRTUAL"))
108 : maechler 498
109 : maechler 946 ## Virtual class of dense, logical matrices
110 : mmaechler 3165 setClass("ldenseMatrix", contains = c("lMatrix", "denseMatrix", "VIRTUAL"))
111 : bates 692
112 : maechler 1968 if(FALSE) { ##--not yet--
113 : mmaechler 3165 setClass("idenseMatrix", contains = c("iMatrix", "denseMatrix", "VIRTUAL"))
114 : maechler 1968 }
115 :    
116 : maechler 1548 ## Virtual class of dense, nonzero pattern matrices - rarely used, for completeness
117 : mmaechler 3165 setClass("ndenseMatrix", contains = c("nMatrix", "denseMatrix", "VIRTUAL"),
118 :     slots = c(x = "logical"))
119 : maechler 1548
120 : mmaechler 3165
121 : mmaechler 2237 ## virtual SPARSE ------------
122 :    
123 : mmaechler 3165 setClass("sparseMatrix", contains = c("Matrix", "VIRTUAL"))
124 : mmaechler 2237
125 : maechler 1109 ## diagonal: has 'diag' slot; diag = "U" <--> have identity matrix
126 : mmaechler 3165 setClass("diagonalMatrix", contains = c("sparseMatrix", "VIRTUAL"),
127 :     ## NOTE: ^^^^^^ was dense Matrix, until 0.999375-11 (2008-07)
128 :     slots = c(diag = "character"),
129 : maechler 1258 validity = function(object) {
130 :     d <- object@Dim
131 :     if(d[1] != (n <- d[2])) return("matrix is not square")
132 :     lx <- length(object@x)
133 : mmaechler 2764 if(object@diag == "U") {
134 :     if(lx != 0)
135 :     return("diag = \"U\" (identity matrix) requires empty 'x' slot")
136 :     } else if(object@diag == "N") {
137 :     if(lx != n)
138 :     return("diagonal matrix has 'x' slot of length != 'n'")
139 :     } else return("diagonal matrix 'diag' slot must be \"U\" or \"N\"")
140 : maechler 1258 TRUE
141 :     },
142 : maechler 1109 prototype = prototype(diag = "N")
143 : maechler 1258 )
144 : maechler 1109
145 : bates 922 ## sparse matrices in Triplet representation (dgT, lgT, ..):
146 : mmaechler 3165 setClass("TsparseMatrix", contains = c("sparseMatrix", "VIRTUAL"),
147 :     slots = c(i = "integer", j = "integer"),
148 : maechler 1315 validity = function(object) .Call(Tsparse_validate, object)
149 :     )
150 : maechler 868
151 : mmaechler 3165 setClass("CsparseMatrix", contains = c("sparseMatrix", "VIRTUAL"),
152 :     slots = c(i = "integer", p = "integer"),
153 : mmaechler 2811 prototype = prototype(p = 0L),# to be valid
154 : bates 1556 validity = function(object) .Call(Csparse_validate, object)
155 :     )
156 : bates 922
157 : mmaechler 3165 setClass("RsparseMatrix", contains = c("sparseMatrix", "VIRTUAL"),
158 :     slots = c(p = "integer", j = "integer"),
159 : mmaechler 2811 prototype = prototype(p = 0L),# to be valid
160 : maechler 1968 validity = function(object) .Call(Rsparse_validate, object)
161 : maechler 1575 )
162 : bates 922
163 : mmaechler 3165 setClass("dsparseMatrix", contains = c("dMatrix", "sparseMatrix", "VIRTUAL"))
164 : maechler 676
165 : mmaechler 3165 setClass("lsparseMatrix", contains = c("lMatrix", "sparseMatrix", "VIRTUAL"))
166 : bates 692
167 : maechler 1968 if(FALSE) { ##--not yet--
168 : mmaechler 3165 setClass("isparseMatrix", contains = c("iMatrix", "sparseMatrix", "VIRTUAL"))
169 : maechler 1968 }
170 :    
171 : maechler 1548 ## these are the "pattern" matrices for "symbolic analysis" of sparse OPs:
172 : mmaechler 3165 setClass("nsparseMatrix", contains = c("nMatrix", "sparseMatrix", "VIRTUAL"))
173 : maechler 1548
174 : mmaechler 3069 ## More Class Intersections {for method dispatch}:
175 : mmaechler 3095 if(FALSE) { ## this is "natural" but gives WARNINGs when other packages use "it"
176 : mmaechler 3165 setClass("dCsparseMatrix", contains = c("CsparseMatrix", "dsparseMatrix", "VIRTUAL"))
177 :     setClass("lCsparseMatrix", contains = c("CsparseMatrix", "lsparseMatrix", "VIRTUAL"))
178 :     setClass("nCsparseMatrix", contains = c("CsparseMatrix", "nsparseMatrix", "VIRTUAL"))
179 : mmaechler 2544
180 : mmaechler 3069 ## dense general
181 : mmaechler 3165 setClass("geMatrix", contains = c("denseMatrix", "generalMatrix", "VIRTUAL"))
182 : mmaechler 3069
183 : mmaechler 3095 } else { ## ----------- a version that maybe works better for other pkgs ---------
184 : mmaechler 3069
185 : mmaechler 3095 ##--> setClassUnion() ... below
186 :     }
187 :    
188 :    
189 : maechler 513 ## ------------------ Proper (non-virtual) Classes ----------------------------
190 :    
191 : maechler 898 ##---------------------- DENSE -----------------------------------------
192 : maechler 513
193 : maechler 946 ## numeric, dense, general matrices
194 : maechler 1165 setClass("dgeMatrix", contains = c("ddenseMatrix", "generalMatrix"),
195 : maechler 898 ## checks that length( @ x) == prod( @ Dim):
196 : mmaechler 3114 validity = function(object) .Call(dgeMatrix_validate, object))
197 : maechler 513 ## i.e. "dgeMatrix" cannot be packed, but "ddenseMatrix" can ..
198 : bates 477
199 : maechler 946 ## numeric, dense, non-packed, triangular matrices
200 : bates 477 setClass("dtrMatrix",
201 : bates 1156 contains = c("ddenseMatrix", "triangularMatrix"),
202 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object))
203 : bates 10
204 : maechler 946 ## numeric, dense, packed, triangular matrices
205 : bates 477 setClass("dtpMatrix",
206 : maechler 898 contains = c("ddenseMatrix", "triangularMatrix"),
207 : mmaechler 3114 validity = function(object) .Call(dtpMatrix_validate, object))
208 : bates 10
209 : mmaechler 3114
210 : maechler 946 ## numeric, dense, non-packed symmetric matrices
211 : bates 477 setClass("dsyMatrix",
212 : maechler 1799 contains = c("ddenseMatrix", "symmetricMatrix"),
213 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object))
214 : bates 10
215 : maechler 946 ## numeric, dense, packed symmetric matrices
216 : bates 477 setClass("dspMatrix",
217 : maechler 1165 contains = c("ddenseMatrix", "symmetricMatrix"),
218 : mmaechler 3114 validity = function(object) .Call(dspMatrix_validate, object))
219 : bates 10
220 : maechler 946 ## numeric, dense, non-packed, positive-definite, symmetric matrices
221 : bates 477 setClass("dpoMatrix", contains = "dsyMatrix",
222 : maechler 1443 validity = function(object) .Call(dpoMatrix_validate, object)
223 : maechler 898 )
224 : bates 10
225 : maechler 946 ## numeric, dense, packed, positive-definite, symmetric matrices
226 : bates 482 setClass("dppMatrix", contains = "dspMatrix",
227 : maechler 1443 validity = function(object) .Call(dppMatrix_validate, object)
228 : bates 10
229 : maechler 1548 )
230 : maechler 925 ##----- logical dense Matrices -- e.g. as result of <ddenseMatrix> COMPARISON
231 :    
232 : maechler 1548 ## logical, dense, general matrices
233 : maechler 1165 setClass("lgeMatrix", contains = c("ldenseMatrix", "generalMatrix"),
234 : mmaechler 2996 ## since "lge" inherits from "ldenseMatrix", only need this:
235 : maechler 925 ## checks that length( @ x) == prod( @ Dim):
236 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object))
237 : maechler 925 ## i.e. "lgeMatrix" cannot be packed, but "ldenseMatrix" can ..
238 :    
239 : maechler 1548 ## logical, dense, non-packed, triangular matrices
240 : maechler 925 setClass("ltrMatrix",
241 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object),
242 : maechler 1751 contains = c("ldenseMatrix", "triangularMatrix"))
243 : maechler 925
244 : maechler 1548 ## logical, dense, packed, triangular matrices
245 : maechler 925 setClass("ltpMatrix",
246 : maechler 1751 contains = c("ldenseMatrix", "triangularMatrix"))
247 : maechler 925
248 : maechler 1548 ## logical, dense, non-packed symmetric matrices
249 : maechler 925 setClass("lsyMatrix",
250 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object),
251 : maechler 1751 contains = c("ldenseMatrix", "symmetricMatrix"))
252 : maechler 925
253 : maechler 1548 ## logical, dense, packed symmetric matrices
254 : maechler 925 setClass("lspMatrix",
255 : maechler 1201 contains = c("ldenseMatrix", "symmetricMatrix"),
256 : maechler 1751 validity = function(object) .Call(dspMatrix_validate, object)
257 : mmaechler 2814 ## "dsp", "lsp" and "nsp" have the same validate
258 : maechler 925 )
259 :    
260 : maechler 1548 ##----- nonzero pattern dense Matrices -- "for completeness"
261 :    
262 :     ## logical, dense, general matrices
263 :     setClass("ngeMatrix", contains = c("ndenseMatrix", "generalMatrix"),
264 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object))
265 : maechler 1548 ## i.e. "ngeMatrix" cannot be packed, but "ndenseMatrix" can ..
266 :    
267 :     ## logical, dense, non-packed, triangular matrices
268 :     setClass("ntrMatrix",
269 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object),
270 : maechler 1751 contains = c("ndenseMatrix", "triangularMatrix"))
271 : maechler 1548
272 :     ## logical, dense, packed, triangular matrices
273 :     setClass("ntpMatrix",
274 : maechler 1751 contains = c("ndenseMatrix", "triangularMatrix"))
275 : maechler 1548
276 :     ## logical, dense, non-packed symmetric matrices
277 :     setClass("nsyMatrix",
278 : mmaechler 2996 validity = function(object) .Call(dense_nonpacked_validate, object),
279 : maechler 1751 contains = c("ndenseMatrix", "symmetricMatrix"))
280 : maechler 1548
281 :     ## logical, dense, packed symmetric matrices
282 :     setClass("nspMatrix",
283 :     contains = c("ndenseMatrix", "symmetricMatrix"),
284 : maechler 1751 validity = function(object) .Call(dspMatrix_validate, object)
285 : mmaechler 2814 ## "dsp", "lsp" and "nsp" have the same validate
286 : maechler 1548 )
287 :    
288 :    
289 : maechler 1109 ## 'diagonalMatrix' already has validity checking
290 : mmaechler 3030 ## diagonal, numeric matrices; "dMatrix" has 'x' slot :
291 : mmaechler 2183 setClass("ddiMatrix", contains = c("diagonalMatrix", "dMatrix"))# or "dMatrix"
292 : mmaechler 3030 ## diagonal, logical matrices; "lMatrix" has 'x' slot :
293 : mmaechler 2183 setClass("ldiMatrix", contains = c("diagonalMatrix", "lMatrix"))
294 : maechler 1109
295 : mmaechler 3165 setClass("corMatrix", slots = c(sd = "numeric"), contains = "dpoMatrix",
296 : maechler 1642 validity = function(object) {
297 :     ## assuming that 'dpoMatrix' validity check has already happened:
298 :     n <- object@Dim[2]
299 :     if(length(sd <- object@sd) != n)
300 :     return("'sd' slot must be of length 'dim(.)[1]'")
301 : mmaechler 2800 if(any(!is.finite(sd)))# including NA
302 :     return("'sd' slot has non-finite entries")
303 : maechler 1642 if(any(sd < 0))
304 :     return("'sd' slot has negative entries")
305 :     TRUE
306 :     })
307 : maechler 1109
308 : maechler 1443
309 : maechler 676 ##-------------------- S P A R S E (non-virtual) --------------------------
310 : maechler 513
311 : bates 692 ##---------- numeric sparse matrix classes --------------------------------
312 : maechler 848
313 : maechler 946 ## numeric, sparse, triplet general matrices
314 : bates 477 setClass("dgTMatrix",
315 : maechler 1165 contains = c("TsparseMatrix", "dsparseMatrix", "generalMatrix"),
316 : maechler 1661 validity = function(object) .Call(xTMatrix_validate, object)
317 : maechler 898 )
318 : bates 10
319 : bates 922 ## Should not have dtTMatrix inherit from dgTMatrix because a dtTMatrix could
320 : maechler 946 ## be less than fully stored if diag = "U". Methods for the dgTMatrix
321 :     ## class would not produce correct results even though all the slots
322 :     ## are present.
323 : bates 922
324 : maechler 946 ## numeric, sparse, triplet triangular matrices
325 : bates 477 setClass("dtTMatrix",
326 : bates 922 contains = c("TsparseMatrix", "dsparseMatrix", "triangularMatrix"),
327 : maechler 1710 validity = function(object) .Call(tTMatrix_validate, object)
328 : maechler 898 )
329 : bates 10
330 : maechler 1710 ## numeric, sparse, triplet symmetric matrices(also only store one triangle)
331 : bates 482 setClass("dsTMatrix",
332 : maechler 1165 contains = c("TsparseMatrix", "dsparseMatrix", "symmetricMatrix"),
333 : maechler 1710 validity = function(object) .Call(tTMatrix_validate, object)
334 : maechler 898 )
335 : bates 10
336 : maechler 946 ## numeric, sparse, sorted compressed sparse column-oriented general matrices
337 : bates 477 setClass("dgCMatrix",
338 : maechler 1165 contains = c("CsparseMatrix", "dsparseMatrix", "generalMatrix"),
339 : maechler 1661 validity = function(object) .Call(xCMatrix_validate, object)
340 : maechler 898 )
341 : bates 10
342 : bates 1896 ## special case: indicator rows for a factor - needs more careful definition
343 : mmaechler 3165 ##setClass("indicators", contains = "dgCMatrix", slots = c(levels = "character"))
344 : bates 1896
345 : bates 922 ## see comments for dtTMatrix above
346 : maechler 946 ## numeric, sparse, sorted compressed sparse column-oriented triangular matrices
347 : bates 477 setClass("dtCMatrix",
348 : bates 922 contains = c("CsparseMatrix", "dsparseMatrix", "triangularMatrix"),
349 : maechler 1710 validity = function(object) .Call(tCMatrix_validate, object)
350 : maechler 898 )
351 : bates 477
352 : bates 922 ## see comments for dsTMatrix above
353 : maechler 946 ## numeric, sparse, sorted compressed sparse column-oriented symmetric matrices
354 : bates 477 setClass("dsCMatrix",
355 : maechler 1165 contains = c("CsparseMatrix", "dsparseMatrix", "symmetricMatrix"),
356 : maechler 1710 validity = function(object) .Call(tCMatrix_validate, object)
357 : maechler 898 )
358 : bates 477
359 : mmaechler 2497 if(FALSE) ## TODO ??? Class of positive definite (Csparse symmetric) Matrices:
360 : mmaechler 2170 setClass("dpCMatrix", contains = "dsCMatrix",
361 : mmaechler 2497 validity = function(object) TODO("test for pos.definite ??"))
362 : mmaechler 2170
363 : maechler 946 ## numeric, sparse, sorted compressed sparse row-oriented general matrices
364 : bates 477 setClass("dgRMatrix",
365 : maechler 1201 contains = c("RsparseMatrix", "dsparseMatrix", "generalMatrix"),
366 : maechler 1968 validity = function(object) .Call(xRMatrix_validate, object)
367 : maechler 898 )
368 : bates 477
369 : maechler 946 ## numeric, sparse, sorted compressed sparse row-oriented triangular matrices
370 : bates 477 setClass("dtRMatrix",
371 : maechler 1174 contains = c("RsparseMatrix", "dsparseMatrix", "triangularMatrix"),
372 : maechler 1968 validity = function(object) .Call(tRMatrix_validate, object)
373 : maechler 898 )
374 : bates 477
375 : maechler 946 ## numeric, sparse, sorted compressed sparse row-oriented symmetric matrices
376 : bates 477 setClass("dsRMatrix",
377 : maechler 1174 contains = c("RsparseMatrix", "dsparseMatrix", "symmetricMatrix"),
378 : maechler 1968 validity = function(object) .Call(tRMatrix_validate, object)
379 : maechler 898 )
380 : bates 477
381 : bates 692 ##---------- logical sparse matrix classes --------------------------------
382 :    
383 : maechler 1968 ## these classes are typically result of Matrix comparisons, e.g.,
384 :     ## <..Matrix> >= v (and hence can have NA's)
385 : bates 692
386 : maechler 946 ## logical, sparse, triplet general matrices
387 : bates 692 setClass("lgTMatrix",
388 : maechler 1165 contains = c("TsparseMatrix", "lsparseMatrix", "generalMatrix"),
389 : maechler 1661 validity = function(object) .Call(xTMatrix_validate, object)
390 : maechler 898 )
391 : bates 692
392 : maechler 946 ## logical, sparse, triplet triangular matrices
393 : bates 692 setClass("ltTMatrix",
394 : bates 922 contains = c("TsparseMatrix", "lsparseMatrix", "triangularMatrix"),
395 : mmaechler 2170 validity = function(object) .Call(tTMatrix_validate, object)
396 : maechler 898 )
397 : bates 692
398 : maechler 946 ## logical, sparse, triplet symmetric matrices
399 : bates 692 setClass("lsTMatrix",
400 : maechler 1165 contains = c("TsparseMatrix", "lsparseMatrix", "symmetricMatrix"),
401 : mmaechler 2170 validity = function(object) .Call(tTMatrix_validate, object)
402 : maechler 898 )
403 : bates 692
404 : maechler 946 ## logical, sparse, sorted compressed sparse column-oriented general matrices
405 : bates 692 setClass("lgCMatrix",
406 : maechler 1201 contains = c("CsparseMatrix", "lsparseMatrix", "generalMatrix"),
407 : maechler 1661 validity = function(object) .Call(xCMatrix_validate, object)
408 : maechler 898 )
409 : bates 692
410 : maechler 946 ## logical, sparse, sorted compressed sparse column-oriented triangular matrices
411 : bates 692 setClass("ltCMatrix",
412 : maechler 1201 contains = c("CsparseMatrix", "lsparseMatrix", "triangularMatrix"),
413 : maechler 1661 validity = function(object) .Call(xCMatrix_validate, object)
414 : maechler 898 )
415 : bates 692
416 : maechler 946 ## logical, sparse, sorted compressed sparse column-oriented symmetric matrices
417 : bates 692 setClass("lsCMatrix",
418 : maechler 1201 contains = c("CsparseMatrix", "lsparseMatrix", "symmetricMatrix"),
419 : maechler 1661 validity = function(object) .Call(xCMatrix_validate, object)
420 : maechler 898 )
421 : bates 692
422 : maechler 946 ## logical, sparse, sorted compressed sparse row-oriented general matrices
423 : bates 692 setClass("lgRMatrix",
424 : maechler 1201 contains = c("RsparseMatrix", "lsparseMatrix", "generalMatrix"),
425 : maechler 1968 validity = function(object) .Call(xRMatrix_validate, object)
426 : maechler 898 )
427 : bates 692
428 : maechler 946 ## logical, sparse, sorted compressed sparse row-oriented triangular matrices
429 : bates 692 setClass("ltRMatrix",
430 : maechler 1201 contains = c("RsparseMatrix", "lsparseMatrix", "triangularMatrix"),
431 : maechler 1968 validity = function(object) .Call(tRMatrix_validate, object)
432 : maechler 898 )
433 : bates 692
434 : maechler 946 ## logical, sparse, sorted compressed sparse row-oriented symmetric matrices
435 : bates 692 setClass("lsRMatrix",
436 : maechler 1201 contains = c("RsparseMatrix", "lsparseMatrix", "symmetricMatrix"),
437 : maechler 1968 validity = function(object) .Call(tRMatrix_validate, object)
438 : maechler 898 )
439 : bates 692
440 : maechler 1548 ##---------- nonzero pattern sparse matrix classes ---------------------------
441 :    
442 :     ## these classes are used in symbolic analysis to determine the
443 :     ## locations of non-zero entries
444 :    
445 :     ## nonzero pattern, sparse, triplet general matrices
446 :     setClass("ngTMatrix",
447 : maechler 1575 contains = c("TsparseMatrix", "nsparseMatrix", "generalMatrix")
448 :     ## validity: Tsparse_validate should be enough
449 : maechler 1548 )
450 :    
451 :     ## nonzero pattern, sparse, triplet triangular matrices
452 :     setClass("ntTMatrix",
453 :     contains = c("TsparseMatrix", "nsparseMatrix", "triangularMatrix"),
454 : maechler 1575 ## validity: Tsparse_ and triangular*_validate should be enough
455 : maechler 1548 )
456 :    
457 :     ## nonzero pattern, sparse, triplet symmetric matrices
458 :     setClass("nsTMatrix",
459 : maechler 1599 contains = c("TsparseMatrix", "nsparseMatrix", "symmetricMatrix"),
460 : maechler 1575 ## validity: Tsparse_ and symmetric*_validate should be enough
461 : maechler 1548 )
462 :    
463 : mmaechler 2628 ## nonzero pattern, sparse, sorted compressed column-oriented matrices
464 : maechler 1548 setClass("ngCMatrix",
465 :     contains = c("CsparseMatrix", "nsparseMatrix", "generalMatrix"),
466 : maechler 1575 ## validity: Csparse_validate should be enough
467 : maechler 1548 )
468 :    
469 : mmaechler 2628 setClass("ngCMatrix",
470 :     contains = c("CsparseMatrix", "nsparseMatrix", "generalMatrix"),
471 :     ## validity: Csparse_validate should be enough
472 :     )
473 :    
474 : maechler 1548 ## nonzero pattern, sparse, sorted compressed column-oriented triangular matrices
475 :     setClass("ntCMatrix",
476 :     contains = c("CsparseMatrix", "nsparseMatrix", "triangularMatrix"),
477 : maechler 1575 ## validity: Csparse_ and triangular*_validate should be enough
478 : maechler 1548 )
479 :    
480 :     ## nonzero pattern, sparse, sorted compressed column-oriented symmetric matrices
481 :     setClass("nsCMatrix",
482 :     contains = c("CsparseMatrix", "nsparseMatrix", "symmetricMatrix"),
483 : maechler 1575 ## validity: Csparse_ and symmetric*_validate should be enough
484 : maechler 1548 )
485 :    
486 :     ## nonzero pattern, sparse, sorted compressed row-oriented general matrices
487 :     setClass("ngRMatrix",
488 : maechler 1738 contains = c("RsparseMatrix", "nsparseMatrix", "generalMatrix"),
489 : maechler 1548 )
490 :    
491 :     ## nonzero pattern, sparse, sorted compressed row-oriented triangular matrices
492 :     setClass("ntRMatrix",
493 : maechler 1738 contains = c("RsparseMatrix", "nsparseMatrix", "triangularMatrix"),
494 : maechler 1548 )
495 :    
496 :     ## nonzero pattern, sparse, sorted compressed row-oriented symmetric matrices
497 :     setClass("nsRMatrix",
498 : maechler 1738 contains = c("RsparseMatrix", "nsparseMatrix", "symmetricMatrix"),
499 : maechler 1548 )
500 :    
501 : maechler 1968 if(FALSE) { ##--not yet--
502 :    
503 :     ##---------- integer sparse matrix classes --------------------------------
504 :    
505 :     ## integer, sparse, triplet general matrices
506 :     setClass("igTMatrix",
507 :     contains = c("TsparseMatrix", "isparseMatrix", "generalMatrix"),
508 :     validity = function(object) .Call(xTMatrix_validate, object)
509 :     )
510 :    
511 :     ## integer, sparse, triplet triangular matrices
512 :     setClass("itTMatrix",
513 :     contains = c("TsparseMatrix", "isparseMatrix", "triangularMatrix"),
514 : mmaechler 2170 validity = function(object) .Call(tTMatrix_validate, object)
515 : maechler 1968 )
516 :    
517 :     ## integer, sparse, triplet symmetric matrices
518 :     setClass("isTMatrix",
519 :     contains = c("TsparseMatrix", "isparseMatrix", "symmetricMatrix"),
520 : mmaechler 2170 validity = function(object) .Call(tTMatrix_validate, object)
521 : maechler 1968 )
522 :    
523 :     ## integer, sparse, sorted compressed sparse column-oriented general matrices
524 :     setClass("igCMatrix",
525 :     contains = c("CsparseMatrix", "isparseMatrix", "generalMatrix"),
526 :     validity = function(object) .Call(xCMatrix_validate, object)
527 :     )
528 :    
529 :     ## integer, sparse, sorted compressed sparse column-oriented triangular matrices
530 :     setClass("itCMatrix",
531 :     contains = c("CsparseMatrix", "isparseMatrix", "triangularMatrix"),
532 :     validity = function(object) .Call(xCMatrix_validate, object)
533 :     )
534 :    
535 :     ## integer, sparse, sorted compressed sparse column-oriented symmetric matrices
536 :     setClass("isCMatrix",
537 :     contains = c("CsparseMatrix", "isparseMatrix", "symmetricMatrix"),
538 :     validity = function(object) .Call(xCMatrix_validate, object)
539 :     )
540 :    
541 :     ## integer, sparse, sorted compressed sparse row-oriented general matrices
542 :     setClass("igRMatrix",
543 :     contains = c("RsparseMatrix", "isparseMatrix", "generalMatrix"),
544 :     validity = function(object) .Call(xRMatrix_validate, object)
545 :     )
546 :    
547 :     ## integer, sparse, sorted compressed sparse row-oriented triangular matrices
548 :     setClass("itRMatrix",
549 :     contains = c("RsparseMatrix", "isparseMatrix", "triangularMatrix"),
550 :     validity = function(object) .Call(tRMatrix_validate, object)
551 :     )
552 :    
553 :     ## integer, sparse, sorted compressed sparse row-oriented symmetric matrices
554 :     setClass("isRMatrix",
555 :     contains = c("RsparseMatrix", "isparseMatrix", "symmetricMatrix"),
556 :     validity = function(object) .Call(tRMatrix_validate, object)
557 :     )
558 :     }##--not yet--
559 :    
560 : mmaechler 2892 ##-------------------- index and permutation matrices--------------------------
561 : maechler 1443
562 : mmaechler 3165 setClass("indMatrix", slots = c(perm = "integer"),
563 : mmaechler 2894 contains = c("sparseMatrix", "generalMatrix"),
564 :     validity = function(object) {
565 : mmaechler 3064 n <- object@Dim[1]
566 :     d <- object@Dim[2]
567 : mmaechler 2894 perm <- object@perm
568 :     if (length(perm) != n)
569 :     return(paste("length of 'perm' slot must be", n))
570 : mmaechler 3064 if(n > 0 && (any(perm > d) || any(perm < 1)))
571 : mmaechler 2894 return("'perm' slot is not a valid index")
572 :     TRUE
573 :     })
574 : mmaechler 2892
575 : mmaechler 3165 setClass("pMatrix", slots = c(perm = "integer"),
576 : mmaechler 2892 contains = c("indMatrix"),
577 : maechler 1443 validity = function(object) {
578 :     d <- object@Dim
579 :     if (d[2] != (n <- d[1])) return("pMatrix must be square")
580 :     perm <- object@perm
581 :     if (length(perm) != n)
582 :     return(paste("length of 'perm' slot must be", n))
583 :     if(n > 0 &&
584 :     !(all(range(perm) == c(1, n)) && length(unique(perm)) == n))
585 :     return("'perm' slot is not a valid permutation")
586 :     TRUE
587 :     })
588 :    
589 :    
590 : maechler 1201 ### Factorization classes ---------------------------------------------
591 : bates 692
592 : maechler 1443 ## Mother class:
593 : mmaechler 3165 setClass("MatrixFactorization", slots = c(Dim = "integer"), contains = "VIRTUAL",
594 : mmaechler 3114 validity = function(object) .Call(MatrixFactorization_validate, object))
595 : maechler 513
596 : mmaechler 3165 setClass("CholeskyFactorization", contains = "MatrixFactorization", "VIRTUAL")
597 : mmaechler 2565
598 : maechler 1443 ## -- Those (exceptions) inheriting from "Matrix" : ---
599 : bates 1150
600 : mmaechler 2565 setClass("Cholesky", contains = c("dtrMatrix", "CholeskyFactorization"))
601 : bates 1150
602 : mmaechler 2565 #unUsed: setClass("LDL", contains = c("dtrMatrix", "CholeskyFactorization"))
603 : bates 638
604 : mmaechler 2565 setClass("pCholesky", contains = c("dtpMatrix", "CholeskyFactorization"))
605 : maechler 1444
606 : maechler 1654 ## These are currently only produced implicitly from *solve()
607 : mmaechler 3165 setClass("BunchKaufman", contains = c("dtrMatrix", "MatrixFactorization"),
608 :     slots = c(perm = "integer"),
609 : mmaechler 3114 validity = function(object) .Call(BunchKaufman_validate, object))
610 : bates 631
611 : mmaechler 3165 setClass("pBunchKaufman", contains = c("dtpMatrix", "MatrixFactorization"),
612 :     slots = c(perm = "integer"),
613 : mmaechler 3114 validity = function(object) .Call(pBunchKaufman_validate, object))
614 : bates 638
615 : maechler 1443 ## -- the usual ``non-Matrix'' factorizations : ---------
616 : maechler 513
617 : mmaechler 3165 setClass("CHMfactor", # cholmod_factor struct as S4 object
618 :     contains = c("CholeskyFactorization", "VIRTUAL"),
619 :     slots = c(colcount = "integer", perm = "integer", type = "integer"),
620 : maechler 1571 validity = function(object) .Call(CHMfactor_validate, object))
621 : bates 1150
622 : maechler 1258 setClass("CHMsuper", # supernodal cholmod_factor
623 : mmaechler 3165 contains = c("CHMfactor", "VIRTUAL"),
624 :     slots = c(super = "integer", pi = "integer", px = "integer",
625 :     s = "integer"),
626 : maechler 1443 validity = function(object) .Call(CHMsuper_validate, object))
627 : bates 1150
628 : maechler 1258 setClass("CHMsimpl", # simplicial cholmod_factor
629 : mmaechler 3165 contains = c("CHMfactor", "VIRTUAL"),
630 :     slots = c(p = "integer", i = "integer", nz = "integer",
631 :     nxt = "integer", prv = "integer"),
632 : maechler 1443 validity = function(object) .Call(CHMsimpl_validate, object))
633 : bates 1150
634 : mmaechler 3165 setClass("dCHMsuper", contains = "CHMsuper", slots = c(x = "numeric"))
635 : bates 1150
636 : maechler 1548 setClass("nCHMsuper", contains = "CHMsuper")
637 : bates 1150
638 : mmaechler 3165 setClass("dCHMsimpl", contains = "CHMsimpl", slots = c(x = "numeric"))
639 : bates 1150
640 : maechler 1548 setClass("nCHMsimpl", contains = "CHMsimpl")
641 : bates 1150
642 : maechler 1407 ##--- LU ---
643 : bates 1150
644 : mmaechler 3165 setClass("LU", contains = c("MatrixFactorization", "VIRTUAL"))
645 : maechler 1407
646 :     setClass("denseLU", contains = "LU",
647 : mmaechler 3165 slots = c(x = "numeric", perm = "integer", Dimnames = "list"),
648 : maechler 1407 validity = function(object) .Call(LU_validate, object))
649 :    
650 :     setClass("sparseLU", contains = "LU",
651 : mmaechler 3165 slots = c(L = "dtCMatrix", U = "dtCMatrix",
652 :     p = "integer", q = "integer"))
653 : maechler 1407
654 :     ##--- QR ---
655 :    
656 : maechler 1443 setClass("sparseQR", contains = "MatrixFactorization",
657 : mmaechler 3165 slots = c(V = "dgCMatrix", beta = "numeric",
658 :     p = "integer", R = "dgCMatrix", q = "integer"),
659 : mmaechler 2852 validity = function(object) .Call(sparseQR_validate, object))
660 : maechler 1407
661 : mmaechler 2987 ##-- "SPQR" ---> ./spqr.R for now
662 : mmaechler 2327
663 : maechler 1444 ## "denseQR" -- ? (``a version of'' S3 class "qr")
664 :    
665 : maechler 1407 if (FALSE) { ## unused classes
666 : mmaechler 3165 setClass("csn_QR", slots = c(U = "dgCMatrix", L = "dgCMatrix",
667 :     beta = "numeric"))
668 : maechler 1407
669 : mmaechler 3165 setClass("csn_LU", slots = c(U = "dgCMatrix", L = "dgCMatrix",
670 :     Pinv = "integer"))
671 : maechler 1407
672 : mmaechler 3165 setClass("css_QR", slots = c(Pinv = "integer", Q = "integer",
673 :     parent = "integer", cp = "integer",
674 :     nz = "integer"))
675 : maechler 1407
676 : mmaechler 3165 setClass("css_LU", slots = c(Q = "integer", nz = "integer"))
677 : maechler 1407 }
678 :    
679 : maechler 2106 ##-- Schur ---
680 : maechler 1407
681 : maechler 2113 ## non-"Matrix" Class 1 --- For Eigen values:
682 :     setClassUnion("number", members = c("numeric", "complex"))
683 :    
684 : maechler 2106 setClass("Schur", contains = "MatrixFactorization",
685 : mmaechler 3165 slots = c(T = "Matrix", # <- "block-triangular"; maybe triangular
686 :     Q = "Matrix", EValues = "number"),
687 : maechler 2106 validity = function(object) {
688 :     dim <- object@Dim
689 :     if((n <- dim[1]) != dim[2])
690 :     "'Dim' slot is not (n,n)"
691 :     else if(any(dim(object@T) != n))
692 :     "'dim(T)' is incorrect"
693 :     else if(any(dim(object@Q) != n))
694 :     "'dim(Q)' is incorrect"
695 :     else if(length(object@EValues) != n)
696 :     "'EValues' is not of correct length"
697 :     else TRUE
698 :     })
699 :    
700 :    
701 : maechler 953 ### Class Union : no inheritance, but is(*, <class>) :
702 : maechler 1189
703 : mmaechler 2780 setClassUnion("mMatrix", members = c("matrix", "Matrix"))
704 : mmaechler 3189 if(FALSE) ## to be used in setMethod("c", "numM...") -- once that works
705 :     setClassUnion("numMatrixLike", members = c("logical", "integer", "numeric", "mMatrix"))
706 : mmaechler 2780
707 : mmaechler 2881 ## CARE: Sometimes we'd want all those for which 'x' contains all the data.
708 :     ## e.g. Diagonal() is "ddiMatrix" with 'x' slot of length 0, does *not* contain 1
709 :     setClassUnion("xMatrix", ## those Matrix classes with an 'x' slot
710 :     c("dMatrix",
711 :     "iMatrix",
712 :     "lMatrix",
713 :     "ndenseMatrix",
714 :     "zMatrix"))
715 :    
716 : mmaechler 3095 if(TRUE) { ##--- variant of setClass("dCsparse..." ..) etc working better for other pkgs -----
717 : mmaechler 2881
718 : mmaechler 3095 setClassUnion("dCsparseMatrix", members = c("dgCMatrix", "dtCMatrix", "dsCMatrix"))
719 :     setClassUnion("lCsparseMatrix", members = c("lgCMatrix", "ltCMatrix", "lsCMatrix"))
720 :     setClassUnion("nCsparseMatrix", members = c("ngCMatrix", "ntCMatrix", "nsCMatrix"))
721 :    
722 :     ## dense general
723 :     setClassUnion("geMatrix", members = c("dgeMatrix", "lgeMatrix", "ngeMatrix"))
724 :     }
725 :    
726 :    
727 :    
728 : maechler 1189 ## Definition Packed := dense with length( . @x) < prod( . @Dim)
729 : maechler 1258 ## ~~~~~~
730 :     ## REPLACED the following with isPacked() in ./Auxiliaries.R :
731 : maechler 1227 ## setClassUnion("packedMatrix",
732 : maechler 1258 ## members = c("dspMatrix", "dppMatrix", "dtpMatrix",
733 :     ## "lspMatrix", "ltpMatrix", "diagonalMatrix"))
734 : maechler 953
735 :    
736 : maechler 513 ## --------------------- non-"Matrix" Classes --------------------------------
737 :    
738 : maechler 886 ## --- "General" (not Matrix at all) ----
739 :    
740 : mmaechler 2507 ## e.g. for "Arith" methods:
741 :     setClassUnion("numLike", members = c("numeric", "logical"))
742 :    
743 : mmaechler 2930 ##setClassUnion("numIndex", members = "numeric")
744 : mmaechler 2497
745 :     ## Note "rle" is a sealed oldClass (and "virtual" as w/o prototype)
746 : mmaechler 3165 setClass("rleDiff", slots = c(first = "numLike", rle = "rle"),
747 : mmaechler 2525 prototype = prototype(first = integer(),
748 : mmaechler 3165 rle = rle(integer())),
749 : mmaechler 2497 validity = function(object) {
750 :     if(length(object@first) != 1)
751 :     return("'first' must be of length one")
752 :     rl <- object@rle
753 :     if(!is.list(rl) || length(rl) != 2 ||
754 :     !identical(sort(names(rl)), c("lengths", "values")))
755 :     return("'rle' must be a list (lengths = *, values = *)")
756 :     if(length(lens <- rl$lengths) != length(vals <- rl$values))
757 :     return("'lengths' and 'values' differ in length")
758 :     if(any(lens <= 0))
759 :     return("'lengths' must be positive")
760 :     TRUE
761 :     })
762 :    
763 : mmaechler 2688 ### 2010-03-04 -- thinking about *implementing* some 'abIndex' methodology,
764 : mmaechler 2525 ### I conclude that the following structure would probably be even more
765 :     ### efficient than the "rleDiff" one :
766 : mmaechler 2688 ### IDEA: Store subsequences in a numeric matrix of three rows, where
767 :     ### ----- one column = [from, to, by] defining a sub seq()ence
768 :    
769 :     ## for now, at least use it, and [TODO!] define "seqMat" <--> "abIndex" coercions:
770 : mmaechler 2525 setClass("seqMat", contains = "matrix",
771 : mmaechler 2688 prototype = prototype(matrix(0, nrow = 3, ncol=0)),
772 : mmaechler 2525 validity = function(object) {
773 :     if(!is.numeric(object)) return("is not numeric")
774 :     d <- dim(object)
775 : mmaechler 2688 if(length(d) != 3 || d[1] != 3)
776 :     return("not a 3 x n matrix")
777 : mmaechler 2525 if(any(object != floor(object)))
778 :     return("some entries are not integer valued")
779 :     TRUE
780 :     })
781 :    
782 : mmaechler 2497 setClass("abIndex", # 'ABSTRact Index'
783 : mmaechler 3165 slots = c(kind = "character",
784 :     ## one of ("int32", "double", "rleDiff")
785 : mmaechler 2497 # i.e., numeric or "rleDiff"
786 : mmaechler 3165 x = "numLike", # for numeric [length 0 otherwise]
787 :     rleD = "rleDiff"), # "rleDiff" result
788 : mmaechler 2497 prototype = prototype(kind = "int32", x = integer(0)),# rleD = ... etc
789 :     validity = function(object) {
790 :     switch(object@kind,
791 :     "int32" = if(!is.integer(object@x))
792 :     return("'x' slot must be integer when kind is 'int32'")
793 :     ,
794 :     "double" = if(!is.double(object@x))
795 :     return("'x' slot must be double when kind is 'double'")
796 :     ,
797 :     "rleDiff" = {
798 :     if(length(object@x))
799 :     return("'x' slot must be empty when kind is 'rleDiff'")
800 :     },
801 :     ## otherwise
802 :     return("'kind' must be one of (\"int32\", \"double\", \"rleDiff\")")
803 :     )
804 :     TRUE
805 :     })
806 :    
807 : maechler 1708 ## for 'i' in x[i] or A[i,] : (numeric = {double, integer})
808 : mmaechler 2497 ## TODO: allow "abIndex" as well !
809 : maechler 886 setClassUnion("index", members = c("numeric", "logical", "character"))
810 :    
811 : mmaechler 2497 ## "atomic vectors" (-> ?is.atomic ) -- but note that is.atomic(<matrix>) !
812 : maechler 1708 ## --------------- those that we want to convert from old-style "matrix"
813 : maechler 2165 setClassUnion("atomicVector", ## "double" is not needed, and not liked by some
814 :     members = c("logical", "integer", "numeric",
815 : maechler 1708 "complex", "raw", "character"))
816 : maechler 886
817 : mmaechler 3191 setClassUnion("numericVector", members = c("logical", "integer", "numeric"))
818 :    
819 :     setClassUnion("Mnumeric", members = c("numericVector", "Matrix"))
820 :     ## not "matrix" as that extends "vector" and contains "character", "structure" ...
821 :    
822 :     setValidity("Mnumeric",
823 :     function(object) {
824 :     if(is.numeric(object) ||
825 :     is.logical(object) ||
826 :     inherits(object, "Matrix")) return(TRUE)
827 :     ## else
828 :     "Not a valid 'Mnumeric' class object"
829 :     })
830 :    
831 :    
832 :    
833 : maechler 1407 ## --- Matrix - related (but not "Matrix" nor "Decomposition/Factorization):
834 : maechler 1331
835 : maechler 1845 ### Sparse Vectors ---- here use 1-based indexing ! -----------
836 : mmaechler 2242
837 :     ## 'longindex' should allow sparseVectors of "length" > 2^32,
838 :     ## which is necessary e.g. when converted from large sparse matrices
839 :     ## setClass("longindex", contains = "numeric")
840 :     ## but we use "numeric" instead, for simplicity (efficiency?)
841 : maechler 1845 setClass("sparseVector",
842 : mmaechler 3165 slots = c(length = "numeric", i = "numeric"), contains = "VIRTUAL",
843 : mmaechler 2242 ## "longindex" "longindex"
844 :     ## note that "numeric" contains "integer" (if I like it or not..)
845 :     prototype = prototype(length = 0),
846 : maechler 1845 validity = function(object) {
847 : mmaechler 3030 n <- object@length
848 :     if(anyNA(i <- object@i)) "'i' slot has NAs"
849 :     else if(any(!is.finite(i))) "'i' slot is not all finite"
850 :     else if(any(i < 1)) "'i' must be >= 1"
851 :     else if(n == 0 && length(i))"'i' must be empty when the object length is zero"
852 :     else if(any(i > n)) sprintf("'i' must be in 1:%d", n)
853 : mmaechler 2648 else if(is.unsorted(i, strictly=TRUE))
854 :     "'i' must be sorted strictly increasingly"
855 : maechler 1845 else TRUE
856 :     })
857 : mmaechler 2648
858 :     ##' initialization -- ensuring that 'i' is sorted (and 'x' alongside)
859 : mmaechler 3114 if(getRversion() >= "3.2.0") {
860 : mmaechler 2648 setMethod("initialize", "sparseVector", function(.Object, i, x, ...)
861 :     {
862 :     has.x <- !missing(x)
863 :     if(!missing(i)) {
864 : mmaechler 3114 i <- ## (be careful to assign in all cases)
865 :     if(is.unsorted(i, strictly=TRUE)) {
866 :     if(is(.Object, "xsparseVector") && has.x) {
867 :     si <- sort.int(i, index.return=TRUE)
868 :     x <- x[si$ix]
869 :     si$x
870 :     }
871 :     else
872 :     sort.int(i, method = "quick")
873 :     }
874 :     else i
875 :     }
876 :     if(has.x) x <- x
877 :     callNextMethod()
878 :     })
879 :     } else { ## R < 3.2.0
880 :     setMethod("initialize", "sparseVector", function(.Object, i, x, ...)
881 :     {
882 :     has.x <- !missing(x)
883 :     if(!missing(i)) {
884 : mmaechler 2648 .Object@i <- ## (be careful to assign in all cases)
885 :     if(is.unsorted(i, strictly=TRUE)) {
886 :     if(is(.Object, "xsparseVector") && has.x) {
887 :     si <- sort.int(i, index.return=TRUE)
888 :     x <- x[si$ix]
889 :     si$x
890 :     }
891 :     else
892 :     sort.int(i, method = "quick")
893 :     }
894 :     else i
895 :     }
896 :     if(has.x) .Object@x <- x
897 : mmaechler 3030 callNextMethod(.Object, ...)
898 : mmaechler 2648 })
899 : mmaechler 3114 }
900 : mmaechler 2648
901 : maechler 1845 .validXspVec <- function(object) {
902 : mmaechler 2633 ## n <- object@length
903 : mmaechler 2514 if(length(object@i) != length(object@x))
904 :     "'i' and 'x' differ in length"
905 :     else TRUE
906 : maechler 1845 }
907 :     setClass("dsparseVector",
908 : mmaechler 3165 slots = c(x = "numeric"), contains = "sparseVector",
909 : maechler 1845 validity = .validXspVec)
910 :     setClass("isparseVector",
911 : mmaechler 3165 slots = c(x = "integer"), contains = "sparseVector",
912 : maechler 1845 validity = .validXspVec)
913 :     setClass("lsparseVector",
914 : mmaechler 3165 slots = c(x = "logical"), contains = "sparseVector",
915 : maechler 1845 validity = .validXspVec)
916 :     setClass("zsparseVector",
917 : mmaechler 3165 slots = c(x = "complex"), contains = "sparseVector",
918 : maechler 1845 validity = .validXspVec)
919 :     ## nsparse has no new slot: 'i' just contains the locations!
920 :     setClass("nsparseVector", contains = "sparseVector")
921 : maechler 1708
922 : maechler 1922 setClassUnion("xsparseVector", ## those sparseVector's with an 'x' slot
923 :     c("dsparseVector",
924 :     "isparseVector",
925 :     "lsparseVector",
926 :     "zsparseVector"))
927 : maechler 1845
928 : mmaechler 3195 ## for 'value' in x[..] <- value hence for all "contents" of our Matrices:
929 :     setClassUnion("replValue", members = c("numeric", "logical", "complex", "raw"))
930 :     setClassUnion("replValueSp", members = c("replValue", "sparseVector", "Matrix"))
931 : maechler 1845
932 : mmaechler 3195
933 : bates 10 setClass("determinant",
934 : mmaechler 3165 slots = c(modulus = "numeric",
935 :     logarithm = "logical",
936 :     sign = "integer",
937 :     call = "call"))

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