From a975fb24ae2a8ae06c1ff9604fcc825447ffa165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Walter?= Date: Sun, 26 Oct 2003 21:10:10 +0000 Subject: [PATCH] Eliminating element proxies' operator reference(). Thanks to Michael Stevens. svn path=/trunk/boost/boost/numeric/ublas/; revision=20495 --- include/boost/numeric/ublas/banded.hpp | 32 +- include/boost/numeric/ublas/config.hpp | 3 + include/boost/numeric/ublas/functional.hpp | 51 ++- include/boost/numeric/ublas/hermitian.hpp | 133 ++++++- include/boost/numeric/ublas/matrix.hpp | 36 +- include/boost/numeric/ublas/matrix_assign.hpp | 24 +- include/boost/numeric/ublas/matrix_proxy.hpp | 170 ++++---- include/boost/numeric/ublas/matrix_sparse.hpp | 148 +++++-- include/boost/numeric/ublas/operation.hpp | 24 +- .../boost/numeric/ublas/operation_blocked.hpp | 8 +- .../boost/numeric/ublas/operation_sparse.hpp | 4 +- .../boost/numeric/ublas/storage_sparse.hpp | 5 +- include/boost/numeric/ublas/symmetric.hpp | 32 +- include/boost/numeric/ublas/traits.hpp | 368 ++++++++++-------- include/boost/numeric/ublas/triangular.hpp | 32 +- include/boost/numeric/ublas/vector.hpp | 24 +- include/boost/numeric/ublas/vector_assign.hpp | 12 +- .../boost/numeric/ublas/vector_of_vector.hpp | 12 +- include/boost/numeric/ublas/vector_proxy.hpp | 66 ++-- include/boost/numeric/ublas/vector_sparse.hpp | 136 +++++-- 20 files changed, 848 insertions(+), 472 deletions(-) diff --git a/include/boost/numeric/ublas/banded.hpp b/include/boost/numeric/ublas/banded.hpp index 9b7b5ff0..83c5b774 100644 --- a/include/boost/numeric/ublas/banded.hpp +++ b/include/boost/numeric/ublas/banded.hpp @@ -84,7 +84,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size1 (), ae ().size2 (), lower, upper, true); #endif - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -213,7 +213,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE banded_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -230,7 +230,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE banded_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -247,19 +247,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE banded_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE banded_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE banded_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1243,7 +1243,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE banded_adaptor &operator = (const banded_adaptor &m) { - matrix_assign (scalar_assign (), *this, m); + matrix_assign (scalar_assign (), *this, m); return *this; } BOOST_UBLAS_INLINE @@ -1254,49 +1254,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE banded_adaptor &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae)); + matrix_assign (scalar_assign (), *this, matrix (ae)); return *this; } template BOOST_UBLAS_INLINE banded_adaptor &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE banded_adaptor& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae)); + matrix_assign (scalar_assign (), *this, matrix (*this + ae)); return *this; } template BOOST_UBLAS_INLINE banded_adaptor &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE banded_adaptor& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae)); + matrix_assign (scalar_assign (), *this, matrix (*this - ae)); return *this; } template BOOST_UBLAS_INLINE banded_adaptor &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE banded_adaptor& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE banded_adaptor& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1313,7 +1313,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &m) { BOOST_UBLAS_CHECK (lower_ == m.lower_, bad_size ()); BOOST_UBLAS_CHECK (upper_ == m.upper_, bad_size ()); - matrix_swap (scalar_swap (), *this, m); + matrix_swap (scalar_swap (), *this, m); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS diff --git a/include/boost/numeric/ublas/config.hpp b/include/boost/numeric/ublas/config.hpp index 703f6dbb..4395a8cd 100644 --- a/include/boost/numeric/ublas/config.hpp +++ b/include/boost/numeric/ublas/config.hpp @@ -26,8 +26,11 @@ #include #include #include +#include +#include #include #include +#include // Compiler specific problems: default configuration #if defined (BOOST_STRICT_CONFIG) || ! (\ diff --git a/include/boost/numeric/ublas/functional.hpp b/include/boost/numeric/ublas/functional.hpp index 2894dc2b..97ec0336 100644 --- a/include/boost/numeric/ublas/functional.hpp +++ b/include/boost/numeric/ublas/functional.hpp @@ -171,7 +171,7 @@ namespace boost { namespace numeric { namespace ublas { template struct scalar_binary_assign_functor { - typedef typename type_traits::reference argument1_type; + typedef typename type_traits::type>::reference argument1_type; typedef typename type_traits::const_reference argument2_type; }; @@ -189,6 +189,14 @@ namespace boost { namespace numeric { namespace ublas { void operator () (argument1_type t1, argument2_type t2) const { t1 = t2; } + + template + static + BOOST_UBLAS_INLINE + scalar_assign make_debug_functor () { + return scalar_assign (); + } + }; template struct scalar_plus_assign: @@ -201,6 +209,13 @@ namespace boost { namespace numeric { namespace ublas { void operator () (argument1_type t1, argument2_type t2) const { t1 += t2; } + + template + static + BOOST_UBLAS_INLINE + scalar_plus_assign make_debug_functor () { + return scalar_plus_assign (); + } }; template struct scalar_minus_assign: @@ -213,6 +228,13 @@ namespace boost { namespace numeric { namespace ublas { void operator () (argument1_type t1, argument2_type t2) const { t1 -= t2; } + + template + static + BOOST_UBLAS_INLINE + scalar_minus_assign make_debug_functor () { + return scalar_minus_assign (); + } }; template struct scalar_multiplies_assign: @@ -225,6 +247,13 @@ namespace boost { namespace numeric { namespace ublas { void operator () (argument1_type t1, argument2_type t2) const { t1 *= t2; } + + template + static + BOOST_UBLAS_INLINE + scalar_multiplies_assign make_debug_functor () { + return scalar_multiplies_assign (); + } }; template struct scalar_divides_assign: @@ -237,13 +266,19 @@ namespace boost { namespace numeric { namespace ublas { void operator () (argument1_type t1, argument2_type t2) const { t1 /= t2; } + + template + static + BOOST_UBLAS_INLINE + scalar_divides_assign make_debug_functor () { + return scalar_divides_assign (); + } }; template struct scalar_binary_swap_functor { - typedef typename type_traits::reference argument1_type; - typedef typename type_traits::reference argument2_type; - typedef typename promote_traits::promote_type result_type; + typedef typename type_traits::type>::reference argument1_type; + typedef typename type_traits::type>::reference argument2_type; }; template @@ -251,12 +286,18 @@ namespace boost { namespace numeric { namespace ublas { public scalar_binary_swap_functor { typedef typename scalar_binary_swap_functor::argument1_type argument1_type; typedef typename scalar_binary_swap_functor::argument2_type argument2_type; - typedef typename scalar_binary_swap_functor::result_type result_type; BOOST_UBLAS_INLINE void operator () (argument1_type t1, argument2_type t2) const { std::swap (t1, t2); } + + template + static + BOOST_UBLAS_INLINE + scalar_swap make_debug_functor () { + return scalar_swap (); + } }; // Vector functors diff --git a/include/boost/numeric/ublas/hermitian.hpp b/include/boost/numeric/ublas/hermitian.hpp index 61c69290..ba09a5fe 100644 --- a/include/boost/numeric/ublas/hermitian.hpp +++ b/include/boost/numeric/ublas/hermitian.hpp @@ -43,6 +43,7 @@ namespace boost { namespace numeric { namespace ublas { } #ifdef BOOST_UBLAS_STRICT_HERMITIAN + template class hermitian_matrix_element: public container_reference { @@ -60,6 +61,9 @@ namespace boost { namespace numeric { namespace ublas { hermitian_matrix_element (matrix_type &m, size_type i, size_type j, value_type d): container_reference (m), i_ (i), j_ (j), d_ (d), dirty_ (false) {} BOOST_UBLAS_INLINE + hermitian_matrix_element (const hermitian_matrix_element &p): + container_reference (p), it_ (p.it_), i_ (p.i_), d_ (p.d_), dirty_ (p.dirty_) {} + BOOST_UBLAS_INLINE ~hermitian_matrix_element () { if (dirty_) ((*this) ()).at (i_, j_, d_); @@ -168,18 +172,31 @@ namespace boost { namespace numeric { namespace ublas { } // Conversion - // FIXME: GCC 3.1 warns, if enabled -#ifndef __GNUC__ BOOST_UBLAS_INLINE operator const_reference () const { return d_; } -#endif +#ifdef BOOST_UBLAS_DEPRECATED BOOST_UBLAS_INLINE operator reference () { dirty_ = true; return d_; } +#endif + + // Swapping + BOOST_UBLAS_INLINE + void swap (hermitian_matrix_element &p) { + if (this != &p) { + dirty_ = true; + p.dirty_ = true; + std::swap (d_, p.d_); + } + } + BOOST_UBLAS_INLINE + friend void swap (hermitian_matrix_element &p1, hermitian_matrix_element &p2) { + p1.swap (p2); + } private: size_type i_; @@ -187,6 +204,84 @@ namespace boost { namespace numeric { namespace ublas { value_type d_; bool dirty_; }; + + template + struct type_traits > { + typedef typename M::value_type element_type; + typedef type_traits > self_type; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::const_reference const_reference; + typedef hermitian_matrix_element reference; + typedef typename type_traits::real_type real_type; + typedef typename type_traits::precision_type precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = type_traits::plus_complexity); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = type_traits::multiplies_complexity); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return type_traits::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return type_traits::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return type_traits::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return type_traits::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return type_traits::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return type_traits::norm_1 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return type_traits::norm_2 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return type_traits::norm_inf (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + return type_traits::equals (t1, t2); + } + }; + + template + struct promote_traits, T2> { + typedef typename promote_traits::value_type, T2>::promote_type promote_type; + }; + template + struct promote_traits > { + typedef typename promote_traits::value_type>::promote_type promote_type; + }; + template + struct promote_traits, hermitian_matrix_element > { + typedef typename promote_traits::value_type, + typename hermitian_matrix_element::value_type>::promote_type promote_type; + }; + #endif // Array based hermitian matrix class @@ -255,7 +350,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size1 (), ae ().size2 (), true); #endif - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -369,7 +464,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE hermitian_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -386,7 +481,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE hermitian_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -403,7 +498,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE hermitian_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template @@ -413,7 +508,7 @@ namespace boost { namespace numeric { namespace ublas { // otherwise the resulting matrix isn't hermitian. // Thanks to Peter Schmitteckert for spotting this. BOOST_UBLAS_CHECK (type_traits::imag (at) == 0, non_real ()); - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template @@ -423,7 +518,7 @@ namespace boost { namespace numeric { namespace ublas { // otherwise the resulting matrix isn't hermitian. // Thanks to Peter Schmitteckert for spotting this. BOOST_UBLAS_CHECK (type_traits::imag (at) == 0, non_real ()); - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1356,7 +1451,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE hermitian_adaptor &operator = (const hermitian_adaptor &m) { - matrix_assign (scalar_assign (), *this, m, functor_type ()); + matrix_assign (scalar_assign (), *this, m, functor_type ()); return *this; } BOOST_UBLAS_INLINE @@ -1367,37 +1462,37 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE hermitian_adaptor &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE hermitian_adaptor &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_assign (), *this, ae, functor_type ()); return *this; } template BOOST_UBLAS_INLINE hermitian_adaptor& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (*this + ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE hermitian_adaptor &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_plus_assign (), *this, ae, functor_type ()); return *this; } template BOOST_UBLAS_INLINE hermitian_adaptor& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (*this - ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE hermitian_adaptor &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_minus_assign (), *this, ae, functor_type ()); return *this; } template @@ -1407,7 +1502,7 @@ namespace boost { namespace numeric { namespace ublas { // otherwise the resulting matrix isn't hermitian. // Thanks to Peter Schmitteckert for spotting this. BOOST_UBLAS_CHECK (type_traits::imag (at) == 0, non_real ()); - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template @@ -1417,7 +1512,7 @@ namespace boost { namespace numeric { namespace ublas { // otherwise the resulting matrix isn't hermitian. // Thanks to Peter Schmitteckert for spotting this. BOOST_UBLAS_CHECK (type_traits::imag (at) == 0, non_real ()); - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1432,7 +1527,7 @@ namespace boost { namespace numeric { namespace ublas { // Too unusual semantic. // BOOST_UBLAS_CHECK (this != &m, external_logic ()); if (this != &m) - matrix_swap (scalar_swap (), *this, m, functor_type ()); + matrix_swap (scalar_swap (), *this, m, functor_type ()); } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS BOOST_UBLAS_INLINE diff --git a/include/boost/numeric/ublas/matrix.hpp b/include/boost/numeric/ublas/matrix.hpp index cee14991..dd42a44c 100644 --- a/include/boost/numeric/ublas/matrix.hpp +++ b/include/boost/numeric/ublas/matrix.hpp @@ -88,7 +88,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size1 (), ae ().size2 (), true); #endif - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -164,7 +164,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -181,7 +181,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -198,19 +198,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1017,7 +1017,7 @@ namespace boost { namespace numeric { namespace ublas { vector_of_vector (const matrix_expression &ae): size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), data_ (1) { resize (ae ().size1 (), ae ().size2 (), false); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -1095,7 +1095,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector_of_vector &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -1112,7 +1112,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector_of_vector &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -1129,19 +1129,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector_of_vector &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_of_vector& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE vector_of_vector& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -3354,7 +3354,7 @@ namespace boost { namespace numeric { namespace ublas { // Raising exceptions abstracted as requested during review. // throw std::bad_alloc (); bad_size ().raise (); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -3439,7 +3439,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -3456,7 +3456,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -3473,19 +3473,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE c_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE c_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } diff --git a/include/boost/numeric/ublas/matrix_assign.hpp b/include/boost/numeric/ublas/matrix_assign.hpp index ee79b4d5..2819b364 100644 --- a/include/boost/numeric/ublas/matrix_assign.hpp +++ b/include/boost/numeric/ublas/matrix_assign.hpp @@ -516,8 +516,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, row_major_tag ()); - indexing_matrix_assign (functor1_type (), cm, e, row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, row_major_tag ()); + indexing_matrix_assign (functor1_type::template make_debug_functor::reference, value_type> (), cm, e, row_major_tag ()); #endif typename M::iterator1 it1 (m.begin1 ()); typename M::iterator1 it1_end (m.end1 ()); @@ -646,8 +646,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, column_major_tag ()); - indexing_matrix_assign (functor1_type (), cm, e, column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, column_major_tag ()); + indexing_matrix_assign (functor1_type::template make_debug_functor::reference, value_type> (), cm, e, column_major_tag ()); #endif typename M::iterator2 it2 (m.begin2 ()); typename M::iterator2 it2_end (m.end2 ()); @@ -774,8 +774,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, row_major_tag ()); - indexing_matrix_assign (functor_type (), cm, e, row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, row_major_tag ()); + indexing_matrix_assign (functor_type::template make_debug_functor::reference, value_type> (), cm, e, row_major_tag ()); #endif m.clear (); typename E::const_iterator1 it1e (e ().begin1 ()); @@ -812,8 +812,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, column_major_tag ()); - indexing_matrix_assign (functor_type (), cm, e, column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, column_major_tag ()); + indexing_matrix_assign (functor_type::template make_debug_functor::reference, value_type> (), cm, e, column_major_tag ()); #endif m.clear (); typename E::const_iterator2 it2e (e ().begin2 ()); @@ -852,8 +852,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, row_major_tag ()); - indexing_matrix_assign (functor1_type (), cm, e, row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, row_major_tag ()); + indexing_matrix_assign (functor1_type::template make_debug_functor::reference, value_type> (), cm, e, row_major_tag ()); #endif typename M::iterator1 it1 (m.begin1 ()); typename M::iterator1 it1_end (m.end1 ()); @@ -1059,8 +1059,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, m, column_major_tag ()); - indexing_matrix_assign (functor1_type (), cm, e, column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, m, column_major_tag ()); + indexing_matrix_assign (functor1_type::template make_debug_functor::reference, value_type> (), cm, e, column_major_tag ()); #endif typename M::iterator2 it2 (m.begin2 ()); typename M::iterator2 it2_end (m.end2 ()); diff --git a/include/boost/numeric/ublas/matrix_proxy.hpp b/include/boost/numeric/ublas/matrix_proxy.hpp index df0daac9..c9a1667f 100644 --- a/include/boost/numeric/ublas/matrix_proxy.hpp +++ b/include/boost/numeric/ublas/matrix_proxy.hpp @@ -157,62 +157,62 @@ namespace boost { namespace numeric { namespace ublas { matrix_row &operator = (const matrix_row &mr) { // FIXME: the rows could be differently sized. // std::copy (mr.begin (), mr.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (mr)); + vector_assign (scalar_assign (), *this, vector (mr)); return *this; } BOOST_UBLAS_INLINE matrix_row &assign_temporary (matrix_row &mr) { // FIXME: this is suboptimal. // return *this = mr; - vector_assign (scalar_assign (), *this, mr); + vector_assign (scalar_assign (), *this, mr); return *this; } template BOOST_UBLAS_INLINE matrix_row &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_row &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_row &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_row &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_row &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_row &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_row &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_row &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -231,7 +231,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == mr.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mr.begin ()); - vector_swap (scalar_swap (), *this, mr); + vector_swap (scalar_swap (), *this, mr); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -674,62 +674,62 @@ namespace boost { namespace numeric { namespace ublas { matrix_column &operator = (const matrix_column &mc) { // FIXME: the columns could be differently sized. // std::copy (mc.begin (), mc.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (mc)); + vector_assign (scalar_assign (), *this, vector (mc)); return *this; } BOOST_UBLAS_INLINE matrix_column &assign_temporary (matrix_column &mc) { // FIXME: this is suboptimal. // return *this = mc; - vector_assign (scalar_assign (), *this, mc); + vector_assign (scalar_assign (), *this, mc); return *this; } template BOOST_UBLAS_INLINE matrix_column &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_column &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_column &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_column &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_column &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_column &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_column &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_column &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -748,7 +748,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == mc.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mc.begin ()); - vector_swap (scalar_swap (), *this, mc); + vector_swap (scalar_swap (), *this, mc); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -1195,62 +1195,62 @@ namespace boost { namespace numeric { namespace ublas { matrix_vector_range &operator = (const matrix_vector_range &mvr) { // FIXME: the ranges could be differently sized. // std::copy (mvr.begin (), mvr.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (mvr)); + vector_assign (scalar_assign (), *this, vector (mvr)); return *this; } BOOST_UBLAS_INLINE matrix_vector_range &assign_temporary (matrix_vector_range &mvr) { // FIXME: this is suboptimal. // return *this = mvr; - vector_assign (scalar_assign (), *this, mvr); + vector_assign (scalar_assign (), *this, mvr); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_vector_range &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1269,7 +1269,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == mvr.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mvr.begin ()); - vector_swap (scalar_swap (), *this, mvr); + vector_swap (scalar_swap (), *this, mvr); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -1710,62 +1710,62 @@ namespace boost { namespace numeric { namespace ublas { matrix_vector_slice &operator = (const matrix_vector_slice &mvs) { // FIXME: the slices could be differently sized. // std::copy (mvs.begin (), mvs.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (mvs)); + vector_assign (scalar_assign (), *this, vector (mvs)); return *this; } BOOST_UBLAS_INLINE matrix_vector_slice &assign_temporary (matrix_vector_slice &mvs) { // FIXME: this is suboptimal. // return *this = mvs; - vector_assign (scalar_assign (), *this, mvs); + vector_assign (scalar_assign (), *this, mvs); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_vector_slice &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1784,7 +1784,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == mvs.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mvs.begin ()); - vector_swap (scalar_swap (), *this, mvs); + vector_swap (scalar_swap (), *this, mvs); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -2234,62 +2234,62 @@ namespace boost { namespace numeric { namespace ublas { matrix_vector_indirect &operator = (const matrix_vector_indirect &mvi) { // FIXME: the indirects could be differently sized. // std::copy (mvi.begin (), mvi.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (mvi)); + vector_assign (scalar_assign (), *this, vector (mvi)); return *this; } BOOST_UBLAS_INLINE matrix_vector_indirect &assign_temporary (matrix_vector_indirect &mvi) { // FIXME: this is suboptimal. // return *this = mvi; - vector_assign (scalar_assign (), *this, mvi); + vector_assign (scalar_assign (), *this, mvi); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_vector_indirect &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -2308,7 +2308,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == mvi.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), mvi.begin ()); - vector_swap (scalar_swap (), *this, mvi); + vector_swap (scalar_swap (), *this, mvi); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -2751,7 +2751,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE matrix_range &operator = (const matrix_range &mr) { - matrix_assign (scalar_assign (), *this, mr); + matrix_assign (scalar_assign (), *this, mr); return *this; } BOOST_UBLAS_INLINE @@ -2761,49 +2761,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix_range &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae)); + matrix_assign (scalar_assign (), *this, matrix (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_range &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_range& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae)); + matrix_assign (scalar_assign (), *this, matrix (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_range &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_range& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae)); + matrix_assign (scalar_assign (), *this, matrix (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_range &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_range& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_range& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -2821,7 +2821,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &mr) { BOOST_UBLAS_CHECK (size1 () == mr.size1 (), bad_size ()); BOOST_UBLAS_CHECK (size2 () == mr.size2 (), bad_size ()); - matrix_swap (scalar_swap (), *this, mr); + matrix_swap (scalar_swap (), *this, mr); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -3703,7 +3703,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE matrix_slice &operator = (const matrix_slice &ms) { - matrix_assign (scalar_assign (), *this, ms); + matrix_assign (scalar_assign (), *this, ms); return *this; } BOOST_UBLAS_INLINE @@ -3713,49 +3713,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix_slice &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae)); + matrix_assign (scalar_assign (), *this, matrix (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_slice &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_slice& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae)); + matrix_assign (scalar_assign (), *this, matrix (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_slice &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_slice& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae)); + matrix_assign (scalar_assign (), *this, matrix (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_slice &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_slice& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_slice& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -3773,7 +3773,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &ms) { BOOST_UBLAS_CHECK (size1 () == ms.size1 (), bad_size ()); BOOST_UBLAS_CHECK (size2 () == ms.size2 (), bad_size ()); - matrix_swap (scalar_swap (), *this, ms); + matrix_swap (scalar_swap (), *this, ms); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -4653,7 +4653,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE matrix_indirect &operator = (const matrix_indirect &mi) { - matrix_assign (scalar_assign (), *this, mi); + matrix_assign (scalar_assign (), *this, mi); return *this; } BOOST_UBLAS_INLINE @@ -4663,49 +4663,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE matrix_indirect &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae)); + matrix_assign (scalar_assign (), *this, matrix (ae)); return *this; } template BOOST_UBLAS_INLINE matrix_indirect &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_indirect& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae)); + matrix_assign (scalar_assign (), *this, matrix (*this + ae)); return *this; } template BOOST_UBLAS_INLINE matrix_indirect &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_indirect& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae)); + matrix_assign (scalar_assign (), *this, matrix (*this - ae)); return *this; } template BOOST_UBLAS_INLINE matrix_indirect &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE matrix_indirect& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE matrix_indirect& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -4723,7 +4723,7 @@ namespace boost { namespace numeric { namespace ublas { if (this != &mi) { BOOST_UBLAS_CHECK (size1 () == mi.size1 (), bad_size ()); BOOST_UBLAS_CHECK (size2 () == mi.size2 (), bad_size ()); - matrix_swap (scalar_swap (), *this, mi); + matrix_swap (scalar_swap (), *this, mi); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index 1406e834..8ee9d17d 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -44,7 +44,6 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE sparse_matrix_element (const value_type &d): container_reference (), it_ (), i_ (), j_ (), d_ (d), dirty_ (false) { - // This constructor is only needed to enable compiling adaptors of sparse matrices. external_logic ().raise (); } BOOST_UBLAS_INLINE @@ -60,6 +59,9 @@ namespace boost { namespace numeric { namespace ublas { d_ = *it; } BOOST_UBLAS_INLINE + sparse_matrix_element (const sparse_matrix_element &p): + container_reference (p), it_ (p.it_), i_ (p.i_), d_ (p.d_), dirty_ (p.dirty_) {} + BOOST_UBLAS_INLINE ~sparse_matrix_element () { if (dirty_) { if (! it_) @@ -172,18 +174,31 @@ namespace boost { namespace numeric { namespace ublas { } // Conversion - // FIXME: GCC 3.1 warns, if enabled -#ifndef __GNUC__ BOOST_UBLAS_INLINE operator const_reference () const { return d_; } -#endif +#ifdef BOOST_UBLAS_DEPRECATED BOOST_UBLAS_INLINE operator reference () { dirty_ = true; return d_; } +#endif + + // Swapping + BOOST_UBLAS_INLINE + void swap (sparse_matrix_element &p) { + if (this != &p) { + dirty_ = true; + p.dirty_ = true; + std::swap (d_, p.d_); + } + } + BOOST_UBLAS_INLINE + friend void swap (sparse_matrix_element &p1, sparse_matrix_element &p2) { + p1.swap (p2); + } private: pointer it_; @@ -193,6 +208,83 @@ namespace boost { namespace numeric { namespace ublas { bool dirty_; }; + template + struct type_traits > { + typedef typename M::value_type element_type; + typedef type_traits > self_type; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::const_reference const_reference; + typedef sparse_matrix_element reference; + typedef typename type_traits::real_type real_type; + typedef typename type_traits::precision_type precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = type_traits::plus_complexity); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = type_traits::multiplies_complexity); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return type_traits::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return type_traits::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return type_traits::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return type_traits::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return type_traits::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return type_traits::norm_1 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return type_traits::norm_2 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return type_traits::norm_inf (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + return type_traits::equals (t1, t2); + } + }; + + template + struct promote_traits, T2> { + typedef typename promote_traits::value_type, T2>::promote_type promote_type; + }; + template + struct promote_traits > { + typedef typename promote_traits::value_type>::promote_type promote_type; + }; + template + struct promote_traits, sparse_matrix_element > { + typedef typename promote_traits::value_type, + typename sparse_matrix_element::value_type>::promote_type promote_type; + }; + #endif // Array based sparse matrix class @@ -250,7 +342,7 @@ namespace boost { namespace numeric { namespace ublas { sparse_matrix (const matrix_expression &ae, size_type non_zeros = 0): size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), non_zeros_ (non_zeros), data_ () { reserve (non_zeros_); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -371,7 +463,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -388,7 +480,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -405,19 +497,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE sparse_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE sparse_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1362,7 +1454,7 @@ namespace boost { namespace numeric { namespace ublas { sparse_vector_of_sparse_vector (const matrix_expression &ae, size_type non_zeros = 0): size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), non_zeros_ (non_zeros), data_ () { data_ [functor_type::size1 (size1_, size2_)] = vector_data_value_type (); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -1475,7 +1567,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector_of_sparse_vector &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -1492,7 +1584,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector_of_sparse_vector &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -1509,19 +1601,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector_of_sparse_vector &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE sparse_vector_of_sparse_vector& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE sparse_vector_of_sparse_vector& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -2534,7 +2626,7 @@ namespace boost { namespace numeric { namespace ublas { index2_data_ (non_zeros), value_data_ (non_zeros) { index1_data_ [filled1_ - 1] = k_based (filled2_); reserve (non_zeros_, false); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -2719,7 +2811,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -2736,7 +2828,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -2753,19 +2845,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE compressed_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE compressed_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -3837,7 +3929,7 @@ namespace boost { namespace numeric { namespace ublas { sorted_ (true), index1_data_ (non_zeros), index2_data_ (non_zeros), value_data_ (non_zeros) { reserve (non_zeros_, false); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -4036,7 +4128,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -4053,7 +4145,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -4070,19 +4162,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE coordinate_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE coordinate_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } diff --git a/include/boost/numeric/ublas/operation.hpp b/include/boost/numeric/ublas/operation.hpp index a5142016..d7ac2c4f 100644 --- a/include/boost/numeric/ublas/operation.hpp +++ b/include/boost/numeric/ublas/operation.hpp @@ -74,7 +74,7 @@ namespace boost { namespace numeric { namespace ublas { v.assign (zero_vector (e1.size1 ())); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v); - indexing_vector_assign (scalar_plus_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_plus_assign::reference, value_type> (), cv, prod (e1, e2)); #endif axpy_prod (e1, e2, v, orientation_category ()); #ifdef BOOST_UBLAS_TYPE_CHECK @@ -197,7 +197,7 @@ namespace boost { namespace numeric { namespace ublas { v.assign (zero_vector (e1 ().size1 ())); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v); - indexing_vector_assign (scalar_plus_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_plus_assign::reference, value_type> (), cv, prod (e1, e2)); #endif axpy_prod (e1, e2, v, iterator_category ()); #ifdef BOOST_UBLAS_TYPE_CHECK @@ -269,7 +269,7 @@ namespace boost { namespace numeric { namespace ublas { v.assign (zero_vector (e2 ().size2 ())); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v); - indexing_vector_assign (scalar_plus_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_plus_assign::reference, value_type> (), cv, prod (e1, e2)); #endif axpy_prod (e1, e2, v, orientation_category ()); #ifdef BOOST_UBLAS_TYPE_CHECK @@ -392,7 +392,7 @@ namespace boost { namespace numeric { namespace ublas { v.assign (zero_vector (e2 ().size2 ())); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v); - indexing_vector_assign (scalar_plus_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_plus_assign::reference, value_type> (), cv, prod (e1, e2)); #endif axpy_prod (e1, e2, v, iterator_category ()); #ifdef BOOST_UBLAS_TYPE_CHECK @@ -428,7 +428,7 @@ namespace boost { namespace numeric { namespace ublas { #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), row_major_tag ()); #endif size_type size1 (e1 ().size1 ()); size_type size2 (e1 ().size2 ()); @@ -455,7 +455,7 @@ namespace boost { namespace numeric { namespace ublas { #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), row_major_tag ()); #endif typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); @@ -501,8 +501,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), column_major_tag ()); #endif size_type size1 (e2 ().size1 ()); size_type size2 (e2 ().size2 ()); @@ -529,7 +529,7 @@ namespace boost { namespace numeric { namespace ublas { #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), column_major_tag ()); #endif typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); @@ -631,7 +631,7 @@ namespace boost { namespace numeric { namespace ublas { #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), row_major_tag ()); #endif size_type size (BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ())); for (size_type k = 0; k < size; ++ k) { @@ -659,8 +659,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename M::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK - matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + matrix cm (m.size1 (), m.size2 ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), column_major_tag ()); #endif size_type size (BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size1 ())); for (size_type k = 0; k < size; ++ k) { diff --git a/include/boost/numeric/ublas/operation_blocked.hpp b/include/boost/numeric/ublas/operation_blocked.hpp index a1596aec..f32726d2 100644 --- a/include/boost/numeric/ublas/operation_blocked.hpp +++ b/include/boost/numeric/ublas/operation_blocked.hpp @@ -34,7 +34,7 @@ namespace boost { namespace numeric { namespace ublas { V v (e1 ().size1 ()); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v.size ()); - indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_assign::reference, value_type> (), cv, prod (e1, e2)); #endif size_type i_size = e1 ().size1 (); size_type j_size = BOOST_UBLAS_SAME (e1 ().size2 (), e2 ().size ()); @@ -87,7 +87,7 @@ namespace boost { namespace numeric { namespace ublas { V v (e2 ().size2 ()); #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v.size ()); - indexing_vector_assign (scalar_assign (), cv, prod (e1, e2)); + indexing_vector_assign (scalar_assign::reference, value_type> (), cv, prod (e1, e2)); #endif size_type i_size = BOOST_UBLAS_SAME (e1 ().size (), e2 ().size1 ()); size_type j_size = e2 ().size2 (); @@ -140,7 +140,7 @@ namespace boost { namespace numeric { namespace ublas { M m (e1 ().size1 (), e2 ().size2 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), row_major_tag ()); disable_type_check = true; #endif size_type i_size = e1 ().size1 (); @@ -199,7 +199,7 @@ namespace boost { namespace numeric { namespace ublas { M m (e1 ().size1 (), e2 ().size2 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), column_major_tag ()); disable_type_check = true; #endif size_type i_size = e1 ().size1 (); diff --git a/include/boost/numeric/ublas/operation_sparse.hpp b/include/boost/numeric/ublas/operation_sparse.hpp index 808de7db..06b23157 100644 --- a/include/boost/numeric/ublas/operation_sparse.hpp +++ b/include/boost/numeric/ublas/operation_sparse.hpp @@ -38,7 +38,7 @@ namespace boost { namespace numeric { namespace ublas { vector temporary (e2 ().size2 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), row_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), row_major_tag ()); #endif typename expression1_type::const_iterator1 it1 (e1 ().begin1 ()); typename expression1_type::const_iterator1 it1_end (e1 ().end1 ()); @@ -101,7 +101,7 @@ namespace boost { namespace numeric { namespace ublas { vector temporary (e1 ().size1 ()); #ifdef BOOST_UBLAS_TYPE_CHECK matrix cm (m.size1 (), m.size2 ()); - indexing_matrix_assign (scalar_assign (), cm, prod (e1, e2), column_major_tag ()); + indexing_matrix_assign (scalar_assign::reference, value_type> (), cm, prod (e1, e2), column_major_tag ()); #endif typename expression2_type::const_iterator2 it2 (e2 ().begin2 ()); typename expression2_type::const_iterator2 it2_end (e2 ().end2 ()); diff --git a/include/boost/numeric/ublas/storage_sparse.hpp b/include/boost/numeric/ublas/storage_sparse.hpp index 17c6c0d8..28325ae3 100644 --- a/include/boost/numeric/ublas/storage_sparse.hpp +++ b/include/boost/numeric/ublas/storage_sparse.hpp @@ -153,20 +153,19 @@ namespace boost { namespace numeric { namespace ublas { } // Element access - // FIXME: GCC 3.1 warn's, if enabled -#ifndef __GNUC__ BOOST_UBLAS_INLINE typename sparse_storage_element_traits::data_const_reference operator [] (typename sparse_storage_element_traits::index_type i) const { return d_ [i]; } -#endif +#ifdef BOOST_UBLAS_DEPRECATED BOOST_UBLAS_INLINE typename sparse_storage_element_traits::data_reference operator [] (typename sparse_storage_element_traits::index_type i) { dirty_ = true; return d_ [i]; } +#endif // Assignment template diff --git a/include/boost/numeric/ublas/symmetric.hpp b/include/boost/numeric/ublas/symmetric.hpp index 417acd1f..015f2ce1 100644 --- a/include/boost/numeric/ublas/symmetric.hpp +++ b/include/boost/numeric/ublas/symmetric.hpp @@ -103,7 +103,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size1 (), ae ().size2 (), true); #endif - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -191,7 +191,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE symmetric_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -208,7 +208,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE symmetric_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -225,19 +225,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE symmetric_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE symmetric_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE symmetric_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1100,7 +1100,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE symmetric_adaptor &operator = (const symmetric_adaptor &m) { - matrix_assign (scalar_assign (), *this, m, functor_type ()); + matrix_assign (scalar_assign (), *this, m, functor_type ()); return *this; } BOOST_UBLAS_INLINE @@ -1111,49 +1111,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE symmetric_adaptor &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_assign (), *this, ae, functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (*this + ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_plus_assign (), *this, ae, functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae), functor_type ()); + matrix_assign (scalar_assign (), *this, matrix (*this - ae), functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae, functor_type ()); + matrix_assign (scalar_minus_assign (), *this, ae, functor_type ()); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE symmetric_adaptor& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1168,7 +1168,7 @@ namespace boost { namespace numeric { namespace ublas { // Too unusual semantic // BOOST_UBLAS_CHECK (this != &m, external_logic ()); if (this != &m) - matrix_swap (scalar_swap (), *this, m, functor_type ()); + matrix_swap (scalar_swap (), *this, m, functor_type ()); } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS BOOST_UBLAS_INLINE diff --git a/include/boost/numeric/ublas/traits.hpp b/include/boost/numeric/ublas/traits.hpp index 40daa1b6..b85f42d9 100644 --- a/include/boost/numeric/ublas/traits.hpp +++ b/include/boost/numeric/ublas/traits.hpp @@ -36,7 +36,6 @@ namespace boost { namespace numeric { namespace ublas { typedef T real_type; typedef T precision_type; -#ifdef BOOST_UBLAS_DEPRECATED BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = 0); BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = 0); @@ -100,7 +99,6 @@ namespace boost { namespace numeric { namespace ublas { self_type::norm_inf (t2)), BOOST_UBLAS_TYPE_CHECK_MIN); } -#endif }; template<> @@ -558,161 +556,6 @@ namespace boost { namespace numeric { namespace ublas { }; #endif - template - struct promote_traits { - // Default promotion will badly fail, if the types are different. - // Thanks to Kresimir Fresl for spotting this. - BOOST_STATIC_ASSERT ((boost::is_same::value)); - typedef T1 promote_type; - }; - - template<> - struct promote_traits { - typedef double promote_type; - }; - template<> - struct promote_traits { - typedef double promote_type; - }; -#ifdef BOOST_UBLAS_USE_LONG_DOUBLE - template<> - struct promote_traits { - typedef long double promote_type; - }; - template<> - struct promote_traits { - typedef long double promote_type; - }; - template<> - struct promote_traits { - typedef long double promote_type; - }; - template<> - struct promote_traits { - typedef long double promote_type; - }; -#endif - - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, float> { - typedef std::complex promote_type; - }; - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, float> { - typedef std::complex promote_type; - }; -#ifdef BOOST_UBLAS_USE_LONG_DOUBLE - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, float> { - typedef std::complex promote_type; - }; -#endif - - template<> - struct promote_traits > { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits, double> { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, double> { - typedef std::complex promote_type; - }; -#ifdef BOOST_UBLAS_USE_LONG_DOUBLE - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, double> { - typedef std::complex promote_type; - }; -#endif - -#ifdef BOOST_UBLAS_USE_LONG_DOUBLE - template<> - struct promote_traits > { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits, long double> { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits > { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits, long double> { - // Here we'd better go the conservative way. - // typedef std::complex promote_type; - typedef std::complex promote_type; - }; - template<> - struct promote_traits > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, long double> { - typedef std::complex promote_type; - }; -#endif - - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; -#ifdef BOOST_UBLAS_USE_LONG_DOUBLE - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; - template<> - struct promote_traits, std::complex > { - typedef std::complex promote_type; - }; -#endif - #ifdef BOOST_UBLAS_USE_INTERVAL template<> struct type_traits > { @@ -1134,7 +977,217 @@ namespace boost { namespace numeric { namespace ublas { }; #endif #endif +#endif +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template + struct promote_traits { + typedef boost::mpl::vector builtins; + typedef typename boost::mpl::find::type iter1; + typedef typename boost::mpl::find::type iter2; + BOOST_STATIC_CONSTANT (int, index1 = iter1::pos::value); + BOOST_STATIC_CONSTANT (int, index2 = iter2::pos::value); + typedef typename boost::mpl::if_c= index2, + iter1, + iter2>::type::type builtin_promote_type; + typedef typename boost::mpl::if_c::value, + T1, + builtin_promote_type>::type promote_type; + }; + + template + struct promote_traits, T2> { + typedef std::complex::promote_type> promote_type; + }; + template + struct promote_traits > { + typedef std::complex::promote_type> promote_type; + }; + template + struct promote_traits, std::complex > { + typedef std::complex::promote_type> promote_type; + }; + +#ifdef BOOST_UBLAS_USE_INTERVAL + template + struct promote_traits, T2> { + typedef boost::numeric::interval::promote_type> promote_type; + }; + template + struct promote_traits > { + typedef boost::numeric::interval::promote_type> promote_type; + }; + template + struct promote_traits, boost::numeric::interval > { + typedef boost::numeric::interval::promote_type> promote_type; + }; +#endif +#else + template + struct promote_traits { + // Default promotion will badly fail, if the types are different. + // Thanks to Kresimir Fresl for spotting this. + BOOST_STATIC_ASSERT ((boost::is_same::value)); + typedef T1 promote_type; + }; + + template<> + struct promote_traits { + typedef double promote_type; + }; + template<> + struct promote_traits { + typedef double promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits { + typedef long double promote_type; + }; + template<> + struct promote_traits { + typedef long double promote_type; + }; + template<> + struct promote_traits { + typedef long double promote_type; + }; + template<> + struct promote_traits { + typedef long double promote_type; + }; +#endif + + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, float> { + typedef std::complex promote_type; + }; + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, float> { + typedef std::complex promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, float> { + typedef std::complex promote_type; + }; +#endif + + template<> + struct promote_traits > { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits, double> { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, double> { + typedef std::complex promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, double> { + typedef std::complex promote_type; + }; +#endif + +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits > { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits, long double> { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits > { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits, long double> { + // Here we'd better go the conservative way. + // typedef std::complex promote_type; + typedef std::complex promote_type; + }; + template<> + struct promote_traits > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, long double> { + typedef std::complex promote_type; + }; +#endif + + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; +#ifdef BOOST_UBLAS_USE_LONG_DOUBLE + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; + template<> + struct promote_traits, std::complex > { + typedef std::complex promote_type; + }; +#endif + +#ifdef BOOST_UBLAS_USE_INTERVAL template<> struct promote_traits, boost::numeric::interval > { typedef boost::numeric::interval promote_type; @@ -1283,6 +1336,7 @@ namespace boost { namespace numeric { namespace ublas { }; #endif #endif +#endif #endif struct unknown_storage_tag {}; diff --git a/include/boost/numeric/ublas/triangular.hpp b/include/boost/numeric/ublas/triangular.hpp index 8fed8d22..a92920ed 100644 --- a/include/boost/numeric/ublas/triangular.hpp +++ b/include/boost/numeric/ublas/triangular.hpp @@ -81,7 +81,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size1 (), ae ().size2 (), true); #endif - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -182,7 +182,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE triangular_matrix &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -199,7 +199,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE triangular_matrix &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -216,19 +216,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE triangular_matrix &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE triangular_matrix& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE triangular_matrix& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1119,7 +1119,7 @@ namespace boost { namespace numeric { namespace ublas { // Assignment BOOST_UBLAS_INLINE triangular_adaptor &operator = (const triangular_adaptor &m) { - matrix_assign (scalar_assign (), *this, m); + matrix_assign (scalar_assign (), *this, m); return *this; } BOOST_UBLAS_INLINE @@ -1130,49 +1130,49 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE triangular_adaptor &operator = (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (ae)); + matrix_assign (scalar_assign (), *this, matrix (ae)); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor& operator += (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this + ae)); + matrix_assign (scalar_assign (), *this, matrix (*this + ae)); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor& operator -= (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, matrix (*this - ae)); + matrix_assign (scalar_assign (), *this, matrix (*this - ae)); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE triangular_adaptor& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1187,7 +1187,7 @@ namespace boost { namespace numeric { namespace ublas { // Too unusual semantic. // BOOST_UBLAS_CHECK (this != &m, external_logic ()); if (this != &m) - matrix_swap (scalar_swap (), *this, m); + matrix_swap (scalar_swap (), *this, m); } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS BOOST_UBLAS_INLINE diff --git a/include/boost/numeric/ublas/vector.hpp b/include/boost/numeric/ublas/vector.hpp index 45a4506f..8d9d0548 100644 --- a/include/boost/numeric/ublas/vector.hpp +++ b/include/boost/numeric/ublas/vector.hpp @@ -82,7 +82,7 @@ namespace boost { namespace numeric { namespace ublas { #else resize (ae ().size (), true); #endif - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); } // Accessors @@ -160,7 +160,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template @@ -177,7 +177,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -194,19 +194,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE vector &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE vector &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1293,7 +1293,7 @@ namespace boost { namespace numeric { namespace ublas { // Raising exceptions abstracted as requested during review. // throw std::bad_alloc (); bad_size ().raise (); - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); } // Accessors @@ -1377,7 +1377,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_vector &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template @@ -1394,7 +1394,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_vector &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -1411,19 +1411,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE c_vector &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE c_vector &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE c_vector &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } diff --git a/include/boost/numeric/ublas/vector_assign.hpp b/include/boost/numeric/ublas/vector_assign.hpp index 140329f2..7db1ec9c 100644 --- a/include/boost/numeric/ublas/vector_assign.hpp +++ b/include/boost/numeric/ublas/vector_assign.hpp @@ -284,8 +284,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename V::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v.size ()); - indexing_vector_assign (scalar_assign (), cv, v); - indexing_vector_assign (functor_type (), cv, e); + indexing_vector_assign (scalar_assign::reference, value_type> (), cv, v); + indexing_vector_assign (functor_type::template make_debug_functor::reference, value_type> (), cv, e); #endif typename V::iterator it (v.begin ()); typename V::iterator it_end (v.end ()); @@ -339,8 +339,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename V::value_type value_type; #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v.size ()); - indexing_vector_assign (scalar_assign (), cv, v); - indexing_vector_assign (functor_type (), cv, e); + indexing_vector_assign (scalar_assign::reference, value_type> (), cv, v); + indexing_vector_assign (functor_type::template make_debug_functor::reference, value_type> (), cv, e); #endif v.clear (); typename E::const_iterator ite (e ().begin ()); @@ -368,8 +368,8 @@ namespace boost { namespace numeric { namespace ublas { typedef typename V::reference reference; #ifdef BOOST_UBLAS_TYPE_CHECK vector cv (v.size ()); - indexing_vector_assign (scalar_assign (), cv, v); - indexing_vector_assign (functor_type (), cv, e); + indexing_vector_assign (scalar_assign::reference, value_type> (), cv, v); + indexing_vector_assign (functor_type::template make_debug_functor::reference, value_type> (), cv, e); #endif typename V::iterator it (v.begin ()); typename V::iterator it_end (v.end ()); diff --git a/include/boost/numeric/ublas/vector_of_vector.hpp b/include/boost/numeric/ublas/vector_of_vector.hpp index c44d6bb4..a073a74d 100644 --- a/include/boost/numeric/ublas/vector_of_vector.hpp +++ b/include/boost/numeric/ublas/vector_of_vector.hpp @@ -89,7 +89,7 @@ namespace boost { namespace numeric { namespace ublas { for (size_type i = 0; i < functor_type::size1 (size1_, size2_); ++ i) static_cast (data_ [i]).resize (functor_type::size2 (size1_, size2_)); data_ [functor_type::size1 (size1_, size2_)] = vector_data_value_type (); - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); } // Accessors @@ -204,7 +204,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE generalized_vector_of_vector &assign (const matrix_expression &ae) { - matrix_assign (scalar_assign (), *this, ae); + matrix_assign (scalar_assign (), *this, ae); return *this; } template @@ -221,7 +221,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE generalized_vector_of_vector &plus_assign (const matrix_expression &ae) { - matrix_assign (scalar_plus_assign (), *this, ae); + matrix_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -238,19 +238,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE generalized_vector_of_vector &minus_assign (const matrix_expression &ae) { - matrix_assign (scalar_minus_assign (), *this, ae); + matrix_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE generalized_vector_of_vector& operator *= (const AT &at) { - matrix_assign_scalar (scalar_multiplies_assign (), *this, at); + matrix_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE generalized_vector_of_vector& operator /= (const AT &at) { - matrix_assign_scalar (scalar_divides_assign (), *this, at); + matrix_assign_scalar (scalar_divides_assign (), *this, at); return *this; } diff --git a/include/boost/numeric/ublas/vector_proxy.hpp b/include/boost/numeric/ublas/vector_proxy.hpp index d5dba580..da1c0b22 100644 --- a/include/boost/numeric/ublas/vector_proxy.hpp +++ b/include/boost/numeric/ublas/vector_proxy.hpp @@ -169,62 +169,62 @@ namespace boost { namespace numeric { namespace ublas { vector_range &operator = (const vector_range &vr) { // FIXME: the ranges could be differently sized. // std::copy (vr.begin (), vr.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (vr)); + vector_assign (scalar_assign (), *this, vector (vr)); return *this; } BOOST_UBLAS_INLINE vector_range &assign_temporary (vector_range &vr) { // FIXME: this is suboptimal. // return *this = vr; - vector_assign (scalar_assign (), *this, vr); + vector_assign (scalar_assign (), *this, vr); return *this; } template BOOST_UBLAS_INLINE vector_range &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE vector_range &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_range &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE vector_range &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_range &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE vector_range &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_range &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE vector_range &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -243,7 +243,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == vr.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), vr.begin ()); - vector_swap (scalar_swap (), *this, vr); + vector_swap (scalar_swap (), *this, vr); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -720,62 +720,62 @@ namespace boost { namespace numeric { namespace ublas { vector_slice &operator = (const vector_slice &vs) { // FIXME: the slices could be differently sized. // std::copy (vs.begin (), vs.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (vs)); + vector_assign (scalar_assign (), *this, vector (vs)); return *this; } BOOST_UBLAS_INLINE vector_slice &assign_temporary (vector_slice &vs) { // FIXME: this is suboptimal. // return *this = vs; - vector_assign (scalar_assign (), *this, vs); + vector_assign (scalar_assign (), *this, vs); return *this; } template BOOST_UBLAS_INLINE vector_slice &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE vector_slice &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_slice &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE vector_slice &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_slice &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE vector_slice &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_slice &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE vector_slice &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -794,7 +794,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == vs.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), vs.begin ()); - vector_swap (scalar_swap (), *this, vs); + vector_swap (scalar_swap (), *this, vs); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS @@ -1273,62 +1273,62 @@ namespace boost { namespace numeric { namespace ublas { vector_indirect &operator = (const vector_indirect &vi) { // FIXME: the indirect_arrays could be differently sized. // std::copy (vi.begin (), vi.end (), begin ()); - vector_assign (scalar_assign (), *this, vector (vi)); + vector_assign (scalar_assign (), *this, vector (vi)); return *this; } BOOST_UBLAS_INLINE vector_indirect &assign_temporary (vector_indirect &vi) { // FIXME: this is suboptimal. // return *this = vi; - vector_assign (scalar_assign (), *this, vi); + vector_assign (scalar_assign (), *this, vi); return *this; } template BOOST_UBLAS_INLINE vector_indirect &operator = (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (ae)); + vector_assign (scalar_assign (), *this, vector (ae)); return *this; } template BOOST_UBLAS_INLINE vector_indirect &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_indirect &operator += (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this + ae)); + vector_assign (scalar_assign (), *this, vector (*this + ae)); return *this; } template BOOST_UBLAS_INLINE vector_indirect &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_indirect &operator -= (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, vector (*this - ae)); + vector_assign (scalar_assign (), *this, vector (*this - ae)); return *this; } template BOOST_UBLAS_INLINE vector_indirect &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE vector_indirect &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE vector_indirect &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1347,7 +1347,7 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (size () == vi.size (), bad_size ()); // Sparse ranges may be nonconformant now. // std::swap_ranges (begin (), end (), vi.begin ()); - vector_swap (scalar_swap (), *this, vi); + vector_swap (scalar_swap (), *this, vi); } } #ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index b4fa1dd6..ae1121e5 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -43,7 +43,6 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE sparse_vector_element (const value_type &d): container_reference (), it_ (), i_ (), d_ (d), dirty_ (false) { - // This constructor is only needed to enable compiling adaptors of sparse vectors. external_logic ().raise (); } BOOST_UBLAS_INLINE @@ -59,6 +58,9 @@ namespace boost { namespace numeric { namespace ublas { d_ = *it; } BOOST_UBLAS_INLINE + sparse_vector_element (const sparse_vector_element &p): + container_reference (p), it_ (p.it_), i_ (p.i_), d_ (p.d_), dirty_ (p.dirty_) {} + BOOST_UBLAS_INLINE ~sparse_vector_element () { if (dirty_) { if (! it_) @@ -171,18 +173,31 @@ namespace boost { namespace numeric { namespace ublas { } // Conversion - // FIXME: GCC 3.1 warns, if enabled -#ifndef __GNUC__ BOOST_UBLAS_INLINE operator const_reference () const { return d_; } -#endif +#ifdef BOOST_UBLAS_DEPRECATED BOOST_UBLAS_INLINE operator reference () { dirty_ = true; return d_; } +#endif + + // Swapping + BOOST_UBLAS_INLINE + void swap (sparse_vector_element &p) { + if (this != &p) { + dirty_ = true; + p.dirty_ = true; + std::swap (d_, p.d_); + } + } + BOOST_UBLAS_INLINE + friend void swap (sparse_vector_element &p1, sparse_vector_element &p2) { + p1.swap (p2); + } private: pointer it_; @@ -191,6 +206,83 @@ namespace boost { namespace numeric { namespace ublas { bool dirty_; }; + template + struct type_traits > { + typedef typename V::value_type element_type; + typedef type_traits > self_type; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::const_reference const_reference; + typedef sparse_vector_element reference; + typedef typename type_traits::real_type real_type; + typedef typename type_traits::precision_type precision_type; + + BOOST_STATIC_CONSTANT (std::size_t, plus_complexity = type_traits::plus_complexity); + BOOST_STATIC_CONSTANT (std::size_t, multiplies_complexity = type_traits::multiplies_complexity); + + static + BOOST_UBLAS_INLINE + real_type real (const_reference t) { + return type_traits::real (t); + } + static + BOOST_UBLAS_INLINE + real_type imag (const_reference t) { + return type_traits::imag (t); + } + static + BOOST_UBLAS_INLINE + value_type conj (const_reference t) { + return type_traits::conj (t); + } + + static + BOOST_UBLAS_INLINE + real_type abs (const_reference t) { + return type_traits::abs (t); + } + static + BOOST_UBLAS_INLINE + value_type sqrt (const_reference t) { + return type_traits::sqrt (t); + } + + static + BOOST_UBLAS_INLINE + real_type norm_1 (const_reference t) { + return type_traits::norm_1 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_2 (const_reference t) { + return type_traits::norm_2 (t); + } + static + BOOST_UBLAS_INLINE + real_type norm_inf (const_reference t) { + return type_traits::norm_inf (t); + } + + static + BOOST_UBLAS_INLINE + bool equals (const_reference t1, const_reference t2) { + return type_traits::equals (t1, t2); + } + }; + + template + struct promote_traits, T2> { + typedef typename promote_traits::value_type, T2>::promote_type promote_type; + }; + template + struct promote_traits > { + typedef typename promote_traits::value_type>::promote_type promote_type; + }; + template + struct promote_traits, sparse_vector_element > { + typedef typename promote_traits::value_type, + typename sparse_vector_element::value_type>::promote_type promote_type; + }; + #endif // Array based sparse vector class @@ -246,7 +338,7 @@ namespace boost { namespace numeric { namespace ublas { sparse_vector (const vector_expression &ae, size_type non_zeros = 0): size_ (ae ().size ()), non_zeros_ (non_zeros), data_ () { reserve (non_zeros_); - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); } // Accessors @@ -363,7 +455,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template @@ -380,7 +472,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -397,19 +489,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE sparse_vector &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE sparse_vector &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE sparse_vector &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -736,7 +828,7 @@ namespace boost { namespace numeric { namespace ublas { size_ (ae ().size ()), non_zeros_ (non_zeros), filled_ (0), index_data_ (non_zeros), value_data_ (non_zeros) { reserve (non_zeros_, false); - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); } // Accessors @@ -880,7 +972,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_vector &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template @@ -897,7 +989,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_vector &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -914,19 +1006,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE compressed_vector &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE compressed_vector &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE compressed_vector &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; } @@ -1300,7 +1392,7 @@ namespace boost { namespace numeric { namespace ublas { size_ (ae ().size ()), non_zeros_ (non_zeros), filled_ (0), sorted_ (true), index_data_ (non_zeros), value_data_ (non_zeros) { reserve (non_zeros_, false); - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); } // Accessors @@ -1451,7 +1543,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_vector &assign (const vector_expression &ae) { - vector_assign (scalar_assign (), *this, ae); + vector_assign (scalar_assign (), *this, ae); return *this; } template @@ -1468,7 +1560,7 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_vector &plus_assign (const vector_expression &ae) { - vector_assign (scalar_plus_assign (), *this, ae); + vector_assign (scalar_plus_assign (), *this, ae); return *this; } template @@ -1485,19 +1577,19 @@ namespace boost { namespace numeric { namespace ublas { template BOOST_UBLAS_INLINE coordinate_vector &minus_assign (const vector_expression &ae) { - vector_assign (scalar_minus_assign (), *this, ae); + vector_assign (scalar_minus_assign (), *this, ae); return *this; } template BOOST_UBLAS_INLINE coordinate_vector &operator *= (const AT &at) { - vector_assign_scalar (scalar_multiplies_assign (), *this, at); + vector_assign_scalar (scalar_multiplies_assign (), *this, at); return *this; } template BOOST_UBLAS_INLINE coordinate_vector &operator /= (const AT &at) { - vector_assign_scalar (scalar_divides_assign (), *this, at); + vector_assign_scalar (scalar_divides_assign (), *this, at); return *this; }