Learn R Programming

LinkedMatrix (version 1.4.0)

LinkedMatrix: Create an Empty, Prespecified LinkedMatrix Object

Description

This function creates an empty LinkedMatrix object of a certain size, a certain number of nodes, and certain types of nodes.

Usage

LinkedMatrix(nrow, ncol, nNodes, linkedBy, nodeInitializer, ...)

Arguments

nrow

The number of rows of the whole matrix.

ncol

The number of columns of the whole matrix.

nNodes

The number of nodes.

linkedBy

Whether the matrix is linked by columns or rows.

nodeInitializer

The name of a function or a function (nodeIndex, nrow, ncol, ...) where nodeIndex is the index of the node, nrow is a partition of the total number of rows, ncol is a partition of the total number of columns, and ... are additional parameters passed into the function. The function is expected to return a matrix-like object of dimensions nrow and ncol. Pre-defined node initializers include matrixNodeInitializer to initialize matrices and ffNodeInitializer to initialize ff objects.

...

Additional arguments passed into the nodeInitializer function.

Value

A ColumnLinkedMatrix object if linkedBy is columns or a RowLinkedMatrix object if linkedBy is rows.

See Also

ColumnLinkedMatrix and RowLinkedMatrix to create ColumnLinkedMatrix and RowLinkedMatrix objects from a list of matrix-like objects.

Examples

Run this code
# NOT RUN {
# Create an empty 15x10 RowLinkedMatrix with 3 matrix nodes
m1 <- LinkedMatrix(nrow = 15, ncol = 10, nNodes = 3, linkedBy = "rows",
                   nodeInitializer = "matrixNodeInitializer")
dim(m1)
nNodes(m1)
all(sapply(m1, inherits, "matrix"))

# Create an empty 15x10 RowLinkedMatrix with 3 ff nodes
m2 <- LinkedMatrix(nrow = 15, ncol = 10, nNodes = 3, linkedBy = "rows",
                   nodeInitializer = "ffNodeInitializer", vmode = "byte")
dim(m2)
nNodes(m2)
all(sapply(m2, inherits, "ff_matrix"))

# Create an empty 15x10 RowLinkedMatrix with 3 big.matrix nodes
m3 <- LinkedMatrix(nrow = 15, ncol = 10, nNodes = 3, linkedBy = "rows",
                   nodeInitializer = function(nodeIndex, nrow, ncol, ...) {
                       bigmemory::big.matrix(nrow = nrow, ncol = ncol)
                   })
dim(m3)
nNodes(m3)
all(sapply(m3, inherits, "big.matrix"))
# }

Run the code above in your browser using DataLab