t3toolbox.tucker_tensor_train.t3_sub#

t3toolbox.tucker_tensor_train.t3_sub(x: t3toolbox.backend.common.typ.Union[TuckerTensorTrain, t3toolbox.backend.common.NDArray], y: t3toolbox.backend.common.typ.Union[TuckerTensorTrain, t3toolbox.backend.common.NDArray], squash: bool = True, use_jax: bool = False) t3toolbox.backend.common.typ.Union[TuckerTensorTrain, t3toolbox.backend.common.NDArray]#

Subtract Tucker tensor trains, x - y, yielding a Tucker tensor train with summed ranks.

Subtraction is defined with respect to the dense N0 x … x N(d-1) tensors that are represented by the Tucker tensor trains, even though these dense tensors are not formed during computations.

For corewise subtraction, see t3toolbox.corewise.corewise_sub()

T3 + T3 = T3 T3 + dense = dense dense + T3 = dense dense + dense = dense

Parameters:
  • x (TuckerTensorTrain) – First summand. structure=((N0,…,N(d-1)), (n1,…,nd), (r0, r1,…,rd))

  • y (TuckerTensorTrain) – Second summand. structure=((N0,…,N(d-1)), (m1,…,md), (q0, q1,…,qd))

  • squash (bool) – Squash the first and last TT cores so that r0=rd=1 in the result. Default: True.

  • xnp – Linear algebra backend. Default: np (numpy)

Returns:

Difference of Tucker tensor trains, x-y.
  • shape=(N0,…,N(d-1),

  • tucker_ranks=(n0+m0,…,n(d-1)+m(d-1),

  • TT ranks=(1, r1+q1,…,r(d-1)+q(d-1),1)) if squash=True,

or (r0+q0, r1+q1,…,r(d-1)+q(d-1),rd+qd)) if squash=False.

Return type:

TuckerTensorTrain

Raises:

ValueError

  • Error raised if either of the TuckerTensorTrains are internally inconsistent

  • Error raised if the TuckerTensorTrains have different shapes.

See also

TuckerTensorTrain, t3_shape, t3_add, t3_scale, t3_neg, corewise_neg()

Examples

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> x = t3.t3_corewise_randn((14,15,16), (4,5,6), (1,3,2,1))
>>> y = t3.t3_corewise_randn((14,15,16), (3,7,2), (1,5,6,1))
>>> x_minus_y = t3.t3_sub(x, y)
>>> print(x_minus_y.uniform_structure)
((14, 15, 16), (7, 12, 8), (2, 8, 8, 2), ())
>>> print(np.linalg.norm(x.to_dense() - y.to_dense() - x_minus_y.to_dense()))
3.5875705233607603e-13