# pyCP_APR.numpy_backend package¶

## pyCP_APR.numpy_backend.CP_APR module¶

Python implementation of the CP-APR algorithm [1-4] with Numpy backend.

This backend can be used to factorize sparse tensorsin COO format and dense Numpy tensors.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

class pyCP_APR.numpy_backend.CP_APR.CP_APR_MU(epsilon=1e-10, kappa=0.01, kappa_tol=1e-10, max_inner_iters=10, n_iters=1000, print_inner_itn=0, verbose=10, simple_verbose=False, stoptime=1000000.0, tol=0.0001, random_state=42, return_type='numpy')[source]

Bases: `object`

Initilize the CP_APR_MU class.

Parameters
• epsilon (float, optional) -- Prevents zero division. Default is 1e-10.

• kappa (float, optional) -- Fix slackness level. Default is 1e-2.

• kappa_tol (float, optional) -- Tolerance on complementary slackness. The default is 1e-10.

• max_inner_iters (int, optional) -- Number of inner iterations per epoch. Default is 10.

• n_iters (int, optional) -- Number of iterations during optimization or epoch. Default is 1000.

• print_inner_itn (int, optional) -- Print every n inner iterations. Does not print if 0. Default is 0.

• verbose (int, optional) -- Print every n epoch, or `n_iters`. Does not print if 0. Default is 10.

• simple_verbose (bool, optional) -- Turns off details for verbose, such as fit, but instead shows a progress bar.

• stoptime (float, optional) -- Number of seconds before early stopping. Default is 1e6.

• tol (float, optional) -- KKT violations tolerance. Default is 1e-4.

• random_state (int, optional) -- Random seed for initial M. The default is 42.

train(tensor=[], coords=[], values=[], rank=2, Minit='random', Type='sptensor')[source]

Factorize the tensor X (i.e. compute the KRUSKAL tensor M).

Parameters
• tensor (array) --

Original dense tensor X.

Use with Type = 'tensor' and pass the tensor parameter as a dense Numpy array.

• coords (Numpy array (i.e. array that is a list of list)) --

Array of non-zero coordinates for sparse tensor X. COO format.

Each entry in this array is a coordinate of a non-zero value in the tensor.

Used when Type = 'sptensor' and tensor parameter is not passed.

len(Coords) is number of total entiries in X, and len(coords[0]) should give the number of dimensions.

• values (Numpy array (i.e. list of non-zero values corresponding to each list of non-zero coordinates)) --

Array of non-zero tensor entries. COO format.

Used when Type = 'sptensor' and tensor parameter is not passed.

Length of values must match the length of coords.

• rank (int) -- Tensor rank, i.e. number of components to extract. The default is 2.

• Minit (string or dictionary of latent factors) --

Initial value of latent factors.

If Minit = 'random', initial factors are chosen randomly from uniform distribution between 0 and 1.

Else, pass dictionary where the key is the mode number and value is array size d x r where d is the number of elements on the dimension and r is the rank.

The default is "random".

• Type (string) --

Type of tensor (i.e. sparse or dense).

Use 'sptensor' for sparse, and 'tensor' for dense tensors.

If 'sptensor' used, pass the list of non-zero coordinates using the Coords parameter and the corresponding list of non-zero elements with values parameter.

The default is 'sptensor'.

Returns

result -- KRUSKAL tensor M is returned. The latent factors can be found with the key 'Factors'.

The weight of each component can be found with the key 'Weights'.

Return type

dict

## pyCP_APR.numpy_backend.accum module¶

pyCP_APR.numpy_backend.accum.accum(accmap, a, func=None, size=None, fill_value=0, dtype=None)[source]

An accumulation function similar to Matlab's accumarray function.

Parameters
• accmap (ndarray) -- This is the "accumulation map". It maps input (i.e. indices into a) to their destination in the output array. The first a.ndim dimensions of accmap must be the same as a.shape. That is, accmap.shape[:a.ndim] must equal a.shape. For example, if a has shape (15,4), then accmap.shape[:2] must equal (15,4). In this case accmap[i,j] gives the index into the output array where element (i,j) of a is to be accumulated. If the output is, say, a 2D, then accmap must have shape (15,4,2). The value in the last dimension give indices into the output array. If the output is 1D, then the shape of accmap can be either (15,4) or (15,4,1)

• a (ndarray) -- The input data to be accumulated.

• func (callable or None) -- The accumulation function. The function will be passed a list of values from a to be accumulated. If None, numpy.sum is assumed.

• size (ndarray or None) -- The size of the output array. If None, the size will be determined from accmap.

• fill_value (scalar) -- The default value for elements of the output array.

• dtype (numpy data type, or None) -- The data type of the output array. If None, the data type of a is used.

Returns

out -- The accumulated results.

The shape of out is size if size is given. Otherwise the shape is determined by the (lexicographically) largest indices of the output found in accmap.

Return type

ndarray

Examples

```>>> from numpy import array, prod
>>> a = array([[1,2,3],[4,-1,6],[-1,8,9]])
>>> a
array([[ 1,  2,  3],
[ 4, -1,  6],
[-1,  8,  9]])
>>> # Sum the diagonals.
>>> accmap = array([[0,1,2],[2,0,1],[1,2,0]])
>>> s = accum(accmap, a)
array([9, 7, 15])
>>> # A 2D output, from sub-arrays with shapes and positions like this:
>>> # [ (2,2) (2,1)]
>>> # [ (1,2) (1,1)]
>>> accmap = array([
[[0,0],[0,0],[0,1]],
[[0,0],[0,0],[0,1]],
[[1,0],[1,0],[1,1]],
])
>>> # Accumulate using a product.
>>> accum(accmap, a, func=prod, dtype=float)
array([[ -8.,  18.],
[ -8.,   9.]])
>>> # Same accmap, but create an array of lists of values.
>>> accum(accmap, a, func=lambda x: x, dtype='O')
array([[[1, 2, 4, -1], [3, 6]],
[[-1, 8], [9]]], dtype=object)
```

## pyCP_APR.numpy_backend.arrange_ktensor module¶

Python implementation of arrange utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.arrange_ktensor.arrange(M, p=[])[source]

This function arranges the components of KRUSKAL tensor M.

Parameters
• M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

• p (list, optional) -- permutation. The default is [].

Returns

M -- KRUSKAL tensor class. ktensor.K_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.double_ktensor module¶

Python implementation of double utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.double_ktensor.double(M)[source]

This function converts the KTENSOR M to a double array.

Parameters

M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

Returns

A -- Double array of M.

Return type

array

## pyCP_APR.numpy_backend.fixsigns_ktensor module¶

Python implementation of fixsigns_oneargin utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.fixsigns_ktensor.fixsigns_oneargin(K)[source]

Fix sign ambiguity of a ktensor.

Parameters

M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

Returns

K -- KRUSKAL tensor where signs on latent factor columns have been flipped.

Return type

array

## pyCP_APR.numpy_backend.innerprod_ktensor module¶

Python implementation of innerprod utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.innerprod_ktensor.innerprod(M, X)[source]

This function takes the inner product of tensor X and KRUSKAL tensor M.

Parameters
• M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

• X (class) -- Original tensor. sptensor.SP_TENSOR.

Returns

res -- inner product of tensor X and KRUSKAL tensor M.

Return type

array

## pyCP_APR.numpy_backend.ipermute_tensor module¶

Python implementation of ipermute utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.ipermute_tensor.ipermute(X, order)[source]

This function inverse-permutes the dimensions of X.

Parameters
• X (dense tensor) -- Dense tensor object X.

• order (array) -- Vector order.

Returns

X -- Inverse permute of X by the order specified.

Return type

dense tensor

## pyCP_APR.numpy_backend.khatrirao_ktensor module¶

Takes the Khatrirao product of KRUSKAL tensor M.

References

[1] Mrdmnd. (n.d.). mrdmnd/scikit-tensor. GitHub. https://github.com/mrdmnd/scikit-tensor/blob/master/src/tensor_tools.py.

pyCP_APR.numpy_backend.khatrirao_ktensor.khatrirao(M_, dims, reverse=True)[source]

KHATRIRAO Khatri-Rao product of matrices. Citation: Mrdmnd. (n.d.). mrdmnd/scikit-tensor. GitHub. https://github.com/mrdmnd/scikit-tensor/blob/master/src/tensor_tools.py.

Parameters
• M (object) --

• ktensor.K_TENSOR. (KRUSKAL tensor class.) --

• dims (list) -- which modes to multiply.

• reverse (bool, optional) -- When true, product is in reverse order. The default is True.

Raises

ValueError -- Invalid tensors.

Returns

P -- Khatri-Rao product of matrices.

Return type

array

## pyCP_APR.numpy_backend.khatrirao_sptensor module¶

Python implementation of khatrirao utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.khatrirao_sptensor.khatrirao(X, M, n)[source]

Takes the Khatrirao product of sparse tensor X and KRUSKAL tesor M

Parameters
• M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

• X (sptensor tensor) -- Sparse tensor X.

• n (int) -- Mode to skip

Returns

K -- KRUSKAL tensor where signs on latent factor columns have been flipped.

Return type

array

## pyCP_APR.numpy_backend.ktensor module¶

ktensor.py contains the K_TENSOR class for KRUSKAL tensor M object representation.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

class pyCP_APR.numpy_backend.ktensor.K_TENSOR(Rank, Size, Minit='random', random_state=42, order=- 1)[source]

Bases: `object`

Initilize the K_TENSOR class.

Creates the object representation of M.

If initial M is not passed, by default, creates M from uniform distribution.

Parameters
• Rank (int) -- Tensor rank, i.e. number of components in M.

• Size (list) -- Shape of the tensor.

• Minit (string or dictionary of latent factors) --

Initial value of latent factors.

If Minit = 'random', initial factors are chosen randomly from uniform distribution between 0 and 1.

Else, pass dictionary where the key is the mode number and value is array size d x r where d is the number of elements on the dimension and r is the rank.

The default is "random".

• random_state (int, optional) -- Random seed for initial M. The default is 42.

• order (int, optional) -- Currently not used. The default is -1.

deep_copy_factors()[source]

Creates a deep copy of the latent factors in M.

Returns

factors -- Copy of the latent factors of M.

Return type

dict

## pyCP_APR.numpy_backend.norm_ktensor module¶

Python implementation of norm utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.norm_ktensor.norm(M)[source]

This function takes the Frobenius norm of a KRUSKAL tensor M.

Parameters

M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

Returns

nrm -- Frobenius norm of M.

Return type

float

## pyCP_APR.numpy_backend.normalize_ktensor module¶

Python implementation of normalize utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.normalize_ktensor.arrange(M, p=[])[source]

This function arranges the components of KRUSKAL tensor M.

Parameters

p (list, optional) -- permutation. The default is [].

pyCP_APR.numpy_backend.normalize_ktensor.normalize(M, normtype=1, N=- 1, mode=- 1)[source]

This function normalizes the columns of the factor matrices.

Parameters
• M (object) -- KRUSKAL tensor M class. ktensor.K_TENSOR.

• normtype (int, optional) -- Determines the type of normalization. The default is 1.

• N (int, optional) -- Factor matrix number. The default is -1.

• mode (int, optional) -- Dimension number. The default is -1.

Returns

M -- Normalized KRUSKAL tensor M class. ktensor.K_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.permute_ktensor module¶

Python implementation of permute utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.permute_ktensor.permute(M, order)[source]

This function permutes the dimensions of the KRUSKAL tensor M.

Parameters
• M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

• order (array) -- Vector order.

Returns

M -- KRUSKAL tensor class. ktensor.K_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.permute_tensor module¶

Python implementation of permute utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.permute_tensor.permute(X, order)[source]

This function permutes the dimensions of X.

Parameters
• X (object) -- Dense tensor class. tensor.TENSOR.

• order (array) -- Vector order.

Returns

X -- Dense tensor class. tensor.TENSOR.

Return type

object

## pyCP_APR.numpy_backend.redistribute_ktensor module¶

Python implementation of redistribute utility with Numpy backend from the MATLAB Tensor Toolbox [1]. .. rubric:: References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.redistribute_ktensor.redistribute(M, mode)[source]

This function distributes the weights to a specified dimension or mode.

Parameters
• M (object) -- KRUSKAL tensor class. ktensor.K_TENSOR.

• mode (int) -- Dimension number.

Returns

M -- KRUSKAL tensor class. ktensor.K_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.sptensor module¶

sptensor.py contains the SP_TENSOR class which is the object representation of the sparse tensor X in COO format.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

class pyCP_APR.numpy_backend.sptensor.SP_TENSOR(Coords, Values, Size=[])[source]

Bases: `object`

Initilize the SP_TENSOR class.

Sorts the tensor entries.

Parameters
• Coords (Numpy array (i.e. array that is a list of list)) --

Array of non-zero coordinates for sparse tensor X. COO format.

Each entry in this array is a coordinate of a non-zero value in the tensor.

Used when Type = 'sptensor' and tensor parameter is not passed.

len(Coords) is number of total entiries in X, and len(coords[0]) should give the number of dimensions.

• Values (Numpy array (i.e. list of non-zero values corresponding to each list of non-zero coordinates)) --

Array of non-zero tensor entries. COO format.

Used when Type = 'sptensor' and tensor parameter is not passed.

Length of values must match the length of coords.

• Size (list) -- Optional parameter to specify the size of the sparse tensor.

todense()[source]

## pyCP_APR.numpy_backend.tenmat_ktensor module¶

tenmat.py creates a matricized tensor.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

pyCP_APR.numpy_backend.tenmat_ktensor.tenmat(X, mode)[source]

Create a matricized tensor. :param X: Kruskal tensor, ktensor.K_TENSOR. :type X: class :param mode: Dimension number to unfold on. :type mode: int

Returns

X -- Matriced version of the sparse tensor in as dense matrix.

Return type

np.ndarray

## pyCP_APR.numpy_backend.tenmat_sptensor module¶

tenmat.py creates a matricized tensor.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

pyCP_APR.numpy_backend.tenmat_sptensor.tenmat(X, mode)[source]

Create a matricized tenso, i.e. the unfolding of the tensor. :param X: Sparse tensor. sptensor.SP_TENSOR. :type X: class :param mode: Dimension number to unfold on. :type mode: int

Returns

X -- Matriced version of the sparse tensor in as dense matrix.

Return type

np.ndarray

## pyCP_APR.numpy_backend.tenmat_tensor module¶

tenmat.py creates a matricized tensor.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

[2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794.

[3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489.

[4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

pyCP_APR.numpy_backend.tenmat_tensor.tenmat(X, mode)[source]

Create a matricized tensor. :param X: Dense. tensor. tensor.TENSOR. :type X: class :param mode: Dimension number to unfold on. :type mode: int

Returns

X -- Matriced version of the sparse tensor in as dense matrix.

Return type

np.ndarray

## pyCP_APR.numpy_backend.tensor module¶

tensor.py contains the TENSOR class for tensor X object representation.

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021. [2] Dense tensors: B. W. Bader and T. G. Kolda, Algorithm 862: MATLAB Tensor Classes for Fast Algorithm Prototyping, ACM Trans. Mathematical Software, 32(4):635-653, 2006, http://dx.doi.org/10.1145/1186785.1186794. [3] Sparse, Kruskal, and Tucker tensors: B. W. Bader and T. G. Kolda, Efficient MATLAB Computations with Sparse and Factored Tensors, SIAM J. Scientific Computing, 30(1):205-231, 2007, http://dx.doi.org/10.1137/060676489. [4] Chi, E.C. and Kolda, T.G., 2012. On tensors, sparsity, and nonnegative factorizations. SIAM Journal on Matrix Analysis and Applications, 33(4), pp.1272-1299.

@author: Maksim Ekin Eren

class pyCP_APR.numpy_backend.tensor.TENSOR(Tensor)[source]

Bases: `object`

Initilize the tensor X class.

Creates the object representation of X.

Parameters

Tensor (array) -- Dense Numpy tensor.

Returns

Return type

None.

## pyCP_APR.numpy_backend.tt_dimscheck module¶

Python implementation of tt_dimscheck utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.tt_dimscheck.tt_dimscheck(dims, N, M)[source]

Processes tensor dimensions.

Parameters
• dims (list or int) -- Dimension indices.

• N (int) -- tensor order.

• M (int) -- Multiplicants

Returns

• sdims (list) -- index for M muliplicands

• vidx (list) -- index for M muliplicands

## pyCP_APR.numpy_backend.ttm_sptensor module¶

Python implementation of ttm utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.ttm_sptensor.ttm(X, V, varargin={})[source]

Tensor times matrix operation.

Parameters
• X (object) -- Sparse tensor. sptensor.SP_TENSOR.

• V (np.ndarray) -- Numpy array.

• varargin (dict) -- Optional parameter to specify tflag and or mode settings.

Returns

Y -- Sparse tensor. sptensor.SP_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.ttm_tensor module¶

Python implementation of ttm utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.ttm_tensor.ttm(X, V, varargin={})[source]

Tensor times matrix operation.

Parameters
• X (object) -- Sparse tensor. sptensor.SP_TENSOR.

• V (np.ndarray) -- Numpy array.

• varargin (dict) -- Optional parameter to specify tflag and or mode settings.

Returns

Y -- Sparse tensor. sptensor.SP_TENSOR.

Return type

object

## pyCP_APR.numpy_backend.ttv_sptensor module¶

Python implementation of ttv utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.ttv_sptensor.ttv(X, vecs, dims=[])[source]

Tensor times vector for KRUSKAL tensor M.

Parameters
• X (object) -- Sparse tensor. sptensor.SP_TENSOR.

• vecs (array) -- coluumn vector.

• dims (list) -- list of dimension indices.

Returns

c -- product of KRUSKAL tensor X with a (column) vector vecs.

Return type

array

## pyCP_APR.numpy_backend.ttv_tensor module¶

Python implementation of ttv utility with Numpy backend from the MATLAB Tensor Toolbox [1].

References

[1] General software, latest release: Brett W. Bader, Tamara G. Kolda and others, Tensor Toolbox for MATLAB, Version 3.2.1, www.tensortoolbox.org, April 5, 2021.

pyCP_APR.numpy_backend.ttv_tensor.ttv(X, vecs)[source]

Tensor times vector for KRUSKAL tensor M.

Parameters
• X (object) -- Dense tensor class. tensor.TENSOR.

• vecs (array) -- coluumn vector.

Returns

c -- product of KRUSKAL tensor X with a (column) vector vecs.

Return type

array