Newer
Older
Jakub Klinkovský
committed
/***************************************************************************
VectorView.h - description
-------------------
begin : Sep 1, 2018
copyright : (C) 2018 by Tomas Oberhuber et al.
email : tomas.oberhuber@fjfi.cvut.cz
Jakub Klinkovský
committed
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
// Implemented by: Jakub Klinkovský
Jakub Klinkovský
committed
#include <TNL/Containers/ArrayView.h>
namespace TNL {
namespace Containers {
template< typename Real, typename Device, typename Index >
class Vector;
template< int Size, typename Real >
class StaticVector;
template< typename Real = double,
typename Device = Devices::Host,
typename Index = int >
class VectorView
: public ArrayView< Real, Device, Index >
{
using BaseType = ArrayView< Real, Device, Index >;
Jakub Klinkovský
committed
using NonConstReal = typename std::remove_const< Real >::type;
Jakub Klinkovský
committed
public:
using RealType = Real;
using DeviceType = Device;
using IndexType = Index;
using HostType = VectorView< Real, Devices::Host, Index >;
using CudaType = VectorView< Real, Devices::Cuda, Index >;
// inherit all ArrayView's constructors
#ifndef __NVCC__
using BaseType::ArrayView;
#else
// workaround for a bug in nvcc 8.0 (seems to be fixed in 9.0)
Jakub Klinkovský
committed
using ArrayView< Real, Device, Index >::ArrayView;
#endif
// initialization by base class is not a copy constructor so it has to be explicit
template< typename Element_ > // template catches both const and non-const qualified Element
__cuda_callable__
VectorView( const ArrayView< Element_, Device, Index >& view )
: BaseType::ArrayView( view ) {}
Jakub Klinkovský
committed
static String getType();
// All other Vector methods follow...
void addElement( IndexType i, RealType value );
void addElement( IndexType i,
RealType value,
RealType thisElementMultiplicator );
template< typename Vector >
VectorView& operator-=( const Vector& vector );
Jakub Klinkovský
committed
template< typename Vector >
VectorView& operator+=( const Vector& vector );
Jakub Klinkovský
committed
VectorView& operator*=( RealType c );
Jakub Klinkovský
committed
VectorView& operator/=( RealType c );
Jakub Klinkovský
committed
Jakub Klinkovský
committed
NonConstReal max() const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
NonConstReal min() const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
NonConstReal absMax() const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
NonConstReal absMin() const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
template< typename ResultType = NonConstReal, typename Real_ >
Jakub Klinkovský
committed
Jakub Klinkovský
committed
template< typename ResultType = NonConstReal >
Jakub Klinkovský
committed
template< typename Vector >
Jakub Klinkovský
committed
NonConstReal differenceMax( const Vector& v ) const;
Jakub Klinkovský
committed
template< typename Vector >
Jakub Klinkovský
committed
NonConstReal differenceMin( const Vector& v ) const;
Jakub Klinkovský
committed
template< typename Vector >
Jakub Klinkovský
committed
NonConstReal differenceAbsMax( const Vector& v ) const;
Jakub Klinkovský
committed
template< typename Vector >
Jakub Klinkovský
committed
NonConstReal differenceAbsMin( const Vector& v ) const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
template< typename ResultType = NonConstReal, typename Vector, typename Real_ >
ResultType differenceLpNorm( const Vector& v, Real_ p ) const;
Jakub Klinkovský
committed
Jakub Klinkovský
committed
template< typename ResultType = NonConstReal, typename Vector >
ResultType differenceSum( const Vector& v ) const;
Jakub Klinkovský
committed
void scalarMultiplication( Real alpha );
//! Computes scalar dot product
template< typename Vector >
NonConstReal scalarProduct( const Vector& v ) const;
Jakub Klinkovský
committed
//! Computes this = thisMultiplicator * this + alpha * x.
Jakub Klinkovský
committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
template< typename Vector >
void addVector( const Vector& x,
Real alpha = 1.0,
Real thisMultiplicator = 1.0 );
//! Computes this = thisMultiplicator * this + multiplicator1 * v1 + multiplicator2 * v2.
template< typename Vector >
void addVectors( const Vector& v1,
Real multiplicator1,
const Vector& v2,
Real multiplicator2,
Real thisMultiplicator = 1.0 );
void computePrefixSum();
void computePrefixSum( IndexType begin, IndexType end );
void computeExclusivePrefixSum();
void computeExclusivePrefixSum( IndexType begin, IndexType end );
};
} // namespace Containers
} // namespace TNL
#include <TNL/Containers/VectorView_impl.h>