00001 00033 #include <itpp/base/vec.h> 00034 00035 #if defined (HAVE_CBLAS) 00036 # include <itpp/base/cblas.h> 00037 #endif 00038 00039 00040 namespace itpp { 00041 00042 template<> 00043 bool Vec<std::complex<double> >::set(const char *values) 00044 { 00045 std::istringstream buffer(values); 00046 int pos=0, maxpos=10; 00047 00048 alloc(maxpos); 00049 00050 while (buffer.peek() != EOF) { 00051 00052 switch (buffer.peek()) { 00053 case ':': 00054 it_error("set: expressions with ':' are not valid for cvec"); 00055 break; 00056 case ',': 00057 buffer.get(); 00058 break; 00059 default: 00060 pos++; 00061 if (pos > maxpos) { 00062 maxpos *= 2; 00063 set_size(maxpos, true); 00064 } 00065 buffer >> data[pos-1]; 00066 while (buffer.peek() == ' ') { buffer.get(); } 00067 break; 00068 } 00069 00070 } 00071 set_size(pos, true); 00072 00073 return true; 00074 } 00075 00076 template<> 00077 bool Vec<bin>::set(const char *values) 00078 { 00079 std::istringstream buffer(values); 00080 int pos=0, maxpos=10; 00081 short intemp; 00082 00083 alloc(maxpos); 00084 00085 while (buffer.peek() != EOF) { 00086 if (buffer.peek() == ',') { 00087 buffer.get(); 00088 } else { 00089 pos++; 00090 if (pos > maxpos) { 00091 maxpos *= 2; 00092 set_size(maxpos, true); 00093 } 00094 buffer >> intemp; 00095 data[pos-1] = intemp; 00096 while (buffer.peek() == ' ') { buffer.get(); } 00097 } 00098 } 00099 set_size(pos, true); 00100 00101 return true; 00102 } 00103 00104 #if defined(HAVE_CBLAS) 00105 template<> 00106 double dot(const vec &v1, const vec &v2) 00107 { 00108 it_assert1(v1.datasize == v2.datasize, "vec::dot: wrong sizes"); 00109 double r=0.0; 00110 00111 r= cblas_ddot(v1.datasize, v1.data, 1, v2.data, 1); 00112 00113 return r; 00114 } 00115 00116 template<> 00117 std::complex<double> dot(const cvec &v1, const cvec &v2) 00118 { 00119 it_assert1(v1.datasize == v2.datasize, "cvec::dot: wrong sizes"); 00120 std::complex<double> r=0.0; 00121 00122 cblas_zdotu_sub(v1.datasize, v1.data, 1, v2.data, 1, &r); 00123 00124 return r; 00125 } 00126 00127 #endif // HAVE_CBLAS 00128 00129 template<> 00130 bvec Vec<std::complex<double> >::operator==(const std::complex<double>) const 00131 { 00132 it_error("operator==: not implemented for complex"); 00133 bvec temp; 00134 return temp; 00135 } 00136 00137 template<> 00138 bvec Vec<std::complex<double> >::operator!=(const std::complex<double>) const 00139 { 00140 it_error("operator!=: not implemented for complex"); 00141 bvec temp; 00142 return temp; 00143 } 00144 00145 template<> 00146 bvec Vec<std::complex<double> >::operator<=(const std::complex<double>) const 00147 { 00148 it_error("operator<=: not implemented for complex"); 00149 bvec temp; 00150 return temp; 00151 } 00152 00153 template<> 00154 bvec Vec<std::complex<double> >::operator>(const std::complex<double>) const 00155 { 00156 it_error("operator>: not implemented for complex"); 00157 bvec temp; 00158 return temp; 00159 } 00160 00161 template<> 00162 bvec Vec<std::complex<double> >::operator<(const std::complex<double>) const 00163 { 00164 it_error("operator<: not implemented for complex"); 00165 bvec temp; 00166 return temp; 00167 } 00168 00169 template<> 00170 bvec Vec<std::complex<double> >::operator>=(const std::complex<double>) const 00171 { 00172 it_error("operator>=: not implemented for complex"); 00173 bvec temp; 00174 return temp; 00175 } 00176 00177 template<> 00178 Mat<std::complex<double> > Vec<std::complex<double> >::hermitian_transpose() const 00179 { 00180 Mat<std::complex<double> > temp(1, datasize); 00181 for (int i=0; i<datasize; i++) 00182 temp(i) = std::conj(data[i]); 00183 00184 return temp; 00185 } 00186 00187 00188 //--------------------------------------------------------------------- 00189 // Instantiations 00190 //--------------------------------------------------------------------- 00191 00192 //--------- class instantiations ------------- 00193 00194 template class Vec<double>; 00195 template class Vec<int>; 00196 template class Vec<short int>; 00197 template class Vec<std::complex<double> >; 00198 template class Vec<bin>; 00199 00200 //------------- Addition operator ---------- 00201 00202 template const vec operator+(const vec &v1, const vec &v2); 00203 template const cvec operator+(const cvec &v1, const cvec &v2); 00204 template const ivec operator+(const ivec &v1, const ivec &v2); 00205 template const svec operator+(const svec &v1, const svec &v2); 00206 template const bvec operator+(const bvec &v1, const bvec &v2); 00207 00208 template const vec operator+(const vec &v1, double t); 00209 template const cvec operator+(const cvec &v1, std::complex<double> t); 00210 template const ivec operator+(const ivec &v1, int t); 00211 template const svec operator+(const svec &v1, short t); 00212 template const bvec operator+(const bvec &v1, bin t); 00213 00214 template const vec operator+(double t, const vec &v1); 00215 template const cvec operator+(std::complex<double> t, const cvec &v1); 00216 template const ivec operator+(int t, const ivec &v1); 00217 template const svec operator+(short t, const svec &v1); 00218 template const bvec operator+(bin t, const bvec &v1); 00219 00220 //------------- Subraction operator ---------- 00221 00222 template const vec operator-(const vec &v1, const vec &v2); 00223 template const cvec operator-(const cvec &v1, const cvec &v2); 00224 template const ivec operator-(const ivec &v1, const ivec &v2); 00225 template const svec operator-(const svec &v1, const svec &v2); 00226 template const bvec operator-(const bvec &v1, const bvec &v2); 00227 00228 template const vec operator-(const vec &v, double t); 00229 template const cvec operator-(const cvec &v, std::complex<double> t); 00230 template const ivec operator-(const ivec &v, int t); 00231 template const svec operator-(const svec &v, short t); 00232 template const bvec operator-(const bvec &v, bin t); 00233 00234 template const vec operator-(double t, const vec &v); 00235 template const cvec operator-(std::complex<double> t, const cvec &v); 00236 template const ivec operator-(int t, const ivec &v); 00237 template const svec operator-(short t, const svec &v); 00238 template const bvec operator-(bin t, const bvec &v); 00239 00240 //---------- Unary minus ------------- 00241 00242 template const vec operator-(const vec &v); 00243 template const cvec operator-(const cvec &v); 00244 template const ivec operator-(const ivec &v); 00245 template const svec operator-(const svec &v); 00246 template const bvec operator-(const bvec &v); 00247 00248 //------------- Multiplication operator ---------- 00249 00250 #if !defined(HAVE_CBLAS) 00251 template double dot(const vec &v1, const vec &v2); 00252 template std::complex<double> dot(const cvec &v1, const cvec &v2); 00253 #endif 00254 template int dot(const ivec &v1, const ivec &v2); 00255 template short dot(const svec &v1, const svec &v2); 00256 template bin dot(const bvec &v1, const bvec &v2); 00257 00258 template int operator*(const ivec &v1, const ivec &v2); 00259 template short operator*(const svec &v1, const svec &v2); 00260 template bin operator*(const bvec &v1, const bvec &v2); 00261 00262 template const mat outer_product(const vec &v1, const vec &v2); 00263 template const cmat outer_product(const cvec &v1, const cvec &v2); 00264 template const imat outer_product(const ivec &v1, const ivec &v2); 00265 template const smat outer_product(const svec &v1, const svec &v2); 00266 template const bmat outer_product(const bvec &v1, const bvec &v2); 00267 00268 template const vec operator*(const vec &v, double t); 00269 template const cvec operator*(const cvec &v, std::complex<double> t); 00270 template const ivec operator*(const ivec &v, int t); 00271 template const svec operator*(const svec &v, short t); 00272 template const bvec operator*(const bvec &v, bin t); 00273 00274 template const vec operator*(double t, const vec &v); 00275 template const cvec operator*(std::complex<double> t, const cvec &v); 00276 template const ivec operator*(int t, const ivec &v); 00277 template const svec operator*(short t, const svec &v); 00278 template const bvec operator*(bin t, const bvec &v); 00279 00280 //------------- Elementwise Multiplication operator (two vectors) ---------- 00281 00282 template const vec elem_mult(const vec &v1, const vec &v2); 00283 template const cvec elem_mult(const cvec &v1, const cvec &v2); 00284 template const ivec elem_mult(const ivec &v1, const ivec &v2); 00285 template const svec elem_mult(const svec &v1, const svec &v2); 00286 template const bvec elem_mult(const bvec &v1, const bvec &v2); 00287 00288 //------------- Elementwise Multiplication operator (three vectors) ---------- 00289 00290 template const vec elem_mult(const vec &v1, const vec &v2, const vec &v3); 00291 template const cvec elem_mult(const cvec &v1, const cvec &v2, const cvec &v3); 00292 template const ivec elem_mult(const ivec &v1, const ivec &v2, const ivec &v3); 00293 template const svec elem_mult(const svec &v1, const svec &v2, const svec &v3); 00294 template const bvec elem_mult(const bvec &v1, const bvec &v2, const bvec &v3); 00295 00296 //------------- Elementwise Multiplication operator (four vectors) ---------- 00297 00298 template const vec elem_mult(const vec &v1, const vec &v2, const vec &v3, const vec &v4); 00299 template const cvec elem_mult(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4); 00300 template const ivec elem_mult(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4); 00301 template const svec elem_mult(const svec &v1, const svec &v2, const svec &v3, const svec &v4); 00302 template const bvec elem_mult(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4); 00303 00304 //------------- Division operator ---------- 00305 00306 template const vec operator/(const vec &v, double t); 00307 template const cvec operator/(const cvec &v, std::complex<double> t); 00308 template const ivec operator/(const ivec &v, int t); 00309 template const svec operator/(const svec &v, short t); 00310 template const bvec operator/(const bvec &v, bin t); 00311 00312 template const vec operator/(const double t, const vec &v); 00313 template const cvec operator/(const std::complex<double> t, const cvec &v); 00314 template const ivec operator/(const int t, const ivec &v); 00315 template const svec operator/(const short t, const svec &v); 00316 template const bvec operator/(const bin t, const bvec &v); 00317 00318 //------------- Elementwise Division operator ---------- 00319 00320 template const vec elem_div(const vec &v1, const vec &v2); 00321 template const cvec elem_div(const cvec &v1, const cvec &v2); 00322 template const ivec elem_div(const ivec &v1, const ivec &v2); 00323 template const svec elem_div(const svec &v1, const svec &v2); 00324 template const bvec elem_div(const bvec &v1, const bvec &v2); 00325 00326 template const vec elem_div(const double t, const vec &v); 00327 template const cvec elem_div(const std::complex<double> t, const cvec &v); 00328 template const ivec elem_div(const int t, const ivec &v); 00329 template const svec elem_div(const short t, const svec &v); 00330 template const bvec elem_div(const bin t, const bvec &v); 00331 00332 //--------------------- concat operator ----------------- 00333 00334 template const vec concat(const vec &v, const double a); 00335 template const cvec concat(const cvec &v, const std::complex<double> a); 00336 template const ivec concat(const ivec &v, const int a); 00337 template const svec concat(const svec &v, const short a); 00338 template const bvec concat(const bvec &v, const bin a); 00339 00340 template const vec concat(const double a, const vec &v); 00341 template const cvec concat(const std::complex<double> a, const cvec &v); 00342 template const ivec concat(const int a, const ivec &v); 00343 template const svec concat(const short a, const svec &v); 00344 template const bvec concat(const bin a, const bvec &v); 00345 00346 template const vec concat(const vec &v1, const vec &v2); 00347 template const cvec concat(const cvec &v1, const cvec &v2); 00348 template const ivec concat(const ivec &v1, const ivec &v2); 00349 template const svec concat(const svec &v1, const svec &v2); 00350 template const bvec concat(const bvec &v1, const bvec &v2); 00351 00352 template const vec concat(const vec &v1, const vec &v2, const vec &v3); 00353 template const cvec concat(const cvec &v1, const cvec &v2, const cvec &v3); 00354 template const ivec concat(const ivec &v1, const ivec &v2, const ivec &v3); 00355 template const svec concat(const svec &v1, const svec &v2, const svec &v3); 00356 template const bvec concat(const bvec &v1, const bvec &v2, const bvec &v3); 00357 00358 template const vec concat(const vec &v1, const vec &v2, const vec &v3, const vec &v4); 00359 template const cvec concat(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4); 00360 template const ivec concat(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4); 00361 template const svec concat(const svec &v1, const svec &v2, const svec &v3, const svec &v4); 00362 template const bvec concat(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4); 00363 00364 template const vec concat(const vec &v1, const vec &v2, const vec &v3, const vec &v4, const vec &v5); 00365 template const cvec concat(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4, const cvec &v5); 00366 template const ivec concat(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4, const ivec &v5); 00367 template const svec concat(const svec &v1, const svec &v2, const svec &v3, const svec &v4, const svec &v5); 00368 template const bvec concat(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4, const bvec &v5); 00369 00370 // -------------- output stream -------------------- 00371 00372 template std::ostream &operator<<(std::ostream& os, const vec &vect); 00373 template std::ostream &operator<<(std::ostream& os, const cvec &vect); 00374 template std::ostream &operator<<(std::ostream& os, const svec &vect); 00375 template std::ostream &operator<<(std::ostream& os, const ivec &vect); 00376 template std::ostream &operator<<(std::ostream& os, const bvec &vect); 00377 00378 // -------------- input stream -------------------- 00379 00380 template std::istream &operator>>(std::istream& is, vec &vect); 00381 template std::istream &operator>>(std::istream& is, cvec &vect); 00382 template std::istream &operator>>(std::istream& is, svec &vect); 00383 template std::istream &operator>>(std::istream& is, ivec &vect); 00384 template std::istream &operator>>(std::istream& is, bvec &vect); 00385 00386 } // namespace itpp
Generated on Sat Aug 25 23:37:27 2007 for IT++ by Doxygen 1.5.2