Preserving values when resizing c_matrices.

Joaquim Duran <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <CANdawSF0LLTUEB=4Se1Dcrx3jxCUtrEUxkC7GZM-R-kYNuK_qw@mail.gmail.com>
Dear all,

Maybe, I don't see the full image of c_matrix, but IMO, when resizing the
c_matrix, it is not needed copy values to preserve them.

The code of the resize member function of c_matrix:


> BOOST_UBLAS_INLINE

void resize (size_type size1, size_type size2, bool preserve = true) {

if (size1 > N || size2 > M)

bad_size ().raise ();

if (preserve) {

self_type temporary (size1, size2);

// Common elements to preserve

const size_type size1_min = (std::min) (size1, size1_);

const size_type size2_min = (std::min) (size2, size2_);

for (size_type i = 0; i != size1_min; ++i) { // indexing copy over major

for (size_type j = 0; j != size2_min; ++j) {

temporary.data_[i][j] = data_[i][j];

}

}

assign_temporary (temporary);

}

else {

size1_ = size1;

size2_ = size2;

}


> [...]


> private:
>
size_type size1_;
>
size_type size2_;
>
value_type data_ [N] [M];


>
Thanks and Best Regards,
Joaquim Duran
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.