Construct an sptensor from a matrix of subscripts for non-zero values, a vector of non-zero values, and the numeric dimensions of the tensor.

sptensor(subs, vals, dims)

# S4 method for matrix,ANY,numeric
sptensor(subs, vals, dims)

# S4 method for matrix,missing,numeric
sptensor(subs, vals, dims)

# S4 method for list,ANY,numeric
sptensor(subs, vals, dims)

Arguments

subs

matrix with length(dims) rows and length(vals) cols. Each row in the matrix corresponds to a different tensor dimension. Each column in the matrix represents a vector of subscripts pointing to a non-zero value in the tensor.

vals

values of non-zero entries. The subscripts for the first value are the first column of the subs matrix, the subscripts for the second value are in the second column of the subs matrix, etc...

dims

sizes of each dimension

See also

sptensor-class for class documentation.

Examples

# A 2x2x2 sparse tensor subs <- matrix(c(1,1,1, 1,1,2), c(3,2)) vals <- c(10,20) dims <- c(2,2,2) X <- sptensor(subs, vals, dims)