Boost logo

Ublas :

Subject: [ublas] Preserving values when resizing c_matrices.
From: Joaquim Duran (jduran.gm_at_[hidden])
Date: 2013-09-30 19:46:47


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