DD-AVX  2.0.0
DD-AVX_dd_vector.hpp
Go to the documentation of this file.
1 #ifndef DD_VECTOR_HPP
2 #define DD_VECTOR_HPP
3 
4 class d_real_vector;
5 struct dd_real;
6 
9 {
10 public:
11  typename std::vector<double>::iterator dd_hi_iter;
12  typename std::vector<double>::iterator dd_lo_iter;
13 
14  dd_real_vector_ref(typename std::vector<double>::iterator hi, typename std::vector<double>::iterator lo)
15  : dd_hi_iter(hi), dd_lo_iter(lo) {}
16 
17  operator double() const{
18  return *dd_hi_iter;
19  }
20 
21  operator dd_real() const{
22  return dd_real(*dd_hi_iter, *dd_lo_iter);
23  }
24 
25  void operator=(dd_real c){
26  *dd_hi_iter = c.x[0];
27  *dd_lo_iter = c.x[1];
28  }
29 
31  *dd_hi_iter = *c.dd_hi_iter;
32  *dd_lo_iter = *c.dd_lo_iter;
33  }
34 
35  void operator=(double& c){
36  *dd_hi_iter = c;
37  *dd_lo_iter = 0.0;
38  }
39 
40  dd_real operator+(const dd_real a);
41  dd_real operator+(dd_real_vector_ref c);
42  dd_real operator+(double c);
43  dd_real operator-(const dd_real a);
44  dd_real operator-(dd_real_vector_ref c);
45  dd_real operator-(double c);
46  dd_real operator*(const dd_real a);
47  dd_real operator*(dd_real_vector_ref c);
48  dd_real operator*(double c);
49  dd_real operator/(const dd_real a);
50  dd_real operator/(dd_real_vector_ref c);
51  dd_real operator/(double c);
52 // QD_API std::ostream& operator<<(std::ostream &s, const dd_real &a);
53 // QD_API std::istream& operator>>(std::istream &s, dd_real &a);
54 };
55 
56 dd_real operator+(const dd_real a, const dd_real_vector_ref b);
57 dd_real operator+(const double a, const dd_real_vector_ref b);
58 dd_real operator-(const dd_real a, const dd_real_vector_ref b);
59 dd_real operator-(const double a, const dd_real_vector_ref b);
60 dd_real operator*(const dd_real a, const dd_real_vector_ref b);
61 dd_real operator*(const double a, const dd_real_vector_ref b);
62 dd_real operator/(const dd_real a, const dd_real_vector_ref b);
63 dd_real operator/(const double a, const dd_real_vector_ref b);
64 
67 
68  private:
69  int N=0;
70 
71  public:
72  std::vector<double> hi;
73  std::vector<double> lo;
75 
78  N=n;
79  hi.resize(N);
80  lo.resize(N);
81  }
82 
84  dd_real_vector(int n, double val){
85  N=n;
86  hi.resize(N, val);
87  lo.resize(N, 0.0);
88  }
89 
91  dd_real_vector(int n, dd_real val){
92  N=n;
93  hi.resize(N, val.x[0]);
94  lo.resize(N, val.x[1]);
95  }
96 
99  return dd_real_vector_ref(hi.begin() + i, lo.begin() + i);
100  }
101 //--cast -------------------------------------
103  operator std::vector<double>();
104 
106  operator double*();
107 
109  operator d_real_vector();
110 
111 //--getinfo---------------------------------------
113  int size() const{return N;};
114 
116  double* data(){return hi.data();};
118  double* hi_data(){return hi.data();};
120  double* lo_data(){return lo.data();};
121 
123  std::vector<double> HI(){return this->hi;}
125  std::vector<double> LO(){return this->lo;}
126 
128  dd_real at(int i){
129  dd_real tmp;
130  tmp.x[0] = hi[i];
131  tmp.x[1] = lo[i];
132  return tmp;
133  };
134 
135 //--I/O---------------------------------------
137  void print_all(){ for(int i=0; i<N; i++) std::cout << hi[i] << ", " << lo[i] << std::endl; }
139  void print(int i){ std::cout << hi[i] << ", " << lo[i] << std::endl;}
140 
142  void input(const char* filename);
144  void input_mm(FILE *file);
146  void input_plane(FILE *file);
148  void output_mm(const char *filename);
150  void output_plane(const char *filename);
151 
152 //--allocate, free---------------------------------------
154  void resize(int n){
155  N=n;
156  hi.resize(N);
157  lo.resize(N);
158  }
159 
161  void resize(int n, double val){
162  N=n;
163  hi.resize(N, val);
164  lo.resize(N, 0.0);
165  };
166 
168  void resize(int n, dd_real val){
169  N=n;
170  hi.resize(N, val.x[0]);
171  lo.resize(N, val.x[1]);
172  };
173 
175  void push_back(const double val){
176  N=N+1;
177  hi.push_back(val);
178  lo.push_back(0.0);
179  }
180 
182  void push_back(const dd_real val){
183  N=N+1;
184  hi.push_back(val.x[0]);
185  lo.push_back(val.x[1]);
186  }
187 
189  void clear(){
190  N=0;
191  hi.clear();
192  lo.clear();
193  }
194 
195 //--copy---------------------------------------
197  void copy(const dd_real_vector& vec);
199  void copy(const d_real_vector& vec);
201  void copy(const std::vector<double>& vec);
203  void copy(const std::vector<dd_real>& vec);
204 
210  dd_real_vector& operator=(const std::vector<double>& vec);
212  dd_real_vector& operator=(const std::vector<dd_real>& vec);
213 
214 //--comparision---------------------------------------
215 
217  bool operator==(const dd_real_vector& vec);
219  bool operator==(const d_real_vector& vec);
221  bool operator==(const std::vector<double>& vec);
223  bool operator==(const std::vector<dd_real>& vec);
224 
226  bool operator!=(const dd_real_vector& vec);
228  bool operator!=(const d_real_vector& vec);
230  bool operator!=(const std::vector<double>& vec);
232  bool operator!=(const std::vector<dd_real>& vec);
233 
234 //--minus---------------------------------------
236  void minus();
239 
240 //--add---------------------------------------
242  void add(dd_real_vector& vec1, dd_real_vector& vec2);
244  void add(d_real_vector& vec1, dd_real_vector& vec2);
246  void add(dd_real_vector& vec1, d_real_vector& vec2);
248  void add(d_real_vector& vec1, d_real_vector& vec2);
249 
254 
259 
260 //--sub---------------------------------------
262  void sub(dd_real_vector& vec1, dd_real_vector& vec2);
264  void sub(d_real_vector& vec1, dd_real_vector& vec2);
266  void sub(dd_real_vector& vec1, d_real_vector& vec2);
268  void sub(d_real_vector& vec1, d_real_vector& vec2);
269 
274 
279 
280 //--mul---------------------------------------
282  void mul(dd_real_vector& vec1, dd_real_vector& vec2);
284  void mul(d_real_vector& vec1, dd_real_vector& vec2);
286  void mul(dd_real_vector& vec1, d_real_vector& vec2);
288  void mul(d_real_vector& vec1, d_real_vector& vec2);
289 
294 
299 
300 //--div---------------------------------------
302  void div(dd_real_vector& vec1, dd_real_vector& vec2);
304  void div(d_real_vector& vec1, dd_real_vector& vec2);
306  void div(dd_real_vector& vec1, d_real_vector& vec2);
308  void div(d_real_vector& vec1, d_real_vector& vec2);
309 
314 
319 };
320 #endif
dd_real operator*(const dd_real a, const dd_real_vector_ref b)
dd_real operator+(const dd_real a, const dd_real_vector_ref b)
dd_real operator/(const dd_real a, const dd_real_vector_ref b)
dd_real operator-(const dd_real a, const dd_real_vector_ref b)
Double precision vector class, This class is almost same as std::vector<double>
Double-double precision vector reference class.
dd_real operator/(const dd_real a)
dd_real operator*(const dd_real a)
void operator=(dd_real_vector_ref &c)
std::vector< double >::iterator dd_lo_iter
dd_real_vector_ref(typename std::vector< double >::iterator hi, typename std::vector< double >::iterator lo)
dd_real operator-(const dd_real a)
void operator=(double &c)
std::vector< double >::iterator dd_hi_iter
void operator=(dd_real c)
dd_real operator+(const dd_real a)
Double-double precision vector class.
std::vector< double > lo
void copy(const dd_real_vector &vec)
copy from dd_real_vector
Definition: vector_copy.cpp:48
std::vector< double > LO()
get lo array pointer
bool operator!=(const dd_real_vector &vec)
comparision function
dd_real_vector operator/=(dd_real_vector &vec)
all elemetnt arithmetic function
dd_real_vector operator*(dd_real_vector &vec)
all elemetnt arithmetic function
void output_plane(const char *filename)
output vector to plane file
void print_all()
output all elements to standard I/O
int size() const
get size
std::vector< double > HI()
get hi array pointer
void push_back(const dd_real val)
push_back, this method is almost same as std::vector
dd_real_vector_ref operator[](int i)
get vec[i] value
void mul(dd_real_vector &vec1, dd_real_vector &vec2)
all elemetnt arithmetic function
double * hi_data()
get hi array pointer
dd_real_vector operator+=(dd_real_vector &vec)
all elemetnt arithmetic function
double * lo_data()
get lo array pointer
dd_real_vector operator+(dd_real_vector &vec)
all elemetnt arithmetic function
void input_mm(FILE *file)
create vector from matrix market file
dd_real_vector operator/(dd_real_vector &vec)
all elemetnt arithmetic function
void print(int i)
output vec[i] to standard I/O
dd_real_vector(int n, double val)
create size N, all element is val DD vector
void input_plane(FILE *file)
create vector from plane file
void div(dd_real_vector &vec1, dd_real_vector &vec2)
all elemetnt arithmetic function
dd_real_vector(int n)
create size N DD vector
dd_real_vector(int n, dd_real val)
create size N, all element is val DD vector
void sub(dd_real_vector &vec1, dd_real_vector &vec2)
all elemetnt arithmetic function
double * data()
get hi array pointer
dd_real_vector operator*=(dd_real_vector &vec)
all elemetnt arithmetic function
void clear()
clear, this method is almost same as std::vector
void resize(int n, double val)
resize, this method is almost same as std::vector
dd_real_vector & operator=(const dd_real_vector &vec)
copy from dd_real_vector
Definition: vector_copy.cpp:81
std::vector< double > hi
dd_real at(int i)
get vec[i] value
bool operator==(const dd_real_vector &vec)
comparision function
dd_real_vector operator-()
sign
void resize(int n, dd_real val)
resize, this method is almost same as std::vector
void input(const char *filename)
create vector from file
dd_real_vector operator-=(dd_real_vector &vec)
all elemetnt arithmetic function
void output_mm(const char *filename)
output vector to matrix market file
void add(dd_real_vector &vec1, dd_real_vector &vec2)
all elemetnt arithmetic function
void push_back(const double val)
push_back, this method is almost same as std::vector
void minus()
sign
Definition: vector_minus.cpp:4
void resize(int n)
resize, this method is almost same as std::vector