mirror of
https://github.com/boostorg/ublas.git
synced 2026-02-23 04:02:10 +00:00
RESIZE FIXES
Drop incorrect element requirement to be value_type(0) constructable use matrix_resize_preserve where possible c_vector/matrix don't initialise on construction svn path=/trunk/boost/boost/numeric/ublas/; revision=26961
This commit is contained in:
@@ -115,8 +115,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
upper_ = upper;
|
||||
if (preserve) {
|
||||
self_type temporary (size1, size2, lower, upper);
|
||||
// FIXME use matrix_resize_preserve on conformant compilers
|
||||
// detail::matrix_resize_preserve<layout_type> (*this, temporary, size_, size_);
|
||||
detail::matrix_resize_preserve<layout_type> (*this, temporary, size_, size_);
|
||||
assign_temporary (temporary);
|
||||
}
|
||||
else
|
||||
@@ -129,7 +128,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
size2_ = size2;
|
||||
lower_ = lower;
|
||||
upper_ = upper;
|
||||
data ().resize ((std::max) (size1, size2) * (lower + 1 + upper), value_type (0));
|
||||
data ().resize ((std::max) (size1, size2) * (lower + 1 + upper), value_type ());
|
||||
}
|
||||
|
||||
// Element access
|
||||
|
||||
@@ -319,8 +319,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
size_ = size;
|
||||
if (preserve) {
|
||||
self_type temporary (size_, size_);
|
||||
// FIXME use matrix_resize_preserve on conformant compilers
|
||||
// detail::matrix_resize_preserve<layout_type> (*this, temporary, size_, size_);
|
||||
detail::matrix_resize_preserve<layout_type> (*this, temporary, size_, size_);
|
||||
assign_temporary (temporary);
|
||||
}
|
||||
else
|
||||
@@ -333,7 +332,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
BOOST_UBLAS_INLINE
|
||||
void resize_packed_preserve (size_type size) {
|
||||
size_ = BOOST_UBLAS_SAME (size, size);
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type (0));
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ());
|
||||
}
|
||||
|
||||
// Element access
|
||||
|
||||
@@ -3096,16 +3096,12 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
BOOST_UBLAS_INLINE
|
||||
c_matrix ():
|
||||
size1_ (N), size2_ (M) /* , data_ () */ {
|
||||
for (size_type i = 0; i < size1_; ++ i)
|
||||
std::fill (data_ [i], data_ [i] + size2_, value_type (0));
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
c_matrix (size_type size1, size_type size2):
|
||||
size1_ (size1), size2_ (size2) /* , data_ () */ {
|
||||
if (size1_ > N || size2_ > M)
|
||||
bad_size ().raise ();
|
||||
for (size_type i = 0; i < size1_; ++ i)
|
||||
std::fill (data_ [i], data_ [i] + size2_, value_type (0));
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
c_matrix (const c_matrix &m):
|
||||
@@ -3159,9 +3155,11 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
assign_temporary (temporary);
|
||||
}
|
||||
else {
|
||||
// only necessary for non POD to maintain default initialised invariant
|
||||
std::fill (data_ + size1_*size2_, data_ + size1+size2, value_type ());
|
||||
size1_ = size1;
|
||||
size2_ = size2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Element access
|
||||
|
||||
@@ -124,8 +124,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
size_ = size;
|
||||
if (preserve) {
|
||||
self_type temporary (size_, size_);
|
||||
// FIXME use matrix_resize_preserve on conformant compilers
|
||||
// detail::matrix_resize_preserve<triangular_type> (*this, temporary, size_, size_);
|
||||
detail::matrix_resize_preserve<triangular_type> (*this, temporary, size_, size_);
|
||||
assign_temporary (temporary);
|
||||
}
|
||||
else
|
||||
@@ -138,7 +137,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
BOOST_UBLAS_INLINE
|
||||
void resize_packed_preserve (size_type size) {
|
||||
size_ = BOOST_UBLAS_SAME (size, size);
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type (0));
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ());
|
||||
}
|
||||
|
||||
// Element access
|
||||
|
||||
@@ -102,8 +102,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
size2_ = size2;
|
||||
if (preserve) {
|
||||
self_type temporary (size1_, size2_);
|
||||
// FIXME use matrix_resize_preserve on conformant compilers
|
||||
// detail::matrix_resize_preserve<orienation_type> (*this, temporary, size1_, size2_);
|
||||
detail::matrix_resize_preserve<orienation_type> (*this, temporary, size1_, size2_);
|
||||
assign_temporary (temporary);
|
||||
}
|
||||
else
|
||||
@@ -113,7 +112,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
void resize_packed_preserve (size_type size1, size_type size2) {
|
||||
size1_ = size1;
|
||||
size2_ = size2;
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size1_, size2_), value_type (0));
|
||||
data ().resize (triangular_type::packed_size (layout_type (), size1_, size2_), value_type ());
|
||||
}
|
||||
|
||||
// Element access
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
BOOST_UBLAS_INLINE
|
||||
void resize (size_type size, bool preserve = true) {
|
||||
if (preserve)
|
||||
data ().resize (size, typename A::value_type());
|
||||
data ().resize (size, typename A::value_type ());
|
||||
else
|
||||
data ().resize (size);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
template<class A2> // Generic vector assignment without temporary
|
||||
BOOST_UBLAS_INLINE
|
||||
vector &operator = (const vector<T, A2> &v) {
|
||||
resize (v.size ());
|
||||
resize (v.size (), false);
|
||||
assign (v);
|
||||
return *this;
|
||||
}
|
||||
@@ -1182,7 +1182,6 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
size_ (size) /* , data_ () */ {
|
||||
if (size_ > N)
|
||||
bad_size ().raise ();
|
||||
std::fill (data_, data_ + size_, value_type (0));
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
c_vector (const c_vector &v):
|
||||
@@ -1219,7 +1218,8 @@ namespace boost { namespace numeric { namespace ublas {
|
||||
void resize (size_type size, bool preserve = true) {
|
||||
if (size > N)
|
||||
bad_size ().raise ();
|
||||
std::fill (data_ + (std::min) (size, size_), data_ + size, value_type (0));
|
||||
// only necessary for non POD to maintain default initialised invariant
|
||||
std::fill (data_ + size_, data_ + size, value_type ());
|
||||
size_ = size;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user