From bf7d80126307bc9639a40f88ed0701c45c10becf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Thu, 4 Jan 2018 21:27:04 +0100
Subject: [PATCH] Added operator /= to the StaticVector

---
 src/TNL/Containers/StaticVector.h        | 19 ++++++++++++++++++-
 src/TNL/Containers/StaticVector1D_impl.h |  8 ++++++++
 src/TNL/Containers/StaticVector2D_impl.h | 10 ++++++++++
 src/TNL/Containers/StaticVector3D_impl.h | 11 +++++++++++
 src/TNL/Containers/StaticVector_impl.h   | 10 ++++++++++
 5 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/TNL/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h
index ca410edfef..9d5fa6471d 100644
--- a/src/TNL/Containers/StaticVector.h
+++ b/src/TNL/Containers/StaticVector.h
@@ -57,7 +57,11 @@ class StaticVector : public StaticArray< Size, Real >
    //! Multiplication with number
    __cuda_callable__
    StaticVector& operator *= ( const Real& c );
-
+   
+   //! Division by number
+   __cuda_callable__
+   StaticVector& operator /= ( const Real& c );
+   
    //! Addition operator
    __cuda_callable__
    StaticVector operator + ( const StaticVector& u ) const;
@@ -155,6 +159,10 @@ class StaticVector< 1, Real > : public StaticArray< 1, Real >
    //! Multiplication with number
    __cuda_callable__
    StaticVector& operator *= ( const Real& c );
+   
+   //! Division by number
+   __cuda_callable__
+   StaticVector& operator /= ( const Real& c );   
 
    //! Addition operator
    __cuda_callable__
@@ -257,6 +265,10 @@ class StaticVector< 2, Real > : public StaticArray< 2, Real >
    __cuda_callable__
    StaticVector& operator *= ( const Real& c );
 
+   //! Division by number
+   __cuda_callable__
+   StaticVector& operator /= ( const Real& c );   
+
    //! Adding operator
    __cuda_callable__
    StaticVector operator + ( const StaticVector& u ) const;
@@ -357,6 +369,11 @@ class StaticVector< 3, Real > : public StaticArray< 3, Real >
    //! Multiplication with number
    __cuda_callable__
    StaticVector& operator *= ( const Real& c );
+   
+   //! Division by number
+   __cuda_callable__
+   StaticVector& operator /= ( const Real& c );
+   
 
    //! Addition operator
    __cuda_callable__
diff --git a/src/TNL/Containers/StaticVector1D_impl.h b/src/TNL/Containers/StaticVector1D_impl.h
index 3127a62191..f009b52afe 100644
--- a/src/TNL/Containers/StaticVector1D_impl.h
+++ b/src/TNL/Containers/StaticVector1D_impl.h
@@ -86,6 +86,14 @@ StaticVector< 1, Real >& StaticVector< 1, Real >::operator *= ( const Real& c )
    return *this;
 }
 
+template< typename Real >
+__cuda_callable__
+StaticVector< 1, Real >& StaticVector< 1, Real >::operator /= ( const Real& c )
+{
+   this->data[ 0 ] /= c;
+   return *this;
+}
+
 template< typename Real >
 __cuda_callable__
 StaticVector< 1, Real > StaticVector< 1, Real >::operator + ( const StaticVector& u ) const
diff --git a/src/TNL/Containers/StaticVector2D_impl.h b/src/TNL/Containers/StaticVector2D_impl.h
index d66979bf7a..fdcc28aa51 100644
--- a/src/TNL/Containers/StaticVector2D_impl.h
+++ b/src/TNL/Containers/StaticVector2D_impl.h
@@ -97,6 +97,16 @@ StaticVector< 2, Real >& StaticVector< 2, Real >::operator *= ( const Real& c )
    return *this;
 }
 
+template< typename Real >
+__cuda_callable__
+StaticVector< 2, Real >& StaticVector< 2, Real >::operator /= ( const Real& c )
+{
+   const RealType d = 1.0 /c;
+   this->data[ 0 ] *= d;
+   this->data[ 1 ] *= d;
+   return *this;
+}
+
 template< typename Real >
 __cuda_callable__
 StaticVector< 2, Real > StaticVector< 2, Real >::operator + ( const StaticVector& u ) const
diff --git a/src/TNL/Containers/StaticVector3D_impl.h b/src/TNL/Containers/StaticVector3D_impl.h
index d01e82077a..655ed87365 100644
--- a/src/TNL/Containers/StaticVector3D_impl.h
+++ b/src/TNL/Containers/StaticVector3D_impl.h
@@ -101,6 +101,17 @@ StaticVector< 3, Real >& StaticVector< 3, Real >::operator *= ( const Real& c )
    return *this;
 }
 
+template< typename Real >
+__cuda_callable__
+StaticVector< 3, Real >& StaticVector< 3, Real >::operator /= ( const Real& c )
+{
+   const RealType d = 1.0 / c;
+   this->data[ 0 ] *= d;
+   this->data[ 1 ] *= d;
+   this->data[ 2 ] *= d;
+   return *this;
+}
+
 template< typename Real >
 __cuda_callable__
 StaticVector< 3, Real > StaticVector< 3, Real >::operator + ( const StaticVector& u ) const
diff --git a/src/TNL/Containers/StaticVector_impl.h b/src/TNL/Containers/StaticVector_impl.h
index 45e680a098..5f28e277af 100644
--- a/src/TNL/Containers/StaticVector_impl.h
+++ b/src/TNL/Containers/StaticVector_impl.h
@@ -91,6 +91,16 @@ StaticVector< Size, Real >& StaticVector< Size, Real >::operator *= ( const Real
    return *this;
 }
 
+template< int Size, typename Real >
+__cuda_callable__
+StaticVector< Size, Real >& StaticVector< Size, Real >::operator /= ( const Real& c )
+{
+   const RealType d = 1.0 / c;
+   for( int i = 0; i < Size; i++ )
+      this->data[ i ] *= d;
+   return *this;
+}
+
 template< int Size, typename Real >
 __cuda_callable__
 StaticVector< Size, Real > StaticVector< Size, Real >::operator + ( const StaticVector& u ) const
-- 
GitLab