]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add new constructors to specializations of NumberType.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Wed, 23 Aug 2017 21:52:45 +0000 (23:52 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 24 Aug 2017 05:14:58 +0000 (07:14 +0200)
These simply return the input value by refererence if it is of the
same type as the output value.

include/deal.II/base/numbers.h
include/deal.II/base/tensor.h
include/deal.II/base/vectorization.h

index 46bddf1e6a173afdba3537219b1fe65123e93fea..33fcdc6acfa45d261e6ae5cc17b78af9dd400028 100644 (file)
@@ -397,7 +397,7 @@ namespace internal
   template <typename T>
   struct NumberType
   {
-    static DEAL_II_CUDA_HOST_DEV value (const T &t)
+    static DEAL_II_CUDA_HOST_DEV const T &value (const T &t)
     {
       return t;
     }
@@ -406,10 +406,24 @@ namespace internal
   template <typename T>
   struct NumberType<std::complex<T> >
   {
+    static const std::complex<T> &value (const std::complex<T> &t)
+    {
+      return t;
+    }
+
     static std::complex<T> value (const T &t)
     {
       return std::complex<T>(t);
     }
+
+    // Facilitate cast from complex<double> to complex<float>
+    template <typename U>
+    static std::complex<T> value (const std::complex<U> &t)
+    {
+      return std::complex<T>(
+               NumberType<T>::value(t.real()),
+               NumberType<T>::value(t.imag()));
+    }
   };
 }
 
index a52f0720b5dd76df6de1a2bb632459488b6d4d9c..357ea704d01ea16d462d964df2c8ff574221fcd7 100644 (file)
@@ -601,6 +601,11 @@ namespace internal
   template <int rank, int dim, typename T>
   struct NumberType<Tensor<rank,dim,T> >
   {
+    static const Tensor<rank,dim,T> &value (const Tensor<rank,dim,T> &t)
+    {
+      return t;
+    }
+
     static Tensor<rank,dim,T> value (const T &t)
     {
       Tensor<rank,dim,T> tmp;
@@ -612,6 +617,11 @@ namespace internal
   template <int rank, int dim, typename T>
   struct NumberType<Tensor<rank,dim,VectorizedArray<T> > >
   {
+    static const Tensor<rank,dim,VectorizedArray<T> > &value (const Tensor<rank,dim,VectorizedArray<T> > &t)
+    {
+      return t;
+    }
+
     static Tensor<rank,dim,VectorizedArray<T> > value (const T &t)
     {
       Tensor<rank,dim,VectorizedArray<T> > tmp;
index d6c2b238e1a6a5c128182ba933c40851cd47fa45..8e5e1bda7d00f850ba73cac8348c8ccd91febdb4 100644 (file)
@@ -74,6 +74,11 @@ namespace internal
   template <typename T>
   struct NumberType<VectorizedArray<T> >
   {
+    static const VectorizedArray<T> &value (const VectorizedArray<T> &t)
+    {
+      return t;
+    }
+
     static VectorizedArray<T> value (const T &t)
     {
       VectorizedArray<T> tmp;

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.