getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] r5223 - /trunk/getfem/src/gmm/gmm_vector.h


From: Yves . Renard
Subject: [Getfem-commits] r5223 - /trunk/getfem/src/gmm/gmm_vector.h
Date: Wed, 13 Jan 2016 11:57:59 -0000

Author: renard
Date: Wed Jan 13 12:57:57 2016
New Revision: 5223

URL: http://svn.gna.org/viewcvs/getfem?rev=5223&view=rev
Log:
Allows operations mixing complex and real operators

Modified:
    trunk/getfem/src/gmm/gmm_vector.h

Modified: trunk/getfem/src/gmm/gmm_vector.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/gmm/gmm_vector.h?rev=5223&r1=5222&r2=5223&view=diff
==============================================================================
--- trunk/getfem/src/gmm/gmm_vector.h   (original)
+++ trunk/getfem/src/gmm/gmm_vector.h   Wed Jan 13 12:57:57 2016
@@ -58,28 +58,89 @@
 
     operator T() const { return pm->r(l); }
     ref_elt_vector(V *p, size_type ll) : pm(p), l(ll) {}
-    inline ref_elt_vector &operator =(T v)
-      { (*pm).w(l,v); return *this; }
     inline bool operator ==(T v) const { return ((*pm).r(l) == v); }
     inline bool operator !=(T v) const { return ((*pm).r(l) != v); }
+    inline bool operator ==(std::complex<T> v) const
+    { return ((*pm).r(l) == v); }
+    inline bool operator !=(std::complex<T> v) const
+    { return ((*pm).r(l) != v); }
     inline ref_elt_vector &operator +=(T v)
-      { (*pm).w(l,(*pm).r(l) + v); return *this; }
+    { (*pm).w(l,(*pm).r(l) + v); return *this; }
     inline ref_elt_vector &operator -=(T v)
-      { (*pm).w(l,(*pm).r(l) - v); return *this; }
+    { (*pm).w(l,(*pm).r(l) - v); return *this; }
     inline ref_elt_vector &operator /=(T v)
-      { (*pm).w(l,(*pm).r(l) / v); return *this; }
+    { (*pm).w(l,(*pm).r(l) / v); return *this; }
     inline ref_elt_vector &operator *=(T v)
-      { (*pm).w(l,(*pm).r(l) * v); return *this; }
+    { (*pm).w(l,(*pm).r(l) * v); return *this; }
     inline ref_elt_vector &operator =(const ref_elt_vector &re)
-      { *this = T(re); return *this; }
+    { *this = T(re); return *this; }
+    inline ref_elt_vector &operator =(T v)
+    { (*pm).w(l,v); return *this; }
     T operator +()    { return  T(*this);   }
     T operator -()    { return -T(*this);   }
     T operator +(T v) { return T(*this)+ v; }
     T operator -(T v) { return T(*this)- v; }
     T operator *(T v) { return T(*this)* v; }
     T operator /(T v) { return T(*this)/ v; }
+    std::complex<T> operator +(std::complex<T> v) { return T(*this)+ v; }
+    std::complex<T> operator -(std::complex<T> v) { return T(*this)- v; }
+    std::complex<T> operator *(std::complex<T> v) { return T(*this)* v; }
+    std::complex<T> operator /(std::complex<T> v) { return T(*this)/ v; }
+  };
+
+  template<typename T, typename V> class ref_elt_vector<std::complex<T>,V> {
+
+    V *pm;
+    size_type l;
+    
+    public :
+
+    operator std::complex<T>() const { return pm->r(l); }
+    ref_elt_vector(V *p, size_type ll) : pm(p), l(ll) {}
+    inline bool operator ==(std::complex<T> v) const
+    { return ((*pm).r(l) == v); }
+    inline bool operator !=(std::complex<T> v) const
+    { return ((*pm).r(l) != v); }
+    inline bool operator ==(T v) const { return ((*pm).r(l) == v); }
+    inline bool operator !=(T v) const { return ((*pm).r(l) != v); }
+    inline ref_elt_vector &operator +=(std::complex<T> v)
+    { (*pm).w(l,(*pm).r(l) + v); return *this; }
+    inline ref_elt_vector &operator -=(std::complex<T> v)
+    { (*pm).w(l,(*pm).r(l) - v); return *this; }
+    inline ref_elt_vector &operator /=(std::complex<T> v)
+    { (*pm).w(l,(*pm).r(l) / v); return *this; }
+    inline ref_elt_vector &operator *=(std::complex<T> v)
+    { (*pm).w(l,(*pm).r(l) * v); return *this; }
+    inline ref_elt_vector &operator =(const ref_elt_vector &re)
+    { *this = T(re); return *this; }
+    inline ref_elt_vector &operator =(std::complex<T> v)
+    { (*pm).w(l,v); return *this; }
+    inline ref_elt_vector &operator =(T v)
+    { (*pm).w(l,std::complex<T>(v)); return *this; }
+    inline ref_elt_vector &operator +=(T v)
+    { (*pm).w(l,(*pm).r(l) + v); return *this; }
+    inline ref_elt_vector &operator -=(T v)
+    { (*pm).w(l,(*pm).r(l) - v); return *this; }
+    inline ref_elt_vector &operator /=(T v)
+    { (*pm).w(l,(*pm).r(l) / v); return *this; }
+    inline ref_elt_vector &operator *=(T v)
+    { (*pm).w(l,(*pm).r(l) * v); return *this; }
+    std::complex<T> operator +()    { return  std::complex<T>(*this);   }
+    std::complex<T> operator -()    { return -std::complex<T>(*this);   }
+    std::complex<T> operator +(T v) { return std::complex<T>(*this)+ v; }
+    std::complex<T> operator -(T v) { return std::complex<T>(*this)- v; }
+    std::complex<T> operator *(T v) { return std::complex<T>(*this)* v; }
+    std::complex<T> operator /(T v) { return std::complex<T>(*this)/ v; }
+    std::complex<T> operator +(std::complex<T> v)
+    { return std::complex<T>(*this)+ v; }
+    std::complex<T> operator -(std::complex<T> v)
+    { return std::complex<T>(*this)- v; }
+    std::complex<T> operator *(std::complex<T> v)
+    { return std::complex<T>(*this)* v; }
+    std::complex<T> operator /(std::complex<T> v)
+    { return std::complex<T>(*this)/ v; }
   };  
-  
+
   
   template<typename T, typename V> inline
   bool operator ==(T v, const ref_elt_vector<T, V> &re) { return (v==T(re)); }
@@ -98,25 +159,37 @@
   T &operator /=(T &v, const ref_elt_vector<T, V> &re)
   { v /= T(re); return v; }
   template<typename T, typename V> inline
-  T operator +(const ref_elt_vector<T, V> &re) { return T(re); }
-  template<typename T, typename V> inline
-  T operator -(const ref_elt_vector<T, V> &re) { return -T(re); }
-  template<typename T, typename V> inline
-  T operator +(const ref_elt_vector<T, V> &re, T v) { return T(re)+ v; }
-  template<typename T, typename V> inline
   T operator +(T v, const ref_elt_vector<T, V> &re) { return v+ T(re); }
   template<typename T, typename V> inline
-  T operator -(const ref_elt_vector<T, V> &re, T v) { return T(re)- v; }
-  template<typename T, typename V> inline
   T operator -(T v, const ref_elt_vector<T, V> &re) { return v- T(re); }
-  template<typename T, typename V>  inline
-  T operator *(const ref_elt_vector<T, V> &re, T v) { return T(re)* v; }
   template<typename T, typename V> inline
   T operator *(T v, const ref_elt_vector<T, V> &re) { return v* T(re); }
   template<typename T, typename V> inline
-  T operator /(const ref_elt_vector<T, V> &re, T v) { return T(re)/ v; }
-  template<typename T, typename V> inline
   T operator /(T v, const ref_elt_vector<T, V> &re) { return v/ T(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator +(std::complex<T> v, const ref_elt_vector<T, V> &re)
+  { return v+ T(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator -(std::complex<T> v, const ref_elt_vector<T, V> &re)
+  { return v- T(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator *(std::complex<T> v, const ref_elt_vector<T, V> &re)
+  { return v* T(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator /(std::complex<T> v, const ref_elt_vector<T, V> &re)
+  { return v/ T(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator +(T v, const ref_elt_vector<std::complex<T>, V> &re)
+  { return v+ std::complex<T>(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator -(T v, const ref_elt_vector<std::complex<T>, V> &re)
+  { return v- std::complex<T>(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator *(T v, const ref_elt_vector<std::complex<T>, V> &re)
+  { return v* std::complex<T>(re); }
+  template<typename T, typename V> inline
+  std::complex<T> operator /(T v, const ref_elt_vector<std::complex<T>, V> &re)
+  { return v/ std::complex<T>(re); }
   template<typename T, typename V> inline
   typename number_traits<T>::magnitude_type
   abs(const ref_elt_vector<T, V> &re) { return gmm::abs(T(re)); }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]