Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-04-03 15:31:21


Am Donnerstag, 3. April 2008 17:37 schrieb Nico Galoppo:
> Hi,
>
> Here's a little trivia for you advanced ublas users. Often, I write
> routines that are identical for all matrix types (either dense or
> sparse), except for the final 'solve'. e.g. for dense matrices, I'd
> want to use a direct solver, but for sparse matrices, I might prefer
> an iterative solver. Anyways, I am looking for a way to have an
> automatic dispatcher that looks at whether the input type is a sparse
> or dense matrix, and then dispatches to the correctly specialized
> solve function. I know of ways to do this with templated traits, but
> I'd need some way to 'recognize' a sparse matrix type vs. a dense
> one, typically a typedef inside the type declaration should work.
> This would require changes to the ublas native matrix types, *unless*
>
> 1) there already is some kind of typedef in the native types that
> allows us to recognize sparse vs. dense
> 2) i write my own matrix traits class that I then have to specialize
> for each of the ublas native types

I'd suggest to use the type

matrix::storage_category

it can either be one of the following (from traits.hpp)

    struct unknown_storage_tag {};
    struct sparse_proxy_tag: public unknown_storage_tag {};
    struct sparse_tag: public sparse_proxy_tag {};
    struct packed_proxy_tag: public sparse_proxy_tag {};
    struct packed_tag: public packed_proxy_tag {};
    struct dense_proxy_tag: public packed_proxy_tag {};
    struct dense_tag: public dense_proxy_tag {};

Good examples are the various overload in matrix_assign.hpp.

mfg
Gunter