Learn R Programming

tensorr: sparse tensors in R

tensorr provides methods to manipulate and store sparse tensors. Tensors are multi-dimensional generalizations of matrices (two dimensional) and vectors (one dimensional).

It has three main goals:

  • Provide an efficient format to store sparse tensors in R.
  • Provide standard tensor operations such as multiplication and unfolding.
  • Provide standard tensor decomposition techniques such as CP and Tucker.

Installation

The development version of tensorr is available on github.

devtools::install_github("zamorarr/tensorr")

Usage

See the introduction vignette for a comprehensive overview. To create a sparse tensor you have to provide the non-zero values, subscripts to the non-zero values, and the overall dimensions of the tensor.

library(tensorr)

subs <- list(c(1,1,1), c(1,1,2))
vals <- c(10, 20)
dims <- c(2,2,2)
x <- sptensor(subs, vals, dims)
x
#> <A 2x2x2 sparse tensor with 2 non-zero entries>
#> subs: <1,1,1> <1,1,2>
#> vals: 10 20

Tensor References

Many of the dense and sparse implementation ideas were adpated from:

  • B. W. Bader and T. G. Kolda. Algorithm 862: MATLAB tensor classes for fast algorithm prototyping, ACM Transactions on Mathematical Software 32(4):635-653, December 2006.
  • B. W. Bader and T. G. Kolda. Efficient MATLAB computations with sparse and factored tensors, SIAM Journal on Scientific Computing 30(1):205-231, December 2007.
  • scikit-tensor

For a review on tensors, see:

  • T. G. Kolda and B. W. Bader, Tensor Decompositions and Applications, SIAM Review 51(3):455-500, September 2009

Copy Link

Version

Install

install.packages('tensorr')

Monthly Downloads

28

Version

0.1.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Zamora

Last Published

January 21st, 2019

Functions in tensorr (0.1.1)

dtensor-Math

Math Methods for dense tensors
col_apply

Apply a function to columns of a matrix
fill_missing_indices

Fill NULL indices with a range from 1:dim
dtensor-class

An S4 class for a dense tensor
innerprod

Calculate the inner product of a pair of tensors
dtensor-extract

Extract values from a dense tensor
[<-,sptensor,character,missing,ANY-method

Replace values from a sparse tensor
[,sptensor,character,missing,ANY-method

Extract values from a sparse tensor
setops_subs

Apply set function to subscript arrays
show,unfolded_dtensor-method

Show a tensor
norm

Calculate the Frobenius norm of a tensor
sptensor-Math2

Math2 Methods for sparse tensors
matches

Match index in sparse tensor
sptensor-Ops

Ops Methods for dense tensors
dtensor-Math2

Math2 Methods for dense tensors
unfolded_dtensor-class

An S4 class for an unfolded dense tensor
unfold

Unfold (matricize) a tensor along a mode
list_to_matidx

convert list of indices to matrix of indices
mat_to_listidx

convert matrix of indices to list of indices
sptensor-Complex

Complex Methods for sparse tensors
dtensor-Ops

Ops Methods for dense tensors
sptensor-Math

Math Methods for sparse tensors
dtensor-Summary

Summary Methods for dense tensors
is_dtensor

Test if the object is a tensor
length,tensor-method

Length of a tensor
replace_sptensor

Replace values in a sparse tensor
row_apply

Apply a function to rows of a matrix
dimnames_to_indices

Convert dimnames to tensor indices
nzsubs

Subscripts of non-zero values in a tensor
dtensor-Complex

Complex Methods for dense tensors
sptensor

Construct a sparse tensor
nzvals

Non-zero values in a tensor
unfolded_sptensor

Construct an unfolded sparse tensor
dtensor-replace

Replace values from a dense tensor
tensorr

tensorr: sparse tensors in R
ttm

Tensor times matrix
ttv

Tensor times vector
tensor-class

Virtual S4 class for all tensor objects
squeeze

Remove tensor dimensions of size 1
unfolded_tensor-class

Virtual S4 class for unfolded tensor objects
unfolded_dtensor

Construct an unfolded dense tensor
unfolded_sptensor-class

An S4 class for an unfolded sparse tensor
dtensor

Construct a dense tensor
extract_sptensor

Extract indices from a sparse tensor
extract_vec

Extract indices from a sparse tensor
outerprod

Calculate the outer product of a pair of tensors
refold

Refold an unfolded tensor
sptensor-Summary

Summary Methods for sparse tensors
sptensor-class

An S4 class for a sparse tensor
vec_index

Vector Index
zsubs

Subscripts of zero values in a tensor
build_indices

convert args i,j,... to array of coords.
array_index

Array Index
as_sptensor

Convert objects to sparse tensors
dimnames,dtensor-method

Dimension names of a tensor
as_dtensor

Convert objects to dense tensors
dim,dtensor-method

Dimensions of a tensor
as.vector,dtensor-method

Vectorize values of a tensor
allsubs

Subscripts of all values in a tensor
all_are_numeric

Are all values numeric?