]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Templatize the scalar product between vectors on the underlying types. This allows...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 27 Sep 2001 13:11:12 +0000 (13:11 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 27 Sep 2001 13:11:12 +0000 (13:11 +0000)
git-svn-id: https://svn.dealii.org/trunk@5110 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/vector.h
deal.II/lac/include/lac/vector.templates.h
deal.II/lac/source/vector.cc
deal.II/lac/source/vector.long_double.cc

index 7533548e7d3080a025e4ad091016a27210ec2845..bc5305d9b027a156376727cb58a7c6398e61b582 100644 (file)
@@ -203,9 +203,18 @@ class Vector
     Vector<Number> & operator= (const Vector<Number2>& V);
     
                                     /**
-                                     * $U = U * V$: scalar product.
+                                     * Return the scalar product of
+                                     * two vectors.  The return type
+                                     * is the underlying type of
+                                     * @p{this} vector, so the return
+                                     * type and the accuracy with
+                                     * which it the result is
+                                     * computed depend on the order
+                                     * of the arguments of this
+                                     * vector.
                                      */
-    Number operator* (const Vector<Number>& V) const;
+    template <typename Number2>
+    Number operator* (const Vector<Number2> &V) const;
 
                                     /**
                                      * Return square of the $l_2$-norm.
index 3ce808a5ba391b612c88500d6bc4058f88b81a9d..842fdf818fa9dacab5addbd8df88e0ce34ded7cc 100644 (file)
@@ -104,14 +104,15 @@ bool Vector<Number>::all_zero () const
 
 
 template <typename Number>
-Number Vector<Number>::operator * (const Vector<Number>& v) const
+template <typename Number2>
+Number Vector<Number>::operator * (const Vector<Number2>& v) const
 {
   Assert (dim!=0, ExcEmptyVector());
-
-  if (&v == this)
+  
+  if (this == reinterpret_cast<const Vector<Number>*>(&v))
     return norm_sqr();
   
-  Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim));
+  Assert (dim == v.size(), ExcDimensionMismatch(dim, v.size()));
   
   Number sum0 = 0,
         sum1 = 0,
@@ -122,8 +123,8 @@ Number Vector<Number>::operator * (const Vector<Number>& v) const
                                   // allowing pipelined commands to be
                                   // executed in parallel
   const_iterator ptr  = begin(),
-                vptr = v.begin(),
                 eptr = ptr + (dim/4)*4;
+  typename Vector<Number2>::const_iterator vptr = v.begin();
   while (ptr!=eptr)
     {
       sum0 += (*ptr++ * *vptr++);
index 2ff0e2217fca6db31d217b05281597662dd823f1..d007108eebd68ea50c68949ef1bcbc68a8c25405 100644 (file)
 // explicit instantiations
 template class Vector<double>;
 template Vector<double>& Vector<double>::operator=(const Vector<float>&);
+template double Vector<double>::operator*(const Vector<float>&) const;
+template double Vector<double>::operator*(const Vector<double>&) const;
 
 template class Vector<float>;
 template Vector<float>& Vector<float>::operator=(const Vector<double>&);
+template float Vector<float>::operator*(const Vector<float>&) const;
+template float Vector<float>::operator*(const Vector<double>&) const;
 
 // see the .h file for why these functions are disabled.
 // template Vector<float>::Vector (const Vector<double>& v);
index 86b8d0096907a9d84a7ca7b35bb581f972a8bade..e8a7d17ee36b97dc4a11e18a6cf90d66cf33d58e 100644 (file)
 
 // explicit instantiations
 template class Vector<long double>;
+
 template Vector<long double>& Vector<long double>::operator=(const Vector<float>&);
 template Vector<long double>& Vector<long double>::operator=(const Vector<double>&);
 template Vector<double>& Vector<double>::operator=(const Vector<long double>&);
 template Vector<float>& Vector<float>::operator=(const Vector<long double>&);
+
+template float Vector<float>::operator * (const Vector<long double> &) const;
+template double Vector<double>::operator * (const Vector<long double> &) const;
+template long double Vector<long double>::operator * (const Vector<float> &) const;
+template long double Vector<long double>::operator * (const Vector<double> &) const;
 // see the .h file for why these functions are disabled.
 // template Vector<float>::Vector (const Vector<double>& v);
 // template Vector<double>::Vector (const Vector<float>& v);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.