Matrix begin() and end() are broken

Issue #178 duplicate
Nils Deppe created an issue

Hi Klaus,

The matrix begin() and end() are not conforming to the STL interface of what they should do. Could you fix this and add different functions that allow only row/column-wise iteration? This makes using Matrix in generic code a huge pain.

Cheers,

Nils

Comments (2)

  1. Klaus Iglberger

    Hi Nils!

    We understand the motivation for this issue, but do not consider the current, well defined, tested and performant behavior as a bug. Therefore we will take no further action.

    There is many reasons for the current design:

    1. The STL does not contain any 2D data structure, but only 1D containers. Therefore there exists no example for the interface of a 2D STL container and the "STL compliance" argument is rather artificial.
    2. The primary reason why Blaze was created is performance. An "STL compliant" interface either restricts many optimizations (e.g. padding) or would be slow itself (see for instance the talk Taming the Performance Beast, which demonstrates that std::deque may already incur a 5x performance penalty).
    3. We don't generally agree that there is an expected behavior for a begin() and end() function for a 2D data structure. Therefore there is no according interface.

    There is several possible solutions/workarounds:

    • You can implement a free begin() and end() function yourself, with the semantics that match your expectations (also from a performance point of view). If you are interested in truly generic code than you are using the free versions of begin() and end(), anyway (see the talk Free Your Functions!).
    • You can "reinterpret" the underlying memory of a dense matrix as a 1D array by means of CustomVector. Please make sure that you disable padding via BLAZE_USE_PADDING (see <blaze/config/Optimizations.h>).
    • You can resort to a library which favors "STL compliance" over performance, as for instance Boost uBLAS.

    Best regards,

    Klaus!

  2. Log in to comment