|
Ublas : |
Subject: Re: [ublas] Is coordinate_matrixelementassignment/insertion broken in 1.42?
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2010-03-03 17:21:16
Thomas Klimpel schrieb:
> Jesse Perla wrote:
>
>> Thanks for the patch Thomas. So it sounds like this was a problem with
>> the ublas implementation rather than a bug in the std implementation
>> that intel and msvc uses?
>>
>
> Yes, the bug causing "wrong results" is definitively on the ublas side.
>
> But the code path the std implementation ends up using is not the most efficient one. Perhaps I should spy wether GIL has a better solution for the corresponding iterator.
>
The swap and iter_swap methods in storage.hpp had to be introduced
because MSVC (or the contained STL) forced the use of std::swap and
std::iter_swap. The index_pair array and index_triple_array were created
because no better solution for sorting parallel arrays was available at
this time. I still see these classes as dirty hack which only worked
well with GCC. If you have a better alternative to efficiently sort the
three array without having to implement the whole sort algorithm, then
please make some proposal.
Regarding the sort() vs. stable_sort() or inplace_merge(). Some problems
occured because stable_sort makes temporary copies. That's why we had to
carefully track whether the current index_pair (or index_triple) is a
reference to the original containers or is a standalone copy.
Lets try to explain index_triple::swap in storage.hpp:
1772 BOOST_UBLAS_INLINE
1773 void swap(self_type & rhs) {
1774 self_type tmp(rhs);
1775 rhs = *this;
1776 *this = tmp;
1777 }
line 1774: make a copy of rhs into tmp (with is_copy_ == true) in order
to save original values
line 1775: copy my values into rhs (because operator=() assigns v1_,
v2_, v3_ and sets the dirty flag)
line 1776: copy saved values of old rhs into myself and set my dirty flag
The "magic" is hidden in the destructor: The modified values are written
back to original arrays only when the dirty flag is set and is_copy_ is
false.
Its quite surprising that the missing & was not spotted for such a long
time. Maybe iter_swap() was always found and used.
mfg
Gunter
__________ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 4913 (20100303) __________
E-Mail wurde geprüft mit ESET NOD32 Antivirus.