4

What is an appropriate data structure to represent a sparse tesnor in C++? The first option that comes to mind is a boost::unordered_map since it allows operations like fast setting and retrieval of an an element like below:

A(i,j,k,l) = 5

However, I would also like to be able to do contractions over a single index, which would involve summation over one of the indices

C(i,j,k,m) = A(i,j,k,l)*B(l,m)

How easy would it be to implement this operator with a boost::unordered_map? Is there a more appropriate data structure?

D R
  • 19,435
  • 28
  • 102
  • 146
  • 1
    Is in sparse in each dimension? you could implement wrapper around array of or map of a ublas::sparse_matrix. – Anycorn Aug 09 '10 at 22:29

1 Answers1

0

There are tensor libraries available, like:

http://www.codeproject.com/KB/recipes/tensor.aspx

and

http://cadadr.org/fm/package/ftensor.html

Any issue with those? You'd get more tensor operations that way over using a map.

Scott Stafford
  • 40,202
  • 22
  • 116
  • 163
  • The libraries that you mention all use dense tensors, and I need to use sparse tensors as the dimensions of my tensors are too large to be represented efficiently as a dense tensor. – D R Aug 09 '10 at 22:13