/*---------------------------------------------------------------------------* * IT++ * *---------------------------------------------------------------------------* * Copyright (c) 1995-2004 by Tony Ottosson, Thomas Eriksson, Pål Frenger, * * Tobias Ringström, and Jonas Samuelsson. * * * * Permission to use, copy, modify, and distribute this software and its * * documentation under the terms of the GNU General Public License is hereby * * granted. No representations are made about the suitability of this * * software for any purpose. It is provided "as is" without expressed or * * implied warranty. See the GNU General Public License for more details. * *---------------------------------------------------------------------------*/ /*! \file \brief Templated Vector Class Implementation \author Tony Ottosson and Tobias Ringström 1.45 2004/09/05 03:32:18 */ #include "base/vec.h" #ifndef NO_CBLAS #include "base/cblas.h" #endif namespace itpp { template<> bool cvec::set(const char *values) { istringstream buffer(values); int pos=0, maxpos=10; alloc(maxpos); while (buffer.peek()!=EOF) { switch (buffer.peek()) { case ':': it_error("set: expressions with ':' are not valid for cvec"); break; case ',': buffer.get(); break; default: pos++; if (pos > maxpos) { maxpos *= 2; set_size(maxpos, true); } buffer >> data[pos-1]; while (buffer.peek()==' ') { buffer.get(); } break; } } set_size(pos, true); return true; } template<> bool bvec::set(const char *values) { std::istringstream buffer(values); int pos=0, maxpos=10; short intemp; alloc(maxpos); while (buffer.peek()!=EOF) { if (buffer.peek()==',') { buffer.get(); } else { pos++; if (pos > maxpos) { maxpos=maxpos*2; set_size(maxpos, true); } buffer >> intemp; data[pos-1]=intemp; while (buffer.peek()==' ') { buffer.get(); } } } set_size(pos, true); return true; } #ifndef NO_CBLAS template<> double dot(const vec &v1, const vec &v2) { it_assert1(v1.datasize==v2.datasize, "vec::dot: wrong sizes"); double r=0.0; r= cblas_ddot(v1.datasize, v1.data, 1, v2.data, 1); return r; } template<> complex dot(const cvec &v1, const cvec &v2) { it_assert1(v1.datasize==v2.datasize, "cvec::dot: wrong sizes"); complex r=0.0; cblas_zdotu_sub(v1.datasize, v1.data, 1, v2.data, 1, &r); return r; } #endif //NO_CBLAS template<> bvec cvec::operator==(const complex) const { it_error("operator==: not implemented for complex"); bvec temp; return temp; } template<> bvec cvec::operator!=(const complex) const { it_error("operator!=: not implemented for complex"); bvec temp; return temp; } template<> bvec cvec::operator<=(const complex) const { it_error("operator<=: not implemented for complex"); bvec temp; return temp; } template<> bvec cvec::operator>(const complex) const { it_error("operator>: not implemented for complex"); bvec temp; return temp; } template<> bvec cvec::operator<(const complex) const { it_error("operator<: not implemented for complex"); bvec temp; return temp; } template<> bvec cvec::operator>=(const complex) const { it_error("operator>=: not implemented for complex"); bvec temp; return temp; } template<> Mat > cvec::hermitian_transpose() const { Mat > temp(1, datasize); for (int i=0; i template class Vec; //! Template instantiation of Vec template class Vec; //! Template instantiation of Vec template class Vec; //! Template instantiation of Vec > template class Vec >; //! Template instantiation of Vec template class Vec; //------------- Addition operator ---------- //! Template instantiation of operator+ template vec operator+(const vec &v1, const vec &v2); //! Template instantiation of operator+ template cvec operator+(const cvec &v1, const cvec &v2); //! Template instantiation of operator+ template ivec operator+(const ivec &v1, const ivec &v2); //! Template instantiation of operator+ template svec operator+(const svec &v1, const svec &v2); //! Template instantiation of operator+ template bvec operator+(const bvec &v1, const bvec &v2); //! Template instantiation of operator+ template vec operator+(const vec &v1, double t); //! Template instantiation of operator+ template cvec operator+(const cvec &v1, complex t); //! Template instantiation of operator+ template ivec operator+(const ivec &v1, int t); //! Template instantiation of operator+ template svec operator+(const svec &v1, short t); //! Template instantiation of operator+ template bvec operator+(const bvec &v1, bin t); //! Template instantiation of operator+ template vec operator+(double t, const vec &v1); //! Template instantiation of operator+ template cvec operator+(complex t, const cvec &v1); //! Template instantiation of operator+ template ivec operator+(int t, const ivec &v1); //! Template instantiation of operator+ template svec operator+(short t, const svec &v1); //! Template instantiation of operator+ template bvec operator+(bin t, const bvec &v1); //------------- Subraction operator ---------- //! Template instantiation of operator- template vec operator-(const vec &v1, const vec &v2); //! Template instantiation of operator- template cvec operator-(const cvec &v1, const cvec &v2); //! Template instantiation of operator- template ivec operator-(const ivec &v1, const ivec &v2); //! Template instantiation of operator- template svec operator-(const svec &v1, const svec &v2); //! Template instantiation of operator- template bvec operator-(const bvec &v1, const bvec &v2); //! Template instantiation of operator- template vec operator-(const vec &v, double t); //! Template instantiation of operator- template cvec operator-(const cvec &v, complex t); //! Template instantiation of operator- template ivec operator-(const ivec &v, int t); //! Template instantiation of operator- template svec operator-(const svec &v, short t); //! Template instantiation of operator- template bvec operator-(const bvec &v, bin t); //! Template instantiation of operator- template vec operator-(double t, const vec &v); //! Template instantiation of operator- template cvec operator-(complex t, const cvec &v); //! Template instantiation of operator- template ivec operator-(int t, const ivec &v); //! Template instantiation of operator- template svec operator-(short t, const svec &v); //! Template instantiation of operator- template bvec operator-(bin t, const bvec &v); //---------- Unary minus ------------- //! Template instantiation of operator- template vec operator-(const vec &v); //! Template instantiation of operator- template cvec operator-(const cvec &v); //! Template instantiation of operator- template ivec operator-(const ivec &v); //! Template instantiation of operator- template svec operator-(const svec &v); //! Template instantiation of operator- template bvec operator-(const bvec &v); //------------- Multiplication operator ---------- #ifdef NO_CBLAS //! Template instantiation of dot template double dot(const vec &v1, const vec &v2); //! Template instantiation of dot template complex dot(const cvec &v1, const cvec &v2); #endif //! Template instantiation of dot template int dot(const ivec &v1, const ivec &v2); //! Template instantiation of dot template short dot(const svec &v1, const svec &v2); //! Template instantiation of dot template bin dot(const bvec &v1, const bvec &v2); //! Template instantiation of operator* template int operator*(const ivec &v1, const ivec &v2); //! Template instantiation of operator* template short operator*(const svec &v1, const svec &v2); //! Template instantiation of operator* template bin operator*(const bvec &v1, const bvec &v2); //! Template instantiation of outer_product template mat outer_product(const vec &v1, const vec &v2); //! Template instantiation of outer_product template cmat outer_product(const cvec &v1, const cvec &v2); //! Template instantiation of outer_product template imat outer_product(const ivec &v1, const ivec &v2); //! Template instantiation of outer_product template smat outer_product(const svec &v1, const svec &v2); //! Template instantiation of outer_product template bmat outer_product(const bvec &v1, const bvec &v2); //! Template instantiation of operator* template vec operator*(const vec &v, double t); //! Template instantiation of operator* template cvec operator*(const cvec &v, complex t); //! Template instantiation of operator* template ivec operator*(const ivec &v, int t); //! Template instantiation of operator* template svec operator*(const svec &v, short t); //! Template instantiation of operator* template bvec operator*(const bvec &v, bin t); //! Template instantiation of operator* template vec operator*(double t, const vec &v); //! Template instantiation of operator* template cvec operator*(complex t, const cvec &v); //! Template instantiation of operator* template ivec operator*(int t, const ivec &v); //! Template instantiation of operator* template svec operator*(short t, const svec &v); //! Template instantiation of operator* template bvec operator*(bin t, const bvec &v); //------------- Elementwise Multiplication operator (two vectors) ---------- //! Template instantiation of elem_mult template vec elem_mult(const vec &v1, const vec &v2); //! Template instantiation of elem_mult template cvec elem_mult(const cvec &v1, const cvec &v2); //! Template instantiation of elem_mult template ivec elem_mult(const ivec &v1, const ivec &v2); //! Template instantiation of elem_mult template svec elem_mult(const svec &v1, const svec &v2); //! Template instantiation of elem_mult template bvec elem_mult(const bvec &v1, const bvec &v2); //------------- Elementwise Multiplication operator (three vectors) ---------- //! Template instantiation of elem_mult template vec elem_mult(const vec &v1, const vec &v2, const vec &v3); //! Template instantiation of elem_mult template cvec elem_mult(const cvec &v1, const cvec &v2, const cvec &v3); //! Template instantiation of elem_mult template ivec elem_mult(const ivec &v1, const ivec &v2, const ivec &v3); //! Template instantiation of elem_mult template svec elem_mult(const svec &v1, const svec &v2, const svec &v3); //! Template instantiation of elem_mult template bvec elem_mult(const bvec &v1, const bvec &v2, const bvec &v3); //------------- Elementwise Multiplication operator (four vectors) ---------- //! Template instantiation of elem_mult template vec elem_mult(const vec &v1, const vec &v2, const vec &v3, const vec &v4); //! Template instantiation of elem_mult template cvec elem_mult(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4); //! Template instantiation of elem_mult template ivec elem_mult(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4); //! Template instantiation of elem_mult template svec elem_mult(const svec &v1, const svec &v2, const svec &v3, const svec &v4); //! Template instantiation of elem_mult template bvec elem_mult(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4); //------------- Division operator ---------- //! Template instantiation of operator/ template vec operator/(const vec &v, double t); //! Template instantiation of operator/ template cvec operator/(const cvec &v, complex t); //! Template instantiation of operator/ template ivec operator/(const ivec &v, int t); //! Template instantiation of operator/ template svec operator/(const svec &v, short t); //! Template instantiation of operator/ template bvec operator/(const bvec &v, bin t); //! Template instantiation of operator/ template vec operator/(const double t, const vec &v); //! Template instantiation of operator/ template cvec operator/(const complex t, const cvec &v); //! Template instantiation of operator/ template ivec operator/(const int t, const ivec &v); //! Template instantiation of operator/ template svec operator/(const short t, const svec &v); //! Template instantiation of operator/ template bvec operator/(const bin t, const bvec &v); //------------- Elementwise Division operator ---------- //! Template instantiation of elem_div template vec elem_div(const vec &v1, const vec &v2); //! Template instantiation of elem_div template cvec elem_div(const cvec &v1, const cvec &v2); //! Template instantiation of elem_div template ivec elem_div(const ivec &v1, const ivec &v2); //! Template instantiation of elem_div template svec elem_div(const svec &v1, const svec &v2); //! Template instantiation of elem_div template bvec elem_div(const bvec &v1, const bvec &v2); //! Template instantiation of elem_div template vec elem_div(const double t, const vec &v); //! Template instantiation of elem_div template cvec elem_div(const complex t, const cvec &v); //! Template instantiation of elem_div template ivec elem_div(const int t, const ivec &v); //! Template instantiation of elem_div template svec elem_div(const short t, const svec &v); //! Template instantiation of elem_div template bvec elem_div(const bin t, const bvec &v); //--------------------- concat operator ----------------- //! Template instantiation of concat template vec concat(const vec &v, const double a); //! Template instantiation of concat template cvec concat(const cvec &v, const complex a); //! Template instantiation of concat template ivec concat(const ivec &v, const int a); //! Template instantiation of concat template svec concat(const svec &v, const short a); //! Template instantiation of concat template bvec concat(const bvec &v, const bin a); //! Template instantiation of concat template vec concat(const double a, const vec &v); //! Template instantiation of concat template cvec concat(const complex a, const cvec &v); //! Template instantiation of concat template ivec concat(const int a, const ivec &v); //! Template instantiation of concat template svec concat(const short a, const svec &v); //! Template instantiation of concat template bvec concat(const bin a, const bvec &v); //! Template instantiation of concat template vec concat(const vec &v1, const vec &v2); //! Template instantiation of concat template cvec concat(const cvec &v1, const cvec &v2); //! Template instantiation of concat template ivec concat(const ivec &v1, const ivec &v2); //! Template instantiation of concat template svec concat(const svec &v1, const svec &v2); //! Template instantiation of concat template bvec concat(const bvec &v1, const bvec &v2); //! Template instantiation of concat template vec concat(const vec &v1, const vec &v2, const vec &v3); //! Template instantiation of concat template cvec concat(const cvec &v1, const cvec &v2, const cvec &v3); //! Template instantiation of concat template ivec concat(const ivec &v1, const ivec &v2, const ivec &v3); //! Template instantiation of concat template svec concat(const svec &v1, const svec &v2, const svec &v3); //! Template instantiation of concat template bvec concat(const bvec &v1, const bvec &v2, const bvec &v3); //! Template instantiation of concat template vec concat(const vec &v1, const vec &v2, const vec &v3, const vec &v4); //! Template instantiation of concat template cvec concat(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4); //! Template instantiation of concat template ivec concat(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4); //! Template instantiation of concat template svec concat(const svec &v1, const svec &v2, const svec &v3, const svec &v4); //! Template instantiation of concat template bvec concat(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4); //! Template instantiation of concat template vec concat(const vec &v1, const vec &v2, const vec &v3, const vec &v4, const vec &v5); //! Template instantiation of concat template cvec concat(const cvec &v1, const cvec &v2, const cvec &v3, const cvec &v4, const cvec &v5); //! Template instantiation of concat template ivec concat(const ivec &v1, const ivec &v2, const ivec &v3, const ivec &v4, const ivec &v5); //! Template instantiation of concat template svec concat(const svec &v1, const svec &v2, const svec &v3, const svec &v4, const svec &v5); //! Template instantiation of concat template bvec concat(const bvec &v1, const bvec &v2, const bvec &v3, const bvec &v4, const bvec &v5); // -------------- output stream -------------------- //! Template instantiation of output stream template ostream &operator<<(ostream& os, const vec &vect); //! Template instantiation of output stream template ostream &operator<<(ostream& os, const cvec &vect); //! Template instantiation of output stream template ostream &operator<<(ostream& os, const svec &vect); //! Template instantiation of output stream template ostream &operator<<(ostream& os, const ivec &vect); //! Template instantiation of output stream template ostream &operator<<(ostream& os, const bvec &vect); // -------------- input stream -------------------- //! Template instantiation of input stream template istream &operator>>(istream& is, vec &vect); //! Template instantiation of input stream template istream &operator>>(istream& is, cvec &vect); //! Template instantiation of input stream template istream &operator>>(istream& is, svec &vect); //! Template instantiation of input stream template istream &operator>>(istream& is, ivec &vect); //! Template instantiation of input stream template istream &operator>>(istream& is, bvec &vect); } //namespace itpp