Skip to content
Snippets Groups Projects
Commit 72fc00b7 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed assignments operators for StaticVector: +=, -=, *=, /=

parent f9bb987c
No related branches found
No related tags found
No related merge requests found
......@@ -73,48 +73,24 @@ public:
*/
static String getType();
template< typename StaticVectorOperationType >
StaticVector& operator=( const StaticVectorOperationType& vo );
template< typename VectorExpression >
StaticVector& operator=( const VectorExpression& expression );
/**
* \brief Adding operator.
*
* This function adds \e vector from this static vector and returns the resulting static vector.
* The addition is applied to all the vector elements separately.
* \param vector Reference to another vector.
*/
template< typename VectorExpression >
__cuda_callable__
StaticVector& operator+=( const StaticVector& v );
StaticVector& operator+=( const VectorExpression& expression );
/**
* \brief Subtracting operator.
*
* This function subtracts \e vector from this static vector and returns the resulting static vector.
* The subtraction is applied to all the vector elements separately.
* \param vector Reference to another vector.
*/
template< typename VectorExpression >
__cuda_callable__
StaticVector& operator-=( const StaticVector& v );
StaticVector& operator-=( const VectorExpression& expression );
/**
* \brief Multiplication by number.
*
* This function multiplies this static vector by \e c and returns the resulting static vector.
* The multiplication is applied to all the vector elements separately.
* \param c Multiplicator.
*/
template< typename VectorExpression >
__cuda_callable__
StaticVector& operator*=( const Real& c );
StaticVector& operator*=( const VectorExpression& expression );
/**
* \brief Division by number
*
* This function divides this static veSize of static array. Number of its elements.ctor by \e c and returns the resulting static vector.
* The division is applied to all the vector elements separately.
* \param c Divisor.
*/
template< typename VectorExpression >
__cuda_callable__
StaticVector& operator/=( const Real& c );
StaticVector& operator/=( const VectorExpression& expression );
/**
* \brief Changes the type of static vector to \e OtherReal while the size remains the same.
......
......@@ -17,40 +17,6 @@
namespace TNL {
namespace Containers {
namespace detail {
////
// Functors used together with StaticFor for static loop unrolling in the
// implementation of the StaticVector
template< typename LeftReal, typename RightReal = LeftReal >
struct addVectorFunctor
{
void __cuda_callable__ operator()( int i, LeftReal* data, const RightReal* v ) const
{
data[ i ] += v[ i ];
}
};
template< typename LeftReal, typename RightReal = LeftReal >
struct subtractVectorFunctor
{
void __cuda_callable__ operator()( int i, LeftReal* data, const RightReal* v ) const
{
data[ i ] -= v[ i ];
}
};
template< typename LeftReal, typename RightReal = LeftReal >
struct scalarMultiplicationFunctor
{
void __cuda_callable__ operator()( int i, LeftReal* data, const RightReal v ) const
{
data[ i ] *= v;
}
};
} // namespace detail
template< int Size, typename Real >
template< typename T1,
typename T2,
......@@ -96,43 +62,47 @@ String StaticVector< Size, Real >::getType()
}
template< int Size, typename Real >
template< typename RHS >
template< typename VectorExpression >
StaticVector< Size, Real >&
StaticVector< Size, Real >::operator=( const RHS& rhs )
StaticVector< Size, Real >::operator=( const VectorExpression& expression )
{
Algorithms::VectorAssignment< StaticVector< Size, Real >, RHS >::assignStatic( *this, rhs );
Algorithms::VectorAssignment< StaticVector< Size, Real >, VectorExpression >::assignStatic( *this, expression );
return *this;
}
template< int Size, typename Real >
template< typename VectorExpression >
__cuda_callable__
StaticVector< Size, Real >& StaticVector< Size, Real >::operator+=( const StaticVector& v )
StaticVector< Size, Real >& StaticVector< Size, Real >::operator+=( const VectorExpression& expression )
{
StaticFor< 0, Size >::exec( detail::addVectorFunctor< Real >{}, this->getData(), v.getData() );
Algorithms::VectorAssignmentWithOperation< StaticVector, VectorExpression >::additionStatic( *this, expression );
return *this;
}
template< int Size, typename Real >
template< typename VectorExpression >
__cuda_callable__
StaticVector< Size, Real >& StaticVector< Size, Real >::operator-=( const StaticVector& v )
StaticVector< Size, Real >& StaticVector< Size, Real >::operator-=( const VectorExpression& expression )
{
StaticFor< 0, Size >::exec( detail::subtractVectorFunctor< Real >{}, this->getData(), v.getData() );
Algorithms::VectorAssignmentWithOperation< StaticVector, VectorExpression >::subtractionStatic( *this, expression );
return *this;
}
template< int Size, typename Real >
template< typename VectorExpression >
__cuda_callable__
StaticVector< Size, Real >& StaticVector< Size, Real >::operator*=( const Real& c )
StaticVector< Size, Real >& StaticVector< Size, Real >::operator*=( const VectorExpression& expression )
{
StaticFor< 0, Size >::exec( detail::scalarMultiplicationFunctor< Real >{}, this->getData(), c );
Algorithms::VectorAssignmentWithOperation< StaticVector, VectorExpression >::multiplicationStatic( *this, expression );
return *this;
}
template< int Size, typename Real >
template< typename VectorExpression >
__cuda_callable__
StaticVector< Size, Real >& StaticVector< Size, Real >::operator/=( const Real& c )
StaticVector< Size, Real >& StaticVector< Size, Real >::operator/=( const VectorExpression& expression )
{
StaticFor< 0, Size >::exec( detail::scalarMultiplicationFunctor< Real >{}, this->getData(), 1.0 / c );
Algorithms::VectorAssignmentWithOperation< StaticVector, VectorExpression >::divisionStatic( *this, expression );
return *this;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment