Commit 56c21012 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added more static asserts to expression templates

parent d37e5540
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -65,10 +65,12 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionV
                                                        typename T2::ConstLocalViewType,
                                                        Operation >;

   static_assert( HasEnabledDistributedExpressionTemplates< T1 >::value,
                  "Invalid operand in distributed binary expression templates - distributed expression templates are not enabled for the left operand." );
   static_assert( HasEnabledDistributedExpressionTemplates< T2 >::value,
                  "Invalid operand in distributed binary expression templates - distributed expression templates are not enabled for the right operand." );
   static_assert( std::is_same< typename T1::DeviceType, typename T2::DeviceType >::value,
                  "Attempt to mix operands which have different DeviceType." );
   static_assert( IsStaticArrayType< T1 >::value == IsStaticArrayType< T2 >::value,
                  "Attempt to mix static and non-static operands in binary expression templates." );

   DistributedBinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a ), op2( b )
@@ -131,6 +133,9 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionV
   using LocalRangeType = typename T1::LocalRangeType;
   using ConstLocalViewType = BinaryExpressionTemplate< typename T1::ConstLocalViewType, T2, Operation >;

   static_assert( HasEnabledDistributedExpressionTemplates< T1 >::value,
                  "Invalid operand in distributed binary expression templates - distributed expression templates are not enabled for the left operand." );

   DistributedBinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a ), op2( b ) {}

@@ -184,6 +189,9 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariabl
   using LocalRangeType = typename T2::LocalRangeType;
   using ConstLocalViewType = BinaryExpressionTemplate< T1, typename T2::ConstLocalViewType, Operation >;

   static_assert( HasEnabledDistributedExpressionTemplates< T2 >::value,
                  "Invalid operand in distributed binary expression templates - distributed expression templates are not enabled for the right operand." );

   DistributedBinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a ), op2( b ) {}

@@ -238,6 +246,9 @@ struct DistributedUnaryExpressionTemplate
   using LocalRangeType = typename T1::LocalRangeType;
   using ConstLocalViewType = UnaryExpressionTemplate< typename T1::ConstLocalViewType, Operation >;

   static_assert( HasEnabledDistributedExpressionTemplates< T1 >::value,
                  "Invalid operand in distributed unary expression templates - distributed expression templates are not enabled for the operand." );

   DistributedUnaryExpressionTemplate( const T1& a )
   : operand( a ) {}

+13 −2
Original line number Diff line number Diff line
@@ -63,10 +63,12 @@ struct BinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, Ve
   using IndexType = typename T1::IndexType;
   using ConstViewType = BinaryExpressionTemplate;

   static_assert( HasEnabledExpressionTemplates< T1 >::value,
                  "Invalid operand in binary expression templates - expression templates are not enabled for the left operand." );
   static_assert( HasEnabledExpressionTemplates< T2 >::value,
                  "Invalid operand in binary expression templates - expression templates are not enabled for the right operand." );
   static_assert( std::is_same< typename T1::DeviceType, typename T2::DeviceType >::value,
                  "Attempt to mix operands which have different DeviceType." );
   static_assert( IsStaticArrayType< T1 >::value == IsStaticArrayType< T2 >::value,
                  "Attempt to mix static and non-static operands in binary expression templates." );

   BinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a.getConstView() ), op2( b.getConstView() )
@@ -112,6 +114,9 @@ struct BinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, Ar
   using IndexType = typename T1::IndexType;
   using ConstViewType = BinaryExpressionTemplate;

   static_assert( HasEnabledExpressionTemplates< T1 >::value,
                  "Invalid operand in binary expression templates - expression templates are not enabled for the left operand." );

   BinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a.getConstView() ), op2( b ) {}

@@ -152,6 +157,9 @@ struct BinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorEx
   using IndexType = typename T2::IndexType;
   using ConstViewType = BinaryExpressionTemplate;

   static_assert( HasEnabledExpressionTemplates< T2 >::value,
                  "Invalid operand in binary expression templates - expression templates are not enabled for the right operand." );

   BinaryExpressionTemplate( const T1& a, const T2& b )
   : op1( a ), op2( b.getConstView() ) {}

@@ -193,6 +201,9 @@ struct UnaryExpressionTemplate
   using IndexType = typename T1::IndexType;
   using ConstViewType = UnaryExpressionTemplate;

   static_assert( HasEnabledExpressionTemplates< T1 >::value,
                  "Invalid operand in unary expression templates - expression templates are not enabled for the operand." );

   UnaryExpressionTemplate( const T1& a )
   : operand( a.getConstView() ) {}

+19 −6
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ struct StaticBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariab
                  "Left-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( IsStaticArrayType< T2 >::value,
                  "Right-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( HasEnabledStaticExpressionTemplates< T1 >::value,
                  "Invalid operand in static binary expression templates - static expression templates are not enabled for the left operand." );
   static_assert( HasEnabledStaticExpressionTemplates< T2 >::value,
                  "Invalid operand in static binary expression templates - static expression templates are not enabled for the right operand." );
   static_assert( T1::getSize() == T2::getSize(),
                  "Attempt to mix static operands with different sizes." );

@@ -108,12 +112,14 @@ template< typename T1,
          typename Operation >
struct StaticBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, ArithmeticVariable  >
{
   static_assert( IsStaticArrayType< T1 >::value,
                  "Left-hand side operand of static expression is not static, i.e. based on static vector." );

   using VectorOperandType = T1;
   using RealType = decltype( Operation::evaluate( std::declval<T1>()[0], std::declval<T2>() ) );

   static_assert( IsStaticArrayType< T1 >::value,
                  "Left-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( HasEnabledStaticExpressionTemplates< T1 >::value,
                  "Invalid operand in static binary expression templates - static expression templates are not enabled for the left operand." );

   static constexpr int getSize() { return T1::getSize(); };

   __cuda_callable__
@@ -154,12 +160,14 @@ template< typename T1,
          typename Operation >
struct StaticBinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorExpressionVariable  >
{
   static_assert( IsStaticArrayType< T2 >::value,
                  "Right-hand side operand of static expression is not static, i.e. based on static vector." );

   using VectorOperandType = T2;
   using RealType = decltype( Operation::evaluate( std::declval<T1>(), std::declval<T2>()[0] ) );

   static_assert( IsStaticArrayType< T2 >::value,
                  "Right-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( HasEnabledStaticExpressionTemplates< T2 >::value,
                  "Invalid operand in static binary expression templates - static expression templates are not enabled for the right operand." );

   static constexpr int getSize() { return T2::getSize(); };

   __cuda_callable__
@@ -204,6 +212,11 @@ struct StaticUnaryExpressionTemplate
   using VectorOperandType = T1;
   using RealType = decltype( Operation::evaluate( std::declval<T1>()[0] ) );

   static_assert( IsStaticArrayType< T1 >::value,
                  "The operand of static expression is not static, i.e. based on static vector." );
   static_assert( HasEnabledStaticExpressionTemplates< T1 >::value,
                  "Invalid operand in static unary expression templates - static expression templates are not enabled for the operand." );

   static constexpr int getSize() { return T1::getSize(); };

   __cuda_callable__