[eigen] sparse matrix wrapper flavour

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


as you might know there is no ideal sparse matrix format, and
according the write/update access pattern you need, you have to use
different implementations or temporary wrappers.

For instance let's assume you have a compressed sparse matrix
(SparseMatrix): the most efficient to use but you can only fill it in
a fully coherent order. So in order to overcome this limitation you
might copy your current matrix to a temporary sparse matrix which
offer a higher degree of flexibility (but which is also slower) like a
one based on std::map (HashMatrix) :

SparseMatrix m;
// do whatever with m
// after that now you need random access:
   HashMatrix hm(m);
   for (...)
      hm(rand(),rand()) = rand();
   m = hm;
}  // hm gets automatically freed

that works, but it's not very convenient especially when you write
generic code and you don't know which kind of matrix you're dealing
with. (FYI, I identified 4 different access patterns, so I'll
implement 4 different sparse matrix types). So here comes the idea of
generic "SparseSetters" or "SparseWrappers" or whatever name. In
practice I imagine something like that:

    typename SparseWrapper<MyMatrixType, AccessPattern>::type w(m);
    // use w according to the access pattern you requested
// at the deletion of the wrapper, m is automatically updated.

So if MyMatrixType already provide the access pattern you requested,
then SparseWrapper<MyMatrixType, AccessPattern>::type will degenerate
to a reference to m. Moreover the wrapper should support all matrix
operations, typically you want to be able to write:

wrapper.col(i) += ...;

To avoid redundancy, I see two approaches to implement such wrappers:
1 - they inherit the corresponding sparse matrix class and simply
overload the constructor, destructor and store a reference to m;
2 - they store an object of the corresponding sparse matrix type and
define operator* and operator-> such that they behave like a pointer.

I think both approaches are more or less equivalent:
(1) allows to overwrite some matrix functions if needed,
(2) implies a pointer like style that emphasis the fact your dealing
with something different

so I think that's just a matter of flavour... any opinion ?


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/