Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-05-24 04:36:26


On Thursday 24 May 2007 04:48, Markus Weimer wrote:
> Hi,
>
> I have an additional question: Does uBLAS support runtime polymorphsim?

Sorry, no chance. The template mechanism only provides compile time
polymorphism, which results in (near) optimal performance. If you want
runtime polymorphism you have to create a new hierachy of classes that
encapsulate ublas classes. (But beware: the result will be a very long
compile time because all possible type will be instantiated by the compiler).

> Think of the following PseudoCode example:
>
> matrix getMatrix():
> if(config.useDense()) return denseMatrix;
> else return sparseMatrix
>
> And somewhere else I want to deal with the returned matrix irregarding its
> storage structure.
>
> Is that possible?

Yes but only if you config options are known at compile time. I usually use
constructions like

select (config.type)
 case ct_dense: call foo< matrix<...> > ();
 case ct_sparse: call foo< compressed_matrix<..> >();
...

The best way is to implement templated functions which only use the common
interface.

(BTW: Are you primarily interested in performance or flexibility?)

mfg
Gunter