Commit 67ae0bcd authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Experimental/ExpressionTemplates folder was removed.

parent c2499c2c
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
set( headers StaticVectorExpressions.h
	     VectorExpressions.h
)

#IF( BUILD_CUDA )
#    CUDA_ADD_EXECUTABLE( tnl-expression-templates expression-templates.cu )
#ELSE(  BUILD_CUDA )
#    ADD_EXECUTABLE( tnl-expression-templates expression-templates.cpp )
#    ADD_EXECUTABLE( tnl-expression-templates-static expression-templates-static.cpp )
#ENDIF( BUILD_CUDA )
#
#INSTALL( TARGETS tnl-expression-templates
#         RUNTIME DESTINATION bin
#         PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
#
#INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Experimental/ExpressionTemplates )
+0 −97
Original line number Diff line number Diff line
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   OverloadedOperators.h
 * Author: legler
 *
 * Created on December 4, 2018, 7:55 PM
 */

#ifndef OVERLOADEDOPERATORS_H
#define OVERLOADEDOPERATORS_H

#include <vector>

//using std::vector;

template< class T >
std::vector<T> operator+(const std::vector<T> &a, const std::vector<T> &b)
{
std::vector<T> res(a.size());
for (std::size_t i = 0; i<a.size(); i++)
res[i] = a[i] + b[i];
return res;
}

template< class T >
std::vector<T> operator-(const std::vector<T> &a, const std::vector<T> &b)
{
std::vector<T> res(a.size());
for (std::size_t i = 0; i<a.size(); i++)
res[i] = a[i] + b[i];
return res;
}
/*
template< class T>
std::vector<T> operator*(const T &a, const std::vector<T> &b)
{
std::vector<T> res(a.size());
for (size_t i = 0; i<a.size(); i++)
res[i] = a + b[i];
return res;
}

template< class T>
std::vector<T> operator*(const std::vector<T> &a, const T &b)
{
std::vector<T> res(a.size());
for (size_t i = 0; i<a.size(); i++)
res[i] = a[i] + b;
return res;
}
*/
/*
template<typename T>
class Vec
{
public:
	std::vector<T> data;
	
	Vec(const std::size_t size) : data(size)
	{}
	
	Vec(const std::size_t size, const double init) : data(size, init)
	{}

        Vec operator+ ( const Vec& a,  const Vec& b )
        {
            Vec<T> res(a.data.size());
            for (std::size_t i = 0; i<a.data.size(); i++)
            res[i] = a[i] + b[i];
            return res;
        }
        
        Vec operator- ( const Vec& a,  const Vec& b )
        {
            Vec<T> res(a.data.size());
            for (std::size_t i = 0; i<a.data.size(); i++)
            res[i] = a[i] - b[i];
            return res;
        }
        
        Vec operator* ( const T& a,  const Vec& b )
        {
            Vec<T> res(b.data.size());
            for (std::size_t i = 0; i<b.data.size(); i++)
            res[i] = a * b[i];
            return res;
        }
};
*/

#endif /* OVERLOADEDOPERATORS_H */
+0 −306
Original line number Diff line number Diff line
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * File:   StaticVectorExpressions.h
 * Author: oberhuber
 *
 * Created on November 29, 2018, 2:53 PM
 */

#pragma once
#include <TNL/Containers/StaticVector.h>
#include <TNL/Containers/Algorithms/ExpressionTemplatesOperations.h>
#include <TNL/Containers/Algorithms/ExpressionVariableType.h>

namespace TNL {




template< typename T1 >
class StaticVectorAbsoluteValue
{
        const T1 &op1;

    public:

        StaticVectorAbsoluteValue( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::abs( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorExponentialFunction
{
        const T1 &op1;

    public:

        StaticVectorExponentialFunction( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::exp( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorNaturalLogarithm
{
        const T1 &op1;

    public:

        StaticVectorNaturalLogarithm( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::log( op1[ i ] );
        }

        int getSize() const
        {
            return op1.getSize();
        }
};
/*
template< typename T1 >
class StaticVectorSquareRoot
{
        const T1 &op1;

    public:

        StaticVectorSquareRoot( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::sqrt( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorSine
{
        const T1 &op1;

    public:

        StaticVectorSine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::sin( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorCosine
{
        const T1 &op1;

    public:

        StaticVectorCosine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::cos( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorTangent
{
        const T1 &op1;

    public:

        StaticVectorTangent( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::tan( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorArcSine
{
        const T1 &op1;

    public:

        StaticVectorArcSine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::asin( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorArcCosine
{
        const T1 &op1;

    public:

        StaticVectorArcCosine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::acos( op1[ i ] );
        }

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

template< typename T1 >
class StaticVectorArcTangent
{
        const T1 &op1;

    public:

        StaticVectorArcTangent( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        RealType operator[]( const int i ) const
        {
            return std::atan( op1[ i ] );
        }

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


template< typename T1 >
StaticVectorAbsoluteValue< T1 > abs( const T1 &a )
{
    return StaticVectorAbsoluteValue< T1 >( a );
}

template< typename T1 >
StaticVectorExponentialFunction< T1 > exp( const T1 &a )
{
    return StaticVectorExponentialFunction< T1 >( a );
}

template< typename T1 >
StaticVectorNaturalLogarithm< T1 > log( const T1 &a )
{
    return StaticVectorNaturalLogarithm< T1 >( a );
}
/*
template< typename T1 >
StaticVectorSquareRoot< T1 > sqrt( const T1 &a )
{
    return StaticVectorSquareRoot< T1 >( a );
}*/

/*
template< typename T1 >
StaticVectorSine< T1 > sin( const T1 &a )
{
    return StaticVectorSine< T1 >( a );
}

template< typename T1 >
StaticVectorCosine< T1 > cos( const T1 &a )
{
    return StaticVectorCosine< T1 >( a );
}

template< typename T1 >
StaticVectorTangent< T1 > tan( const T1 &a )
{
    return StaticVectorTangent< T1 >( a );
}

template< typename T1 >
StaticVectorArcSine< T1 > asin( const T1 &a )
{
    return StaticVectorArcSine< T1 >( a );
}

template< typename T1 >
StaticVectorArcCosine< T1 > acos( const T1 &a )
{
    return StaticVectorArcCosine< T1 >( a );
}

template< typename T1 >
StaticVectorArcTangent< T1 > atan( const T1 &a )
{
    return StaticVectorArcTangent< T1 >( a );
}*/

} //namespace TNL
+0 −385
Original line number Diff line number Diff line
/* 
 * File: VectorExpressions.h
 * Author: Vojtěch Legler
 *
 * Created on November 29, 2018, 2:53 PM
 */

#pragma once

#include <TNL/Containers/VectorView.h>

template< typename T1, typename T2 >
class VectorAddition
{
        const T1 op1;
        const T2 op2;
        
    public:

        VectorAddition( const T1 &a, const T2 &b ): op1( a ), op2( b ){}
        
        VectorAddition( const VectorAddition &v ): op1( v.op1 ), op2( v.op2 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__ 
        RealType operator[]( const int i ) const
        {
            return op1[ i ] + op2[ i ];
        }

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

template< typename T1, typename T2 >
class VectorSubtraction
{
        const T1 op1;
        const T2 op2;
    
    public:
        
        VectorSubtraction( const T1& a, const T2& b ): op1( a ), op2( b ){}
        
        VectorSubtraction( const VectorSubtraction &v ): op1( v.op1 ), op2( v.op2 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return op1[ i ] - op2[ i ];
        }

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

template< typename Scalar, typename T2 >
class VectorMultiplicationLeftSide
{
        const Scalar c;
        const T2 op2;
    
    public:
        
        VectorMultiplicationLeftSide( const Scalar& a, const T2& b ): c( a ), op2( b ){}
        
        VectorMultiplicationLeftSide( const VectorMultiplicationLeftSide &v ): c( v.c ), op2( v.op2 ){}

        using RealType = typename T2::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return c * op2[ i ];
        }

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

template< typename T1 >
class VectorAbsoluteValue
{
        const T1 op1;
    
    public:
        
        VectorAbsoluteValue( const T1& a ): op1( a ){}
        
        VectorAbsoluteValue( const VectorAbsoluteValue &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::abs( op1[ i ] );
        }

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

template< typename T1 >
class VectorExponentialFunction
{
        const T1 op1;
    
    public:
        
        VectorExponentialFunction( const T1& a ): op1( a ){}
        
        VectorExponentialFunction( const VectorExponentialFunction &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::exp( op1[ i ] );
        }

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

template< typename T1 >
class VectorNaturalLogarithm
{
        const T1 op1;
    
    public:
        
        VectorNaturalLogarithm( const T1& a ): op1( a ){}
        
        VectorNaturalLogarithm( const VectorNaturalLogarithm &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::log( op1[ i ] );
        }

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

template< typename T1 >
class VectorSine
{
        const T1 op1;
    
    public:
        
        VectorSine( const T1& a ): op1( a ){}
        
        VectorSine( const VectorSine &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::sin( op1[ i ] );
        }

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

template< typename T1 >
class VectorCosine
{
        const T1 op1;
    
    public:
        
        VectorCosine( const T1& a ): op1( a ){}
        
        VectorCosine( const VectorCosine &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::cos( op1[ i ] );
        }

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

template< typename T1 >
class VectorTangent
{
        const T1 op1;
    
    public:
        
        VectorTangent( const T1& a ): op1( a ){}
        
        VectorTangent( const VectorTangent &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::tan( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcSine
{
        const T1 op1;
    
    public:
        
        VectorArcSine( const T1& a ): op1( a ){}
        
        VectorArcSine( const VectorArcSine &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::asin( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcCosine
{
        const T1 op1;
    
    public:
        
        VectorArcCosine( const T1& a ): op1( a ){}
        
        VectorArcCosine( const VectorArcCosine &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::acos( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcTangent
{
        const T1 op1;
    
    public:
        
        VectorArcTangent( const T1& a ): op1( a ){}
        
        VectorArcTangent( const VectorArcTangent &v ): op1( v.op1 ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::atan( op1[ i ] );
        }

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

template< typename T1, typename T2 >
VectorAddition< T1, T2 > operator+( const T1 &a, const T2 &b )
{
    return VectorAddition< T1, T2 >( a, b );
}

template< typename T1, typename T2 >
VectorSubtraction< T1, T2 > operator-( const T1 &a, const T2 &b )
{
    return VectorSubtraction< T1, T2 >( a, b );
}

template< typename Scalar, typename T2 >
VectorMultiplicationLeftSide< Scalar, T2 > operator*( const Scalar &a, const T2 &b )
{
    return VectorMultiplicationLeftSide< Scalar, T2 >( a, b );
}

template< typename T1 >
VectorAbsoluteValue< T1 > abs( const T1 &a )
{
    return VectorAbsoluteValue< T1 >( a );
}

template< typename T1 >
VectorExponentialFunction< T1 > exp( const T1 &a )
{
    return VectorExponentialFunction< T1 >( a );
}

template< typename T1 >
VectorNaturalLogarithm< T1 > log( const T1 &a )
{
    return VectorNaturalLogarithm< T1 >( a );
}

template< typename T1 >
VectorSine< T1 > sin( const T1 &a )
{
    return VectorSine< T1 >( a );
}

template< typename T1 >
VectorCosine< T1 > cos( const T1 &a )
{
    return VectorCosine< T1 >( a );
}

template< typename T1 >
VectorTangent< T1 > tan( const T1 &a )
{
    return VectorTangent< T1 >( a );
}

template< typename T1 >
VectorArcSine< T1 > asin( const T1 &a )
{
    return VectorArcSine< T1 >( a );
}

template< typename T1 >
VectorArcCosine< T1 > acos( const T1 &a )
{
    return VectorArcCosine< T1 >( a );
}

template< typename T1 >
VectorArcTangent< T1 > atan( const T1 &a )
{
    return VectorArcTangent< T1 >( a );
}
+0 −362
Original line number Diff line number Diff line
/* 
 * File: VectorExpressions.h
 * Author: Vojtěch Legler
 *
 * Created on November 29, 2018, 2:53 PM
 */

#pragma once

#include <TNL/Containers/Vector.h>

template< typename T1, typename T2 >
class VectorAddition
{
        const T1 &op1;
        const T2 &op2;
    
    public:
        
        VectorAddition( const T1& a, const T2& b ): op1( a ), op2( b ){}

        using RealType = typename T1::RealType;

        __cuda_callable__ 
        RealType operator[]( const int i ) const
        {
            return op1[ i ] + op2[ i ];
        }

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

template< typename T1, typename T2 >
class VectorSubtraction
{
        const T1 &op1;
        const T2 &op2;
    
    public:
        
        VectorSubtraction( const T1& a, const T2& b ): op1( a ), op2( b ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return op1[ i ] - op2[ i ];
        }

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

template< typename Scalar, typename T2 >
class VectorMultiplicationLeftSide
{
        const Scalar &c;
        const T2 &op2;
    
    public:
        
        VectorMultiplicationLeftSide( const Scalar& a, const T2& b ): c( a ), op2( b ){}

        using RealType = typename T2::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return c * op2[ i ];
        }

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

template< typename T1 >
class VectorAbsoluteValue
{
        const T1 &op1;
    
    public:
        
        VectorAbsoluteValue( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::abs( op1[ i ] );
        }

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

template< typename T1 >
class VectorExponentialFunction
{
        const T1 &op1;
    
    public:
        
        VectorExponentialFunction( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::exp( op1[ i ] );
        }

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

template< typename T1 >
class VectorNaturalLogarithm
{
        const T1 &op1;
    
    public:
        
        VectorNaturalLogarithm( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::log( op1[ i ] );
        }

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

template< typename T1 >
class VectorSine
{
        const T1 &op1;
    
    public:
        
        VectorSine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::sin( op1[ i ] );
        }

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

template< typename T1 >
class VectorCosine
{
        const T1 &op1;
    
    public:
        
        VectorCosine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::cos( op1[ i ] );
        }

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

template< typename T1 >
class VectorTangent
{
        const T1 &op1;
    
    public:
        
        VectorTangent( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::tan( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcSine
{
        const T1 &op1;
    
    public:
        
        VectorArcSine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::asin( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcCosine
{
        const T1 &op1;
    
    public:
        
        VectorArcCosine( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::acos( op1[ i ] );
        }

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

template< typename T1 >
class VectorArcTangent
{
        const T1 &op1;
    
    public:
        
        VectorArcTangent( const T1& a ): op1( a ){}

        using RealType = typename T1::RealType;

        __cuda_callable__
        RealType operator[]( const int i ) const
        {
            return std::atan( op1[ i ] );
        }

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


template< typename T1, typename T2 >
VectorAddition< T1, T2 > operator+( const T1 &a, const T2 &b )
{
    return VectorAddition< T1, T2 >( a, b );
}

template< typename T1, typename T2 >
VectorSubtraction< T1, T2 > operator-( const T1 &a, const T2 &b )
{
    return VectorSubtraction< T1, T2 >( a, b );
}

template< typename Scalar, typename T2 >
VectorMultiplicationLeftSide< Scalar, T2 > operator*( const Scalar &a, const T2 &b )
{
    return VectorMultiplicationLeftSide< Scalar, T2 >( a, b );
}

template< typename T1 >
VectorAbsoluteValue< T1 > abs( const T1 &a )
{
    return VectorAbsoluteValue< T1 >( a );
}

template< typename T1 >
VectorExponentialFunction< T1 > exp( const T1 &a )
{
    return VectorExponentialFunction< T1 >( a );
}

template< typename T1 >
VectorNaturalLogarithm< T1 > log( const T1 &a )
{
    return VectorNaturalLogarithm< T1 >( a );
}

template< typename T1 >
VectorSine< T1 > sin( const T1 &a )
{
    return VectorSine< T1 >( a );
}

template< typename T1 >
VectorCosine< T1 > cos( const T1 &a )
{
    return VectorCosine< T1 >( a );
}

template< typename T1 >
VectorTangent< T1 > tan( const T1 &a )
{
    return VectorTangent< T1 >( a );
}

template< typename T1 >
VectorArcSine< T1 > asin( const T1 &a )
{
    return VectorArcSine< T1 >( a );
}

template< typename T1 >
VectorArcCosine< T1 > acos( const T1 &a )
{
    return VectorArcCosine< T1 >( a );
}

template< typename T1 >
VectorArcTangent< T1 > atan( const T1 &a )
{
    return VectorArcTangent< T1 >( a );
}
Loading