Raw File
Tip revision: 3af563a42794ba169e7902198d1edd919617a958 authored by Rafael Ballester on 16 March 2023, 15:48:54 UTC
Updated doc (ranks_cp actually must be an integer, not a list)
Tip revision: 3af563a
tntorch -- Tensor Network Learning with PyTorch

.. image:: tntorch.svg
   :width: 300 px
   :align: center

This is a `PyTorch <>`__-powered library for tensor modeling and learning that features transparent support for the `tensor train (TT) model <>`_, `CANDECOMP/PARAFAC (CP) <>`_, the `Tucker model <>`_, and more. Supported operations (CPU and GPU) include:

- Basic and fancy `indexing <tutorials/introduction.html>`_ of tensors, broadcasting, assignment, etc.
- Tensor `decomposition and reconstruction <tutorials/decompositions.html>`_
- Element-wise and tensor-tensor `arithmetics <tutorials/arithmetics.html>`_
- Building tensors from black-box functions using `cross-approximation <tutorials/cross.html>`_
- Statistics and `sensitivity analysis <tutorials/sobol.html>`_
- Optimization using autodifferentiation, useful for e.g. `regression <tutorials/completion.html>`_ or `classification <tutorials/classification.html>`_
- Misc. operations on tensors: stacking, unfolding, sampling, `derivating <tutorials/derivatives.html>`_, etc.

Get the Code

You can clone the project from `tntorch's GitHub page <>`_:

.. code-block:: bash

    git clone

or get it as a `zip file <>`_.

The main dependencies are `NumPy <>`_ and `PyTorch <>`_ (we recommend to install those with `Conda <>`_ or `Miniconda <>`_). To install *tntorch*, run:

.. code-block:: bash

   cd tntorch
   pip install .

First Steps

Some basic tensor manipulation:

.. code-block:: python

   import tntorch as tn
   t = tn.ones(64, 64)  # 64 x 64 tensor, filled with ones
   t = t[:, :, None] + 2*t[:, None, :]  # Singleton dimensions, broadcasting, and arithmetics
   print(tn.mean(t))  # Result: 3

Decomposing a tensor:
.. code-block:: python

   import tntorch as tn
   data = ...  # A NumPy or PyTorch tensor
   t1 = tn.Tensor(data, ranks_cp=5)  # A CP decomposition
   t2 = tn.Tensor(data, ranks_tucker=5)  # A Tucker decomposition
   t3 = tn.Tensor(data, ranks_tt=5)  # A tensor train decomposition

To get fully on board, check out the complete documentation:

.. toctree::

   Welcome <self>

.. toctree::
   :maxdepth: 1

back to top