
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> #
> # Inverse of the matrix:  
> #
> library(bdsmatrix)

Attaching package: 'bdsmatrix'

The following object is masked from 'package:base':

    backsolve

> aeq <- function(x,y) all.equal(as.vector(x), as.vector(y))
> 
> tmat <- bdsmatrix(c(3,2,2,4), 
+ 	      c(22,1,2,21,3,20,19,4,18,17,5,16,15,6,7, 8,14,9,10,13,11,12),
+ 	      matrix(c(1,0,1,1,0,0,1,1,0,1,0,10,0,
+                        0,1,1,0,1,1,0,1,1,0,1,0,10), ncol=2))
> dimnames(tmat) <- list(NULL, letters[1:13])
> 
> smat <- as.matrix(tmat)
> 
> inv1 <- solve(smat)
> inv2 <- as.matrix(solve(tmat)) # the result is a full, non-sparse matrix
> aeq(inv1, inv2)
[1] TRUE
> 
> inv3 <- solve(gchol(tmat))         #sparse version, not all parts will be there
> inherits(inv3, 'bdsmatrix')         #This should be true
[1] TRUE
> aeq(inv3@blocksize, tmat@blocksize) # Should be the same shape at tmat
[1] TRUE
> inv3 <- as.matrix(inv3)		    # What is returned should be correct
> aeq(inv1[1:3,1:3], inv3[1:3, 1:3])
[1] TRUE
> aeq(inv1[4:5,4:5], inv3[4:5, 4:5])
[1] TRUE
> aeq(inv1[6:7,6:7], inv3[6:7, 6:7])
[1] TRUE
> aeq(inv1[8:11,8:11], inv3[8:11, 8:11])
[1] TRUE
> aeq(inv1[,12:13], inv3[, 12:13])    # and rmat the same too
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  0.832   0.035   0.883 
