Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxVector Class Reference

Class definition for vectors. More...

#include <HxVector.h>

List of all members.

Constructors

 HxVector ()
 Empty vector. More...

 HxVector (int n)
 Empty vector of given size. More...

 HxVector (int n, double *data)
 vector with given data. More...

 HxVector (double a0, double a1)
 Vector of size 2, with given values. More...

 HxVector (double a0, double a1, double a2)
 Vector of size 3, with given values. More...

 HxVector (double a0, double a1, double a2, double a3)
 Vector of size 4, with given values. More...

 HxVector (const HxVector &v)
 Copy constructor. More...

 HxVector (const HxMatrix &m)
 Copy from matrix constructor. More...


Inquiry

int nElem () const
 Number of elements. More...

int valid () const
 Indicates whether the vector is valid. More...


Operators

HxVector & operator= (double a)
 Assign constant value. More...

HxVector & operator= (const HxVector &v)
 Normal assignment. More...

double & operator[] (int i) const
 Subscripting, start with 0. More...

HxVector operator- () const
 Unary minus. More...

double operator * (const HxVector &a, const HxVector &b)
 Multiplication. More...

HxVector operator * (const double a, const HxVector &b)
 Multiplication. More...

HxVector operator * (const HxVector &a, const double b)
 Multiplication. More...

HxVector operator/ (const HxVector &a, double b)
 Division. More...

HxVector operator/ (double a, const HxVector &b)
 Division. More...

HxVector operator+ (const HxVector &a, const HxVector &b)
 Addition. More...

HxVector operator+ (const HxVector &a, double b)
 Addition. More...

HxVector operator+ (double a, const HxVector &b)
 Addition. More...

HxVector operator- (const HxVector &a, const HxVector &b)
 Subtraction. More...

HxVector operator- (const HxVector &a, double b)
 Subtraction. More...

HxVector operator- (double a, const HxVector &b)
 Subtraction. More...

int operator== (const HxVector &a, const HxVector &b)
 Equal. More...

int operator!= (const HxVector &a, const HxVector &b)
 Not equal. More...


Operations

HxMatrix t () const
 Transpose Matrix. More...

HxMatrix diag () const
 Diagonal Matrix. More...

HxVector add (const HxVector &b) const
 Addition. More...

HxVector add (const double val) const
 Addition. More...

HxVector sub (const HxVector &b) const
 Subtraction. More...

HxVector sub (const double val) const
 Subtraction. More...

HxVector mul (const HxVector &b) const
 Multiplication. More...

HxVector mul (const HxMatrix &m) const
 Multiplication. More...

HxVector mul (const double val) const
 Multiplication. More...

HxVector div (const double val) const
 Division. More...

HxVector sin () const
 Apply sin to each element. More...

HxVector cos () const
 Apply cos to each element. More...

HxVector tan () const
 Apply tan to each element. More...

HxVector sinh () const
 Apply sinh to each element. More...

HxVector cosh () const
 Apply cosh to each element. More...

HxVector tanh () const
 Apply tanh to each element. More...

HxVector exp () const
 Apply exp to each element. More...

HxVector log () const
 Apply log to each element. More...

HxVector sqrt () const
 Apply sqrt to each element. More...

HxVector abs () const
 Apply abs to each element. More...

HxVector sgn () const
 Apply sgn to each element. More...

HxVector map (double(*f)(double)) const
 Map f to each element of this. More...


Public Methods

 ~HxVector ()
std::ostream & put (std::ostream &os) const


Detailed Description

Class definition for vectors.

The vector may have arbitrary size.


Constructor & Destructor Documentation

HxVector::HxVector   [inline]
 

Empty vector.

00221 {
00222     _n = 0;
00223     _data = 0;
00224 }

HxVector::HxVector int    n [inline]
 

Empty vector of given size.

00227 {
00228     _n = n;
00229     _data = new double[_n];
00230 }

HxVector::HxVector int    n,
double *    data
[inline]
 

vector with given data.

00233 {
00234     _n = n;
00235     _data = data;
00236 }

HxVector::HxVector double    a0,
double    a1
[inline]
 

Vector of size 2, with given values.

00239 {
00240     _n = 2;
00241     _data = new double[_n];
00242     _data[0] = a0;
00243     _data[1] = a1;
00244 }

HxVector::HxVector double    a0,
double    a1,
double    a2
[inline]
 

Vector of size 3, with given values.

00247 {
00248     _n = 3;
00249     _data = new double[_n];
00250     _data[0] = a0;
00251     _data[1] = a1;
00252     _data[2] = a2;
00253 }

HxVector::HxVector double    a0,
double    a1,
double    a2,
double    a3
[inline]
 

Vector of size 4, with given values.

00256 {
00257     _n = 4;
00258     _data = new double[_n];
00259     _data[0] = a0;
00260     _data[1] = a1;
00261     _data[2] = a2;
00262     _data[3] = a3;
00263 }

HxVector::HxVector const HxVector &    v [inline]
 

Copy constructor.

00266 {
00267     _n = v.nElem();
00268     _data = new double[_n];
00269 
00270     double* t = v._data;
00271     double* u = _data;
00272     int i = v.nElem();
00273     while (--i >= 0)
00274         *u++ = *t++;
00275 }

HxVector::HxVector const HxMatrix &    m
 

Copy from matrix constructor.

00040 {
00041     _n = m.nElem();
00042     _data = new double[_n];
00043 
00044     double* t = m._data;
00045     double* u = _data;
00046     int i = m.nElem();
00047     while (--i >= 0)
00048         *u++ = *t++;
00049 }


Member Function Documentation

int HxVector::nElem   const [inline]
 

Number of elements.

00284 { 
00285     return _n; 
00286 }

int HxVector::valid   const [inline]
 

Indicates whether the vector is valid.

00290 {
00291     return (_n != 0);
00292 }

HxVector & HxVector::operator= double    a [inline]
 

Assign constant value.

00296 {
00297     int i = nElem();
00298     double *t = _data;
00299     while (--i >= 0)
00300         *t++ = a;
00301     return *this;
00302 }

HxVector & HxVector::operator= const HxVector &    v [inline]
 

Normal assignment.

00306 {
00307     if (this != &v) {
00308         delete [] _data;
00309         _n = v.nElem();
00310         _data = new double [_n];
00311         double *t = _data;
00312         double *u = v._data;
00313         int i = v.nElem();
00314         while (--i >= 0)
00315             *t++ = *u++;
00316     }
00317     return *this;
00318 }

double & HxVector::operator[] int    i const [inline]
 

Subscripting, start with 0.

00322 { 
00323     return _data[i];
00324 } 

HxVector HxVector::operator-   const [inline]
 

Unary minus.

00328 {
00329     HxVector m(*this);
00330     double* t = m._data;
00331     double* u = _data;
00332     int i = nElem();
00333     while (--i >= 0)
00334         *t++ = -(*u++);
00335     return m;
00336 }

HxMatrix HxVector::t   const
 

Transpose Matrix.

00113 {
00114     HxMatrix m(nElem(), 1);
00115     int i;
00116     for (i=0 ; i<nElem() ; i++)
00117             m[0][i] = (*this)[i];
00118     return m;
00119 }

HxMatrix HxVector::diag   const
 

Diagonal Matrix.

00123 {
00124     int n = nElem();
00125     HxMatrix m(n, n, 0.0);
00126 
00127     double *t = _data;
00128 
00129     for (int i = 0; i < nElem(); i++)
00130         m[i][i] = *t++;
00131 
00132     return m;
00133 }

HxVector HxVector::add const HxVector &    b const
 

Addition.

Equivalent to : a+b

00138 {
00139     return *this+b;
00140 }

HxVector HxVector::add const double    val const
 

Addition.

Equivalent to : a+val

00144 {
00145     return *this+val;
00146 }

HxVector HxVector::sub const HxVector &    b const
 

Subtraction.

Equivalent to : a-b

00150 {
00151     return *this-b;
00152 }

HxVector HxVector::sub const double    val const
 

Subtraction.

Equivalent to : a-val

00156 {
00157     return *this-val;
00158 }

HxVector HxVector::mul const HxVector &    b const
 

Multiplication.

Equivalent to : a*b

00162 {
00163     return *this*b;
00164 }

HxVector HxVector::mul const HxMatrix &    m const
 

Multiplication.

Equivalent to : a*v

00174 {
00175     
00176     if (this->nElem() != m.nRow()) {
00177         error("nonconformant HxVector * HxMatrix operands.");
00178         return HxVector(0);
00179     }
00180     HxVector v(m.nCol());
00181     double sum;
00182     int i, j;
00183     for (i=0 ; i<m.nCol() ; i++) {
00184         sum = 0;
00185         for (j=0 ; j<m.nRow() ; j++)
00186             sum += (*this)[j] * m[j][i];
00187         v[i] = sum;
00188     }
00189     return v;
00190 
00191 
00192 
00193 }

HxVector HxVector::mul const double    val const
 

Multiplication.

Equivalent to : a*val

00168 {
00169     return *this*val;
00170 }

HxVector HxVector::div const double    val const
 

Division.

Equivalent to : a/val

00197 {
00198     return *this/val;
00199 }

HxVector HxVector::sin   const
 

Apply sin to each element.

00203 {
00204     return map(::sin);
00205 }

HxVector HxVector::cos   const
 

Apply cos to each element.

00209 {
00210     return map(::cos);
00211 }

HxVector HxVector::tan   const
 

Apply tan to each element.

00215 {
00216     return map(::tan);
00217 }

HxVector HxVector::sinh   const
 

Apply sinh to each element.

00221 {
00222     return map(::sinh);
00223 }

HxVector HxVector::cosh   const
 

Apply cosh to each element.

00227 {
00228     return map(::cosh);
00229 }

HxVector HxVector::tanh   const
 

Apply tanh to each element.

00233 {
00234     return map(::tanh);
00235 }

HxVector HxVector::exp   const
 

Apply exp to each element.

00239 {
00240     return map(::exp);
00241 }

HxVector HxVector::log   const
 

Apply log to each element.

00245 {
00246     return map(::log);
00247 }

HxVector HxVector::sqrt   const
 

Apply sqrt to each element.

00251 {
00252     return map(::sqrt);
00253 }

HxVector HxVector::abs   const
 

Apply abs to each element.

00257 {
00258     return map(::fabs);
00259 }

HxVector HxVector::sgn   const
 

Apply sgn to each element.

00265 {
00266     return map(::sgn);
00267 }

HxVector HxVector::map double(*    f)(double) const [inline]
 

Map f to each element of this.

00450 {
00451     HxVector m(*this);
00452     double* t = m._data;
00453     double* u = _data;
00454     int i = nElem();
00455     while (--i >= 0)
00456             *t++ = f(*u++);
00457     return m;
00458 }


Friends And Related Function Documentation

double operator * const HxVector &    a,
const HxVector &    b
[friend]
 

Multiplication.

00053 {
00054     if (a.nElem() != b.nElem()) {
00055         error("nonconformant HxVector * HxVector operands.");
00056         return 0;
00057     }
00058     double sum = 0;
00059     int i;
00060     for (i=0 ; i<a.nElem() ; i++)
00061         sum += a[i] * b[i];
00062     return sum;
00063 }

HxVector operator * const double    a,
const HxVector &    b
[friend]
 

Multiplication.

00352 {
00353     HxVector m(b);
00354     double* t = m._data;
00355     double* u = b._data;
00356     int i = b.nElem();
00357     while (--i >= 0)
00358     *t++ = a * *u++;
00359     return m;
00360 }

HxVector operator * const HxVector &    a,
const double    b
[friend]
 

Multiplication.

00340 {
00341     HxVector m(a);
00342     double* t = m._data;
00343     double* u = a._data;
00344     int i = a.nElem();
00345     while (--i >= 0)
00346         *t++ = *u++ * b;
00347     return m;
00348 }

HxVector operator/ const HxVector &    a,
double    b
[friend]
 

Division.

00364 {
00365     HxVector m(a);
00366     double* t = m._data;
00367     double* u = a._data;
00368     int i = a.nElem();
00369     while (--i >= 0)
00370         *t++ = *u++ / b;
00371     return m;
00372 }

HxVector operator/ double    a,
const HxVector &    b
[friend]
 

Division.

00376 {
00377     HxVector m(b);
00378     double* t = m._data;
00379     double* u = b._data;
00380     int i = b.nElem();
00381     while (--i >= 0)
00382         *t++ = a / *u++;
00383     return m;
00384 }

HxVector operator+ const HxVector &    a,
const HxVector &    b
[friend]
 

Addition.

00067 {
00068     if (a.nElem() != b.nElem()) {
00069         error("nonconformant HxVector + HxVector operands.");
00070         return HxVector(0);
00071     }
00072     HxVector m(a.nElem());
00073     int i;
00074     for (i=0 ; i<a.nElem() ; i++) {
00075         m[i] = a[i] + b[i];
00076     }
00077     return m;
00078 }

HxVector operator+ const HxVector &    a,
double    b
[friend]
 

Addition.

00388 {
00389     HxVector m(a);
00390     double* t = m._data;
00391     double* u = a._data;
00392     int i = a.nElem();
00393     while (--i >= 0)
00394         *t++ = *u++ + b;
00395     return m;
00396 }

HxVector operator+ double    a,
const HxVector &    b
[friend]
 

Addition.

00400 {
00401     HxVector m(b);
00402     double* t = m._data;
00403     double* u = b._data;
00404     int i = b.nElem();
00405     while (--i >= 0)
00406         *t++ = a + *u++;
00407     return m;
00408 }

HxVector operator- const HxVector &    a,
const HxVector &    b
[friend]
 

Subtraction.

00082 {
00083     if (a.nElem() != b.nElem()) {
00084         error("nonconformant HxVector - HxVector operands.");
00085         return HxVector(0);
00086     }
00087     HxVector m(a.nElem());
00088     int i;
00089     for (i=0 ; i<a.nElem() ; i++) {
00090         m[i] = a[i] - b[i];
00091     }
00092     return m;
00093 }

HxVector operator- const HxVector &    a,
double    b
[friend]
 

Subtraction.

00412 {
00413     HxVector m(a);
00414     double* t = m._data;
00415     double* u = a._data;
00416     int i = a.nElem();
00417     while (--i >= 0)
00418         *t++ = *u++ - b;
00419     return m;
00420 }

HxVector operator- double    a,
const HxVector &    b
[friend]
 

Subtraction.

00424 {
00425     HxVector m(b);
00426     double* t = m._data;
00427     double* u = b._data;
00428     int i = b.nElem();
00429     while (--i >= 0)
00430         *t++ = a - *u++;
00431     return m;
00432 }

int operator== const HxVector &    a,
const HxVector &    b
[friend]
 

Equal.

00097 {
00098     if (a.nElem() != b.nElem())
00099         return 0;
00100     double *t = a._data;
00101     double *u = b._data;
00102     int i = a.nElem();
00103     while (--i >= 0) {
00104         if (fabs(*t++ - *u++) > HxMatrix_EPS)
00105             return 0;
00106     }
00107     return 1;
00108 }

int operator!= const HxVector &    a,
const HxVector &    b
[friend]
 

Not equal.

00436 {
00437     return !(a == b);
00438 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 3 14:19:11 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001