ParGeMSLR
|
The class of sequential integer vector. More...
#include <int_vector.hpp>
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... | |
T | Max () const |
Get the max value in the vector. More... | |
int | MaxIndex () const |
Get the index of the max value in the vector. More... | |
T | 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... | |
![]() | |
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... | |
The class of sequential integer vector.
template pargemslr::IntVectorClass< T >::IntVectorClass | ( | ) |
The constructor of IntVectorClass. The default memory location is the host memory.
pargemslr::IntVectorClass< T >::IntVectorClass | ( | const IntVectorClass< T > & | vec | ) |
The copy constructor of IntVectorClass.
pargemslr::IntVectorClass< T >::IntVectorClass | ( | IntVectorClass< T > && | vec | ) |
The move constructor of IntVectorClass.
[in] | vec | The vector. |
|
virtual |
The destructor of IntVectorClass. Simply a call to the free function.
template long int & pargemslr::IntVectorClass< T >::Back | ( | ) |
Get the reference of the last index in the vector.
template int pargemslr::IntVectorClass< T >::BinarySearch | ( | const T & | val, |
int & | idx, | ||
bool | ascending | ||
) |
Binary search between [s, e] inside an array.
[in] | val | The target value. |
[out] | idx | If found the value, set to the index of the value. Otherwise the position to insert, or -1 if s > e. |
[in] | descend | The array is descend or ascend. |
|
virtual |
Free the current vector.
Reimplemented from pargemslr::VectorVirtualClass< 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.
[in] | data | The target memory address. |
[in] | length | The new length of this vector. |
[in] | loc_from | The location of the input data. |
[in] | loc_to | The location of the new vector. |
|
virtual |
Fill the vector with constant value.
[in] | v | The value to be filled. |
Implements pargemslr::VectorVirtualClass< T >.
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.
[in] | v_out | The output vector. |
[out] | v_in | The input vector. |
|
virtual |
Get the data pointer of the vector.
Implements pargemslr::VectorVirtualClass< T >.
|
virtual |
Get the data location of the vector.
Implements pargemslr::VectorVirtualClass< T >.
|
virtual |
Get the length of the vector.
Implements pargemslr::VectorVirtualClass< T >.
template long int pargemslr::IntVectorClass< T >::Max | ( | ) | const |
Get the max value in the vector.
template int pargemslr::IntVectorClass< T >::MaxIndex | ( | ) | const |
Get the index of the max value in the vector.
template long int pargemslr::IntVectorClass< T >::Min | ( | ) | const |
Get the min value in the vector.
template int pargemslr::IntVectorClass< T >::MinIndex | ( | ) | const |
Get the index of the min value in the vector.
|
virtual |
Move the data to another memory location.
[in] | location | The location move to. |
Implements pargemslr::VectorVirtualClass< T >.
IntVectorClass< T > & pargemslr::IntVectorClass< T >::operator= | ( | const IntVectorClass< T > & | vec | ) |
IntVectorClass< T > & pargemslr::IntVectorClass< T >::operator= | ( | IntVectorClass< T > && | vec | ) |
|
virtual |
Get the reference of an index in the vector.
[in] | i | The index. |
Implements pargemslr::VectorVirtualClass< T >.
template int pargemslr::IntVectorClass< T >::Perm | ( | IntVectorClass< int > & | perm | ) |
Sort the current vector.
[in] | perm | The permutation vector. |
template int pargemslr::IntVectorClass< T >::Plot | ( | int | conditiona, |
int | conditionb, | ||
int | width | ||
) |
Print the vector.
[in] | conditiona | First condition. |
[in] | conditionb | Secend condition, only print when conditiona == conditionb. |
[in] | width | The plot width. |
template int pargemslr::IntVectorClass< T >::PushBack | ( | T | v | ) |
Insert value at the end of the vector, expand the vector when necessary.
Work only when the vector is holding data.
[in] | v | The value to be inserted. |
template int pargemslr::IntVectorClass< T >::Resize | ( | int | length, |
bool | keepdata, | ||
bool | setzero | ||
) |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The new length of this vector. |
[in] | keepdata | Set to true to keep the data in the current vector. |
[in] | setzero | Set to true to fill the new extra memory with 0 if the vector is expanded. |
template int pargemslr::IntVectorClass< T >::Resize | ( | int | length, |
int | reserve, | ||
bool | keepdata, | ||
bool | setzero | ||
) |
Resize the vector. Re-allocate memory when necessary.
[in] | length | The new length of this vector. |
[in] | reserve | The new reserve length in the memory, should be no less than length. |
[in] | keepdata | Set to true to keep the data in the current vector. |
[in] | setzero | Set to true to fill the new extra memory with 0 if the vector is expanded. |
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.
[in] | v_out | The output vector. |
[out] | v_in | The input vector. |
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.
[in] | length | The length of the vector. |
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.
[in] | length | The length of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
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.
[in] | length | The length of the vector. |
[in] | location | The location of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
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.
[in] | length | The length of the vector. |
[in] | reserve | The length allocated in the memory, should be no less than length. |
[in] | location | The location of the vector. |
[in] | setzero | Call calloc if we need to fill the memory with 0. |
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.
[in] | vec | The target vector. |
[in] | length | The new length of this vector. |
[in] | shift | The shift in the target vector. this->_data = vec.GetData() + shift. |
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.
[in] | vec | The target vector. |
[in] | length | The new length of this vector. |
[in] | shift | The shift in the target vector. this->_data = vec.GetData() + shift. |
[in] | hold_data | Set to true if this vector should free the data. Typically this function should not be used. |
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.
[in] | data | The address of the data. |
[in] | length | The new length of this vector. |
[in] | location | The location of the data. |
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.
[in] | data | The address of the data. |
[in] | length | The new length of this vector. |
[in] | location | The location of the data. |
[in] | hold_data | Set to true if we need to free data. |
template int pargemslr::IntVectorClass< T >::Sort | ( | bool | ascending | ) |
Sort the current vector.
[in] | ascending | Sort in ascending or descending. |
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.
[out] | order | The order vector. |
[in] | ascending | Sort in ascending or descending. |
[in] | stable | Use stable sort or not. |
template int pargemslr::IntVectorClass< T >::UnitPerm | ( | ) |
Generate a unit permutation vector.
Should call Setup first to set the length and data of this vector.