Skip to main content

Tensor learning in Python.

Project description

https://badge.fury.io/py/tensorly.svg https://anaconda.org/tensorly/tensorly/badges/version.svg https://travis-ci.org/tensorly/tensorly.svg?branch=master https://coveralls.io/repos/github/tensorly/tensorly/badge.svg?branch=master https://badges.gitter.im/tensorly/tensorly.svg

TensorLy

TensorLy is a Python library that aims at making tensor learning simple and accessible. It allows to easily perform tensor decomposition, tensor learning and tensor algebra. Its backend system allows to seamlessly perform computation with NumPy, MXNet, PyTorch, TensorFlow or CuPy, and run methods at scale on CPU or GPU.


Installing TensorLy

The only pre-requisite is to have Python 3 installed. The easiest way is via the Anaconda distribution.

With pip (recommended)

With conda

pip install -U tensorly
conda install -c tensorly tensorly

Development (from git)

# clone the repository
git clone https://github.com/tensorly/tensorly
cd tensorly
# Install in editable mode with `-e` or, equivalently, `--editable`
pip install -e .

Note: TensorLy depends on NumPy by default. If you want to use the MXNet or PyTorch backends, you will need to install these packages separately.

For detailed instruction, please see the documentation.


Running the tests

Testing and documentation are an essential part of this package and all functions come with uni-tests and documentation.

The tests are ran using the pytest package (though you can also use nose). First install pytest:

pip install pytest

Then to run the test, simply run, in the terminal:

pytest -v tensorly

Alternatively, you can specify for which backend you wish to run the tests:

TENSORLY_BACKEND='numpy' pytest -v tensorly

Quickstart

Create a small third order tensor of size 3 x 4 x 2 and perform simple operations on it:

import tensorly as tl
import numpy as np


tensor = tl.tensor(np.arange(24).reshape((3, 4, 2)))
unfolded = tl.unfold(tensor, mode=0)
tl.fold(unfolded, mode=0, shape=tensor.shape)

Applying tensor decomposition is easy:

from tensorly.decomposition import tucker
# Apply Tucker decomposition
core, factors = tucker(tensor, rank=[2, 2, 2])
# Reconstruct the full tensor from the decomposed form
tl.tucker_to_tensor(core, factors)

You can change the backend to perform computation with a different framework. Note that using MXNet, PyTorch, TensorFlow or CuPy requires to have installed them first. For instance, after setting the backend to PyTorch, all the computation is done by PyTorch, and tensors can be created on GPU:

tl.set_backend('pytorch') # Or 'mxnet', 'numpy', 'tensorflow' or 'cupy'
tensor = tl.tensor(np.arange(24).reshape((3, 4, 2)), device='cuda:0')
type(tensor) # torch.Tensor

For more information on getting started, checkout the user-guide and for a detailed reference of the functions and their documentation, refer to the API

If you see a bug, open an issue, or better yet, a pull-request!


Citing

If you use TensorLy in an academic paper, please cite:

@article{tensorly,
  author    = {Jean Kossaifi and Yannis Panagakis and Anima Anandkumar and Maja Pantic},
  title     = {TensorLy: Tensor Learning in Python},
  journal   = {CoRR},
  volume    = {abs/1610.09555},
  year      = {2018},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensorly-0.4.3.tar.gz (52.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensorly-0.4.3-py3-none-any.whl (81.4 kB view details)

Uploaded Python 3

File details

Details for the file tensorly-0.4.3.tar.gz.

File metadata

  • Download URL: tensorly-0.4.3.tar.gz
  • Upload date:
  • Size: 52.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tensorly-0.4.3.tar.gz
Algorithm Hash digest
SHA256 1e8b6cb85d5564054c17b4f881cf181dc666cbc92bfb564a9a9989b85d048772
MD5 d10f1ffa9e29fc6dbfe9e052077e4641
BLAKE2b-256 4e09498e3f07eb63a5a9f6f654030988155554ee6b243518a54b9b93152caf64

See more details on using hashes here.

File details

Details for the file tensorly-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: tensorly-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 81.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tensorly-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 456e0466f56e01e80e578214050be601018f66c22649b1a0665b55c5c8bd1fec
MD5 eb8c0ab1c99b4bd8bd49649b23f58f04
BLAKE2b-256 f41ad7805cdbafe391e0b3256a51ff2319d5ab2326fa1f7495ce53d574562a9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page