20
$\begingroup$

I am looking for a C++ tensor library that supports dimension-agnostic code. Specifically, I need to perform operations along each dimension (up to 3), e.g. calculating a weighted sum. The dimensions is a template parameter (and thus a compile-time constant). Another constraint is that the library should be relatively lightweight, so rather Eigen/Boost-style than Trilinos/PETSc.

Any suggestions?

Note: I have had a look at Eigen and think it almost fits the profile exactly, if it weren't limited to 2D tensors. If I am mistaken by this, please correct me.

$\endgroup$

10 Answers 10

9
$\begingroup$

FTensor is a lightweight, header only, fully templated library that includes ergonomic summation notation. It has been tested extensively in 2, 3, and 4 dimensions, but should work fine for any number of dimensions.

$\endgroup$
6
$\begingroup$

For what its worth, Eigen does have a Tensor class as an unsupported module.

http://eigen.tuxfamily.org/dox-devel/unsupported/group_CXX11_Tensor__Module.html

I haven't used it myself so can't say more about it.

The Armadillo class library has a 3rd-order tensor class.

http://arma.sourceforge.net/

I haven't used the tensor capabilities of Armadillo either but have experimented with the standard matrix classes and they seem relatively easy to use and have good performance.

$\endgroup$
  • 2
    $\begingroup$ More specifically, Armadillo has the Cube class, which implements 3rd order tensors $\endgroup$ – mtall May 22 '14 at 16:59
6
$\begingroup$

I think this new taco lib is really good too.

The Tensor Algebra Compiler (taco) is a C++ library that computes tensor algebra expressions on sparse and dense tensors. It uses novel compiler techniques to get performance competitive with hand-optimized kernels in widely used libraries for both sparse tensor algebra and sparse linear algebra.

You can use taco as a C++ library that lets you load tensors, read tensors from files, and compute tensor expressions. You can also use taco as a code generator that generates C functions that compute tensor expressions.

Talk: https://www.youtube.com/watch?v=Kffbzf9etLE Paper: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf

$\endgroup$
  • 2
    $\begingroup$ Welcome to SciComp.SE! Could you expand your answer to describe the library (links can go dead) and especially how it meets the requirements of the OP? Otherwise it's more of a comment. $\endgroup$ – Christian Clason Feb 4 '18 at 9:19
  • $\begingroup$ Seems like a very interesting library! It looks like this generates an extra compilation step, though. I'm wondering whether it would be possible to implement this using templates instead? $\endgroup$ – HelloGoodbye Mar 27 at 9:42
5
$\begingroup$

XTensor is a modern approach and is getting more and more popular. https://github.com/QuantStack/xtensor

$\endgroup$
4
$\begingroup$

The deal.II library (http://www.dealii.org), while written for much larger purposes, also has a sub-library of tensor classes that likely does a lot of what you want to do. In particular, it uses templates for the dimension.

(Disclaimer: I am one of the principal authors of this library.)

$\endgroup$
2
$\begingroup$

The library Boost.Numeric.uBlas recently added a tensor extension which is shipped with Boost version 1.70. Please have a look at https://github.com/boostorg/ublas. It provides standard matrix and tensor operations with runtime-variable order (number of dimensions), dimensions for the first- and last-order storage formats (column- and row-major). You can also easily use the Einstein summation convention to express aribtrary tensor multiplications. Boost.Numeric.uBlas is header only and easy to integrate into existing projects.

$\endgroup$
1
$\begingroup$

I have not used it myself but libtensor seems to fulfill your requirements.

$\endgroup$
1
$\begingroup$

this is a multidimensional array C++ library https://github.com/ContinuumIO/libdynd

$\endgroup$
1
$\begingroup$

LTensor (https://code.google.com/p/ltensor/) is a VERY easy to use C++ template library for tensors up to rank 4 (based on indical notation), fast and lightweight too. You don't need to compile anything only need to include the main header file. I have used it on several projects and worked ok.

It has some built-in features for rank-2 tensors like linear solvers, svd, LU and Cholesky decompositions, etc. I didn't use any of them (I use other libraries for that).

$\endgroup$
0
$\begingroup$

There is also ITensor (requires C++17).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.