diff --git a/src/TNL/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h index 132c64cbfb631f9b1f42dbdfabc3cafda09397fc..17e9fe34f15729ed1ae4ef2662cc8a922f22956b 100644 --- a/src/TNL/Containers/StaticVector.h +++ b/src/TNL/Containers/StaticVector.h @@ -76,6 +76,26 @@ class StaticVector : public StaticArray< Size, Real > StaticVector( const std::initializer_list< Real > &elems ); + /** + * \brief Constructor that sets components of arrays with Size = 2. + * + * \param v1 Real of the first array component. + * \param v2 Real of the second array component. + */ + __cuda_callable__ + inline StaticVector( const Real& v1, const Real& v2 ); + + /** + * \brief Constructor that sets components of arrays with Size = 3. + * + * \param v1 Real of the first array component. + * \param v2 Real of the second array component. + * \param v3 Real of the third array component. + */ + __cuda_callable__ + inline StaticVector( const Real& v1, const Real& v2, const Real& v3 ); + + template< typename T1, typename T2, template< typename, typename > class Operation > @@ -168,298 +188,10 @@ class StaticVector : public StaticArray< Size, Real > Real lpNorm( const Real& p ) const; }; -/** - * \brief Specific static vector with the size of 1. Works like the class StaticVector. - */ -template< typename Real > -class StaticVector< 1, Real > : public StaticArray< 1, Real > -{ - public: - using RealType = Real; - using IndexType = int; - using ThisType = StaticVector< 1, Real >; - - constexpr static int size = 1; - - using StaticArray< 1, Real >::getSize; - //using StaticArray< 1, Real >::operator ==; - //using StaticArray< 1, Real >::operator !=; - - - - /** \brief See StaticVector::StaticVector().*/ - __cuda_callable__ - StaticVector(); - - /** \brief See StaticVector::StaticVector(const Real v[Size]).*/ - // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer - // reference: https://stackoverflow.com/q/4610503 - template< typename _unused = void > - __cuda_callable__ - StaticVector( const Real v[ 1 ] ); - - /** \brief See StaticVector::StaticVector( const Real& v ).*/ - __cuda_callable__ - StaticVector( const Real& v ); - - /** \brief See StaticVector::StaticVector( const StaticVector< Size, Real >& v ).*/ - __cuda_callable__ - StaticVector( const StaticVector< 1, Real >& v ); - - StaticVector( const std::initializer_list< Real > &elems ); - - template< typename T1, - typename T2, - template< typename, typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ); - - template< typename T, - template< typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ); - - bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - /** \brief See StaticVector::getType().*/ - static String getType(); - - template< typename StaticVectorOperationType > - StaticVector& operator = ( const StaticVectorOperationType& vo ); - - /** \brief See StaticVector::operator += ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator += ( const StaticVector& v ); - - /** \brief See StaticVector::operator -= ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator -= ( const StaticVector& v ); - - /** \brief See StaticVector::operator *= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator *= ( const Real& c ); - - /** \brief See StaticVector::operator /= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator /= ( const Real& c ); - - template< typename OtherReal > - __cuda_callable__ - operator StaticVector< 1, OtherReal >() const; - - /** \brief See StaticVector::abs() const.*/ - __cuda_callable__ - StaticVector abs() const; - - /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ - __cuda_callable__ - Real lpNorm( const Real& p ) const; -}; - -/** - * \brief Specific static vector with the size of 2. Works like the class StaticVector. - */ -template< typename Real > -class StaticVector< 2, Real > : public StaticArray< 2, Real > -{ - public: - using RealType = Real; - using IndexType = int; - using ThisType = StaticVector< 2, Real >; - - constexpr static int size = 2; - - using StaticArray< 2, Real >::getSize; - //using StaticArray< 2, Real >::operator ==; - //using StaticArray< 2, Real >::operator !=; - - - /** \brief See StaticVector::StaticVector().*/ - __cuda_callable__ - StaticVector(); - - /** \brief See StaticVector::StaticVector(const Real v[Size]).*/ - // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer - // reference: https://stackoverflow.com/q/4610503 - template< typename _unused = void > - __cuda_callable__ - StaticVector( const Real v[ 2 ] ); - - /** \brief See StaticVector::StaticVector( const Real& v ).*/ - __cuda_callable__ - StaticVector( const Real& v ); - - /** - * \brief Constructor that sets the two static vector components to value \e v1 and \e v2. - * - * \param v1 Reference to the value of first vector component. - * \param v2 Reference to the value of second vector component. - */ - __cuda_callable__ - StaticVector( const Real& v1, const Real& v2 ); - - /** \brief See StaticVector::StaticVector( const StaticVector< Size, Real >& v ).*/ - __cuda_callable__ - StaticVector( const StaticVector< 2, Real >& v ); - - StaticVector( const std::initializer_list< Real > &elems ); - - template< typename T1, - typename T2, - template< typename, typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ); - - template< typename T, - template< typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ); - - bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - /** \brief See StaticVector::getType().*/ - static String getType(); - - template< typename StaticVectorOperationType > - StaticVector& operator = ( const StaticVectorOperationType& vo ); - - /** \brief See StaticVector::operator += ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator += ( const StaticVector& v ); - - /** \brief See StaticVector::operator -= ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator -= ( const StaticVector& v ); - - /** \brief See StaticVector::operator *= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator *= ( const Real& c ); - - /** \brief See StaticVector::operator /= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator /= ( const Real& c ); - - template< typename OtherReal > - __cuda_callable__ - operator StaticVector< 2, OtherReal >() const; - - /** \brief See StaticVector::abs() const.*/ - __cuda_callable__ - StaticVector abs() const; - - /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ - __cuda_callable__ - Real lpNorm( const Real& p ) const; -}; - -/** - * \brief Specific static vector with the size of 3. Works like the class StaticVector. - */ -template< typename Real > -class StaticVector< 3, Real > : public StaticArray< 3, Real > -{ - public: - using RealType = Real; - using IndexType = int; - using ThisType = StaticVector< 3, Real >; - - constexpr static int size = 3; - - using StaticArray< 3, Real >::getSize; - //using StaticArray< 3, Real >::operator ==; - //using StaticArray< 3, Real >::operator !=; - - - /** \brief See StaticVector::StaticVector().*/ - __cuda_callable__ - StaticVector(); - - /** \brief See StaticVector::StaticVector(const Real v[Size]).*/ - // Note: the template avoids ambiguity of overloaded functions with literal 0 and pointer - // reference: https://stackoverflow.com/q/4610503 - template< typename _unused = void > - __cuda_callable__ - StaticVector( const Real v[ 3 ] ); - - /** \brief See StaticVector::StaticVector( const Real& v ).*/ - __cuda_callable__ - StaticVector( const Real& v ); - - /** - * \brief Constructor that sets the three static vector components to value \e v1 \e v2 and \e v3. - * - * \param v1 Reference to the value of first vector component. - * \param v2 Reference to the value of second vector component. - * \param v3 Reference to the value of third vector component. - */ - __cuda_callable__ - StaticVector( const Real& v1, const Real& v2, const Real& v3 ); - - /** \brief See StaticVector::StaticVector( const StaticVector< Size, Real >& v ).*/ - __cuda_callable__ - StaticVector( const StaticVector< 3, Real >& v ); - - StaticVector( const std::initializer_list< Real > &elems ); - - template< typename T1, - typename T2, - template< typename, typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ); - - template< typename T, - template< typename > class Operation > - __cuda_callable__ - StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ); - - bool setup( const Config::ParameterContainer& parameters, - const String& prefix = "" ); - - /** \brief See StaticVector::getType().*/ - static String getType(); - - template< typename StaticVectorOperationType > - StaticVector& operator = ( const StaticVectorOperationType& vo ); - - /** \brief See StaticVector::operator += ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator += ( const StaticVector& v ); - - /** \brief See StaticVector::operator -= ( const StaticVector& v ).*/ - __cuda_callable__ - StaticVector& operator -= ( const StaticVector& v ); - - /** \brief See StaticVector::operator *= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator *= ( const Real& c ); - - /** \brief See StaticVector::operator /= ( const Real& c ).*/ - __cuda_callable__ - StaticVector& operator /= ( const Real& c ); - - template< typename OtherReal > - __cuda_callable__ - operator StaticVector< 3, OtherReal >() const; - - /** \brief See StaticVector::abs() const.*/ - __cuda_callable__ - StaticVector abs() const; - - /** \brief See StaticVector::lpNorm( const Real& p ) const.*/ - __cuda_callable__ - Real lpNorm( const Real& p ) const; - -}; - } // namespace Containers } // namespace TNL -#include <TNL/Containers/StaticVector_impl.h> -#include <TNL/Containers/StaticVector1D_impl.h> -#include <TNL/Containers/StaticVector2D_impl.h> -#include <TNL/Containers/StaticVector3D_impl.h> +#include <TNL/Containers/StaticVector.hpp> namespace TNL { @@ -592,4 +324,4 @@ struct IsStatic< Containers::StaticVector< Size, Real > > } // namespace TNL #include <TNL/Containers/StaticVectorExpressions.h> -#include <TNL/Containers/Expressions/StaticExpressionTemplates.h> \ No newline at end of file +#include <TNL/Containers/Expressions/StaticExpressionTemplates.h> diff --git a/src/TNL/Containers/StaticVector_impl.h b/src/TNL/Containers/StaticVector.hpp similarity index 70% rename from src/TNL/Containers/StaticVector_impl.h rename to src/TNL/Containers/StaticVector.hpp index aa281b4c4e43a79399f7b27093ff611fa6a36256..a3c3dc5b668d55ccca4028d0f699a54cc42736a2 100644 --- a/src/TNL/Containers/StaticVector_impl.h +++ b/src/TNL/Containers/StaticVector.hpp @@ -17,6 +17,22 @@ namespace TNL { namespace Containers { +namespace Detail { + +//// +// Lambdas used together with StaticFor for static loop unrolling in the +// implementation of the StaticVector +template< typename LeftReal, typename RightReal = LeftReal > +auto addVectorLambda = [] __cuda_callable__ ( int i, LeftReal* data, const RightReal* v ) { data[ i ] += v[ i ]; }; + +template< typename LeftReal, typename RightReal = LeftReal > +auto subtractVectorLambda = [] __cuda_callable__ ( int i, LeftReal* data, const RightReal* v ) { data[ i ] -= v[ i ]; }; + +template< typename LeftReal, typename RightReal = LeftReal > +auto scalarMultiplicationLambda = [] __cuda_callable__ ( int i, LeftReal* data, const RightReal v ) { data[ i ] *= v; }; + +} //namespace Detail + template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >::StaticVector() @@ -51,6 +67,20 @@ StaticVector< Size, Real >::StaticVector( const std::initializer_list< Real > &e { } +template< int Size, typename Real > + __cuda_callable__ +StaticVector< Size, Real >::StaticVector( const Real& v1, const Real& v2 ) +: StaticArray< Size, Real >( v1, v2 ) +{ +} + +template< int Size, typename Real > + __cuda_callable__ +StaticVector< Size, Real >::StaticVector( const Real& v1, const Real& v2, const Real& v3 ) +: StaticArray< Size, Real >( v1, v2, v3 ) +{ +} + template< int Size, typename Real > template< typename T1, typename T2, @@ -76,8 +106,12 @@ StaticVector< Size, Real >::setup( const Config::ParameterContainer& parameters, const String& prefix ) { for( int i = 0; i < Size; i++ ) - if( ! parameters.template getParameter< double >( prefix + convertToString( i ), this->data[ i ] ) ) + { + double aux; + if( ! parameters.template getParameter< double >( prefix + convertToString( i ), aux ) ) return false; + this->data[ i ] = aux; + } return true; } @@ -104,8 +138,9 @@ template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >& StaticVector< Size, Real >::operator += ( const StaticVector& v ) { - for( int i = 0; i < Size; i++ ) - this->data[ i ] += v[ i ]; + //for( int i = 0; i < Size; i++ ) + // this->data[ i ] += v[ i ]; + StaticFor< 0, Size >::exec( Detail::addVectorLambda< Real >, this->getData(), v.getData() ); return *this; } @@ -113,8 +148,9 @@ template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >& StaticVector< Size, Real >::operator -= ( const StaticVector& v ) { - for( int i = 0; i < Size; i++ ) - this->data[ i ] -= v[ i ]; + //for( int i = 0; i < Size; i++ ) + // this->data[ i ] -= v[ i ]; + StaticFor< 0, Size >::exec( Detail::subtractVectorLambda< Real >, this->getData(), v.getData() ); return *this; } @@ -122,8 +158,9 @@ template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >& StaticVector< Size, Real >::operator *= ( const Real& c ) { - for( int i = 0; i < Size; i++ ) - this->data[ i ] *= c; + //for( int i = 0; i < Size; i++ ) + // this->data[ i ] *= c; + StaticFor< 0, Size >::exec( Detail::scalarMultiplicationLambda< Real >, this->getData(), c ); return *this; } @@ -131,9 +168,10 @@ 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; + //const RealType d = 1.0 / c; + //for( int i = 0; i < Size; i++ ) + // this->data[ i ] *= d; + StaticFor< 0, Size >::exec( Detail::scalarMultiplicationLambda< Real >, this->getData(), 1.0 / c ); return *this; } @@ -144,8 +182,9 @@ StaticVector< Size, Real >:: operator StaticVector< Size, OtherReal >() const { StaticVector< Size, OtherReal > aux; - for( int i = 0; i < Size; i++ ) - aux[ i ] = this->data[ i ]; + //for( int i = 0; i < Size; i++ ) + // aux[ i ] = this->data[ i ]; + StaticFor< 0, Size >::exec( Detail::assignArrayLambda< OtherReal, Real >, aux.getData(), this->getData() ); return aux; } diff --git a/src/TNL/Containers/StaticVector1D_impl.h b/src/TNL/Containers/StaticVector1D_impl.h deleted file mode 100644 index 5e2fdcaba47f71b14decd16539db06fcc63b28b2..0000000000000000000000000000000000000000 --- a/src/TNL/Containers/StaticVector1D_impl.h +++ /dev/null @@ -1,161 +0,0 @@ -/*************************************************************************** - StaticVector1D_impl.h - description - ------------------- - begin : Feb 10, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/StaticVector.h> -#include <TNL/Containers/Algorithms/VectorAssignment.h> -#include <TNL/Containers/StaticVectorExpressions.h> - -namespace TNL { -namespace Containers { - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector() -{ -} - -template< typename Real > - template< typename _unused > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector( const Real v[ 1 ] ) -: StaticArray< 1, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector( const Real& v ) -: StaticArray< 1, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector( const StaticVector< 1, Real >& v ) -: StaticArray< 1, Real >( v ) -{ -} - -template< typename Real > -StaticVector< 1, Real >::StaticVector( const std::initializer_list< Real > &elems ) -: StaticArray< 1, Real >( elems ) -{ -} - -template< typename Real > - template< typename T1, - typename T2, - template< typename, typename > class Operation > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 1, Real >, Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation > >::assignStatic( *this, op ); -}; - -template< typename Real > - template< typename T, - template< typename > class Operation > -__cuda_callable__ -StaticVector< 1, Real >::StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 1, Real >, Expressions::StaticUnaryExpressionTemplate< T, Operation > >::assignStatic( *this, op ); -}; - -template< typename Real > -bool -StaticVector< 1, Real >::setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - this->data[ 0 ] = parameters.getParameter< double >( prefix + "0" ); - return true; -} - -template< typename Real > -String StaticVector< 1, Real >::getType() -{ - return String( "Containers::StaticVector< " ) + - convertToString( 1 ) + - String( ", " ) + - TNL::getType< Real >() + - String( " >" ); -} - -template< typename Real > - template< typename RHS > -StaticVector< 1, Real >& -StaticVector< 1, Real >::operator =( const RHS& rhs ) -{ - Algorithms::VectorAssignment< StaticVector< 1, Real >, RHS >::assignStatic( *this, rhs ); - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real >& StaticVector< 1, Real >::operator += ( const StaticVector& v ) -{ - this->data[ 0 ] += v[ 0 ]; - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real >& StaticVector< 1, Real >::operator -= ( const StaticVector& v ) -{ - this->data[ 0 ] -= v[ 0 ]; - 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 Real& c ) -{ - this->data[ 0 ] /= c; - return *this; -} - -template< typename Real > - template< typename OtherReal > -__cuda_callable__ -StaticVector< 1, Real >:: -operator StaticVector< 1, OtherReal >() const -{ - StaticVector< 1, OtherReal > aux; - aux[ 0 ] = this->data[ 0 ]; - return aux; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 1, Real > -StaticVector< 1, Real >::abs() const -{ - return StaticVector< 1, Real >( TNL::abs( this->data[ 0 ] ) ); -} - -template< typename Real > -__cuda_callable__ -Real -StaticVector< 1, Real >::lpNorm( const Real& p ) const -{ - return TNL::abs( this->data[ 0 ] ); -} - -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/StaticVector2D_impl.h b/src/TNL/Containers/StaticVector2D_impl.h deleted file mode 100644 index b1606b6540f752815731dc02803bde6bf0fb7909..0000000000000000000000000000000000000000 --- a/src/TNL/Containers/StaticVector2D_impl.h +++ /dev/null @@ -1,181 +0,0 @@ -/*************************************************************************** - StaticVector2D_impl.h - description - ------------------- - begin : Feb 10, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/StaticVector.h> -#include <TNL/Containers/StaticVectorExpressions.h> - -namespace TNL { -namespace Containers { - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector() -{ -} - -template< typename Real > - template< typename _unused > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const Real v[ 2 ] ) -: StaticArray< 2, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const Real& v ) -: StaticArray< 2, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const Real& v1, const Real& v2 ) -: StaticArray< 2, Real >( v1, v2 ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const StaticVector< 2, Real >& v ) -: StaticArray< 2, Real >( v ) -{ -} - -template< typename Real > -StaticVector< 2, Real >::StaticVector( const std::initializer_list< Real > &elems ) -: StaticArray< 2, Real >( elems ) -{ -} - -template< typename Real > - template< typename T1, - typename T2, - template< typename, typename > class Operation > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 2, Real >, Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation > >::assignStatic( *this, op ); -}; - -template< typename Real > - template< typename T, - template< typename > class Operation > -__cuda_callable__ -StaticVector< 2, Real >::StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 2, Real >, Expressions::StaticUnaryExpressionTemplate< T, Operation > >::assignStatic( *this, op ); -}; - -template< typename Real > -bool -StaticVector< 2, Real >::setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - this->data[ 0 ] = parameters.getParameter< double >( prefix + "0" ); - this->data[ 1 ] = parameters.getParameter< double >( prefix + "1" ); - return true; -} - -template< typename Real > -String StaticVector< 2, Real >::getType() -{ - return String( "Containers::StaticVector< " ) + - convertToString( 2 ) + - String( ", " ) + - TNL::getType< Real >() + - String( " >" ); -} - -template< typename Real > - template< typename RHS > -StaticVector< 2, Real >& -StaticVector< 2, Real >::operator =( const RHS& rhs ) -{ - Algorithms::VectorAssignment< StaticVector< 2, Real >, RHS >::assignStatic( *this, rhs ); - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >& StaticVector< 2, Real >::operator += ( const StaticVector& v ) -{ - this->data[ 0 ] += v[ 0 ]; - this->data[ 1 ] += v[ 1 ]; - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >& StaticVector< 2, Real >::operator -= ( const StaticVector& v ) -{ - this->data[ 0 ] -= v[ 0 ]; - this->data[ 1 ] -= v[ 1 ]; - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real >& StaticVector< 2, Real >::operator *= ( const Real& c ) -{ - this->data[ 0 ] *= c; - this->data[ 1 ] *= 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 > - template< typename OtherReal > -__cuda_callable__ -StaticVector< 2, Real >:: -operator StaticVector< 2, OtherReal >() const -{ - StaticVector< 2, OtherReal > aux; - aux[ 0 ] = this->data[ 0 ]; - aux[ 1 ] = this->data[ 1 ]; - return aux; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 2, Real > -StaticVector< 2, Real >::abs() const -{ - return StaticVector< 2, Real >( TNL::abs( this->data[ 0 ] ), - TNL::abs( this->data[ 1 ] ) ); -} - -template< typename Real > -__cuda_callable__ -Real -StaticVector< 2, Real >::lpNorm( const Real& p ) const -{ - if( p == 1.0 ) - return TNL::abs( this->data[ 0 ] ) + TNL::abs( this->data[ 1 ] ); - if( p == 2.0 ) - return TNL::sqrt( this->data[ 0 ] * this->data[ 0 ] + - this->data[ 1 ] * this->data[ 1 ] ); - return TNL::pow( TNL::pow( TNL::abs( this->data[ 0 ] ), p ) + - TNL::pow( TNL::abs( this->data[ 1 ] ), p ), 1.0 / p ); -} - -} // namespace Containers -} // namespace TNL diff --git a/src/TNL/Containers/StaticVector3D_impl.h b/src/TNL/Containers/StaticVector3D_impl.h deleted file mode 100644 index 36a89cb6958d3b83d1d41987d7c18c04b584b740..0000000000000000000000000000000000000000 --- a/src/TNL/Containers/StaticVector3D_impl.h +++ /dev/null @@ -1,193 +0,0 @@ -/*************************************************************************** - StaticVector3D_impl.h - description - ------------------- - begin : Feb 10, 2014 - copyright : (C) 2014 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Containers/StaticVector.h> -#include <TNL/Containers/StaticVectorExpressions.h> - -namespace TNL { -namespace Containers { - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector() -{ -} - -template< typename Real > - template< typename _unused > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const Real v[ 3 ] ) -: StaticArray< 3, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const Real& v ) -: StaticArray< 3, Real >( v ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const Real& v1, const Real& v2, const Real& v3 ) -: StaticArray< 3, Real >( v1, v2, v3 ) -{ -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const StaticVector< 3, Real >& v ) -: StaticArray< 3, Real >( v ) -{ -} - -template< typename Real > -StaticVector< 3, Real >::StaticVector( const std::initializer_list< Real > &elems ) -: StaticArray< 3, Real >( elems ) -{ -} - -template< typename Real > - template< typename T1, - typename T2, - template< typename, typename > class Operation > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 3, Real >, Expressions::StaticBinaryExpressionTemplate< T1, T2, Operation > >::assignStatic( *this, op ); -}; - -template< typename Real > - template< typename T, - template< typename > class Operation > -__cuda_callable__ -StaticVector< 3, Real >::StaticVector( const Expressions::StaticUnaryExpressionTemplate< T, Operation >& op ) -{ - Algorithms::VectorAssignment< StaticVector< 3, Real >, Expressions::StaticUnaryExpressionTemplate< T, Operation > >::assignStatic( *this, op ); -}; - - -template< typename Real > -bool -StaticVector< 3, Real >::setup( const Config::ParameterContainer& parameters, - const String& prefix ) -{ - this->data[ 0 ] = parameters.getParameter< double >( prefix + "0" ); - this->data[ 1 ] = parameters.getParameter< double >( prefix + "1" ); - this->data[ 2 ] = parameters.getParameter< double >( prefix + "2" ); - return true; -} - -template< typename Real > -String StaticVector< 3, Real >::getType() -{ - return String( "Containers::StaticVector< " ) + - convertToString( 3 ) + - String( ", " ) + - TNL::getType< Real >() + - String( " >" ); -} - -template< typename Real > - template< typename RHS > -StaticVector< 3, Real >& -StaticVector< 3, Real >::operator =( const RHS& rhs ) -{ - Algorithms::VectorAssignment< StaticVector< 3, Real >, RHS >::assignStatic( *this, rhs ); - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >& StaticVector< 3, Real >::operator += ( const StaticVector& v ) -{ - this->data[ 0 ] += v[ 0 ]; - this->data[ 1 ] += v[ 1 ]; - this->data[ 2 ] += v[ 2 ]; - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >& StaticVector< 3, Real >::operator -= ( const StaticVector& v ) -{ - this->data[ 0 ] -= v[ 0 ]; - this->data[ 1 ] -= v[ 1 ]; - this->data[ 2 ] -= v[ 2 ]; - return *this; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real >& StaticVector< 3, Real >::operator *= ( const Real& c ) -{ - this->data[ 0 ] *= c; - this->data[ 1 ] *= c; - this->data[ 2 ] *= 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 > - template< typename OtherReal > -__cuda_callable__ -StaticVector< 3, Real >:: -operator StaticVector< 3, OtherReal >() const -{ - StaticVector< 3, OtherReal > aux; - aux[ 0 ] = this->data[ 0 ]; - aux[ 1 ] = this->data[ 1 ]; - aux[ 2 ] = this->data[ 2 ]; - return aux; -} - -template< typename Real > -__cuda_callable__ -StaticVector< 3, Real > -StaticVector< 3, Real >::abs() const -{ - return StaticVector< 3, Real >( TNL::abs( this->data[ 0 ] ), - TNL::abs( this->data[ 1 ] ), - TNL::abs( this->data[ 2 ] ) ); -} - -template< typename Real > -__cuda_callable__ -Real -StaticVector< 3, Real >::lpNorm( const Real& p ) const -{ - if( p == 1.0 ) - return TNL::abs( this->data[ 0 ] ) + - TNL::abs( this->data[ 1 ] ) + - TNL::abs( this->data[ 2 ] ); - if( p == 2.0 ) - return TNL::sqrt( this->data[ 0 ] * this->data[ 0 ] + - this->data[ 1 ] * this->data[ 1 ] + - this->data[ 2 ] * this->data[ 2 ] ); - return TNL::pow( TNL::pow( TNL::abs( this->data[ 0 ] ), p ) + - TNL::pow( TNL::abs( this->data[ 1 ] ), p ) + - TNL::pow( TNL::abs( this->data[ 2 ] ), p ), 1.0 / p ); -} - -} // namespace Containers -} // namespace TNL