Skip to content
Snippets Groups Projects
Commit d9d17ce8 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Another expression templates fixes.

parent 71202bc9
No related branches found
No related tags found
1 merge request!34Runge kutta
......@@ -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 );
}
};
......
......@@ -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 ) );
......
......@@ -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 ) );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment