Commit 1e06cff2 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring TypeTraits: replaced IsStaticType with IsStaticArrayType

parent 19083de3
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -11,18 +11,18 @@
#pragma once

#include <iostream>

#include <TNL/TypeTraits.h>
#include <TNL/Containers/Expressions/TypeTraits.h>
#include <TNL/Containers/Expressions/ExpressionTemplatesOperations.h>
#include <TNL/Containers/Expressions/ExpressionVariableType.h>
#include <TNL/Containers/Expressions/DistributedComparison.h>
#include <TNL/Containers/Expressions/IsStatic.h>
#include <TNL/Containers/Expressions/TypeTraits.h>

#include <TNL/Communicators/MPIPrint.h>

#include <typeinfo>
#include <cxxabi.h>


namespace TNL {
namespace Containers {
namespace Expressions {
@@ -80,8 +80,7 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, Communicator, Vec
   using CommunicationGroup = typename CommunicatorType::CommunicationGroup;

   static_assert( std::is_same< typename T1::DeviceType, typename T2::DeviceType >::value, "Attempt to mix operands allocated on different device types." );
   static_assert( IsStaticType< T1 >::value == IsStaticType< T2 >::value, "Attempt to mix static and non-static operands in binary expression templates." );
   static constexpr bool isStatic() { return false; }
   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, const CommunicationGroup& group )
      : op1( a ), op2( b ), communicationGroup( group ) {}
@@ -133,8 +132,6 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, Communicator, Vec
   using CommunicatorType = Communicator;
   using CommunicationGroup = typename CommunicatorType::CommunicationGroup;

   static constexpr bool isStatic() { return false; }

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

@@ -185,8 +182,6 @@ struct DistributedBinaryExpressionTemplate< T1, T2, Operation, Communicator, Ari
   using CommunicatorType = Communicator;
   using CommunicationGroup = typename CommunicatorType::CommunicationGroup;

   static constexpr bool isStatic() { return false; }

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

@@ -241,7 +236,6 @@ struct DistributedUnaryExpressionTemplate< T1, Operation, Parameter, Communicato
   using IndexType = typename T1::IndexType;
   using CommunicatorType = Communicator;
   using CommunicationGroup = typename CommunicatorType::CommunicationGroup;
   static constexpr bool isStatic() { return false; }

   DistributedUnaryExpressionTemplate( const T1& a, const Parameter& p, const CommunicationGroup& group )
   : operand( a ), parameter( p ), communicationGroup( group ) {}
@@ -296,7 +290,6 @@ struct DistributedUnaryExpressionTemplate< T1, Operation, void, Communicator, Ve
   using IndexType = typename T1::IndexType;
   using CommunicatorType = Communicator;
   using CommunicationGroup = typename CommunicatorType::CommunicationGroup;
   static constexpr bool isStatic() { return false; }

   DistributedUnaryExpressionTemplate( const T1& a, const CommunicationGroup& group )
      : operand( a ), communicationGroup( group ){}
@@ -2944,4 +2937,5 @@ std::ostream& operator << ( std::ostream& str, const Containers::Expressions::Di
   str << expression.getElement( expression.getLocalSize() - 1 ) << " ]";
   return str;
}

} // namespace TNL
+4 −3
Original line number Diff line number Diff line
@@ -11,11 +11,12 @@
#pragma once

#include <iostream>

#include <TNL/TypeTraits.h>
#include <TNL/Containers/Expressions/TypeTraits.h>
#include <TNL/Containers/Expressions/ExpressionTemplatesOperations.h>
#include <TNL/Containers/Expressions/ExpressionVariableType.h>
#include <TNL/Containers/Expressions/Comparison.h>
#include <TNL/Containers/Expressions/IsStatic.h>
#include <TNL/Containers/Expressions/TypeTraits.h>

namespace TNL {
namespace Containers {
@@ -67,7 +68,7 @@ struct BinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, Ve
   using IndexType = typename T1::IndexType;

   static_assert( std::is_same< typename T1::DeviceType, typename T2::DeviceType >::value, "Attempt to mix operands allocated on different device types." );
   static_assert( IsStaticType< T1 >::value == IsStaticType< T2 >::value, "Attempt to mix static and non-static operands in binary expression templates." );
   static_assert( IsStaticArrayType< T1 >::value == IsStaticArrayType< T2 >::value, "Attempt to mix static and non-static operands in binary expression templates." );
   static constexpr bool is() { return false; }

   BinaryExpressionTemplate( const T1& a, const T2& b ): op1( a ), op2( b ){}
+0 −33
Original line number Diff line number Diff line
/***************************************************************************
                          IsStatic.h  -  description
                             -------------------
    begin                : May 1, 2019
    copyright            : (C) 2019 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

namespace TNL {
   namespace Containers {
      namespace Expressions {


template< typename T >
struct IsStaticType
{
   static constexpr bool value = false;
};

template< int Size,
          typename Real >
struct IsStaticType< StaticVector< Size, Real > >
{
   static constexpr bool value = true;
};

      } //namespace Expressions
   } //namespace Containers
} //namespace TNL
 No newline at end of file
+14 −40
Original line number Diff line number Diff line
@@ -11,18 +11,18 @@
#pragma once

#include <iostream>

#include <TNL/TypeTraits.h>
#include <TNL/Containers/Expressions/TypeTraits.h>
#include <TNL/Containers/Expressions/ExpressionTemplatesOperations.h>
#include <TNL/Containers/Expressions/ExpressionVariableType.h>
#include <TNL/Containers/Expressions/StaticComparison.h>
#include <TNL/Containers/Expressions/IsStatic.h>
#include <TNL/Containers/Expressions/TypeTraits.h>
#include <TNL/Containers/Expressions/VerticalOperations.h>

namespace TNL {
namespace Containers {
namespace Expressions {


template< typename T1,
          template< typename > class Operation,
          typename Parameter = void,
@@ -56,23 +56,6 @@ struct IsExpressionTemplate< StaticBinaryExpressionTemplate< T1, T2, Operation,
{};


template< typename T1,
          template< typename > class Operation,
          typename Parameter >
struct IsStaticType< StaticUnaryExpressionTemplate< T1, Operation, Parameter > >
{
   static constexpr bool value = StaticUnaryExpressionTemplate< T1, Operation, Parameter >::isStatic();
};

template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
struct IsStaticType< StaticBinaryExpressionTemplate< T1, T2, Operation > >
{
   static constexpr bool value = StaticBinaryExpressionTemplate< T1, T2, Operation >::isStatic();
};


////
// Static binary expression template
template< typename T1,
@@ -80,15 +63,13 @@ template< typename T1,
          template< typename, typename > class Operation >
struct StaticBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, VectorExpressionVariable >
{
   static_assert( IsStaticType< T1 >::value, "Left-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( IsStaticType< T2 >::value, "Right-hand side operand of static expression is not static, i.e. based on static vector." );
   static_assert( IsStaticArrayType< T1 >::value, "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." );
   using RealType = typename T1::RealType;

   static_assert( IsStaticType< T1 >::value == IsStaticType< T2 >::value, "Attempt to mix static and non-static operands in binary expression templates" );
   static_assert( IsStaticArrayType< T1 >::value == IsStaticArrayType< T2 >::value, "Attempt to mix static and non-static operands in binary expression templates" );
   static_assert( T1::getSize() == T2::getSize(), "Attempt to mix static operands with different sizes." );

   static constexpr bool isStatic() { return true; }

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

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

   using RealType = typename T1::RealType;

   static constexpr bool isStatic() { return true; }

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


@@ -201,12 +180,10 @@ template< typename T1,
          template< typename, typename > class Operation >
struct StaticBinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorExpressionVariable  >
{
   static_assert( IsStaticType< T2 >::value, "Right-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." );

   using RealType = typename T2::RealType;

   static constexpr bool isStatic() { return true; }

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


@@ -265,12 +242,10 @@ template< typename T1,
          typename Parameter >
struct StaticUnaryExpressionTemplate< T1, Operation, Parameter, VectorExpressionVariable >
{
   static_assert( IsStaticType< T1 >::value, "Operand of static expression is not static, i.e. based on static vector." );
   static_assert( IsStaticArrayType< T1 >::value, "Operand of static expression is not static, i.e. based on static vector." );

   using RealType = typename T1::RealType;

   static constexpr bool isStatic() { return true; }

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

   __cuda_callable__
@@ -331,8 +306,6 @@ struct StaticUnaryExpressionTemplate< T1, Operation, void, VectorExpressionVaria
{
   using RealType = typename T1::RealType;

   static constexpr bool isStatic() { return true; }

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

   __cuda_callable__
@@ -1729,6 +1702,7 @@ std::ostream& operator << ( std::ostream& str, const Containers::Expressions::St
   str << expression[ expression.getSize() - 1 ] << " ]";
   return str;
}

} // namespace Expressions
} // namespace Containers

+0 −8
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@

#include <TNL/String.h>
#include <TNL/File.h>
#include <TNL/TypeTraits.h>

namespace TNL {
namespace Containers {
@@ -222,13 +221,6 @@ template< int Size, typename Value >
std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a );

} // namespace Containers

template< int Size, typename Value_ >
struct IsStatic< Containers::StaticArray< Size, Value_ > >
{
   static constexpr bool Value = true;
};

} // namespace TNL

#include <TNL/Containers/StaticArray.hpp>
Loading