ParGeMSLR
int_vector.hpp
Go to the documentation of this file.
1 #ifndef PARGEMSLR_INT_VECTOR_H
2 #define PARGEMSLR_INT_VECTOR_H
3 
9 #include "../utils/utils.hpp"
10 #include "vector.hpp"
11 #include <algorithm>
12 #include <iostream>
13 
14 #ifdef PARGEMSLR_CUDA
15 #include "cusparse.h"
16 #endif
17 
18 namespace pargemslr
19 {
20 
25  template <typename T>
27  {
28  private:
29 
34  T* _data;
35 
40  int _length;
41 
46  int _maxlength;
47 
52  bool _hold_data;
53 
58  int _location;
59 
60 
61  public:
62 
68 
74 
81 
89 
97 
102  virtual ~IntVectorClass();
103 
110  int Setup(int length);
111 
119  int Setup(int length, bool setzero);
120 
129  int Setup(int length, int location, bool setzero);
130 
141  int Setup(int length, int reserve, int location, bool setzero);
142 
152  int SetupPtr( T* data, int length, int location);
153 
163  int SetupPtr( T* data, int length, int location, bool hold_data);
164 
173  int SetupPtr(const IntVectorClass<T> &vec, int length, int shift);
174 
184  int SetupPtr(const IntVectorClass<T> &vec, int length, int shift, bool hold_data);
185 
195  int Copy(const T *data, int length, int loc_from, int loc_to);
196 
204  int PushBack(T v);
205 
214  int Resize(int length, bool keepdata, bool setzero);
215 
225  int Resize(int length, int reserve, bool keepdata, bool setzero);
226 
233  virtual T& operator[] (int i);
234 
240  T& Back();
241 
247  virtual int Clear();
248 
254  virtual T* GetData() const;
255 
261  virtual int GetDataLocation() const;
262 
268  virtual int GetLengthLocal() const;
269 
276  virtual int Fill(const T &v);
277 
284  int UnitPerm();
285 
291  T Max() const;
292 
298  int MaxIndex() const;
299 
305  T Min() const;
306 
312  int MinIndex() const;
313 
322  int BinarySearch(const T &val, int &idx, bool ascending);
323 
330  int Sort(bool ascending);
331 
341  int Sort(IntVectorClass<int> &order, bool ascending, bool stable);
342 
349  int Perm(IntVectorClass<int> &perm);
350 
359  int Plot( int conditiona, int conditionb, int width);
360 
370  template <typename T1>
372 
382  template <typename T1>
384 
391  virtual int MoveData( const int &location);
392 
393  };
394 
397  template<> struct PargemslrIsComplex<IntVectorClass<complexs> > : public std::true_type {};
398  template<> struct PargemslrIsComplex<IntVectorClass<complexd> > : public std::true_type {};
399 
400 }
401 
402 #endif
pargemslr::IntVectorClass::Setup
int Setup(int length)
Free the current vector, and malloc memory to initilize the vector.
Definition: int_vector.cpp:134
vector.hpp
The virtual vector classes.
pargemslr::IntVectorClass::Min
T Min() const
Get the min value in the vector.
Definition: int_vector.cpp:513
pargemslr::IntVectorClass::GetData
virtual T * GetData() const
Get the data pointer of the vector.
Definition: int_vector.cpp:391
pargemslr::IntVectorClass::GatherPerm
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))
Definition: int_vector.cpp:667
pargemslr::IntVectorClass::~IntVectorClass
virtual ~IntVectorClass()
The destructor of IntVectorClass.
Definition: int_vector.cpp:383
pargemslr::IntVectorClass::Copy
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.
Definition: int_vector.cpp:254
pargemslr::IntVectorClass::Sort
int Sort(bool ascending)
Sort the current vector.
Definition: int_vector.cpp:531
pargemslr::IntVectorClass::operator=
IntVectorClass< T > & operator=(const IntVectorClass< T > &vec)
The = operator of IntVectorClass.
Definition: int_vector.cpp:71
pargemslr::IntVectorClass::Plot
int Plot(int conditiona, int conditionb, int width)
Print the vector.
Definition: int_vector.cpp:715
pargemslr::IntVectorClass::Resize
int Resize(int length, bool keepdata, bool setzero)
Resize the vector. Re-allocate memory when necessary.
Definition: int_vector.cpp:313
pargemslr::IntVectorClass::PushBack
int PushBack(T v)
Insert value at the end of the vector, expand the vector when necessary.
Definition: int_vector.cpp:297
pargemslr::IntVectorClass::operator[]
virtual T & operator[](int i)
Get the reference of an index in the vector.
Definition: int_vector.cpp:116
pargemslr::IntVectorClass::SetupPtr
int SetupPtr(T *data, int length, int location)
Free the current vector, and points the vector to an address in the memory.
Definition: int_vector.cpp:205
pargemslr::IntVectorClass::Max
T Max() const
Get the max value in the vector.
Definition: int_vector.cpp:495
pargemslr::IntVectorClass::GetDataLocation
virtual int GetDataLocation() const
Get the data location of the vector.
Definition: int_vector.cpp:399
pargemslr::IntVectorClass::IntVectorClass
IntVectorClass()
The constructor of IntVectorClass.
Definition: int_vector.cpp:20
pargemslr::IntVectorClass::Back
T & Back()
Get the reference of the last index in the vector.
Definition: int_vector.cpp:126
pargemslr::IntVectorClass::MaxIndex
int MaxIndex() const
Get the index of the max value in the vector.
Definition: int_vector.cpp:505
pargemslr::IntVectorClass::BinarySearch
int BinarySearch(const T &val, int &idx, bool ascending)
Binary search between [s, e] inside an array.
Definition: int_vector.cpp:419
pargemslr::IntVectorClass::GetLengthLocal
virtual int GetLengthLocal() const
Get the length of the vector.
Definition: int_vector.cpp:411
pargemslr::ComplexValueClass
The template class complex.
Definition: complex.hpp:24
pargemslr::IntVectorClass
The class of sequential integer vector.
Definition: int_vector.hpp:27
pargemslr::IntVectorClass::ScatterRperm
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)
Definition: int_vector.cpp:628
pargemslr::IntVectorClass::UnitPerm
int UnitPerm()
Generate a unit permutation vector.
Definition: int_vector.cpp:465
pargemslr::IntVectorClass::MinIndex
int MinIndex() const
Get the index of the min value in the vector.
Definition: int_vector.cpp:523
pargemslr::IntVectorClass::MoveData
virtual int MoveData(const int &location)
Move the data to another memory location.
Definition: int_vector.cpp:705
pargemslr::IntVectorClass::Fill
virtual int Fill(const T &v)
Fill the vector with constant value.
Definition: int_vector.cpp:434
pargemslr::IntVectorClass::Clear
virtual int Clear()
Free the current vector.
Definition: int_vector.cpp:274
pargemslr::VectorVirtualClass
The virtual class of all vector classes.
Definition: vector.hpp:22
pargemslr::PargemslrIsComplex
Tell if a value is a complex value.
Definition: complex.hpp:684
pargemslr::IntVectorClass::Perm
int Perm(IntVectorClass< int > &perm)
Apply permutation to the current vector v := v(perm).
Definition: int_vector.cpp:604