Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-02-11 04:13:35


Currently, real matrices can be assigned to complex matrices due to the
automatic conversion from double to complex. The other direction however
is not supported. To make following code work :

numerics::matrix< std::complex< double > > complex_matrix(8,3);
numerics::matrix< double > double_matrix(8,3);
double_matrix[0] = complex_matrix[0] ;

I patched following files (2 patches follow):

Index: functional.h
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/Attic/functional.h,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 functional.h
--- functional.h 21 Jan 2002 20:50:48 -0000 1.1.2.7
+++ functional.h 11 Feb 2002 09:07:21 -0000
@@ -141,6 +141,20 @@
              t1 = t2;
          }
      };
+
+ template<class T1>
+ struct scalar_assign< T1, std::complex<T1> > :
+ public scalar_binary_functor<T1, std::complex< T1 > > {
+ typedef typename scalar_binary_functor<T1, std::complex< T1 >
>::argument1_type argument1_type;
+ typedef typename scalar_binary_functor<T1, std::complex< T1 >
>::argument2_type argument2_type;
+ typedef assign_tag assign_category;
+
+ NUMERICS_INLINE
+ void operator () (argument1_type &t1, const argument2_type &t2)
const {
+ t1 = t2.real();
+ }
+ };
+
      template<class T1, class T2>
      struct scalar_plus_assign:
          public scalar_binary_functor<T1, T2> {

and :

Index: matrix_pr.h
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/Attic/matrix_pr.h,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 matrix_pr.h
--- matrix_pr.h 21 Jan 2002 21:45:39 -0000 1.1.2.6
+++ matrix_pr.h 11 Feb 2002 09:08:14 -0000
@@ -121,7 +121,7 @@
          template<class AE>
          NUMERICS_INLINE
          matrix_row &operator = (const vector_expression<AE> &ae) {
- vector_assign<scalar_assign<value_type, value_type> > ()
(*this, vector<value_type> (ae));
+ vector_assign<scalar_assign<value_type, typename
AE::value_type> > () (*this, vector< typename AE::value_type > (ae));
              return *this;
          }
          template<class AE>

I also noticed the use of the iterating_assign in vector_assign. Would
you also consider a specialisation to use a memcpy when the value_types
are equal and POD types ?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk