IT++ Logo
vec.cpp
Go to the documentation of this file.
1
29#ifndef _MSC_VER
30# include <itpp/config.h>
31#else
32# include <itpp/config_msvc.h>
33#endif
34
35#if defined (HAVE_BLAS)
36# include <itpp/base/blas.h>
37#endif
38
39#include <itpp/base/vec.h>
41#include <cstdio>
42#include <limits>
44
45namespace itpp
46{
47
48template<>
49int Vec<int>::parse_token(const std::string &s) const
50{
51 int out;
52 std::istringstream buffer(s);
53 if (s.find('x', 1) != std::string::npos) {
54 buffer >> std::hex >> out;
55 }
56 else if (((s[0] == '0')
57 || (((s[0] == '-') || (s[0] == '+')) && (s[1] == '0')))
58 && (s.find('8', 1) == std::string::npos)
59 && (s.find('9', 1) == std::string::npos)) {
60 buffer >> std::oct >> out;
61 }
62 else {
63 buffer >> std::dec >> out;
64 }
65 return out;
66}
67
68template<>
69double Vec<double>::parse_token(const std::string &s) const
70{
71 double out;
72 if ((s == "NaN") || (s == "nan") || (s == "NAN")) {
73 if (std::numeric_limits<double>::has_quiet_NaN)
74 out = std::numeric_limits<double>::quiet_NaN();
75 else if (std::numeric_limits<double>::has_signaling_NaN)
76 out = std::numeric_limits<double>::signaling_NaN();
77 else
78 it_error("Vec<double>::set(): NaN not supported");
79 }
80 else if ((s =="-Inf") || (s =="-inf") || (s =="-INF")) {
81 out = -std::numeric_limits<double>::infinity();
82 }
83 else if ((s =="Inf") || (s =="inf") || (s =="INF") ||
84 (s =="+Inf") || (s =="+inf") || (s =="+INF")) {
85 out = std::numeric_limits<double>::infinity();
86 }
87 else {
88 std::istringstream buffer(s);
89 buffer >> out;
90 it_assert(!buffer.fail(), "Vec<double>::set(): Stream operation failed "
91 "(buffer >> out)");
92 }
93 return out;
94}
95
96
97template<>
98void Vec<bin>::set(const std::string &str)
99{
100 bool abc_format;
101 std::vector<std::string> tokens = tokenize(str, abc_format);
102 it_assert(!abc_format, "Vec<bin>::set(): \"a:b:c\" format string not "
103 "supported for binary vectors");
104 set_size(int(tokens.size()));
105 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i) {
106 std::istringstream buffer(tokens[i]);
107 buffer >> data[i];
108 it_assert(!buffer.fail(), "Vec<bin>::set(): Stream operation failed "
109 "(buffer >> data)");
110 }
111}
112
113template<>
114void Vec<short int>::set(const std::string &str)
115{
116 // parser for "short int" is the same as for "int", so reuse it here
117 ivec iv(str);
118 this->operator=(to_svec(iv));
119}
120
121template<>
122void Vec<int>::set(const std::string &str)
123{
124 bool abc_format;
125 std::vector<std::string> tokens = tokenize(str, abc_format);
126 // no "a:b:c" tokens, so the size of output vector is known
127 if (!abc_format) {
128 set_size(int(tokens.size()));
129 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i)
130 data[i] = parse_token(tokens[i]);
131 }
132 else {
133 int pos = 0;
134 set_size((tokens.size() > 20) ? int(tokens.size()) : 20);
135 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i) {
136 // check if the current token is in "a:b[:c]" format
137 if (tokens[i].find(':', 1) == std::string::npos) {
138 if (++pos > datasize) {
139 set_size(2 * datasize, true);
140 }
141 data[pos-1] = parse_token(tokens[i]);
142 }
143 else {
144 int a, b, c;
145 parse_abc_token(tokens[i], a, b, c);
146 if (++pos > datasize) {
147 set_size(2 * datasize, true);
148 }
149 data[pos-1] = a;
150
151 if ((b > 0) && (c >= a)) {
152 while ((data[pos-1] + b) <= c) {
153 if (++pos > datasize) {
154 set_size(2 * datasize, true);
155 }
156 data[pos-1] = data[pos-2] + b;
157 }
158 }
159 else if ((b < 0) && (c <= a)) {
160 while ((data[pos-1] + b) >= c) {
161 if (++pos > datasize) {
162 set_size(2 * datasize, true);
163 }
164 data[pos-1] = data[pos-2] + b;
165 }
166 }
167 else if (b == 0 && c == a) {
168 break;
169 }
170 else {
171 it_error("Vec<int>::set(): Improper data string (a:b:c)");
172 }
173 }
174 }
175 set_size(pos, true);
176 } // if (!abc_format)
177}
178
179
180template<>
181void Vec<double>::set(const std::string &str)
182{
183 bool abc_format;
184 std::vector<std::string> tokens = tokenize(str, abc_format);
185 // no "a:b:c" tokens, so the size of output vector is known
186 if (!abc_format) {
187 set_size(int(tokens.size()));
188 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i)
189 data[i] = parse_token(tokens[i]);
190 }
191 else {
192 int pos = 0;
193 set_size((tokens.size() > 20) ? int(tokens.size()) : 20);
194 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i) {
195 // check if the current token is in "a:b[:c]" format
196 if (tokens[i].find(':', 1) == std::string::npos) {
197 if (++pos > datasize) {
198 set_size(2 * datasize, true);
199 }
200 data[pos-1] = parse_token(tokens[i]);
201 }
202 else {
203 double a, b, c;
204 parse_abc_token(tokens[i], a, b, c);
205 if (++pos > datasize) {
206 set_size(2 * datasize, true);
207 }
208 data[pos-1] = a;
209 // Adding this margin fixes precision problems in e.g. "0:0.2:3",
210 // where the last value was 2.8 instead of 3.
211 double eps_margin = std::fabs((c - a) / b) * eps;
212 if ((b > 0) && (c >= a)) {
213 while ((data[pos-1] + b) <= (c + eps_margin)) {
214 if (++pos > datasize) {
215 set_size(2 * datasize, true);
216 }
217 data[pos-1] = data[pos-2] + b;
218 }
219 }
220 else if ((b < 0) && (c <= a)) {
221 while ((data[pos-1] + b) >= (c - eps_margin)) {
222 if (++pos > datasize) {
223 set_size(2 * datasize, true);
224 }
225 data[pos-1] = data[pos-2] + b;
226 }
227 }
228 else if (b == 0 && c == a) {
229 break;
230 }
231 else {
232 it_error("Vec<double>::set(): Improper data string (a:b:c)");
233 }
234 }
235 }
236 set_size(pos, true);
237 } // if (!abc_format)
238}
239
240template<>
241void Vec<std::complex<double> >::set(const std::string &str)
242{
243 bool abc_format;
244 std::vector<std::string> tokens = tokenize(str, abc_format);
245 it_assert(!abc_format, "Vec<bin>::set(): \"a:b:c\" format string not "
246 "supported for binary vectors");
247 set_size(int(tokens.size()));
248 for (std::vector<std::string>::size_type i = 0; i < tokens.size(); ++i) {
249 std::istringstream buffer(tokens[i]);
250 buffer >> data[i];
251 it_assert(!buffer.fail(), "Vec<complex>::set(): Stream operation failed "
252 "(buffer >> data)");
253 }
254}
255
256#if defined(HAVE_BLAS)
257template<>
258double dot(const vec &v1, const vec &v2)
259{
260 it_assert_debug(v1.length() == v2.length(), "vec::dot(): Wrong sizes");
261 int incr = 1; int v1_l = v1.length();
262 return blas::ddot_(&v1_l, v1._data(), &incr, v2._data(), &incr);
263}
264#else
265template<>
266double dot(const vec &v1, const vec &v2)
267{
268 it_assert_debug(v1.length() == v2.length(), "vec::dot(): Wrong sizes");
269 double r = 0.0;
270 for (int i = 0; i < v1.length(); ++i)
271 r += v1._data()[i] * v2._data()[i];
272 return r;
273}
274#endif // HAVE_BLAS
275
276#if defined(HAVE_BLAS)
277template<>
278mat outer_product(const vec &v1, const vec &v2, bool)
279{
280 it_assert_debug((v1.length() > 0) && (v2.length() > 0),
281 "Vec::outer_product:: Input vector of zero size");
282 int v1_l = v1.length(); int v2_l = v2.length();
283 mat out(v1_l, v2_l);
284 out.zeros();
285 double alpha = 1.0;
286 int incr = 1;
287 blas::dger_(&v1_l, &v2_l, &alpha, v1._data(), &incr,
288 v2._data(), &incr, out._data(), &v1_l);
289 return out;
290}
291
292template<>
293cmat outer_product(const cvec &v1, const cvec &v2, bool hermitian)
294{
295 it_assert_debug((v1.length() > 0) && (v2.length() > 0),
296 "Vec::outer_product:: Input vector of zero size");
297 int v1_l = v1.length(); int v2_l = v2.length();
298 cmat out(v1_l, v2_l);
299 out.zeros();
300 std::complex<double> alpha(1.0);
301 int incr = 1;
302 if (hermitian) {
303 blas::zgerc_(&v1_l, &v2_l, &alpha, v1._data(), &incr,
304 v2._data(), &incr, out._data(), &v1_l);
305 }
306 else {
307 blas::zgeru_(&v1_l, &v2_l, &alpha, v1._data(), &incr,
308 v2._data(), &incr, out._data(), &v1_l);
309 }
310 return out;
311}
312#else
313template<>
314mat outer_product(const vec &v1, const vec &v2, bool)
315{
316 it_assert_debug((v1.length() > 0) && (v2.length() > 0),
317 "Vec::outer_product:: Input vector of zero size");
318 int v1_l = v1.length(); int v2_l = v2.length();
319 mat out(v1_l, v2_l);
320 for (int i = 0; i < v1_l; ++i) {
321 for (int j = 0; j < v2_l; ++j) {
322 out(i, j) = v1._data()[i] * v2._data()[j];
323 }
324 }
325 return out;
326}
327
328template<>
329cmat outer_product(const cvec &v1, const cvec &v2, bool hermitian)
330{
331 it_assert_debug((v1.length() > 0) && (v2.length() > 0),
332 "Vec::outer_product:: Input vector of zero size");
333 int v1_l = v1.length(); int v2_l = v2.length();
334 cmat out(v1_l, v2_l);
335 if (hermitian) {
336 for (int i = 0; i < v1_l; ++i) {
337 for (int j = 0; j < v2_l; ++j) {
338 out(i, j) = v1._data()[i] * conj(v2._data()[j]);
339 }
340 }
341 }
342 else {
343 for (int i = 0; i < v1_l; ++i) {
344 for (int j = 0; j < v2_l; ++j) {
345 out(i, j) = v1._data()[i] * v2._data()[j];
346 }
347 }
348 }
349 return out;
350}
351#endif // HAVE_BLAS
352
353
354template<>
355bvec Vec<std::complex<double> >::operator<=(std::complex<double>) const
356{
357 it_error("operator<=: not implemented for complex");
358 bvec temp;
359 return temp;
360}
361
362template<>
363bvec Vec<std::complex<double> >::operator>(std::complex<double>) const
364{
365 it_error("operator>: not implemented for complex");
366 bvec temp;
367 return temp;
368}
369
370template<>
371bvec Vec<std::complex<double> >::operator<(std::complex<double>) const
372{
373 it_error("operator<: not implemented for complex");
374 bvec temp;
375 return temp;
376}
377
378template<>
379bvec Vec<std::complex<double> >::operator>=(std::complex<double>) const
380{
381 it_error("operator>=: not implemented for complex");
382 bvec temp;
383 return temp;
384}
385
386template<>
387Mat<std::complex<double> > Vec<std::complex<double> >::hermitian_transpose() const
388{
389 Mat<std::complex<double> > temp(1, datasize);
390 for (int i = 0; i < datasize; i++)
391 temp(i) = std::conj(data[i]);
392
393 return temp;
394}
395
396
397//---------------------------------------------------------------------
398// Instantiations
399//---------------------------------------------------------------------
400
401template class ITPP_EXPORT Vec<double>;
402template class ITPP_EXPORT Vec<int>;
403template class ITPP_EXPORT Vec<short int>;
404template class ITPP_EXPORT Vec<std::complex<double> >;
405template class ITPP_EXPORT Vec<bin>;
406
407// addition operator
408
409template ITPP_EXPORT vec operator+(const vec &v1, const vec &v2);
410template ITPP_EXPORT cvec operator+(const cvec &v1, const cvec &v2);
411template ITPP_EXPORT ivec operator+(const ivec &v1, const ivec &v2);
412template ITPP_EXPORT svec operator+(const svec &v1, const svec &v2);
413template ITPP_EXPORT bvec operator+(const bvec &v1, const bvec &v2);
414
415template ITPP_EXPORT vec operator+(const vec &v1, double t);
416template ITPP_EXPORT cvec operator+(const cvec &v1, std::complex<double> t);
417template ITPP_EXPORT ivec operator+(const ivec &v1, int t);
418template ITPP_EXPORT svec operator+(const svec &v1, short t);
419template ITPP_EXPORT bvec operator+(const bvec &v1, bin t);
420
421template ITPP_EXPORT vec operator+(double t, const vec &v1);
422template ITPP_EXPORT cvec operator+(std::complex<double> t, const cvec &v1);
423template ITPP_EXPORT ivec operator+(int t, const ivec &v1);
424template ITPP_EXPORT svec operator+(short t, const svec &v1);
425template ITPP_EXPORT bvec operator+(bin t, const bvec &v1);
426
427// subraction operator
428
429template ITPP_EXPORT vec operator-(const vec &v1, const vec &v2);
430template ITPP_EXPORT cvec operator-(const cvec &v1, const cvec &v2);
431template ITPP_EXPORT ivec operator-(const ivec &v1, const ivec &v2);
432template ITPP_EXPORT svec operator-(const svec &v1, const svec &v2);
433template ITPP_EXPORT bvec operator-(const bvec &v1, const bvec &v2);
434
435template ITPP_EXPORT vec operator-(const vec &v, double t);
436template ITPP_EXPORT cvec operator-(const cvec &v, std::complex<double> t);
437template ITPP_EXPORT ivec operator-(const ivec &v, int t);
438template ITPP_EXPORT svec operator-(const svec &v, short t);
439template ITPP_EXPORT bvec operator-(const bvec &v, bin t);
440
441template ITPP_EXPORT vec operator-(double t, const vec &v);
442template ITPP_EXPORT cvec operator-(std::complex<double> t, const cvec &v);
443template ITPP_EXPORT ivec operator-(int t, const ivec &v);
444template ITPP_EXPORT svec operator-(short t, const svec &v);
445template ITPP_EXPORT bvec operator-(bin t, const bvec &v);
446
447// unary minus
448
449template ITPP_EXPORT vec operator-(const vec &v);
450template ITPP_EXPORT cvec operator-(const cvec &v);
451template ITPP_EXPORT ivec operator-(const ivec &v);
452template ITPP_EXPORT svec operator-(const svec &v);
453template ITPP_EXPORT bvec operator-(const bvec &v);
454
455// multiplication operator
456template ITPP_EXPORT std::complex<double> dot(const cvec &v1, const cvec &v2);
457template ITPP_EXPORT int dot(const ivec &v1, const ivec &v2);
458template ITPP_EXPORT short dot(const svec &v1, const svec &v2);
459template ITPP_EXPORT bin dot(const bvec &v1, const bvec &v2);
460
461template ITPP_EXPORT double operator*(const vec &v1, const vec &v2);
462template ITPP_EXPORT std::complex<double> operator*(const cvec &v1, const cvec &v2);
463template ITPP_EXPORT int operator*(const ivec &v1, const ivec &v2);
464template ITPP_EXPORT short operator*(const svec &v1, const svec &v2);
465template ITPP_EXPORT bin operator*(const bvec &v1, const bvec &v2);
466
467template ITPP_EXPORT imat outer_product(const ivec &v1, const ivec &v2, bool hermitian);
468template ITPP_EXPORT smat outer_product(const svec &v1, const svec &v2, bool hermitian);
469template ITPP_EXPORT bmat outer_product(const bvec &v1, const bvec &v2, bool hermitian);
470
471template ITPP_EXPORT vec operator*(const vec &v, double t);
472template ITPP_EXPORT cvec operator*(const cvec &v, std::complex<double> t);
473template ITPP_EXPORT ivec operator*(const ivec &v, int t);
474template ITPP_EXPORT svec operator*(const svec &v, short t);
475template ITPP_EXPORT bvec operator*(const bvec &v, bin t);
476
477template ITPP_EXPORT vec operator*(double t, const vec &v);
478template ITPP_EXPORT cvec operator*(std::complex<double> t, const cvec &v);
479template ITPP_EXPORT ivec operator*(int t, const ivec &v);
480template ITPP_EXPORT svec operator*(short t, const svec &v);
481template ITPP_EXPORT bvec operator*(bin t, const bvec &v);
482
483// elementwise multiplication
484
485template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b);
486template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b);
487template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b);
488template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b);
489template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b);
490
491template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b, vec &out);
492template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b, cvec &out);
493template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b, ivec &out);
494template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b, svec &out);
495template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b, bvec &out);
496
497template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b, const vec &c);
498template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b, const cvec &c);
499template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b, const ivec &c);
500template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b, const svec &c);
501template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b, const bvec &c);
502
503template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b, const vec &c,
504 vec &out);
505template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b, const cvec &c,
506 cvec &out);
507template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b, const ivec &c,
508 ivec &out);
509template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b, const svec &c,
510 svec &out);
511template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b, const bvec &c,
512 bvec &out);
513
514template ITPP_EXPORT vec elem_mult(const vec &a, const vec &b, const vec &c,
515 const vec &d);
516template ITPP_EXPORT cvec elem_mult(const cvec &a, const cvec &b, const cvec &c,
517 const cvec &d);
518template ITPP_EXPORT ivec elem_mult(const ivec &a, const ivec &b, const ivec &c,
519 const ivec &d);
520template ITPP_EXPORT svec elem_mult(const svec &a, const svec &b, const svec &c,
521 const svec &d);
522template ITPP_EXPORT bvec elem_mult(const bvec &a, const bvec &b, const bvec &c,
523 const bvec &d);
524
525template ITPP_EXPORT void elem_mult_out(const vec &a, const vec &b, const vec &c,
526 const vec &d, vec &out);
527template ITPP_EXPORT void elem_mult_out(const cvec &a, const cvec &b, const cvec &c,
528 const cvec &d, cvec &out);
529template ITPP_EXPORT void elem_mult_out(const ivec &a, const ivec &b, const ivec &c,
530 const ivec &d, ivec &out);
531template ITPP_EXPORT void elem_mult_out(const svec &a, const svec &b, const svec &c,
532 const svec &d, svec &out);
533template ITPP_EXPORT void elem_mult_out(const bvec &a, const bvec &b, const bvec &c,
534 const bvec &d, bvec &out);
535
536// in-place elementwise multiplication
537
538template ITPP_EXPORT void elem_mult_inplace(const vec &a, vec &b);
539template ITPP_EXPORT void elem_mult_inplace(const cvec &a, cvec &b);
540template ITPP_EXPORT void elem_mult_inplace(const ivec &a, ivec &b);
541template ITPP_EXPORT void elem_mult_inplace(const svec &a, svec &b);
542template ITPP_EXPORT void elem_mult_inplace(const bvec &a, bvec &b);
543
544// elementwise multiplication followed by summation
545
546template ITPP_EXPORT double elem_mult_sum(const vec &a, const vec &b);
547template ITPP_EXPORT std::complex<double> elem_mult_sum(const cvec &a, const cvec &b);
548template ITPP_EXPORT int elem_mult_sum(const ivec &a, const ivec &b);
549template ITPP_EXPORT short elem_mult_sum(const svec &a, const svec &b);
550template ITPP_EXPORT bin elem_mult_sum(const bvec &a, const bvec &b);
551
552// division operator
553
554template ITPP_EXPORT vec operator/(const vec &v, double t);
555template ITPP_EXPORT cvec operator/(const cvec &v, std::complex<double> t);
556template ITPP_EXPORT ivec operator/(const ivec &v, int t);
557template ITPP_EXPORT svec operator/(const svec &v, short t);
558template ITPP_EXPORT bvec operator/(const bvec &v, bin t);
559
560template ITPP_EXPORT vec operator/(double t, const vec &v);
561template ITPP_EXPORT cvec operator/(std::complex<double> t, const cvec &v);
562template ITPP_EXPORT ivec operator/(int t, const ivec &v);
563template ITPP_EXPORT svec operator/(short t, const svec &v);
564template ITPP_EXPORT bvec operator/(bin t, const bvec &v);
565
566// elementwise division operator
567
568template ITPP_EXPORT vec elem_div(const vec &a, const vec &b);
569template ITPP_EXPORT cvec elem_div(const cvec &a, const cvec &b);
570template ITPP_EXPORT ivec elem_div(const ivec &a, const ivec &b);
571template ITPP_EXPORT svec elem_div(const svec &a, const svec &b);
572template ITPP_EXPORT bvec elem_div(const bvec &a, const bvec &b);
573
574template ITPP_EXPORT vec elem_div(double t, const vec &v);
575template ITPP_EXPORT cvec elem_div(std::complex<double> t, const cvec &v);
576template ITPP_EXPORT ivec elem_div(int t, const ivec &v);
577template ITPP_EXPORT svec elem_div(short t, const svec &v);
578template ITPP_EXPORT bvec elem_div(bin t, const bvec &v);
579
580template ITPP_EXPORT void elem_div_out(const vec &a, const vec &b, vec &out);
581template ITPP_EXPORT void elem_div_out(const cvec &a, const cvec &b, cvec &out);
582template ITPP_EXPORT void elem_div_out(const ivec &a, const ivec &b, ivec &out);
583template ITPP_EXPORT void elem_div_out(const svec &a, const svec &b, svec &out);
584template ITPP_EXPORT void elem_div_out(const bvec &a, const bvec &b, bvec &out);
585
586// elementwise division followed by summation
587
588template ITPP_EXPORT double elem_div_sum(const vec &a, const vec &b);
589template ITPP_EXPORT std::complex<double> elem_div_sum(const cvec &a, const cvec &b);
590template ITPP_EXPORT int elem_div_sum(const ivec &a, const ivec &b);
591template ITPP_EXPORT short elem_div_sum(const svec &a, const svec &b);
592template ITPP_EXPORT bin elem_div_sum(const bvec &a, const bvec &b);
593
594// concat operator
595
596template ITPP_EXPORT vec concat(const vec &v, double a);
597template ITPP_EXPORT cvec concat(const cvec &v, std::complex<double> a);
598template ITPP_EXPORT ivec concat(const ivec &v, int a);
599template ITPP_EXPORT svec concat(const svec &v, short a);
600template ITPP_EXPORT bvec concat(const bvec &v, bin a);
601
602template ITPP_EXPORT vec concat(double a, const vec &v);
603template ITPP_EXPORT cvec concat(std::complex<double> a, const cvec &v);
604template ITPP_EXPORT ivec concat(int a, const ivec &v);
605template ITPP_EXPORT svec concat(short a, const svec &v);
606template ITPP_EXPORT bvec concat(bin a, const bvec &v);
607
608template ITPP_EXPORT vec concat(const vec &v1, const vec &v2);
609template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2);
610template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2);
611template ITPP_EXPORT svec concat(const svec &v1, const svec &v2);
612template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2);
613
614template ITPP_EXPORT vec concat(const vec &v1, const vec &v2, const vec &v3);
615template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2, const cvec &v3);
616template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2, const ivec &v3);
617template ITPP_EXPORT svec concat(const svec &v1, const svec &v2, const svec &v3);
618template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2, const bvec &v3);
619
620template ITPP_EXPORT vec concat(const vec &v1, const vec &v2,
621 const vec &v3, const vec &v4);
622template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2,
623 const cvec &v3, const cvec &v4);
624template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2,
625 const ivec &v3, const ivec &v4);
626template ITPP_EXPORT svec concat(const svec &v1, const svec &v2,
627 const svec &v3, const svec &v4);
628template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2,
629 const bvec &v3, const bvec &v4);
630
631template ITPP_EXPORT vec concat(const vec &v1, const vec &v2, const vec &v3,
632 const vec &v4, const vec &v5);
633template ITPP_EXPORT cvec concat(const cvec &v1, const cvec &v2, const cvec &v3,
634 const cvec &v4, const cvec &v5);
635template ITPP_EXPORT ivec concat(const ivec &v1, const ivec &v2, const ivec &v3,
636 const ivec &v4, const ivec &v5);
637template ITPP_EXPORT svec concat(const svec &v1, const svec &v2, const svec &v3,
638 const svec &v4, const svec &v5);
639template ITPP_EXPORT bvec concat(const bvec &v1, const bvec &v2, const bvec &v3,
640 const bvec &v4, const bvec &v5);
641
642// I/O streams
643
644template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const vec &vect);
645template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const cvec &vect);
646template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const svec &vect);
647template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const ivec &vect);
648template ITPP_EXPORT std::ostream &operator<<(std::ostream& os, const bvec &vect);
649template ITPP_EXPORT std::istream &operator>>(std::istream& is, vec &vect);
650template ITPP_EXPORT std::istream &operator>>(std::istream& is, cvec &vect);
651template ITPP_EXPORT std::istream &operator>>(std::istream& is, svec &vect);
652template ITPP_EXPORT std::istream &operator>>(std::istream& is, ivec &vect);
653template ITPP_EXPORT std::istream &operator>>(std::istream& is, bvec &vect);
654
655} // namespace itpp
656
Definitions of converters between different vector and matrix types.
#define it_error(s)
Abort unconditionally.
Definition: itassert.h:126
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition: itassert.h:107
#define it_assert(t, s)
Abort if t is not true.
Definition: itassert.h:94
void set(const char *str)
Set the vector equal to the values in the str string.
Definition: vec.h:814
void hermitian_transpose(const Mat< T > &m, Mat< T > &out)
Definition: matfunc.h:318
ivec find(const bvec &invector)
Return a integer vector with indicies where bvec == 1.
Definition: specmat.cpp:40
cvec conj(const cvec &x)
Conjugate of complex value.
Definition: elem_math.h:226
Mat< bin > bmat
bin matrix
Definition: mat.h:508
itpp namespace
Definition: itmex.h:37
svec to_svec(const Vec< T > &v)
Converts a Vec<T> to svec.
Definition: converters.h:65
void elem_mult_inplace(const Mat< Num_T > &m1, Mat< Num_T > &m2)
In-place element wise multiplication of two matrices. Fast version of B = elem_mult(A,...
Definition: mat.h:1630
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition: binary.cpp:36
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
Definition: mat.h:1382
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition: array.h:486
GF2mat operator*(const GF2mat &X, const GF2mat &Y)
GF(2) matrix multiplication.
Definition: gf2mat.cpp:847
Mat< Num_T > operator/(const Mat< Num_T > &m, Num_T t)
Element-wise division by a scalar.
Definition: mat.h:1670
Num_T dot(const Vec< Num_T > &v1, const Vec< Num_T > &v2)
Inner (dot) product of two vectors v1 and v2.
Definition: vec.h:1005
void elem_div_out(const Mat< Num_T > &m1, const Mat< Num_T > &m2, Mat< Num_T > &out)
Element wise division of two matrices, storing the result in matrix out.
Definition: mat.h:1696
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition: binary.cpp:42
const double eps
Constant eps.
Definition: misc.h:109
Mat< Num_T > elem_div(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices.
Definition: mat.h:1688
Num_T elem_div_sum(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices, followed by summation of the resultant elements....
Definition: mat.h:1710
GF2mat operator+(const GF2mat &X, const GF2mat &Y)
GF(2) matrix addition.
Definition: gf2mat.cpp:948
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
Definition: mat.h:1582
Num_T elem_mult_sum(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices, followed by summation of the resultant elements....
Definition: mat.h:1639
void elem_mult_out(const Mat< Num_T > &m1, const Mat< Num_T > &m2, Mat< Num_T > &out)
Element wise multiplication of two matrices, storing the result in matrix out.
Definition: mat.h:1590
Mat< Num_T > outer_product(const Vec< Num_T > &v1, const Vec< Num_T > &v2, bool hermitian=false)
Outer product of two vectors v1 and v2.
Definition: vec.h:1021
Templated Vector Class Definitions.
SourceForge Logo

Generated on Tue Jan 24 2023 00:00:00 for IT++ by Doxygen 1.9.6