Matlab API Documentation¶
- class Tensorino(varargin)¶
Class for multi-dimensional sparse tensors.
Handles sparse tensors with an unlimited number of elements, with the restriction that each individual index dimension must be smaller than 2^32-1.
- Tensorino(varargin)¶
Create a Tensorino.
Usage
t = Tensorino(ind, vals, sz)Uses the rows of
indandvalsto generate aTensorinotof sizesz = [m1 m2 ... mn].indis apxnarray specifying the subscripts of the nonzero values to be inserted intot. The k-th row ofindspecifies the subscripts for the k-th value invals. The argumentvalsmay be scalar, in which case it is expanded to be the same length asind, i.e., it is equivalent tovals * (p, 1).t = Tensorino(ind, vals)Same as the three-argument call, where now the size of the
Tensorinois taken to be the column-wise maximum ofind.t = TensorinoEmpty constructor.
t = Tensorino(a)Copies/converts
aif it is aTensorino, a dense array or a sparse matrix.t = Tensorino(a, sz)Copies/converts
aif it is aTensorino, a dense array or a sparse matrix, and sets the size ofatosz
Example
>> ind = [1 1 1; 1 1 3; 2 2 2; 4 4 4]; >> vals = [0.5; 1.5; 2.5; 3.5]; >> sz = [4 4 4]; >> t = Tensorino(ind, vals, sz) %<-- 4x4x4 Tensorino
Note
Currently the
Tensorinoconstructor does not allow duplicate subscripts inind, unlike the builtin Matlabsparse.
- abs(t)¶
Absolute value and complex magnitude.
Usage
b = abs(t)
- app(t, mat, ind)¶
Apply rescaling matrices on certain indices.
Usage
t_res = app(t, mat1, ind1, mat, ind2, ...)
- conj(t)¶
Complex conjugate.
- ctranspose(a)¶
Complex conjugate transpose.
Only defined for 2D
Tensorinos.Usage
b = ctranspose(a)b = a'
- distance(t1, t2)¶
Compute the Euclidean distance between two :class:`Tensorino`s.
- Arguments
t1, t2 (
Tensorino)- Returns
d (
double) – Euclidean distance, defined as the norm of the difference.
- dot(t1, t2)¶
Compute the scalar dot product of two :class:`Tensorino`s. This is defined as the overlap of the two tensors, which therefore must have sizes. This function is sesquilinear in its arguments.
- Arguments
t1, t2 (
Tensorino) – Tensors of equal structure.- Returns
d (
double) – Scalar dot product of the two tensors.
- eig(t)¶
Find eigenvalues and eigenvectors of a square
Tensorino.Usage
e = eig(t)[V, D] = eig(t)- Arguments
t (
Tensorino) – Input tensor of size[a b ... z a b ... z], interpreted as a (axax … xz) x (axax … xz) matrix.- Returns
Todo
Decide on/document index splitting convention (fixing domain and codomain for matrix decomposition).
See also
- eigs(t, n)¶
Find a few eigenvalues and eigenvectors of a
Tensorino.Todo
Decide on/document index splitting convention (fixing domain and codomain for matrix decomposition).
See also
- find(t)¶
Find subscripts of nonzero elements in a
Tensorino.- Arguments
a (
Tensorino) – input array- Returns
ind ((:, :)
int) – subscripts of nonzero entries.var ((:, 1)
double) – values of nonzero entries.
- full(t)¶
Convert a
Tensorinoto a dense array.- Arguments
a (
Tensorino) – input array.- Returns
d (
double) – dense output array.
Warning
Limited in size!
- groupind(t, g)¶
Group (block) specified sets of contiguous indices.
- Arguments
a (
Tensorino) – input array.g ((1, :)
int) – list of number of contiguous indices to be grouped in each index of the output tensor.
- Returns
b (
Tensorino) – output tensor with grouped indices.
Example
>> t = Tensorino.random([2, 3, 4, 5, 6], .1); >> b = groupind(t, [3, 2]); %<-- 24x30 Tensorino
- imag(t)¶
Complex imaginary part of sparse tensor.
- isequal(t1, t2)¶
Compare equality of two :class:`Tensorino`s.
- Arguments
t1, t2 (
Tensorino) – input tensors to be compared.- Returns
bool (
logical) – comparison result.
- isnumeric(~)¶
Determine whether input is numeric.
- isscalar(~)¶
Determine whether input is scalar.
- isrow(t)¶
Determine whether input is row vector.
- Arguments
t (
Tensorino) – input tensor.- Returns
bool (
logical)
- ldivide(a, b)¶
Elementwise left division for
Tensorino.Usage
ldivide(a, b)a .\ b- Arguments
a (
double) – Scalar to divide byb (
Tensorino) – Input tensor.
- Returns
c (
Tensorino) – Output tensor.
Note
Currently restricted to the case where
ais a scalar.
- minus(t1, t2)¶
Elementwise subtraction for :class:`Tensorino`s.
Note
Scalars are only subtracted from nonzero entries of the
Tensorino.Usage
minus(a, b)a - baandbmust have the same size, unless one is a scalar. A scalar can be subtracted from aTensorinoof any size.
- mrdivide(a, b)¶
Matrix right division for
Tensorino.Usage
mrdivide(a, b)a / b- Arguments
a (
Tensorino) – Input tensor.b (
double) – Scalar to divide by
- Returns
c (
Tensorino) – Output tensor.
Note
Currently restricted to the case where
bis a scalar.
- mtimes(a, b)¶
Matrix multiplication for :class:`Tensorino`s.
Usage
t = mtimes(a, b)t = a * bNote
Currently restricted to the case where either
aorbis a scalar.
- ndims(t)¶
Number of dimensions of a
Tensorino.Note that unlike the builtin Matlab behavior trailing singleton dimensions are not ignored.
Example
>> a = Tensorino.random([4 3 1], .1); >> ndims(a) %<-- returns 3
- numel(t)¶
Number of elements in a sparse array.
- plus(t1, t2)¶
Elementwise addition for :class:`Tensorino`s.
Note
Scalars are only added to nonzero entries of the
Tensorino.Usage
plus(a, b)a + baandbmust have the same size, unless one is a scalar. A scalar can be added to a sparse array of any size.
- purge(t, tol)¶
Set all nonzero values in
Tensorinowho’s absolute value is below a given threshold to zero.
- rdivide(a, b)¶
Elementwise right division for
Tensorino.Usage
rdivide(a, b)a ./ b- Arguments
a (
Tensorino) – Input tensor.b (
double) – Scalar to divide by
- Returns
c (
Tensorino) – Output array.
Note
Currently restricted to the case where
bis a scalar.
- reduce(t, dims)¶
Reduce the size of a
Tensorinoalong given dimensions based on the subscripts of its nonzero elements by dropping all unused index values for each given dimension individually.
- size(t, dim)¶
Tensorinodimensions.Usage
d = size(a)returns the size of the Tensorino.
d = size(a, dim)returns the sizes of the dimensions specified by
dim, which is either an integer or a vector of integer dimensions.
- sparse(t, g_ind)¶
Convert
Tensorinoto a sparse matrix.- Arguments
t (
Tensorino) – input tensor.g_ind ((1, 2)
int, optional) – list of number of contiguous indices to be grouped in each index of the output sparse matrix. Ifndims(t) ~= 2, theng_indmust be provided.
- Returns
m (
sparse) – output sparse matrix, possibly with grouped indices.Ur (???)
Uc (???)
Example
>> ???
- squeeze(t)¶
Remove singleton dimensions from a
Tensorino.Usage
b = squeeze(a)returns a sparse tensor
bwith the same elements asabut with all the singleton dimensions removed.
Example
>> squeeze(Tensorino.random([2, 1, 3], 0.5)) %<-- returns a 2 x 3 Tensorino >> squeeze(Tensorino([1, 1, 1], 1, [1, 1, 1])) %<-- returns a scalar
- subsref(t, s)¶
Subscripted reference for a
Tensorino.Todo
Fix case where all dimensions are indexed, fix indexing with ranges, write docstring.
Usage
a_sub = a(i1, i2, ..., iN)where each
inis an integer index, returns a scalar.a_sub = a(R1, R2, ..., RN)where each
Rnis either a colon, an array of integers representing a slice in this dimension or a logical array representing the logical indexing of this dimension. Returns a sparse array.
Example
>> t = Tensorino([4, 4, 4; 2, 2, 1; 2, 3, 2], [3; 5; 1], [4, 4, 4]); >> t(1, 2, 1) %<-- returns zero >> t(4, 4, 4) %<-- returns 3 >> t(2, :, :) %<-- returns a 1 x 4 x 4 Tensorino
- symp(t)¶
Symbolic something
Todo
Figure out what this does.
- tensorprod(A, B, dimA, dimB, options)¶
Tensor products between two :class:`Tensorino`s.
Usage
C = tensorprod(A, B, dimA, dimB)returns the tensor product of tensors
AandB. The argumentsdimAanddimBare vectors that specify which dimensions to contract inAandB. The size of the output tensor is the size of the uncontracted dimensions ofAfollowed by the size of the uncontracted dimensions ofB.C = tensorprod(A, B)returns the outer product of tensors
AandB. This isequivalent to the previous syntax with
dimA=dimB=[].C = tensorprod(_, 'NumDimensionsA', ndimsA)optionally specifies the number of dimensions in tensor
Ainaddition to combat the removal of trailing singleton dimensions.
- uminus(t)¶
Unary minus.
Usage
b = uminus(a)b = -a
- uplus(a)¶
Unary plus.
Usage
b = uplus(a)b = +a
- static delta(numinds, inddim)¶
Create delta- (ghz-) tensor with given number of indices and index dimension.
- Arguments
numinds (
int) – Number of indices of delta-array.inddim (
int) – Dimension of each index of delta-array.
- Returns
t (
Tensorino) – output delta-array.
- static new(fun, sz, density)¶
Create a
Tensorinowith data generated using a function handle.- Arguments
fun (
function_handle) – Function of signaturefun(dims). If this is left empty, the tensor data will be uninitialized.sz ((1, :)
int) – Size of the sparse tensor.density (
double) – Density of nonzero elements (0 <density< 1).
- Returns
t (
Tensorino) – Output tensor.