Boost logo

Ublas :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-08-16 08:08:26


Michael Stevens wrote:

> Hi Neal,
>
> On Tuesday 16 August 2005 13:02, Neal Becker wrote:
>> I need a way to construct large vectors of complex numbers. I want to
>> bypass the wasteful default construction of the complex elements. What
>> would be the preferred way to do this using ublas? Has anyone already
>> done this?
>
> I have thought about this before. My feeling is that this is another issue
> with the "over encapsulation" of 'std::complex.' There is no reason why
> 'std::complex' should initialise to zero in it's default constructor. The
> class has no invariants to maintain, so it can have an uninitialised
> default constructor just as the C++ builtin types do.
>
> My "preferred" way would therefore be to use a 'complex' class which has
> an initialised default constructor. Sadly there is way such a class can be
> derived from 'std::complex', and no one want to rewrite all of complex. So
> it would be nice to force uBLAS to avoid any kind of construction.
>
> Sadly not even the STL allocator interface of the storage types allows
> this. The only way to do this would be to write a special version of
> 'unbounded_array' which avoids the standard conforming default
> construction of elements.
>
> Michael

Yes, all the points you make here are the same as I was thinking.

BTW, I'm really having a hard time with something that should be obvious.
In storage.hpp, we have:
    // Unbounded array - with allocator
    template<class T, class ALLOC>
    class unbounded_array:

I can't seem to find where the default ALLOC is specified. I must be
missing something obvious, because this code compiles:
int main () {
    using namespace boost::numeric::ublas;
    unbounded_array<double> a (3);
    for (unsigned i = 0; i < a.size (); ++ i) {
        a [i] = i;
        std::cout << a [i] << std::endl;
    }
}