Commit 6abbfef6 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Moving ET source code to containers.

parent d8958f80
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -10,11 +10,12 @@

#pragma once

#include <TNL/Experimental/ExpressionTemplates/ExpressionTemplatesOperations.h>
#include <TNL/Experimental/ExpressionTemplates/ExpressionVariableType.h>
#include <TNL/Containers/Algorithms/ExpressionTemplatesOperations.h>
#include <TNL/Containers/Algorithms/ExpressionVariableType.h>

namespace TNL {
   namespace ExpressionTemplates {
   namespace Containers {
      namespace Algorithms {

template< typename T1,
          typename T2,
@@ -124,6 +125,7 @@ struct BinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorVa

};

/*
template< typename T1, typename T2 >
BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Addition > operator+( const T1 &a, const T2 &b )
{
@@ -147,6 +149,7 @@ BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Division > operator/( con
{
    return BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Division >( a, b );
}

   } //namespace ExpressionTemplates
 */
      } //namespace Algorithms
   } //namespace Containers
} // namespace TNL
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@
#pragma once

namespace TNL {
   namespace ExpressionTemplates {
   namespace Containers {
      namespace Algorithms {

template< typename T1, typename T2 >
struct Addition
@@ -49,6 +50,6 @@ struct Division
   }
};


   } // ExpressionTemplates
      } //namespace Algorithms
   } // namespace Containers
} // namespace TNL
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
#include <type_traits>

namespace TNL {
   namespace Containers {
      namespace Algorithms {

enum ExpressionVariableType { ArithmeticVariable, VectorVariable, OtherVariable };

@@ -67,4 +69,6 @@ struct ExpressionVariableTypeGetter< T, false, true >
   static constexpr ExpressionVariableType value = VectorVariable;
};

      } //namespace Algorithms
   } //namespace Containers
} //namespace TNL
+60 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@

#include <TNL/Containers/StaticArray.h>
#include <TNL/Config/ParameterContainer.h>
#include <TNL/Experimental/ExpressionTemplates/BinaryExpressionTemplate.h>

namespace TNL {
namespace Containers {
@@ -637,6 +636,66 @@ __cuda_callable__
StaticVector< Size, Real > operator * ( const Scalar& c, const StaticVector< Size, Real >& u );
 */

#include <TNL/Experimental/ExpressionTemplates/BinaryExpressionTemplate.h>

template< int Size, typename Real, typename ET >
BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Addition >
operator+( const StaticVector< Size, Real >& a, const ET& b )
{
   return BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Addition >( a, b );
}

template< typename ET, int Size, typename Real >
BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Addition >
operator+( const ET& a, const StaticVector< Size, Real >& b )
{
   return BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Addition >( a, b );
}

template< int Size, typename Real, typename ET >
BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Subtraction >
operator-( const StaticVector< Size, Real >& a, const ET& b )
{
   return BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Subtraction >( a, b );
}

template< typename ET, int Size, typename Real >
BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Subtraction >
operator-( const ET& a, const StaticVector< Size, Real >& b )
{
   return BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Subtraction >( a, b );
}

template< int Size, typename Real, typename ET >
BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Multiplication >
operator*( const StaticVector< Size, Real >& a, const ET& b )
{
   return BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Multiplication >( a, b );
}

template< typename ET, int Size, typename Real >
BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Multiplication >
operator*( const ET& a, const StaticVector< Size, Real >& b )
{
   return BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Multiplication >( a, b );
}

template< int Size, typename Real, typename ET >
BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Division >
operator/( const StaticVector< Size, Real >& a, const ET& b )
{
   return BinaryExpressionTemplate< StaticVector< Size, Real >, ET, ExpressionTemplates::Division >( a, b );
}

template< typename ET, int Size, typename Real >
BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Division >
operator/( const ET& a, const StaticVector< Size, Real >& b )
{
   return BinaryExpressionTemplate< ET, StaticVector< Size, Real >, ExpressionTemplates::Division >( a, b );
}



template< int Size, typename Real >
__cuda_callable__
StaticVector< Size, Real > abs( const StaticVector< Size, Real >& u ) { return u.abs(); };
+0 −133
Original line number Diff line number Diff line
@@ -19,139 +19,6 @@
namespace TNL {


template< typename T1,
          typename T2,
          template< typename, typename > class Operation,
          ExpressionVariableType T1Type = ExpressionVariableTypeGetter< T1 >::value,
          ExpressionVariableType T2Type = ExpressionVariableTypeGetter< T2 >::value >
struct BinaryExpressionTemplate
{
   BinaryExpressionTemplate( const T1& a, const T2& b ){};

   static T1 evaluate( const T1& a, const T2& b )
   {
      return Operation< T1, T2 >::evaluate( a, b );
   }
};

template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
struct BinaryExpressionTemplate< T1, T2, Operation, VectorVariable, VectorVariable >
{
   using RealType = typename T1::RealType;
   using IsExpressionTemplate = bool;

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

   static BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   RealType operator[]( const int i ) const
   {
       return Operation< typename T1::RealType, typename T2::RealType >::evaluate( op1[ i ], op2[ i ] );
   }

   int getSize() const
   {
       return op1.getSize();
   }

   protected:
      const T1 &op1;
      const T2 &op2;

};

template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
struct BinaryExpressionTemplate< T1, T2, Operation, VectorVariable, ArithmeticVariable  >
{
   using RealType = typename T1::RealType;
   using IsExpressionTemplate = bool;

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

   BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   RealType operator[]( const int i ) const
   {
       return Operation< typename T1::RealType, T2 >::evaluate( op1[ i ], op2 );
   }

   int getSize() const
   {
       return op1.getSize();
   }

   protected:
      const T1 &op1;
      const T2 &op2;

};

template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
struct BinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorVariable  >
{
   using RealType = typename T2::RealType;
   using IsExpressionTemplate = bool;

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

   BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   RealType operator[]( const int i ) const
   {
       return Operation< T1, typename T2::RealType >::evaluate( op1, op2[ i ] );
   }

   int getSize() const
   {
       return op2.getSize();
   }

   protected:
      const T1& op1;
      const T2& op2;

};


template< typename T1, typename T2 >
BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Addition > operator+( const T1 &a, const T2 &b )
{
    return BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Addition >( a, b );
}

template< typename T1, typename T2 >
BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Subtraction > operator-( const T1 &a, const T2 &b )
{
    return BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Subtraction >( a, b );
}

template< typename T1, typename T2 >
BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Multiplication > operator*( const T1 &a, const T2 &b )
{
    return BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Multiplication >( a, b );
}

template< typename T1, typename T2 >
BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Division > operator/( const T1 &a, const T2 &b )
{
    return BinaryExpressionTemplate< T1, T2, ExpressionTemplates::Division >( a, b );
}



template< typename T1 >