From 20c656ffa3f30b6050836eb68e85118a80c2e94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Tue, 9 Jul 2019 14:09:34 +0200 Subject: [PATCH] Fixed handling of begin and end parameters in prefix sum methods --- .../Algorithms/VectorOperationsMIC_impl.h | 2 ++ src/TNL/Containers/Vector.h | 8 +++--- src/TNL/Containers/Vector.hpp | 23 +++++++--------- src/TNL/Containers/VectorView.h | 12 ++++----- src/TNL/Containers/VectorView.hpp | 26 +++++++++---------- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/TNL/Containers/Algorithms/VectorOperationsMIC_impl.h b/src/TNL/Containers/Algorithms/VectorOperationsMIC_impl.h index 37aa369f35..7f936c52cc 100644 --- a/src/TNL/Containers/Algorithms/VectorOperationsMIC_impl.h +++ b/src/TNL/Containers/Algorithms/VectorOperationsMIC_impl.h @@ -606,6 +606,7 @@ addVectors( Vector1& v, } } +/* template< typename Vector > void VectorOperations< Devices::MIC >:: @@ -661,6 +662,7 @@ computeExclusivePrefixSum( Vector& v, } } } +*/ } // namespace Algorithms } // namespace Containers diff --git a/src/TNL/Containers/Vector.h b/src/TNL/Containers/Vector.h index b0545a6324..1d59face2f 100644 --- a/src/TNL/Containers/Vector.h +++ b/src/TNL/Containers/Vector.h @@ -310,20 +310,20 @@ public: * \param end Index of the element in this vector which to end with. */ template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive > - void prefixSum( const IndexType begin = 0, const IndexType end = 0 ); + void prefixSum( IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename FlagsArray > - void segmentedPrefixSum( FlagsArray& flags, const IndexType begin = 0, const IndexType end = 0 ); + void segmentedPrefixSum( FlagsArray& flags, IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename VectorExpression > - void prefixSum( const VectorExpression& expression, const IndexType begin = 0, const IndexType end = 0 ); + void prefixSum( const VectorExpression& expression, IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename VectorExpression, typename FlagsArray > - void segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, const IndexType begin = 0, const IndexType end = 0 ); + void segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, IndexType begin = 0, IndexType end = 0 ); }; } // namespace Containers diff --git a/src/TNL/Containers/Vector.hpp b/src/TNL/Containers/Vector.hpp index 855e3296f4..b436983c95 100644 --- a/src/TNL/Containers/Vector.hpp +++ b/src/TNL/Containers/Vector.hpp @@ -362,12 +362,11 @@ template< typename Real, template< Algorithms::PrefixSumType Type > void Vector< Real, Device, Index >:: -prefixSum( const IndexType begin, const IndexType end ) +prefixSum( IndexType begin, IndexType end ) { - if( begin == 0 && end == 0 ) - Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, 0, this->getSize() ); - else - Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, begin, end ); + if( end == 0 ) + end = this->getSize(); + Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, begin, end ); } template< typename Real, @@ -377,13 +376,11 @@ template< typename Real, typename FlagsArray > void Vector< Real, Device, Index >:: -segmentedPrefixSum( FlagsArray& flags, const IndexType begin, const IndexType end ) +segmentedPrefixSum( FlagsArray& flags, IndexType begin, IndexType end ) { - if( begin == 0 && end == 0 ) - Algorithms::VectorOperations< Device >::template segmentedPrefixSum< Type >( *this, flags, 0, this->getSize() ); - else - Algorithms::VectorOperations< Device >::template SegmentedPrefixSum< Type >( *this, flags, begin, end ); - + if( end == 0 ) + end = this->getSize(); + Algorithms::VectorOperations< Device >::template segmentedPrefixSum< Type >( *this, flags, begin, end ); } template< typename Real, @@ -393,7 +390,7 @@ template< typename Real, typename VectorExpression > void Vector< Real, Device, Index >:: -prefixSum( const VectorExpression& expression, const IndexType begin, const IndexType end ) +prefixSum( const VectorExpression& expression, IndexType begin, IndexType end ) { throw Exceptions::NotImplementedError( "Prefix sum with vector expressions is not implemented." ); } @@ -406,7 +403,7 @@ template< typename Real, typename FlagsArray > void Vector< Real, Device, Index >:: -segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, const IndexType begin, const IndexType end ) +segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, IndexType begin, IndexType end ) { throw Exceptions::NotImplementedError( "Prefix sum with vector expressions is not implemented." ); } diff --git a/src/TNL/Containers/VectorView.h b/src/TNL/Containers/VectorView.h index 7c627d334b..85fdf4dae5 100644 --- a/src/TNL/Containers/VectorView.h +++ b/src/TNL/Containers/VectorView.h @@ -80,7 +80,7 @@ public: * however, replaced with the VectorView size. */ __cuda_callable__ - ViewType getView( const IndexType begin = 0, IndexType end = 0 ); + ViewType getView( IndexType begin = 0, IndexType end = 0 ); /** * \brief Returns a non-modifiable view of the vector view. @@ -93,7 +93,7 @@ public: * however, replaced with the VectorView size. */ __cuda_callable__ - ConstViewType getConstView( const IndexType begin = 0, IndexType end = 0 ) const; + ConstViewType getConstView( IndexType begin = 0, IndexType end = 0 ) const; static String getType(); @@ -197,20 +197,20 @@ public: Scalar3 thisMultiplicator = 1.0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive > - void prefixSum( const IndexType begin = 0, const IndexType end = 0 ); + void prefixSum( IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename FlagsArray > - void segmentedPrefixSum( FlagsArray& flags, const IndexType begin = 0, const IndexType end = 0 ); + void segmentedPrefixSum( FlagsArray& flags, IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename VectorExpression > - void prefixSum( const VectorExpression& expression, const IndexType begin = 0, const IndexType end = 0 ); + void prefixSum( const VectorExpression& expression, IndexType begin = 0, IndexType end = 0 ); template< Algorithms::PrefixSumType Type = Algorithms::PrefixSumType::Inclusive, typename VectorExpression, typename FlagsArray > - void segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, const IndexType begin = 0, const IndexType end = 0 ); + void segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, IndexType begin = 0, IndexType end = 0 ); }; } // namespace Containers diff --git a/src/TNL/Containers/VectorView.hpp b/src/TNL/Containers/VectorView.hpp index a0142d5969..57c1cc2ec5 100644 --- a/src/TNL/Containers/VectorView.hpp +++ b/src/TNL/Containers/VectorView.hpp @@ -47,7 +47,7 @@ template< typename Real, __cuda_callable__ typename VectorView< Real, Device, Index >::ViewType VectorView< Real, Device, Index >:: -getView( const IndexType begin, IndexType end ) +getView( IndexType begin, IndexType end ) { if( end == 0 ) end = this->getSize(); @@ -60,7 +60,7 @@ template< typename Real, __cuda_callable__ typename VectorView< Real, Device, Index >::ConstViewType VectorView< Real, Device, Index >:: -getConstView( const IndexType begin, IndexType end ) const +getConstView( IndexType begin, IndexType end ) const { if( end == 0 ) end = this->getSize(); @@ -380,12 +380,11 @@ template< typename Real, template< Algorithms::PrefixSumType Type > void VectorView< Real, Device, Index >:: -prefixSum( const IndexType begin, const IndexType end ) +prefixSum( IndexType begin, IndexType end ) { - if( begin == 0 && end == 0 ) - Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, 0, this->getSize() ); - else - Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, begin, end ); + if( end == 0 ) + end = this->getSize(); + Algorithms::VectorOperations< Device >::template prefixSum< Type >( *this, begin, end ); } template< typename Real, @@ -395,12 +394,11 @@ template< typename Real, typename FlagsArray > void VectorView< Real, Device, Index >:: -segmentedPrefixSum( FlagsArray& flags, const IndexType begin, const IndexType end ) +segmentedPrefixSum( FlagsArray& flags, IndexType begin, IndexType end ) { - if( begin == 0 && end == 0 ) - Algorithms::VectorOperations< Device >::template segmentedPrefixSum< Type >( *this, flags, 0, this->getSize() ); - else - Algorithms::VectorOperations< Device >::template segmentedPrefixSum< Type >( *this, flags, begin, end ); + if( end == 0 ) + end = this->getSize(); + Algorithms::VectorOperations< Device >::template segmentedPrefixSum< Type >( *this, flags, begin, end ); } template< typename Real, @@ -410,7 +408,7 @@ template< typename Real, typename VectorExpression > void VectorView< Real, Device, Index >:: -prefixSum( const VectorExpression& expression, const IndexType begin, const IndexType end ) +prefixSum( const VectorExpression& expression, IndexType begin, IndexType end ) { throw Exceptions::NotImplementedError( "Prefix sum with vector expressions is not implemented." ); } @@ -423,7 +421,7 @@ template< typename Real, typename FlagsArray > void VectorView< Real, Device, Index >:: -segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, const IndexType begin, const IndexType end ) +segmentedPrefixSum( const VectorExpression& expression, FlagsArray& flags, IndexType begin, IndexType end ) { throw Exceptions::NotImplementedError( "Prefix sum with vector expressions is not implemented." ); } -- GitLab