getSM {lazy.mat}R Documentation

Extract a submatrix from a supermatrix

Description

Extract a submatrix from a supermatrix

Usage

getSM(M, i, j, index = 0, SMdim = NULL)

Arguments

M

Input supermatrix with or without SMdim attribute

i

The row number

j

The column number

index

= 1 to retrun the row and column index list.

SMdim

list of the form (nrows=, ncols=) where
nrows is a vector of rows of each submatrix,
ncols is a vector of columns of each submatrix.
This must be given when attributes(M)$SMdim=NULL.

Details

When M is a horizontally stacked supermatrix, use getSM[M,1,j]
When M is a vertically stacked supermatrix, use getSM[M,i,1]

Note on supermatrix
A supermatrix, which sometimes is called as a partitioned matrix or a block matrix, is a matrix whose elements are matrices.

For example, a super matrix shown below consits of 9 submatrices:
.....c1...c1...c2...c1...c2...c3...c4
r1 1111 1112 1212 1113 1213 1313 1413
r2 2111 2112 2212 2113 2213 2313 2413

r3 1121 1122 1222 1123 1223 1323 1423
r4 2121 2122 2222 2123 2223 2323 2423
r5 3121 3122 3222 3123 3223 3323 3423

r6 1131 1122 1222 1123 1233 1333 1433
r7 2131 2122 2222 2123 2233 2333 2433
r8 3131 3122 3222 3123 3233 3333 3433
r9 4131 4132 4232 4123 4233 4333 4433

Using lazy.tools and lazy.mat packages, we can create the above by
SM <- demomat(c(2,3,4),c(1,2,4),supermat=1) .
The generated SM matrix has 9 rows and 7 colums and the SMdim attributes, which, in this case, is a list:
list(nrows=c(2,3,4),mcols=c(1,2,4)) .

How to define supermatrix:
1) Use demomat function and modify the submatrices later using modSM function.
2) Use supermatrix function to initializes a super matrix with the SMdim attributes and assign the submatrices later. using modSM function.
3) Manually define a supermatrix as a usual matrix and add the SMdim attributes to it.

The sub matrices can be accessed by getSM function and can be modifed by modSM function.

To transpose a supermatrix, use transp function instead since it preserves the SMdim attributes.

To print a super matrix with its submatrices being separated, use Printb function.

About SMdim attribute:
SMdim attribute of a supermatrix is a list of the form (nrows=, ncols=) where
nrows is a vector of rows of each submatrix,
ncols is a vector of columns of each submatrix.

Value

a SMdim$nrows[i] x SMdim$ncols[j] matrix
Or when index=1, the index of the form list(rows=, cols=) where the i,j submatrix of S is S[rows,cols].

Examples

SM <- demomat(4,3,2, supermat=2)
Printb(SM)
getSM(SM,2,1)
SM <- demomat(c(3,2),c(3,2))
Printb(SM)
getSM(SM,2,2)
SM[ getSM(SM,2,2,1)[[1]], getSM(SM,2,2,1)[[2]] ]
Printb(SM)


[Package lazy.mat version 0.1.4 Index]