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

The class of sequential integer vector. More...

#include <int_vector.hpp>

Inheritance diagram for pargemslr::IntVectorClass< T >:
pargemslr::VectorVirtualClass< T >

Public Member Functions

 IntVectorClass ()
 The constructor of IntVectorClass. More...
 
 IntVectorClass (const IntVectorClass< T > &vec)
 The copy constructor of IntVectorClass. More...
 
 IntVectorClass (IntVectorClass< T > &&vec)
 The move constructor of IntVectorClass. More...
 
IntVectorClass< T > & operator= (const IntVectorClass< T > &vec)
 The = operator of IntVectorClass. More...
 
IntVectorClass< T > & operator= (IntVectorClass< T > &&vec)
 The = operator of IntVectorClass. More...
 
virtual ~IntVectorClass ()
 The destructor of IntVectorClass. 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 SetupPtr (T *data, int length, int location)
 Free the current vector, and points the vector to an address in the memory. More...
 
int SetupPtr (T *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 IntVectorClass< T > &vec, int length, int shift)
 Free the current vector, and points the vector to a given IntVectorClass. More...
 
int SetupPtr (const IntVectorClass< T > &vec, int length, int shift, bool hold_data)
 Free the current vector, and points the vector to a given IntVectorClass. 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 the 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...
 
T & Back ()
 Get the reference of the last 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 length of the vector. More...
 
virtual int Fill (const T &v)
 Fill the vector with constant value. More...
 
int UnitPerm ()
 Generate a unit permutation vector. 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...
 
template<typename T1 >
int ScatterRperm (const VectorVirtualClass< T1 > &v_in, VectorVirtualClass< T1 > &v_out)
 Copy element from a vector to another vector use vector as map. (v_out(map) := v_in) More...
 
template<typename T1 >
int GatherPerm (const VectorVirtualClass< T1 > &v_in, VectorVirtualClass< T1 > &v_out)
 Copy element from a vector to another vector use this vector as map. (v_out := v_in(map)) More...
 
virtual int MoveData (const int &location)
 Move the data to another memory location. More...
 
- Public Member Functions inherited from pargemslr::VectorVirtualClass< T >
 VectorVirtualClass ()
 The constructor of VectorVirtualClass. More...
 
 VectorVirtualClass (const VectorVirtualClass< T > &vec)
 The copy constructor of VectorVirtualClass. More...
 
 VectorVirtualClass (VectorVirtualClass< T > &&vec)
 The move constructor of VectorVirtualClass. More...
 
virtual ~VectorVirtualClass ()
 The destructor of VectorVirtualClass. More...
 
virtual bool IsParallel () const
 Tell if this is a prallel vector. More...
 
PrecisionEnum GetPrecision () const
 Get the data precision of the vector. More...
 

Detailed Description

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

The class of sequential integer vector.

Constructor & Destructor Documentation

◆ IntVectorClass() [1/3]

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

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

◆ IntVectorClass() [2/3]

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

The copy constructor of IntVectorClass.

◆ IntVectorClass() [3/3]

template<typename T >
pargemslr::IntVectorClass< T >::IntVectorClass ( IntVectorClass< T > &&  vec)

The move constructor of IntVectorClass.

Parameters
[in]vecThe vector.

◆ ~IntVectorClass()

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

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

Member Function Documentation

◆ Back()

template<typename T >
template long int & pargemslr::IntVectorClass< T >::Back ( )

Get the reference of the last index in the vector.

Returns
The reference of the value on the last index.

◆ BinarySearch()

template<typename T >
template int pargemslr::IntVectorClass< 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 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::IntVectorClass< T >::Clear ( )
virtual

Free the current vector.

Returns
Return error message.

Reimplemented from pargemslr::VectorVirtualClass< T >.

◆ Copy()

template<typename T >
template int pargemslr::IntVectorClass< 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.

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.

◆ Fill()

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

Fill the vector with constant value.

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

Implements pargemslr::VectorVirtualClass< T >.

◆ GatherPerm()

template<typename T >
template<typename T1 >
template int pargemslr::IntVectorClass< T >::GatherPerm ( const VectorVirtualClass< T1 > &  v_in,
VectorVirtualClass< T1 > &  v_out 
)

Copy element from a vector to another vector use vector as map. (v_out := v_in(map))
Gather the value from map[i] locatioin of another vector to i location of this vector, the size of v_out is equal to the size of map, but the size of v_in can be larger.

Parameters
[in]v_outThe output vector.
[out]v_inThe input vector.
Returns
Return error message.

◆ GetData()

template<typename T >
template long int * pargemslr::IntVectorClass< T >::GetData ( ) const
virtual

Get the data pointer of the vector.

Returns
Return the data pointer.

Implements pargemslr::VectorVirtualClass< T >.

◆ GetDataLocation()

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

Get the data location of the vector.

Returns
Return the data location of the vector.

Implements pargemslr::VectorVirtualClass< T >.

◆ GetLengthLocal()

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

Get the length of the vector.

Returns
Return the length of the vector.

Implements pargemslr::VectorVirtualClass< T >.

◆ Max()

template<typename T >
template long int pargemslr::IntVectorClass< T >::Max ( ) const

Get the max value in the vector.

Returns
Return the max value.

◆ MaxIndex()

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

Get the index of the max value in the vector.

Returns
Return the index of the max value.

◆ Min()

template<typename T >
template long int pargemslr::IntVectorClass< T >::Min ( ) const

Get the min value in the vector.

Returns
Return the min value.

◆ MinIndex()

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

Get the index of the min value in the vector.

Returns
Return the index of the min value.

◆ MoveData()

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

Move the data to another memory location.

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

Implements pargemslr::VectorVirtualClass< T >.

◆ operator=() [1/2]

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

The = operator of IntVectorClass.

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

◆ operator=() [2/2]

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

The = operator of IntVectorClass.

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

◆ operator[]()

template<typename T >
template long int & pargemslr::IntVectorClass< 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.

Implements pargemslr::VectorVirtualClass< T >.

◆ Perm()

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

Sort the current vector.

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

◆ Plot()

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

Print the vector.

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

◆ PushBack()

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

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.

◆ Resize() [1/2]

template<typename T >
template int pargemslr::IntVectorClass< 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() [2/2]

template<typename T >
template int pargemslr::IntVectorClass< 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.

◆ ScatterRperm()

template<typename T >
template<typename T1 >
template int pargemslr::IntVectorClass< T >::ScatterRperm ( const VectorVirtualClass< T1 > &  v_in,
VectorVirtualClass< T1 > &  v_out 
)

Copy element from a vector to another vector use vector as map. (v_out(map) := v_in)
Scatter the local value at i to the map[i] location of another vector, the size of v_in is equal to the size of map, but the size of v_out can be larger.

Parameters
[in]v_outThe output vector.
[out]v_inThe input vector.
Returns
Return error message.

◆ Setup() [1/4]

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

Free the current vector, and malloc memory to initilize the vector. The memory location is controlled by _location.

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

◆ Setup() [2/4]

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

Free the current vector, and allocate memory to initilize the vector. The memory location is controlled by _location.

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::IntVectorClass< 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::IntVectorClass< 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::IntVectorClass< T >::SetupPtr ( const IntVectorClass< T > &  vec,
int  length,
int  shift 
)

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

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::IntVectorClass< T >::SetupPtr ( const IntVectorClass< T > &  vec,
int  length,
int  shift,
bool  hold_data 
)

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

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 >
int pargemslr::IntVectorClass< T >::SetupPtr ( T *  data,
int  length,
int  location 
)

Free the current vector, and points the vector to an address in the memory.
Data is not freed by this vector.

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

◆ SetupPtr() [4/4]

template<typename T >
int pargemslr::IntVectorClass< T >::SetupPtr ( T *  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 new length of this vector.
[in]locationThe location of the data.
[in]hold_dataSet to true if we need to free data.
Returns
Return error message.

◆ Sort() [1/2]

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

Sort the current vector.

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

◆ Sort() [2/2]

template<typename T >
template int pargemslr::IntVectorClass< 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.

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

◆ UnitPerm()

template<typename T >
template int pargemslr::IntVectorClass< T >::UnitPerm ( )

Generate a unit permutation vector.
Should call Setup first to set the length and data of this vector.

Returns
Return error message.

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