This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using Eigen for tensors and linear algebra operations

Tags: None
(comma "," separated)
mbrenes
Registered Member
Posts
2
Karma
0
Hi,

For my project I need a library that allows me to manipulate tensors; i.e, reshaping from say n number of indices to m number of indices and transposing indices, contracting indices (which I could write myself as matrix multiplications if reshaping and transpositions are available) and most importantly, doing singular value decompositions on tensor objects that have been reshaped as 2-tensors (matrices).

Most of my previous work has been done using PETSc/SLEPc, but those libraries are mostly devoted to sparse operations and no tensor operations are supported. Another heavyweight option could be dealii, but that could take a lot of work. I've been searching for a more lightweight, yet fast, library.
Seems to me that the -unsupported- *Tensor* class of Eigen is my best bet to achieve a balance between developing effort and performance, as I'm not requiring distributed memory parallelism for this particular project.

I'm just wondering if I could use Eigen for those operations. My main concern is that there's no SVD class/methods for Tensor objects, which might mean I'd have to construct Matrix objects using 2D tensor data to use SVD methods for Matrix classes (or perhaps casting could be done?). There seems to be a method for Tensor transpositions (shuffle) but the operation is not done in-place, this is not a deal-breaker for me though.

I would really appreciate any insight, suggestions or comments as to whether I can use Eigen for my purposes.
Thank you.

Best,

Marlon B.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The Tensor class support all the operations you need (including fast contractions). For SVD, you need to see it as an Eigen::Matrix, and you can do this without copy using a Map:

auto mat = MatrixXd::Map(tensor.data(), tensor.rows(), tensor.cols());

then you can use mat as a MatrixXd to compute its SVD:

BDCSVD<MatrixXd> svd(mat,ComputeThinU|ComputeThinV);
mbrenes
Registered Member
Posts
2
Karma
0
Hi ggael,

That sounds great!
Thanks for your help.

Best,
Marlon B.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]