Boost logo

Boost :

From: jhrwalter (walter_at_[hidden])
Date: 2002-03-18 02:13:03


--- In boost_at_y..., Kresimir Fresl <fresl_at_g...> wrote:
>
> jhrwalter wrote:
>
> [...]
> > (but I'm unsure, if valarray<> is a legal array_type of
> > numerics::vector currently ;-).
>
> It is ... with few minor modifications (at least with g++ 3.0.4).
>
> std::valarray<> does not have `iterator' & `const_iterator'
> types.
 
Yes, I remember, that I stopped seeing std::valarray as an option,
when I realized that and tried to imagine, how to work around it
under MSVC ;-)
 
> Therefore `iterator_type' & `const_iterator_type'
> in numerics::vector<> can't be defined. But they are not
> needed if `indexed_iterator<>' is used instead of nested
> iterator classes.
>
> So, I first added
>
> #ifndef NUMERICS_USE_INDEXED_ITERATOR
> typedef typename A::const_iterator const_iterator_type;
> typedef typename A::iterator iterator_type;
> #endif
>
> in numerics::vector<>.
 
I imagine, that we could introduce here some (array_type_?)traits
classes, which define the iterators for valarray via partial
specialization.
 
> But to compile some simple examples with macro
> NUMERICS_USE_INDEXED_ITERATOR defined,
> I had to add few typename's in `vector_pr.h':
>
> line 184:
> NUMERICS_TYPENAME vector_type::iterator::iterator_category>
iterator;
> instead of:
> vector_type::iterator::iterator_category> iterator;
>
> line 186:
> NUMERICS_TYPENAME
vector_type::const_iterator::iterator_category>
> const_iterator;
>
> line 664:
> NUMERICS_TYPENAME vector_type::iterator::iterator_category>
iterator;
>
> and line 666:
> NUMERICS_TYPENAME
vector_type::const_iterator::iterator_category>
> const_iterator;

Yep, one of my usual problems: I'll add these, too. Thanks.
 
> Now this works:
>
> #include <valarray>
> #include <boost/numerics/ublas/vector.h>
>
> typedef numerics::vector<double, std::valarray<double> > vector;
> vector v1(10), v2(10), v3(10);
> v3 = v1 + v2;

Ok, if all agree, that it would be useful to have std::valarray as
another array_type option, I'll try to add some traits logic to
support it at least under the more standard conforming compilers.
 
> BTW, did you measure what is more efficient: indexed_iterator<>
> or iterator classes nested in numerics::vector<>?

Nested pointer based iterators result usually in tighter inner loops
than something like indexed_iterator<> on the compilers I've seen so
far. They are only slower for small vector & matrix sizes, so that we
switch to assignment via subscription in such cases.
 
>
> Sincerely,
>
> fres
 
Regards
 
Joerg
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk