diff --git a/src/TNL/Containers/Expressions/Comparison.h b/src/TNL/Containers/Expressions/Comparison.h index afa346281404fcfeee4134245790862d853a32ee..3b2fa0c1a72831815c9a3bf106cb256bc688d136 100644 --- a/src/TNL/Containers/Expressions/Comparison.h +++ b/src/TNL/Containers/Expressions/Comparison.h @@ -69,9 +69,17 @@ struct Comparison< T1, T2, VectorVariable, VectorVariable > return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } - static bool LE( const T1& a, const T2& b ) + static bool GE( const T1& a, const T2& b ) { - return ! GT( a, b ); + TNL_ASSERT_EQ( a.getSize(), b.getSize(), "Sizes of expressions to be compared do not fit." ); + + using DeviceType = typename T1::DeviceType; + using IndexType = typename T1::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a[ i ] >= b[ i ] ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } static bool LT( const T1& a, const T2& b ) @@ -87,9 +95,17 @@ struct Comparison< T1, T2, VectorVariable, VectorVariable > return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } - static bool GE( const T1& a, const T2& b ) + static bool LE( const T1& a, const T2& b ) { - return ! LT( a, b ); + TNL_ASSERT_EQ( a.getSize(), b.getSize(), "Sizes of expressions to be compared do not fit." ); + + using DeviceType = typename T1::DeviceType; + using IndexType = typename T1::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a[ i ] <= b[ i ] ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } }; @@ -119,34 +135,46 @@ struct Comparison< T1, T2, ArithmeticVariable, VectorVariable > static bool GT( const T1& a, const T2& b ) { - using DeviceType = typename T1::DeviceType; - using IndexType = typename T1::IndexType; + using DeviceType = typename T2::DeviceType; + using IndexType = typename T2::IndexType; auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a > b[ i ] ); }; auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; - return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); + return Algorithms::Reduction< DeviceType >::reduce( b.getSize(), reduction, volatileReduction, fetch, true ); } - static bool LE( const T1& a, const T2& b ) + static bool GE( const T1& a, const T2& b ) { - return ! GT( a, b ); + using DeviceType = typename T2::DeviceType; + using IndexType = typename T2::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a >= b[ i ] ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( b.getSize(), reduction, volatileReduction, fetch, true ); } static bool LT( const T1& a, const T2& b ) { - using DeviceType = typename T1::DeviceType; - using IndexType = typename T1::IndexType; + using DeviceType = typename T2::DeviceType; + using IndexType = typename T2::IndexType; auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a < b[ i ] ); }; auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; - return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); + return Algorithms::Reduction< DeviceType >::reduce( b.getSize(), reduction, volatileReduction, fetch, true ); } - static bool GE( const T1& a, const T2& b ) + static bool LE( const T1& a, const T2& b ) { - return ! LT( a, b ); + using DeviceType = typename T2::DeviceType; + using IndexType = typename T2::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a <= b[ i ] ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( b.getSize(), reduction, volatileReduction, fetch, true ); } }; @@ -185,9 +213,15 @@ struct Comparison< T1, T2, VectorVariable, ArithmeticVariable > return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } - static bool LE( const T1& a, const T2& b ) + static bool GE( const T1& a, const T2& b ) { - return ! GT( a, b ); + using DeviceType = typename T1::DeviceType; + using IndexType = typename T1::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a[ i ] >= b ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } static bool LT( const T1& a, const T2& b ) @@ -201,9 +235,15 @@ struct Comparison< T1, T2, VectorVariable, ArithmeticVariable > return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } - static bool GE( const T1& a, const T2& b ) + static bool LE( const T1& a, const T2& b ) { - return ! LT( a, b ); + using DeviceType = typename T1::DeviceType; + using IndexType = typename T1::IndexType; + + auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( a[ i ] <= b ); }; + auto reduction = [=] __cuda_callable__ ( bool& a, const bool& b ) { a &= b; }; + auto volatileReduction = [=] __cuda_callable__ ( volatile bool& a, volatile bool& b ) { a &= b; }; + return Algorithms::Reduction< DeviceType >::reduce( a.getSize(), reduction, volatileReduction, fetch, true ); } }; diff --git a/src/UnitTests/Containers/StaticVectorTest.cpp b/src/UnitTests/Containers/StaticVectorTest.cpp index 98236ae653e694b480690934807a9e72470300d6..78f53c7cca2e1b546bc062d701341ae6b2b92352 100644 --- a/src/UnitTests/Containers/StaticVectorTest.cpp +++ b/src/UnitTests/Containers/StaticVectorTest.cpp @@ -581,18 +581,18 @@ TYPED_TEST( StaticVectorTest, comparisonOperators ) v = 2.0; w = 4.0; - EXPECT_EQ( u, u ); - EXPECT_EQ( u, 1.0 ); + EXPECT_TRUE( u == u ); + EXPECT_TRUE( u == 1.0 ); EXPECT_TRUE( 1.0 == u ); - EXPECT_EQ( w, v + v ); - EXPECT_EQ( v + v, w ); + EXPECT_TRUE( w == v + v ); + EXPECT_TRUE( v + v == w ); EXPECT_TRUE( abs( w ) == v + v ); EXPECT_TRUE( v + v == abs( w ) ); - EXPECT_NE( u, v ); - EXPECT_NE( u, 2.0 ); + EXPECT_TRUE( u != v ); + EXPECT_TRUE( u != 2.0 ); EXPECT_TRUE( 2.0 != u ); - EXPECT_NE( u, w + w ); + EXPECT_TRUE( u != w + w ); EXPECT_TRUE( w + v != u ); EXPECT_TRUE( abs( w ) != abs( u ) ); EXPECT_TRUE( ( w + v ) != ( u + v ) ); diff --git a/src/UnitTests/Containers/VectorTest-1.h b/src/UnitTests/Containers/VectorTest-1.h index dbd5c928a7ad76bfe1c70805bac7616638711985..3ed15784c81caa8fc5d6cc5d9c73c803f55a2f04 100644 --- a/src/UnitTests/Containers/VectorTest-1.h +++ b/src/UnitTests/Containers/VectorTest-1.h @@ -326,18 +326,18 @@ TYPED_TEST( VectorTest, comparison ) w = 4.0; // Test with Vectors - EXPECT_EQ( _u, _u ); - EXPECT_EQ( _u, 1.0 ); + EXPECT_TRUE( _u == _u ); + EXPECT_TRUE( _u == 1.0 ); EXPECT_TRUE( 1.0 == _u ); - EXPECT_EQ( _w, _v + _v ); + EXPECT_TRUE( _w == _v + _v ); EXPECT_TRUE( _v + _v == _w ); EXPECT_TRUE( abs( _w ) == _v + _v ); EXPECT_TRUE( _v + _v == abs( _w ) ); - EXPECT_NE( _u, _v ); - EXPECT_NE( _u, 2.0 ); + EXPECT_TRUE( _u != _v ); + EXPECT_TRUE( _u != 2.0 ); EXPECT_TRUE( 2.0 != _u ); - EXPECT_NE( _u, _w + _w ); + EXPECT_TRUE( _u != _w + _w ); EXPECT_TRUE( _w + _v != _u ); EXPECT_TRUE( abs( _w ) != abs( _u ) ); EXPECT_TRUE( ( _w + _v ) != ( _u + _v ) ); @@ -372,18 +372,18 @@ TYPED_TEST( VectorTest, comparison ) EXPECT_GT( _v + _w, abs( _u ) ); // Test with VectorViews - EXPECT_EQ( u, u ); - EXPECT_EQ( u, 1.0 ); + EXPECT_TRUE( u == u ); + EXPECT_TRUE( u == 1.0 ); EXPECT_TRUE( 1.0 == u ); - EXPECT_EQ( w, v + v ); - EXPECT_EQ( v + v, w ); + EXPECT_TRUE( w == v + v ); + EXPECT_TRUE( v + v == w ); EXPECT_TRUE( abs( w ) == v + v ); EXPECT_TRUE( v + v == abs( w ) ); - EXPECT_NE( u, v ); - EXPECT_NE( u, 2.0 ); + EXPECT_TRUE( u != v ); + EXPECT_TRUE( u != 2.0 ); EXPECT_TRUE( 2.0 != u ); - EXPECT_NE( u, w + w ); + EXPECT_TRUE( u != w + w ); EXPECT_TRUE( w + v != u ); EXPECT_TRUE( abs( w ) != abs( u ) ); EXPECT_TRUE( ( w + v ) != ( u + v ) );