# SCM Repository

[matrix] Diff of /pkg/tests/indexing.R
 [matrix] / pkg / tests / indexing.R

# Diff of /pkg/tests/indexing.R

revision 2098, Sun Dec 9 00:35:14 2007 UTC revision 2110, Sat Jan 26 20:59:26 2008 UTC
# Line 373  Line 373
373  mc[4,] <- 0  mc[4,] <- 0
374  mc  mc
375
376    S <- as(Diagonal(5),"sparseMatrix")
377  H <- Hilbert(9)  H <- Hilbert(9)
378  Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...  Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...
379  (trH <- tril(Hc[1:5, 1:5]))  (trH <- tril(Hc[1:5, 1:5]))
380  stopifnot(is(trH, "triangularMatrix"), trH@uplo == "L")  stopifnot(is(trH, "triangularMatrix"), trH@uplo == "L",
381              is(S, "triangularMatrix"))
382
383    ## triangular assignment
384    ## the slick (but inefficient in case of sparse!) way to assign sub-diagonals:
385    ## equivalent to tmp <- `diag<-`(S[,-1], -2:1); S[,-1] <- tmp
386    ## which dispatches to (x="TsparseMatrix", i="missing",j="index", value="replValue")
387    diag(S[,-1]) <- -2:1 # used to give a wrong warning
388    ## FIXME? the above *could* return triangular -- but for that
389
390    trH[c(1:2,4), c(2:3,5)] <- 0 # gave an *error* upto Jan.2008
391    trH[ lower.tri(trH) ] <- 0   # ditto, because of callNextMethod()
392
393    m <- Matrix(0+1:28, nrow = 4)
394    m[-3,c(2,4:5,7)] <- m[ 3, 1:4] <- m[1:3, 6] <- 0
395    mT <- as(m, "dgTMatrix")
396    stopifnot(identical(mT[lower.tri(mT)],
397                        m [lower.tri(m) ]))
398    lM <- upper.tri(mT, diag=TRUE)
399    mT[lM] <- 0
400     m[lM] <- 0
401    assert.EQ.mat(mT, as(m,"matrix"))
402    mT[lM] <- -1:0
403     m[lM] <- -1:0
404    assert.EQ.mat(mT, as(m,"matrix"))
405    (mT <- drop0(mT))
406
407  i <- c(1:2, 4, 6:7); j <- c(2:4,6)  i <- c(1:2, 4, 6:7); j <- c(2:4,6)
408  H[i,j] <- 0  H[i,j] <- 0

Legend:
 Removed from v.2098 changed lines Added in v.2110