Boost logo

Ublas :

Subject: Re: [ublas] matrix row/column iterate
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2010-07-09 07:33:30


On Fri, Jul 9, 2010 at 12:26 PM, Kraus Philipp
<philipp.kraus_at_[hidden]> wrote:
> Hello,
>
> I must iterator over a ublas::matrix along rows or columns, but the matrix
> are very large and not sparse.
> Which way is the fastest to iterate along the rows and columns with extract
> the row / column vector?
>

IMHO it is essentially the same.

One may think it depends on the storage layout (column/row-major).
However, looking inside the code of matrix.hpp you can find that:
--- [code] ---
        const_reference operator () (size_type i, size_type j) const {
            return data () [layout_type::element (i, size1_, j, size2_)];
        }
--- [/code] ---

and in functional.hpp

--- [code] ---
        // In basic_row_major class
        static
        size_type element (size_type i, size_type size_i, size_type j,
size_type size_j) {
            // ... checks for preconditions

            return i * size_j + j;
        }

        // In basic_column_major class
        static
        size_type element (size_type i, size_type size_i, size_type j,
size_type size_j) {
            // ... checks for preconditions

            return i + j * size_i;
        }
--- [/code] ---

So the number of operations is essentially the same.

Cheers,

-- Marco