diff --git a/src/TNL/Containers/Algorithms/ArrayAssignment.h b/src/TNL/Containers/Algorithms/ArrayAssignment.h index 73df45c25a9ceead0d0720c7753cc6bcff10ab89..dbf0f82b95cc380d343755167ab4b268403b353b 100644 --- a/src/TNL/Containers/Algorithms/ArrayAssignment.h +++ b/src/TNL/Containers/Algorithms/ArrayAssignment.h @@ -10,15 +10,15 @@ #pragma once -#include<type_traits> -#include<utility> +#include <type_traits> +#include <utility> #include <TNL/Containers/Algorithms/ArrayOperations.h> namespace TNL { namespace Containers { namespace Algorithms { -namespace Details { +namespace detail { /** * SFINAE for checking if T has getArrayData method */ @@ -35,11 +35,11 @@ private: public: static constexpr bool value = ( sizeof( test< T >(0) ) == sizeof( YesType ) ); }; -} // namespace Details +} // namespace detail template< typename Array, typename T, - bool hasGetArrayData = Details::HasGetArrayData< T >::value > + bool hasGetArrayData = detail::HasGetArrayData< T >::value > struct ArrayAssignment{}; /** @@ -62,7 +62,7 @@ struct ArrayAssignment< Array, T, true > ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > ( a.getArrayData(), t.getArrayData(), t.getSize() ); - }; + } }; /** @@ -75,15 +75,15 @@ struct ArrayAssignment< Array, T, false > { static void resize( Array& a, const T& t ) { - }; + } + static void assign( Array& a, const T& t ) { TNL_ASSERT_FALSE( a.empty(), "Cannot assign value to empty array." ); ArrayOperations< typename Array::DeviceType >::template setMemory< typename Array::ValueType, typename Array::IndexType > ( a.getArrayData(), ( typename Array::ValueType ) t, a.getSize() ); - }; - + } }; } // namespace Algorithms diff --git a/src/TNL/Containers/Algorithms/VectorAssignment.h b/src/TNL/Containers/Algorithms/VectorAssignment.h index 222aa64ae6c7cccba772a9cb4cb1c48827daf010..e9de7241f8faff2ee8e9ada81e12c9df1ff74446 100644 --- a/src/TNL/Containers/Algorithms/VectorAssignment.h +++ b/src/TNL/Containers/Algorithms/VectorAssignment.h @@ -10,8 +10,8 @@ #pragma once -#include<type_traits> -#include<utility> +#include <type_traits> +#include <utility> #include <TNL/Containers/Algorithms/VectorOperations.h> #include <TNL/ParallelFor.h> @@ -19,7 +19,7 @@ namespace TNL { namespace Containers { namespace Algorithms { -namespace Details { +namespace detail { /** * SFINAE for checking if T has getSize method * TODO: We should better test operator[] but we need to know the indexing type. @@ -31,20 +31,20 @@ private: typedef char YesType[1]; typedef char NoType[2]; - template< typename C > static YesType& test( decltype(std::declval< C >().getSize() ) ); + template< typename C > static YesType& test( decltype(std::declval< C >().getSize() ) ); template< typename C > static NoType& test(...); public: static constexpr bool value = ( sizeof( test< T >(0) ) == sizeof( YesType ) ); }; -} // namespace Details +} // namespace detail /** * \brief Vector assignment */ template< typename Vector, typename T, - bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > + bool hasSubscriptOperator = detail::HasSubscriptOperator< T >::value > struct VectorAssignment{}; /** @@ -52,7 +52,7 @@ struct VectorAssignment{}; */ template< typename Vector, typename T, - bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > + bool hasSubscriptOperator = detail::HasSubscriptOperator< T >::value > struct VectorAddition{}; /** @@ -60,7 +60,7 @@ struct VectorAddition{}; */ template< typename Vector, typename T, - bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > + bool hasSubscriptOperator = detail::HasSubscriptOperator< T >::value > struct VectorSubtraction{}; /** @@ -68,7 +68,7 @@ struct VectorSubtraction{}; */ template< typename Vector, typename T, - bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > + bool hasSubscriptOperator = detail::HasSubscriptOperator< T >::value > struct VectorMultiplication{}; /** @@ -76,7 +76,7 @@ struct VectorMultiplication{}; */ template< typename Vector, typename T, - bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > + bool hasSubscriptOperator = detail::HasSubscriptOperator< T >::value > struct VectorDivision{}; /** @@ -97,7 +97,7 @@ struct VectorAssignment< Vector, T, true > TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t[ i ]; - }; + } static void assign( Vector& v, const T& t ) { @@ -111,9 +111,8 @@ struct VectorAssignment< Vector, T, true > { data[ i ] = t[ i ]; }; - ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), ass ); - TNL_CHECK_CUDA_DEVICE; - }; + ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), ass ); + } }; /** @@ -126,7 +125,7 @@ struct VectorAssignment< Vector, T, false > { static void resize( Vector& v, const T& t ) { - }; + } __cuda_callable__ static void assignStatic( Vector& v, const T& t ) @@ -134,7 +133,7 @@ struct VectorAssignment< Vector, T, false > TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t; - }; + } static void assign( Vector& v, const T& t ) { @@ -148,7 +147,6 @@ struct VectorAssignment< Vector, T, false > data[ i ] = t; }; ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), ass ); - TNL_CHECK_CUDA_DEVICE; } }; @@ -165,7 +163,7 @@ struct VectorAddition< Vector, T, true > TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] += t[ i ]; - }; + } static void addition( Vector& v, const T& t ) { @@ -179,9 +177,8 @@ struct VectorAddition< Vector, T, true > { data[ i ] += t[ i ]; }; - ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), add ); - TNL_CHECK_CUDA_DEVICE; - }; + ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), add ); + } }; /** @@ -198,7 +195,7 @@ struct VectorAddition< Vector, T, false > TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] += t; - }; + } static void addition( Vector& v, const T& t ) { @@ -212,7 +209,6 @@ struct VectorAddition< Vector, T, false > data[ i ] += t; }; ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), add ); - TNL_CHECK_CUDA_DEVICE; } }; @@ -229,7 +225,7 @@ struct VectorSubtraction< Vector, T, true > TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] -= t[ i ]; - }; + } static void subtraction( Vector& v, const T& t ) { @@ -243,9 +239,8 @@ struct VectorSubtraction< Vector, T, true > { data[ i ] -= t[ i ]; }; - ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), subtract ); - TNL_CHECK_CUDA_DEVICE; - }; + ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), subtract ); + } }; /** @@ -262,7 +257,7 @@ struct VectorSubtraction< Vector, T, false > TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] -= t; - }; + } static void subtraction( Vector& v, const T& t ) { @@ -276,7 +271,6 @@ struct VectorSubtraction< Vector, T, false > data[ i ] -= t; }; ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), subtract ); - TNL_CHECK_CUDA_DEVICE; } }; @@ -293,7 +287,7 @@ struct VectorMultiplication< Vector, T, true > TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] *= t[ i ]; - }; + } static void multiplication( Vector& v, const T& t ) { @@ -307,9 +301,8 @@ struct VectorMultiplication< Vector, T, true > { data[ i ] *= t[ i ]; }; - ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), multiply ); - TNL_CHECK_CUDA_DEVICE; - }; + ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), multiply ); + } }; /** @@ -326,7 +319,7 @@ struct VectorMultiplication< Vector, T, false > TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] *= t; - }; + } static void multiplication( Vector& v, const T& t ) { @@ -340,7 +333,6 @@ struct VectorMultiplication< Vector, T, false > data[ i ] *= t; }; ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), multiply ); - TNL_CHECK_CUDA_DEVICE; } }; @@ -358,7 +350,7 @@ struct VectorDivision< Vector, T, true > TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] /= t[ i ]; - }; + } static void division( Vector& v, const T& t ) { @@ -372,9 +364,8 @@ struct VectorDivision< Vector, T, true > { data[ i ] /= t[ i ]; }; - ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), divide ); - TNL_CHECK_CUDA_DEVICE; - }; + ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), divide ); + } }; /** @@ -391,7 +382,7 @@ struct VectorDivision< Vector, T, false > TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] /= t; - }; + } static void division( Vector& v, const T& t ) { @@ -405,7 +396,6 @@ struct VectorDivision< Vector, T, false > data[ i ] /= t; }; ParallelFor< DeviceType >::exec( ( IndexType ) 0, v.getSize(), divide ); - TNL_CHECK_CUDA_DEVICE; } }; diff --git a/src/TNL/Containers/Vector.h b/src/TNL/Containers/Vector.h index dbce6fb808de38135a7493de7ee5dbbb443f1beb..b0545a632423e6722980eb3c1c9e7ddfafdfc2b7 100644 --- a/src/TNL/Containers/Vector.h +++ b/src/TNL/Containers/Vector.h @@ -11,14 +11,11 @@ #pragma once #include <TNL/Containers/Array.h> -#include <TNL/Containers/Algorithms/PrefixSumType.h> +#include <TNL/Containers/VectorView.h> namespace TNL { namespace Containers { -template< typename Real, typename Device, typename Index > -class VectorView; - /** * \brief This class extends TNL::Array with algebraic operations. * @@ -119,13 +116,13 @@ public: const Scalar thisElementMultiplicator ); template< typename Real_, typename Device_, typename Index_ > - Vector& operator = ( const Vector< Real_, Device_, Index_ >& v ); + Vector& operator=( const Vector< Real_, Device_, Index_ >& v ); template< typename Real_, typename Device_, typename Index_ > - Vector& operator = ( const VectorView< Real_, Device_, Index_ >& v ); + Vector& operator=( const VectorView< Real_, Device_, Index_ >& v ); template< typename VectorExpression > - Vector& operator = ( const VectorExpression& expression ); + Vector& operator=( const VectorExpression& expression ); /** * \brief This function subtracts \e vector from this vector and returns the resulting vector. @@ -134,7 +131,7 @@ public: * \param vector Reference to another vector. */ template< typename VectorExpression > - Vector& operator -= ( const VectorExpression& expression ); + Vector& operator-=( const VectorExpression& expression ); /** * \brief This function adds \e vector to this vector and returns the resulting vector. @@ -143,7 +140,7 @@ public: * \param vector Reference to another vector. */ template< typename VectorExpression > - Vector& operator += ( const VectorExpression& expression ); + Vector& operator+=( const VectorExpression& expression ); /** * \brief This function multiplies this vector by \e c and returns the resulting vector. @@ -152,7 +149,7 @@ public: * \param c Multiplicator. */ template< typename VectorExpression > - Vector& operator *= ( const VectorExpression& expression ); + Vector& operator*=( const VectorExpression& expression ); /** * \brief This function divides this vector by \e c and returns the resulting vector. @@ -161,7 +158,7 @@ public: * \param c Divisor. */ template< typename VectorExpression > - Vector& operator /= ( const VectorExpression& expression ); + Vector& operator/=( const VectorExpression& expression ); /** * \brief Scalar product @@ -169,7 +166,7 @@ public: * @return */ template< typename Vector_ > - Real operator, ( const Vector_& v ) const; + Real operator,( const Vector_& v ) const; /** * \brief Returns the maximum value out of all vector elements. diff --git a/src/TNL/Containers/Vector.hpp b/src/TNL/Containers/Vector.hpp index 478928dcad4c1b486dd731f9a07707f210f0c67f..eca2eba9640c2e25afd98ae64fa826cdc6af1a8f 100644 --- a/src/TNL/Containers/Vector.hpp +++ b/src/TNL/Containers/Vector.hpp @@ -11,8 +11,6 @@ #pragma once #include <TNL/Containers/Vector.h> -#include <TNL/Containers/Algorithms/VectorOperations.h> -#include <TNL/Containers/VectorView.h> namespace TNL { namespace Containers { @@ -111,9 +109,9 @@ template< typename Real, typename Index > template< typename VectorExpression > Vector< Real, Device, Index >& -Vector< Real, Device, Index >::operator = ( const VectorExpression& expression ) +Vector< Real, Device, Index >::operator=( const VectorExpression& expression ) { - Algorithms::VectorAssignment< Vector< Real, Device, Index >, VectorExpression >::assign( *this, expression ); + Algorithms::VectorAssignment< Vector, VectorExpression >::assign( *this, expression ); return *this; } @@ -122,7 +120,7 @@ template< typename Real, typename Index > template< typename Real_, typename Device_, typename Index_ > Vector< Real, Device, Index >& -Vector< Real, Device, Index >::operator = ( const Vector< Real_, Device_, Index_ >& vector ) +Vector< Real, Device, Index >::operator=( const Vector< Real_, Device_, Index_ >& vector ) { Array< Real, Device, Index >::operator=( vector ); return *this; @@ -133,7 +131,7 @@ template< typename Real, typename Index > template< typename Real_, typename Device_, typename Index_ > Vector< Real, Device, Index >& -Vector< Real, Device, Index >::operator = ( const VectorView< Real_, Device_, Index_ >& view ) +Vector< Real, Device, Index >::operator=( const VectorView< Real_, Device_, Index_ >& view ) { Array< Real, Device, Index >::operator=( view ); return *this; @@ -148,7 +146,7 @@ Vector< Real, Device, Index >:: operator-=( const VectorExpression& expression ) { //addVector( vector, -1.0 ); - Algorithms::VectorSubtraction< Vector< Real, Device, Index >, VectorExpression >::subtraction( *this, expression ); + Algorithms::VectorSubtraction< Vector, VectorExpression >::subtraction( *this, expression ); return *this; } @@ -161,7 +159,7 @@ Vector< Real, Device, Index >:: operator+=( const VectorExpression& expression ) { //addVector( vector ); - Algorithms::VectorAddition< Vector< Real, Device, Index >, VectorExpression >::addition( *this, expression ); + Algorithms::VectorAddition< Vector, VectorExpression >::addition( *this, expression ); return *this; } @@ -174,7 +172,7 @@ Vector< Real, Device, Index >:: operator*=( const VectorExpression& expression ) { //Algorithms::VectorOperations< Device >::vectorScalarMultiplication( *this, c ); - Algorithms::VectorMultiplication< Vector< Real, Device, Index >, VectorExpression >::multiplication( *this, expression ); + Algorithms::VectorMultiplication< Vector, VectorExpression >::multiplication( *this, expression ); return *this; } @@ -187,7 +185,7 @@ Vector< Real, Device, Index >:: operator/=( const VectorExpression& expression ) { //Algorithms::VectorOperations< Device >::vectorScalarMultiplication( *this, 1.0 / c ); - Algorithms::VectorDivision< Vector< Real, Device, Index >, VectorExpression >::division( *this, expression ); + Algorithms::VectorDivision< Vector, VectorExpression >::division( *this, expression ); return *this; } diff --git a/src/TNL/Containers/VectorView.h b/src/TNL/Containers/VectorView.h index b552d1b46de67ca562c697305a2cb009f5bf30d2..7c627d334b1217506c3a95230d7a8f677f5fd803 100644 --- a/src/TNL/Containers/VectorView.h +++ b/src/TNL/Containers/VectorView.h @@ -139,7 +139,7 @@ public: * @return */ template< typename Vector_ > - NonConstReal operator, ( const Vector_& v ) const; + NonConstReal operator,( const Vector_& v ) const; NonConstReal max() const; diff --git a/src/TNL/Containers/VectorView.hpp b/src/TNL/Containers/VectorView.hpp index 83547a022b4ab118b641033eae31287bbdef827a..7c7fe5a96280e4b9fcf7609b95d69070e4e54ac8 100644 --- a/src/TNL/Containers/VectorView.hpp +++ b/src/TNL/Containers/VectorView.hpp @@ -129,7 +129,7 @@ template< typename Real, VectorView< Real, Device, Index >& VectorView< Real, Device, Index >::operator=( const VectorExpression& expression ) { - Algorithms::VectorAssignment< VectorView< Real, Device, Index >, VectorExpression >::assign( *this, expression ); + Algorithms::VectorAssignment< VectorView, VectorExpression >::assign( *this, expression ); return *this; } @@ -141,7 +141,7 @@ VectorView< Real, Device, Index >& VectorView< Real, Device, Index >:: operator-=( const VectorExpression& expression ) { - Algorithms::VectorSubtraction< VectorView< Real, Device, Index >, VectorExpression >::subtraction( *this, expression ); + Algorithms::VectorSubtraction< VectorView, VectorExpression >::subtraction( *this, expression ); return *this; } @@ -153,7 +153,7 @@ VectorView< Real, Device, Index >& VectorView< Real, Device, Index >:: operator+=( const VectorExpression& expression ) { - Algorithms::VectorAddition< VectorView< Real, Device, Index >, VectorExpression >::addition( *this, expression ); + Algorithms::VectorAddition< VectorView, VectorExpression >::addition( *this, expression ); return *this; } @@ -165,7 +165,7 @@ VectorView< Real, Device, Index >& VectorView< Real, Device, Index >:: operator*=( const VectorExpression& expression ) { - Algorithms::VectorMultiplication< VectorView< Real, Device, Index >, VectorExpression >::multiplication( *this, expression ); + Algorithms::VectorMultiplication< VectorView, VectorExpression >::multiplication( *this, expression ); return *this; } @@ -177,32 +177,10 @@ VectorView< Real, Device, Index >& VectorView< Real, Device, Index >:: operator/=( const VectorExpression& expression ) { - Algorithms::VectorDivision< VectorView< Real, Device, Index >, VectorExpression >::division( *this, expression ); + Algorithms::VectorDivision< VectorView, VectorExpression >::division( *this, expression ); return *this; } -/*template< typename Real, - typename Device, - typename Index > - template< typename Real_, typename Device_, typename Index_ > -bool -VectorView< Real, Device, Index >:: -operator==( const VectorView< Real_, Device_, Index_ >& v ) const -{ - return ArrayView< Real, Device, Index >::operator ==( v ); -} - -template< typename Real, - typename Device, - typename Index > - template< typename Real_, typename Device_, typename Index_ > -bool -VectorView< Real, Device, Index >:: -operator!=( const VectorView< Real_, Device_, Index_ >& v ) const -{ - return !ArrayView< Real, Device, Index >::operator ==( v ); -}*/ - template< typename Real, typename Device, typename Index > diff --git a/src/UnitTests/Containers/StaticVectorTest.cpp b/src/UnitTests/Containers/StaticVectorTest.cpp index 4788a823de391792ac35bb78dec1122f0d5b2e2b..2282118433745154af7425c59b88b56fed6bfa42 100644 --- a/src/UnitTests/Containers/StaticVectorTest.cpp +++ b/src/UnitTests/Containers/StaticVectorTest.cpp @@ -94,7 +94,7 @@ TYPED_TEST( StaticVectorTest, operators ) using VectorType = typename TestFixture::VectorType; constexpr int size = VectorType::size; - static_assert( Algorithms::Details::HasSubscriptOperator< VectorType >::value, "Subscript operator detection by SFINAE does not work for StaticVector." ); + static_assert( Algorithms::detail::HasSubscriptOperator< VectorType >::value, "Subscript operator detection by SFINAE does not work for StaticVector." ); VectorType u1( 1 ), u2( 2 ), u3( 3 ); diff --git a/src/UnitTests/Containers/VectorTest-1.h b/src/UnitTests/Containers/VectorTest-1.h index c1a29f7895a1c38677c6f2a0e52d03f42dc9617d..e3746ffee5782ec3d568d439f1da37f8ce0b0f30 100644 --- a/src/UnitTests/Containers/VectorTest-1.h +++ b/src/UnitTests/Containers/VectorTest-1.h @@ -99,8 +99,8 @@ TEST( VectorSpecialCasesTest, assignmentThroughView ) using VectorType = Containers::Vector< int, Devices::Host >; using ViewType = VectorView< int, Devices::Host >; - static_assert( Algorithms::Details::HasSubscriptOperator< VectorType >::value, "Subscript operator detection by SFINAE does not work for Vector." ); - static_assert( Algorithms::Details::HasSubscriptOperator< ViewType >::value, "Subscript operator detection by SFINAE does not work for VectorView." ); + static_assert( Algorithms::detail::HasSubscriptOperator< VectorType >::value, "Subscript operator detection by SFINAE does not work for Vector." ); + static_assert( Algorithms::detail::HasSubscriptOperator< ViewType >::value, "Subscript operator detection by SFINAE does not work for VectorView." ); VectorType u( 100 ), v( 100 ); ViewType u_view( u ), v_view( v );