This function is a generalisation, to sparse arrays, of the function
tensor in the tensor package.
tensorSparse has the same syntax and interpretation
as tensor.
For example, if A and B are matrices, then
tensor(A,B,2,1) is the matrix product A %*% B
while tensor(A,B,2,2) is A %*% t(B).
This function tensorSparse handles
sparse vectors (class "sparseVector" in the Matrix package),
sparse matrices (class "sparseMatrix" in the Matrix
package) and sparse three-dimensional arrays (class
"sparse3Darray" in the spatstat.sparse package)
in addition to the usual vectors, matrices and arrays.
The result is a sparse object if at least one of A and B
is sparse. Otherwise, if neither A nor B is sparse, then the
result is computed using tensor.
The main limitation is that the result cannot have more than 3
dimensions (because sparse arrays with more than 3 dimensions are not yet
supported).