X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flinal%2Fvector.h;h=9a9d02822aebe554627178803b4c6bd4c2621ddc;hb=2feea51b078cc53663e411bf80e35044c1ef4a07;hp=a5c9a26cfc1e8152fd4cece0158aa553f3b97c8d;hpb=204db1dfb803a97481f2a8b3bbaf6e20be6e0980;p=libs%2Fmath.git diff --git a/source/linal/vector.h b/source/linal/vector.h index a5c9a26..9a9d028 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -74,17 +74,25 @@ template class Vector: public VectorComponents { public: + typedef T ElementType; + Vector(); Vector(const T *); + + /** Constructs a vector from an array of interleaved values. Intended for + use by Matrix row accessor. */ + Vector(const T *, unsigned); + Vector(T, T); Vector(T, T, T); Vector(T, T, T, T); template Vector(const Vector &); - template - Vector(const Vector &, U); - template - explicit Vector(const Vector &); + + unsigned size() const { return N; } + + template + Vector slice(unsigned) const; Vector &operator*=(T); Vector &operator/=(T); @@ -110,6 +118,13 @@ inline Vector::Vector(const T *d) (*this)[i] = d[i]; } +template +inline Vector::Vector(const T *d, unsigned stride) +{ + for(unsigned i=0; i @@ -145,20 +160,44 @@ inline Vector::Vector(const Vector &v) } template -template -inline Vector::Vector(const Vector &v, U s) +inline Vector compose(const Vector &v, T s) { - for(unsigned i=0; i r; + for(unsigned i=0; i -template -inline Vector::Vector(const Vector &v) +inline Vector compose(T s, const Vector &v) { + Vector r; for(unsigned i=0; i +inline Vector compose(const Vector &v1, const Vector &v2) +{ + Vector r; + for(unsigned i=0; i +template +inline Vector Vector::slice(unsigned j) const +{ + Vector r; + for(unsigned i=0; i @@ -257,6 +296,7 @@ inline T inner_product(const Vector &v1, const Vector &v2) template inline T Vector::norm() const { + using std::sqrt; return sqrt(inner_product(*this, *this)); }