#ifndef __MATH_VECTOR_ #define __MATH_VECTOR_ #include #include #include #include #include #include using namespace std; namespace rpl { template struct math_vector : base_vector { math_vector(rpl_size_t size = 0) : base_vector(size) {} math_vector(rpl_size_t c, rpl_size_t s) : base_vector(s) { if (s != c) { std::cerr << "problem in math_vector cstr size != capa" << std::endl; assert(0); } } math_vector(const math_vector & a) : base_vector(a) {} math_vector(const base_vector & a) : base_vector(a) {} template math_vector(const vector_expression & ve) : base_vector(ve) {} math_vector(const T *a, size_t l) : base_vector(l) { std::copy(a, a+l, base_vector::begin()); } math_vector & operator= (const math_vector& a) { base_vector::operator=(a); return *this;} ~math_vector() {} rpl_size_t capacity() const { return base_vector::size(); } rpl_size_t get_capacity() const { return base_vector::size(); } void set_capacity(size_t cap) { base_vector::resize(cap); } void set_size(size_t size) { base_vector::resize(size); } const T operator[] (size_t i) const { return base_vector::operator()(i); }; T & operator[] (size_t i) { return base_vector::operator()(i); }; void concat(const math_vector & u, const math_vector & v); void assign(size_t at, const math_vector & w, size_t from, size_t to); void assign(const math_vector & v) { base_vector::operator=(v); } void add(const math_vector & v1, const math_vector & v2) { * this = v1 + v2; } void divide(const math_vector & v1, const T & v2) { *this = v1/v2; } }; template inline void multiply(T & d, const math_vector & v1, const math_vector & v2) { d = inner_prod(v1, v2); } template inline T sum_of_squares(const math_vector & v) { return inner_prod(v, v); } template inline bool operator==(const math_vector & v1, const math_vector & v2) { return std::inner_product(v1.begin(), v1.end(), v2.begin(), true, std::logical_and(), std::equal_to()); } template inline void divide(math_vector &res, math_vector & v1, const T & v2) { res.divide(v1,v2); } template inline void negate(math_vector & res, const math_vector & orig) { res.resize(orig.size()); BOOST_AUTO (src, orig.begin()); BOOST_AUTO (dest, res.begin()); for(; src != orig.end(); ++src, ++dest) { negate(*dest,*src); } } template inline void math_vector::concat(const math_vector & u, const math_vector & v) { this->resize(u.size() + v.size()); project(*this, range(0, u.size())) = u; project(*this, range(u.size(), this->size())) = v; } template inline void math_vector::assign(size_t at, const math_vector & w, size_t from, size_t to) { assert(to >= from); size_t new_end = to - from + at; if (new_end > this->size()) { this->resize(new_end); } project(*this, range(at, new_end+1)) = project(w, range(from, to+1)); } // Overloading of cout template ostream & operator << (ostream &s, const math_vector &a) { s << "[ "; for (unsigned int i = 0; i < a.size(); i++) s << a[i] << " "; s << "]"; return s; } }; //end namespace #endif