Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

TensorTrainTools

Guides

  • TensorTrainTools Overview

Symbols

  • RandomTensorTrain
  • TensorTrainCompress
  • TensorTrainContract
  • TensorTrainDecomposition
  • TensorTrainHadamard
  • TensorTrainInnerProduct
  • TensorTrain
  • TensorTrainNorm
  • TensorTrainOrthogonalize
  • TensorTrainPlus
  • TensorTrainScale
RubenRanval`TensorTrainTools`
TensorTrainContract
​
TensorTrainContract
[tt]
contracts a tensor train
tt
back into the dense array it represents
​
Details and Options
▪
TensorTrainContract
reconstructs a full dense array from its Tensor Train (TT) representation (also known as the Matrix Product State representation). It is the inverse of
TensorTrainDecomposition
.
▪
The input is a nonempty list of rank-3 arrays
{
A
1
,
A
2
…,
A
n
}
, where
n
is the number of dimensions of the resulting array.
▪
The bond dimension refers to the size of the internal contracted indices connecting adjacent tensor cores. It effectively dictates the rank and compression level of the Tensor Train.
▪
Each core
A
k
has dimensions
{
χ
k-1
,
d
k
,
χ
k
}
where
d
k
is the size of the
th
k
dimension of the resulting array, and
χ
k
is the bond dimension between cores
k
and
k+1
.
▪
The first core has
χ
0
=1
and the last core has
χ
n
=1
.
▪
Contracting the cores returned by
TensorTrainDecomposition
reconstructs the original array, exactly up to floating-point error when the decomposition was exact, or up to the truncation error when a
"MaxBondDimension"
cap or nonzero
Tolerance
was applied.
Examples  
(3)
Basic Examples  
(1)
Decompose a tensor and contract it back to recover the original array:
In[1]:=
tensor=RandomReal[1,{2,3,4}];​​tensor//MatrixForm
Out[1]//MatrixForm=
0.82289
0.370384
0.775953
0.933255
0.393653
0.765388
0.293522
0.264758
0.0890085
0.766846
0.725353
0.692162
0.529998
0.907113
0.837152
0.237219
0.501381
0.0981147
0.324782
0.973763
0.222511
0.275392
0.868763
0.0271
In[2]:=
tensorTrain=TensorTrainDecomposition@tensor
Out[2]=
TensorTrain
Cores: 3
Max χ: 4
Tensor dims: {2,3,4}

In[3]:=
recon=TensorTrainContract@%
Out[3]=
{{{0.82289,0.370384,0.775953,0.933255},{0.393653,0.765388,0.293522,0.264758},{0.0890085,0.766846,0.725353,0.692162}},{{0.529998,0.907113,0.837152,0.237219},{0.501381,0.0981147,0.324782,0.973763},{0.222511,0.275392,0.868763,0.0271}}}
In[4]:=
%//MatrixForm
Out[4]//MatrixForm=
0.82289
0.370384
0.775953
0.933255
0.393653
0.765388
0.293522
0.264758
0.0890085
0.766846
0.725353
0.692162
0.529998
0.907113
0.837152
0.237219
0.501381
0.0981147
0.324782
0.973763
0.222511
0.275392
0.868763
0.0271
The original and the reconstructed tensors are exactly equal up to floating-point error:
In[5]:=
Max[Abs[tensor-recon]]
Out[5]=
9.99201×
-16
10
Applications  
(1)

Possible Issues  
(1)

SeeAlso
TensorTrainDecomposition
 
▪
TensorContract
RelatedGuides
▪
TensorTrainTools Overview
""

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com