This is the mail archive of the mailing list for the libstdc++ project. See the libstdc++ home page for more information.

[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: valarrays broken

>>>>> «Thomas», Thomas Kunert <> wrote:


Thomas> Fine. I was afraid a major redesign is necessary to fix this without 
Thomas> performance loss. 

No major redesign is necessary. 


Thomas> Yes, -O3 seems to be save.
Thomas> That has enabled me to do some performance tests. 
Thomas> I have taken the operation a = b + 3.0 * c as test 
Thomas> with a, b and c being arrays.

Thomas> This is the speed in MFLOPS:

[ bench results ]

Thomas> Really good work!

Thanks. But I think thanks should really go to Brendan, Jason and

>> I don't know how long it took to Nathan to uglify the complete code.
>> I'm afraid I don't clearly understand your point. My initial version
>> was not uglified. But I strongly agree with the uglification policy as
>> it enables one to use snapshots of the library in user applications
>> (for testing purposes).

Thomas> What kind of user application could break if you write

Thomas>   template<typename Tp>
Thomas>   inline valarray<Tp>
Thomas>   valarray<Tp>::operator[] (const valarray<bool>& m) const
Thomas>   {
Thomas>       size_t s (0);
Thomas>       for (size_t i=0; i<m.size(); ++i)
Thomas>           if (m[i]) ++s;
Thomas>       return valarray<Tp> (mask_array<Tp> (_Array<Tp>(M_data), s,
Thomas>                                          _Array<bool> (m)));
Thomas>   }

Thomas> instead of 

Thomas>   template<typename _Tp>
Thomas>   inline valarray<_Tp>
Thomas>   valarray<_Tp>::operator[] (const valarray<bool>& __m) const
Thomas>   {
Thomas>       size_t __s (0);
Thomas>       for (size_t __i=0; __i<__m.size(); ++__i)
Thomas>           if (__m[__i]) ++__s;
Thomas>       return valarray<_Tp> (mask_array<_Tp> (_Array<_Tp>(_M_data), __s,
Thomas>                                          _Array<bool> (__m)));
Thomas>   }

Thomas> ?

Thomas> IMO, it is rather unlikely that someone has code like `#define i he he'.

Actually the valarray<> implementation is part of a *whole* library and
given name lookup rules, I assume one can easily find such offending
constructs (not necessary involving valarray<>). 

I'm just following a standard coding defined for libstdc++-v3.


-- Gaby
"One reason that life is complex is that it has a 
real part and imaginary part." -- Andrew Koenig