ParGeMSLR
Public Member Functions | List of all members
pargemslr::SequentialVectorClass< T > Class Template Reference

The class of sequential real/complex vector. More...

#include <sequential_vector.hpp>

Public Member Functions

 SequentialVectorClass ()
 The constructor of SequentialVectorClass. More...
 
 SequentialVectorClass (const SequentialVectorClass< T > &vec)
 The copy constructor of SequentialVectorClass. More...
 
 SequentialVectorClass (SequentialVectorClass< T > &&vec)
 The move constructor of SequentialVectorClass. More...
 
SequentialVectorClass< T > & operator= (const SequentialVectorClass< T > &vec)
 The = operator of SequentialVectorClass. More...
 
SequentialVectorClass< T > & operator= (SequentialVectorClass< T > &&vec)
 The = operator of SequentialVectorClass. More...
 
virtual ~SequentialVectorClass ()
 The destructor of SequentialVectorClass. More...
 
int Setup (int length)
 Free the current vector, and malloc memory to initilize the vector. More...
 
int Setup (int length, bool setzero)
 Free the current vector, and allocate memory to initilize the vector. More...
 
int Setup (int length, int location, bool setzero)
 Free the current vector, and allocate memory at give location to initilize the vector. More...
 
int Setup (int length, int reserve, int location, bool setzero)
 Free the current vector, and allocate memory at give location to initilize the vector. More...
 
int SetupPtrStr (SequentialVectorClass< T > &x)
 Setup the length information of a vector pointer to be same as another vector. More...
 
int SetupPtrStr (CsrMatrixClass< T > &A)
 Setup the length information of a vector pointer to be same as the number of rows in a CSR matrix. More...
 
int SetupPtrStr (int length)
 Setup the length information of a vector pointer. More...
 
int UpdatePtr (void *data, int location)
 Update the Ptr with new memory address, keep the current length information. Need to call SetupPtrStr first. More...
 
int SetupPtr (void *data, int length, int location)
 Free the current vector, and points the vector to an address in the memory. More...
 
int SetupPtr (void *data, int length, int location, bool hold_data)
 Free the current vector, and points the vector to an address in the memory. More...
 
int SetupPtr (const VectorClass< T > &vec, int length, int shift)
 Free the current vector, and points the vector to a given VectorClass. More...
 
int SetupPtr (const VectorClass< T > &vec, int length, int shift, bool hold_data)
 Free the current vector, and points the vector to a given VectorClass. More...
 
int Copy (const T *data, int length, int loc_from, int loc_to)
 Free the current vector, allocate memory, and copy data to initilize this vector. More...
 
int PushBack (T v)
 Insert value at the end of the vector, expand the vector when necessary. More...
 
int Resize (int length, bool keepdata, bool setzero)
 Resize the vector. Re-allocate memory when necessary. More...
 
int Resize (int length, int reserve, bool keepdata, bool setzero)
 Resize the vector. Re-allocate memory when necessary. More...
 
virtual T & operator[] (int i)
 Get the reference of an index in the vector. More...
 
virtual int Clear ()
 Free the current vector. More...
 
virtual T * GetData () const
 Get the data pointer of the vector. More...
 
virtual int GetDataLocation () const
 Get the data location of the vector. More...
 
virtual int GetLengthLocal () const
 Get the local length of the vector. More...
 
virtual long int GetLengthGlobal () const
 Get the global length of the vector. More...
 
virtual long int GetStartGlobal () const
 Get the global start index of the vector. More...
 
bool IsHoldingData () const
 Check if the vector holding its own data. More...
 
int SetHoldingData (bool hold_data)
 Set if the vector holding its own data. More...
 
virtual int Fill (const T &v)
 Fill the vector with constant value. More...
 
virtual int Rand ()
 Fill the vector with random value. More...
 
Max () const
 Get the max value in the vector. More...
 
int MaxIndex () const
 Get the index of the max value in the vector. More...
 
Min () const
 Get the min value in the vector. More...
 
int MinIndex () const
 Get the index of the min value in the vector. More...
 
int BinarySearch (const T &val, int &idx, bool ascending)
 Binary search between [s, e] inside an array. More...
 
int Sort (bool ascending)
 Sort the current vector. More...
 
int Sort (IntVectorClass< int > &order, bool ascending, bool stable)
 Get the order such that v[order] is in ascending or descending order. More...
 
int Perm (IntVectorClass< int > &perm)
 Apply permutation to the current vector v := v(perm). More...
 
int Plot (int conditiona, int conditionb, int width)
 Print the vector. More...
 
int PlotAbsGnuPlot (const char *datafilename, int conditiona, int conditionb, bool logx, bool logy, int pttype=0)
 Print the absolute value of this vector using GnuPlot. More...
 
int WriteToDisk (const char *datafilename)
 Write file to disk. More...
 
virtual int Scale (const T &alpha)
 Scale the vector by x = alpha*x, where x is this vector. More...
 
virtual int Axpy (const T &alpha, const VectorClass< T > &x)
 Compute y = alpha * x + y, where y is this vector. Currenlty we don't support x == y. More...
 
virtual int Axpy (const T &alpha, const VectorClass< T > &x, VectorClass< T > &z)
 Compute z = alpha * x + y, where z is this vector. Currenlty we don't support x == y, x == z or y == z. More...
 
virtual int Axpy (const T &alpha, const VectorClass< T > &x, const T &beta, VectorClass< T > &z)
 Compute z = alpha * x + beta * y, where z is this vector. Currenlty we don't support x == y, x == z or y == z. More...
 
virtual int Norm2 (float &norm) const
 Compute the 2-norm of a vector, result is type float. More...
 
virtual int Norm2 (double &norm) const
 Compute the 2-norm of a vector, result is type double. More...
 
virtual int NormInf (float &norm)
 Compute the inf-norm of a vector, result is type float. More...
 
virtual int NormInf (double &norm)
 Compute the inf-norm of a vector, result is type double. More...
 
virtual int Dot (const VectorClass< T > &y, T &t) const
 Compute the dot product. More...
 
virtual int MoveData (const int &location)
 Move the data to another memory location. More...
 
int ReadFromMMFile (const char *vecfile, int idxin)
 Read vector on the host memory, matrix market format. More...
 

Detailed Description

template<typename T>
class pargemslr::SequentialVectorClass< T >

The class of sequential real/complex vector.

Constructor & Destructor Documentation

◆ SequentialVectorClass() [1/3]

template<typename T >
template pargemslr::SequentialVectorClass< T >::SequentialVectorClass ( )

The constructor of SequentialVectorClass. The default memory location is the host memory.

◆ SequentialVectorClass() [2/3]

template<typename T >
pargemslr::SequentialVectorClass< T >::SequentialVectorClass ( const SequentialVectorClass< T > &  vec)

The copy constructor of SequentialVectorClass.

Parameters
[in]vecThe other vector.

◆ SequentialVectorClass() [3/3]

The move constructor of SequentialVectorClass.

Parameters
[in]vecThe other vector.

◆ ~SequentialVectorClass()

template<typename T >
template pargemslr::SequentialVectorClass< T >::~SequentialVectorClass ( )
virtual

The desstructor of seq_vector.

The destructor of SequentialVectorClass. Simply a call to the free function.

The desnstructor of seq_vector. Just call the free function.

Member Function Documentation

◆ Axpy() [1/3]

template<typename T >
int pargemslr::SequentialVectorClass< T >::Axpy ( const T &  alpha,
const VectorClass< T > &  x 
)
virtual

Compute y = alpha * x + y, where y is this vector. Currenlty we don't support x == y.

Parameters
[in]alphaThe alpha value.
[in]xThe vector.
Returns
Return error message.

◆ Axpy() [2/3]

template<typename T >
int pargemslr::SequentialVectorClass< T >::Axpy ( const T &  alpha,
const VectorClass< T > &  x,
const T &  beta,
VectorClass< T > &  z 
)
virtual

Compute z = alpha * x + beta * y, where z is this vector. Currenlty we don't support x == y, x == z or y == z.

Parameters
[in]alphaThe alpha value.
[in]xThe first vector.
[in]betaThe beta value.
[in]yThe second vector.
Returns
Return error message.

◆ Axpy() [3/3]

template<typename T >
int pargemslr::SequentialVectorClass< T >::Axpy ( const T &  alpha,
const VectorClass< T > &  x,
VectorClass< T > &  z 
)
virtual

Compute z = alpha * x + y, where z is this vector. Currenlty we don't support x == y, x == z or y == z.

Parameters
[in]alphaThe alpha value.
[in]xThe first vector.
[in]yThe second vector.
Returns
Return error message.

◆ BinarySearch()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::BinarySearch ( const T &  val,
int &  idx,
bool  ascending 
)

Binary search between [s, e] inside an array.

Parameters
[in]valThe target value.
[out]idxIf found the value, set to the index of the value. Otherwise set to the position to insert, or -1 if s > e.
[in]descendThe array is descend or ascend.
Returns
Return -1 if the value isnot found. Otherwise the index of it.

◆ Clear()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Clear ( )
virtual

Free the current vector.

Returns
Return error message.

Free the current vector.

Returns
Return error messgae.

◆ Copy()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Copy ( const T *  data,
int  length,
int  loc_from,
int  loc_to 
)

Free the current vector, allocate memory, and copy data to initilize the vector.

Free the current vector, allocate memory, and copy data to initilize this vector.

Parameters
[in]dataThe target memory address.
[in]lengthThe new length of this vector.
[in]loc_fromThe location of the input data.
[in]loc_toThe location of the new vector.
Returns
Return error message.

Free the current vector, allocate memory, and copy data to initilize the vector.

Parameters
[in]dataThe target memory address.
[in]lengthThe length of the vector.
[in]loc_fromThe location of the input data.
[in]loc_toThe location of the new vector.
Returns
Return error messgae.

◆ Dot()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Dot ( const VectorClass< T > &  y,
T &  t 
) const
virtual

Compute the dot product.

Parameters
[in]yThe vector.
[out]tThe result.
Returns
Return error message.

◆ Fill()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Fill ( const T &  v)
virtual

Fill the vector with constant value.

Parameters
[in]vThe value to be filled.
Returns
Return error message.

◆ GetData()

template<typename T >
template complexd * pargemslr::SequentialVectorClass< T >::GetData ( ) const
virtual

Get the data pointer of the vector.

Returns
Return the data pointer.

◆ GetDataLocation()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::GetDataLocation ( ) const
virtual

Get the data location of the vector.

Returns
Return the data location of the vector.

◆ GetLengthGlobal()

template<typename T >
template long int pargemslr::SequentialVectorClass< T >::GetLengthGlobal ( ) const
virtual

Get the global length of the vector.

Returns
Return the global length of the vector.

◆ GetLengthLocal()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::GetLengthLocal ( ) const
virtual

Get the local length of the vector.

Returns
Return the local length of the vector.

◆ GetStartGlobal()

template<typename T >
template long int pargemslr::SequentialVectorClass< T >::GetStartGlobal ( ) const
virtual

Get the global start index of the vector.

Returns
Return the global start index of the vector.

◆ IsHoldingData()

template<typename T >
template bool pargemslr::SequentialVectorClass< T >::IsHoldingData ( ) const

Check if the vector holding its own data.

Returns
Return true if vector holding data.

◆ Max()

template<typename T >
template double pargemslr::SequentialVectorClass< T >::Max ( ) const

Get the max value in the vector.
For real vectors only.

Returns
Return the max value.

◆ MaxIndex()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::MaxIndex ( ) const

Get the index of the max value in the vector.
For real vectors only.

Returns
Return the index of the max value.

◆ Min()

template<typename T >
template double pargemslr::SequentialVectorClass< T >::Min ( ) const

Get the min value in the vector.
For real vectors only.

Returns
Return the min value.

◆ MinIndex()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::MinIndex ( ) const

Get the index of the min value in the vector.
For real vectors only.

Returns
Return the index of the min value.

◆ MoveData()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::MoveData ( const int &  location)
virtual

Move the data to another memory location.

Parameters
[in]locationThe location move to.
Returns
Return error message.

◆ Norm2() [1/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Norm2 ( double &  norm) const
virtual

Compute the 2-norm of a vector, result is type double.

Parameters
[out]normThe 2-norm.
Returns
Return error message.

◆ Norm2() [2/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Norm2 ( float &  norm) const
virtual

Compute the 2-norm of a vector, result is type float.

Parameters
[out]normThe 2-norm.
Returns
Return error message.

◆ NormInf() [1/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::NormInf ( double &  norm)
virtual

Compute the inf-norm of a vector, result is type double.

Parameters
[out]normThe inf-norm.
Returns
Return error message.

◆ NormInf() [2/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::NormInf ( float &  norm)
virtual

Compute the inf-norm of a vector, result is type float.

Parameters
[out]normThe inf-norm.
Returns
Return error message.

◆ operator=() [1/2]

template<typename T >
SequentialVectorClass< T > & pargemslr::SequentialVectorClass< T >::operator= ( const SequentialVectorClass< T > &  vec)

The = operator of SequentialVectorClass.

Parameters
[in]vecThe other vector.
Returns
Return the vector.

◆ operator=() [2/2]

template<typename T >
SequentialVectorClass< T > & pargemslr::SequentialVectorClass< T >::operator= ( SequentialVectorClass< T > &&  vec)

The = operator of SequentialVectorClass.

Parameters
[in]vecThe other vector.
Returns
Return the vector.

◆ operator[]()

template<typename T >
template complexd & pargemslr::SequentialVectorClass< T >::operator[] ( int  i)
virtual

Get the reference of an index in the vector.

Parameters
[in]iThe index.
Returns
The reference of the value on that index.

◆ Perm()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Perm ( IntVectorClass< int > &  perm)

Apply permutation to the current vector v := v(perm).

Parameters
[in]permThe permutation vector.
Returns
Return error message.

◆ Plot()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Plot ( int  conditiona,
int  conditionb,
int  width 
)

Print the vector.

Parameters
[in]conditionaFirst condition.
[in]conditionbSecend condition, only plot when conditiona == conditionb.
[in]widthThe plot width.
Returns
Return error message.

◆ PlotAbsGnuPlot()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::PlotAbsGnuPlot ( const char *  datafilename,
int  conditiona,
int  conditionb,
bool  logx,
bool  logy,
int  pttype = 0 
)

Print the absolute value of this vector using GnuPlot.

Parameters
[in]datafilenameThe filename of the temp file holding the data.
[in]conditionaFirst condition.
[in]conditionbSecend condition, only plot when conditiona == conditionb.
[in]logxSet to true to plot in log in x.
[in]logySet to true to plot in log in y.
[in]pttypeThe dot type in GnuPlot.
Returns
Return error message.

◆ PushBack()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::PushBack ( v)

Insert value at the end of the vector, expand the vector when necessary. Work only when the vector is holding data.

Insert value at the end of the vector, expand the vector when necessary.
Work only when the vector is holding data.

Parameters
[in]vThe value to be inserted.
Returns
Return error message.

Insert value at the end of the vector, expand the vector when necessary. Work only when the vector is holding data.

Parameters
[in]vThe value to be inserted.
Returns
Return error messgae.

◆ Rand()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Rand ( )
virtual

Fill the vector with random value.

Returns
Return error message.

◆ ReadFromMMFile()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::ReadFromMMFile ( const char *  vecfile,
int  idxin 
)

Read vector on the host memory, matrix market format.

Parameters
[in]vecfileThe file.
[in]idxinThe index base of the input file. 0-based or 1-based.
Returns
Return error message.

◆ Resize() [1/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Resize ( int  length,
bool  keepdata,
bool  setzero 
)

Resize the vector. Re-allocate memory when necessary.

Parameters
[in]lengthThe new length of this vector.
[in]keepdataSet to true to keep the data in the current vector.
[in]setzeroSet to true to fill the new extra memory with 0 if the vector is expanded.
Returns
Return error message.

Resize the vector. Re-allocate memory when necessary.

Parameters
[in]lengthThe length of the vector.
[in]keepdataDo we keep the data in the current vector.
[in]setzeroDo we Fill the new extra memory with 0 if we expand the vector.
Returns
Return error messgae.

◆ Resize() [2/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Resize ( int  length,
int  reserve,
bool  keepdata,
bool  setzero 
)

Resize the vector. Re-allocate memory when necessary.

Parameters
[in]lengthThe new length of this vector.
[in]reserveThe new reserve length in the memory, should be no less than length.
[in]keepdataSet to true to keep the data in the current vector.
[in]setzeroSet to true to fill the new extra memory with 0 if the vector is expanded.
Returns
Return error message.

Resize the vector. Re-allocate memory when necessary.

Parameters
[in]lengthThe length of the vector.
[in]reserveThe length allocated in the memory, should be no less than length.
[in]keepdataDo we keep the data in the current vector.
[in]setzeroDo we Fill the new extra memory with 0 if we expand the vector.
Returns
Return error messgae.

◆ Scale()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Scale ( const T &  alpha)
virtual

Scale the vector by x = alpha*x, where x is this vector.

Parameters
[in]alphaThe scale.
Returns
Return error message.

◆ SetHoldingData()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::SetHoldingData ( bool  hold_data)

Set if the vector holding its own data.

Returns
Return error message.

◆ Setup() [1/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Setup ( int  length)

Free the current vector, and malloc memory to initilize the vector.

Parameters
[in]lengthThe length of the vector.
Returns
Return error message.

◆ Setup() [2/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Setup ( int  length,
bool  setzero 
)

Free the current vector, and allocate memory to initilize the vector.

Parameters
[in]lengthThe length of the vector.
[in]setzeroCall calloc if we need to fill the memory with 0.
Returns
Return error message.

◆ Setup() [3/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Setup ( int  length,
int  location,
bool  setzero 
)

Free the current vector, and allocate memory at give location to initilize the vector.

Parameters
[in]lengthThe length of the vector.
[in]locationThe location of the vector.
[in]setzeroCall calloc if we need to fill the memory with 0.
Returns
Return error message.

◆ Setup() [4/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Setup ( int  length,
int  reserve,
int  location,
bool  setzero 
)

Free the current vector, and allocate memory at give location to initilize the vector.
The actual memory size is set by the value reserve, and the vector length is given by the value length.

Parameters
[in]lengthThe length of the vector.
[in]reserveThe length allocated in the memory, should be no less than length.
[in]locationThe location of the vector.
[in]setzeroCall calloc if we need to fill the memory with 0.
Returns
Return error message.

◆ SetupPtr() [1/4]

template<typename T >
int pargemslr::SequentialVectorClass< T >::SetupPtr ( const VectorClass< T > &  vec,
int  length,
int  shift 
)

Free the current vector, and points the vector to a given VectorClass. The memory will not be freed by this vector.

Parameters
[in]vecThe target vector.
[in]lengthThe new length of this vector.
[in]shiftThe shift in the target vector. this->_data = vec.GetData() + shift.
Returns
Return error message.

◆ SetupPtr() [2/4]

template<typename T >
int pargemslr::SequentialVectorClass< T >::SetupPtr ( const VectorClass< T > &  vec,
int  length,
int  shift,
bool  hold_data 
)

Free the current vector, and points the vector to a given VectorClass.

Parameters
[in]vecThe target vector.
[in]lengthThe new length of this vector.
[in]shiftThe shift in the target vector. this->_data = vec.GetData() + shift.
[in]hold_dataSet to true if this vector should free the data. Typically this function should not be used.
Returns
Return error message.

◆ SetupPtr() [3/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::SetupPtr ( void *  data,
int  length,
int  location 
)

Free the current vector, and points the vector to an address in the memory. The memory will not be freed by this vector.

Parameters
[in]dataThe address of the data.
[in]lengthThe length of the vector.
[in]locationThe location of the data.
Returns
Return error message.

◆ SetupPtr() [4/4]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::SetupPtr ( void *  data,
int  length,
int  location,
bool  hold_data 
)

Free the current vector, and points the vector to an address in the memory.

Parameters
[in]dataThe address of the data.
[in]lengthThe length of the vector.
[in]locationThe location of the data.
[in]hold_dataSet to true if this vector should free the data.
Returns
Return error message.

◆ SetupPtrStr() [1/3]

template<typename T >
int pargemslr::SequentialVectorClass< T >::SetupPtrStr ( CsrMatrixClass< T > &  A)

Setup the length information of a vector pointer to be same as the number of rows in a CSR matrix.
This will only set the length, need to call UpdatePtr function to set data.

Parameters
[in]AThe CsrMatrixClass.
Returns
Return error message.

◆ SetupPtrStr() [2/3]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::SetupPtrStr ( int  length)

Setup the length information of a vector pointer.
This will only set the length, need to call UpdatePtr function to set data.

Parameters
[in]lengthThe new length.
Returns
Return error message.

◆ SetupPtrStr() [3/3]

template<typename T >
int pargemslr::SequentialVectorClass< T >::SetupPtrStr ( SequentialVectorClass< T > &  x)

Setup the length information of a vector pointer to be same as another vector.
This will only set the length, need to call UpdatePtr function to set data.

Parameters
[in]xThe SequentialVectorClass.
Returns
Return error message.

◆ Sort() [1/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Sort ( bool  ascending)

Sort the current vector.
For real vectors only.

Parameters
[in]ascendingSort in ascending or descending.
Returns
Return error message.

◆ Sort() [2/2]

template<typename T >
template int pargemslr::SequentialVectorClass< T >::Sort ( IntVectorClass< int > &  order,
bool  ascending,
bool  stable 
)

Get the order such that v[order] is in ascending or descending order.
Without modifying the current vector.
For real vectors only.

Parameters
[out]orderThe order vector.
[in]ascendingSort in ascending or descending.
[in]stableUse stable sort or not.
Returns
Return error message.

◆ UpdatePtr()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::UpdatePtr ( void *  data,
int  location 
)

Update the Ptr with new memory address, keep the current length information. Need to call SetupPtrStr first.

Parameters
[in]dataThe address of the data.
[in]locationThe location of the data.
Returns
Return error message.

◆ WriteToDisk()

template<typename T >
template int pargemslr::SequentialVectorClass< T >::WriteToDisk ( const char *  datafilename)

Write file to disk.

Parameters
[in]datafilenameThe filename of the file holding the data.
Returns
Return error message.

The documentation for this class was generated from the following files: