SCM

SCM Repository

[matrix] Diff of /pkg/tests/indexing.Rout.save
ViewVC logotype

Diff of /pkg/tests/indexing.Rout.save

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

revision 1225, Mon Mar 13 14:06:17 2006 UTC revision 1226, Mon Mar 13 14:07:58 2006 UTC
# Line 1  Line 1 
1    
2  R : Copyright 2006, The R Foundation for Statistical Computing  R : Copyright 2006, The R Foundation for Statistical Computing
3  Version 2.2.1 Patched (2006-02-07 r37287)  Version 2.3.0 Under development (unstable) (2006-03-12 r37524)
4  ISBN 3-900051-07-0  ISBN 3-900051-07-0
5    
6  R is free software and comes with ABSOLUTELY NO WARRANTY.  R is free software and comes with ABSOLUTELY NO WARRANTY.
# Line 75  Line 75 
75  +                      LETTERS[1:ncol(mn)])  +                      LETTERS[1:ncol(mn)])
76  > mn["rd", "D"]  > mn["rd", "D"]
77  [1] 25  [1] 25
78  > stopifnot(identical(mn["rc", "D"], mn[3,4]),  > stopifnot(identical(mn["rc", "D"], mn[3,4]), mn[3,4] == 24,
79  +           identical(mn[, "A"], mn[,1]),  +           identical(mn[, "A"], mn[,1]), mn[,1] == 1:7,
80  +           identical(mn[c("re", "rb"), "B"], mn[c(5,2), 2])  +           identical(mn[c("re", "rb"), "B"], mn[c(5,2), 2])
81  +           )  +           )
82  >  >
# Line 91  Line 91 
91  [2,]   -1    9  100  200  [2,]   -1    9  100  200
92  [3,]   -1   10   17   24  [3,]   -1   10   17   24
93  >  >
94  > ## TODO: more --- particularly once we have "m > 10" working!  > g10 <- m [ m > 10 ]
95    > stopifnot(18 == length(g10))
96    > if(paste(R.version$major, R.version$minor, sep=".") >= "2.3")
97    +     ## Buglet in R(<= 2.2.1)'s possibleExtends()
98    +     stopifnot(10 == length(m[ m <= 10 ]))
99  >  >
100  >  >
101  > ### Sparse Matrices  > ### Sparse Matrices --------------------------------------
102  >  >
103  > m <- 1:800  > m <- 1:800
104  > set.seed(101) ; m[sample(800, 600)] <- 0  > set.seed(101) ; m[sample(800, 600)] <- 0
# Line 136  Line 140 
140  1 x 20 sparse Matrix of class "dgCMatrix"  1 x 20 sparse Matrix of class "dgCMatrix"
141    
142  [1,] 7 . . . . . . 287 . . 407 . 487 527 . . . . 727 .  [1,] 7 . . . . . . 287 . . 407 . 487 527 . . . . 727 .
143    > assert.EQ.mat(mC[1:2,], mm[1:2,])
144    > stopifnot(all.equal(mC[,3],   mm[,3]))
145    > assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])
146    >
147  > stopifnot(identical(mC[7,  drop = FALSE],  > stopifnot(identical(mC[7,  drop = FALSE],
148  +                     mC[7,, drop = FALSE]))  +                     mC[7,, drop = FALSE]))
149  > mT[,c(2,4)]  > mT[,c(2,4)]
# Line 181  Line 189 
189  [38,] .  .  [38,] .  .
190  [39,] .  159  [39,] .  159
191  [40,] 80 .  [40,] 80 .
192  > mT[1,]  > stopifnot(all.equal(mT[1,], mm[1,]))
193   [1]   0   0   0 121   0   0 241   0   0   0   0 441   0   0 561   0 641   0   0  > assert.EQ.mat(mT[4,, drop = FALSE], mm[4,, drop = FALSE])
 [20]   0  
 > mT[4, drop = FALSE]  
 1 x 20 sparse Matrix of class "dgTMatrix"  
   
 [1,] . . . . . . . . 324 . . . 484 524 564 . . . . 764  
194  > stopifnot(identical3(mm[,1], mC[,1], mT[,1]),  > stopifnot(identical3(mm[,1], mC[,1], mT[,1]),
195  +         identical3(mm[3,], mC[3,], mT[3,]),  +         identical3(mm[3,], mC[3,], mT[3,]),
196  +         identical3(mT[2,3], mC[2,3], 0),  +         identical3(mT[2,3], mC[2,3], 0),
# Line 200  Line 203 
203  > mc <- mC[1:5, 1:7]  > mc <- mC[1:5, 1:7]
204  > mt <- mT[1:5, 1:7]  > mt <- mT[1:5, 1:7]
205  > ## sub matrix  > ## sub matrix
206    > assert.EQ.mat(mC[1:2, 0:3], mm[1:2, 0:3]) # test 0-index
207  > stopifnot(identical(mc[-(3:5), 0:2], mC[1:2, 0:2]),  > stopifnot(identical(mc[-(3:5), 0:2], mC[1:2, 0:2]),
208  +           identical(mt[-(3:5), 0:2], mT[1:2, 0:2]))  +           identical(mt[-(3:5), 0:2], mT[1:2, 0:2]),
209    +           identical(mC[2:3, 4],      mm[2:3, 4]))
210    > assert.EQ.mat(mC[1:2,], mm[1:2,])
211  > ## sub vector  > ## sub vector
212  > stopifnot(identical4(mc[-(1:4), ], mC[5, 1:7],  > stopifnot(identical4(mc[-(1:4), ], mC[5, 1:7],
213  +                      mt[-(1:4), ], mT[5, 1:7]))  +                      mt[-(1:4), ], mT[5, 1:7]))
# Line 211  Line 217 
217  > ## mixing of negative and positive must give error  > ## mixing of negative and positive must give error
218  > assertError(mT[-1:1,])  > assertError(mT[-1:1,])
219  >  >
220    > ## Sub *Assignment* ---- now works (partially):
221    > mt0 <- mt
222    > mt[1, 4] <- -99
223    > mt[2:3, 1:6] <- 0
224    > mt
225    5 x 7 sparse Matrix of class "dgTMatrix"
226    
227    [1,] . .  . -99 . . 241
228    [2,] . .  . .   . . .
229    [3,] . .  . .   . . 243
230    [4,] . .  . .   . . .
231    [5,] . 45 . .   . . .
232    > m2 <- mt+mt
233    > m2[1,4] <- -200
234    > m2[c(1,3), c(5:6,2)] <- 1:6
235    > stopifnot(m2[1,4] == -200,
236    +           as.vector(m2[c(1,3), c(5:6,2)]) == 1:6)
237    > mt[,3] <- 30
238    > mt[2:3,] <- 250
239    > mt[1:5 %% 2 == 1, 3] <- 0
240    > mt[3:1, 1:7 > 5] <- 0
241    > mt
242    5 x 7 sparse Matrix of class "dgTMatrix"
243    
244    [1,] .   .   .   -99 .   . .
245    [2,] 250 250 250 250 250 . .
246    [3,] 250 250 .   250 250 . .
247    [4,] .   .    30 .   .   . .
248    [5,] .    45 .   .   .   . .
249    >
250    > tt <- as(mt,"matrix")
251    > ii <- c(0,2,5)
252    > jj <- c(2:3,5)
253    > tt[ii, jj] <- 1:6 # 0 is just "dropped"
254    > mt[ii, jj] <- 1:6
255    > assert.EQ.mat(mt, tt)
256  >  >
257  > # now works  > mt[1:5, 2:6]
258  > mT[1, 4] <- -99  5 x 5 sparse Matrix of class "dgTMatrix"
259  > mT[1:2, 1:7]  
260  2 x 7 sparse Matrix of class "dgTMatrix"  [1,] .   .  -99 .   .
261    [2,]   1  3 250   5 .
262    [3,] 250 .  250 250 .
263    [4,] .   30 .   .   .
264    [5,]   2  4 .     6 .
265    > as((mt0 - mt)[1:5,], "dsparseMatrix")# [1,5] and lines 2:3
266    5 x 7 sparse Matrix of class "dgCMatrix"
267    
268    [1,] .    .    .    220 .    .   241
269    [2,] -250   41  -3 -250   -5 202 .
270    [3,] -247 -250 .   -250 -250 .   243
271    [4,] .    .    -30 .    .    .   .
272    [5,] .      43  -4 .      -6 .   .
273    >
274    > mt[c(2,4), ] <- 0
275    > mt[2:3, 4:7] <- 33
276    > validObject(mt)
277    [1] TRUE
278    > mt
279    5 x 7 sparse Matrix of class "dgTMatrix"
280    
281    [1,] .   .   . -99 .  .  .
282    [2,] .   .   .  33 33 33 33
283    [3,] 250 250 .  33 33 33 33
284    [4,] .   .   . .   .  .  .
285    [5,] .     2 4 .    6 .  .
286    >
287    > mc[1,4] <- -99
288    > mc[-1, 3] <- -2:1 # 0 should not be entered; 'value' recycled
289    > mt[-1, 3] <- -2:1
290    > stopifnot(mc@x != 0, mt@x != 0)
291    > mc[1:5 %% 2 == 0, 3] <- 0
292    > validObject(mc)
293    [1] TRUE
294    > mc
295    5 x 7 sparse Matrix of class "dgCMatrix"
296    
297  [1,] . .  . -99 . .   241  [1,] . .  . -99 . .   241
298  [2,] . 42 . .   . 202 .  [2,] . 42 . .   . 202 .
299  > ## At least these now give a nicely understandable error:  [3,] 3 .  -1 .   . .   243
300  > try(mT[2:3, ] <- 0)  [4,] . .  .  .   . .   .
301  Error in "[<-"(`*tmp*`, 2:3, , value = 0) :  [5,] . 45  1 .   . .   .
302          not-yet-implemented 'Matrix[<-' method  > mc[ii, jj] <- 1:6
303    > mc[c(2,5), c(3,5)] <- 3.2
304    > validObject(mc)
305    [1] TRUE
306    > mc
307    5 x 7 sparse Matrix of class "dgCMatrix"
308    
309    [1,] . . .    -99 .   .   241
310    [2,] . 1  3.2 .   3.2 202 .
311    [3,] 3 . -1.0 .   .   .   243
312    [4,] . . .    .   .   .   .
313    [5,] . 2  3.2 .   3.2 .   .
314  >  >
315    > cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''
316    Time elapsed:  16.01 0.15 16.88 0 0
317  >  >

Legend:
Removed from v.1225  
changed lines
  Added in v.1226

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