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

Friends

class HxMatrix


Detailed Description

Class definition for vectors.

The vector may have arbitrary size.


Constructor & Destructor Documentation

HxVector::HxVector   [inline]
 

Empty vector.

00216 {
00217     _n = 0;
00218     _data = 0;
00219 }

HxVector::HxVector int    n [inline]
 

Empty vector of given size.

00222 {
00223     _n = n;
00224     _data = new double[_n];
00225 }

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

vector with given data.

00228 {
00229     _n = n;
00230     _data = data;
00231 }

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

Vector of size 2, with given values.

00234 {
00235     _n = 2;
00236     _data = new double[_n];
00237     _data[0] = a0;
00238     _data[1] = a1;
00239 }

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

Vector of size 3, with given values.

00242 {
00243     _n = 3;
00244     _data = new double[_n];
00245     _data[0] = a0;
00246     _data[1] = a1;
00247     _data[2] = a2;
00248 }

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

Vector of size 4, with given values.

00251 {
00252     _n = 4;
00253     _data = new double[_n];
00254     _data[0] = a0;
00255     _data[1] = a1;
00256     _data[2] = a2;
00257     _data[3] = a3;
00258 }

HxVector::HxVector const HxVector &    v [inline]
 

Copy constructor.

00261 {
00262     _n = v.nElem();
00263     _data = new double[_n];
00264 
00265     double* t = v._data;
00266     double* u = _data;
00267     int i = v.nElem();
00268     while (--i >= 0)
00269         *u++ = *t++;
00270 }

HxVector::HxVector const HxMatrix   m
 

Copy from matrix constructor.

00027 {
00028     _n = m.nElem();
00029     _data = new double[_n];
00030 
00031     double* t = m._data;
00032     double* u = _data;
00033     int i = m.nElem();
00034     while (--i >= 0)
00035         *u++ = *t++;
00036 }


Member Function Documentation

int HxVector::nElem   const [inline]
 

Number of elements.

00279 { 
00280     return _n; 
00281 }

int HxVector::valid   const [inline]
 

Indicates whether the vector is valid.

00285 {
00286     return (_n != 0);
00287 }

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

Assign constant value.

00291 {
00292     int i = nElem();
00293     double *t = _data;
00294     while (--i >= 0)
00295         *t++ = a;
00296     return *this;
00297 }

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

Normal assignment.

00301 {
00302     if (this != &v) {
00303         delete [] _data;
00304         _n = v.nElem();
00305         _data = new double [_n];
00306         double *t = _data;
00307         double *u = v._data;
00308         int i = v.nElem();
00309         while (--i >= 0)
00310             *t++ = *u++;
00311     }
00312     return *this;
00313 }

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

Subscripting, start with 0.

00317 { 
00318     return _data[i];
00319 } 

HxVector HxVector::operator-   const [inline]
 

Unary minus.

00323 {
00324     HxVector m(*this);
00325     double* t = m._data;
00326     double* u = _data;
00327     int i = nElem();
00328     while (--i >= 0)
00329         *t++ = -(*u++);
00330     return m;
00331 }

HxMatrix HxVector::t   const
 

Transpose Matrix.

00099 {
00100     HxMatrix m(nElem(), 1);
00101     int i;
00102     for (i=0 ; i<nElem() ; i++)
00103             m[0][i] = (*this)[i];
00104     return m;
00105 }

HxMatrix HxVector::diag   const
 

Diagonal Matrix.

00109 {
00110     int n = nElem();
00111     HxMatrix m(n, n, 0.0);
00112 
00113     double *t = _data;
00114 
00115     for (int i = 0; i < nElem(); i++)
00116         m[i][i] = *t++;
00117 
00118     return m;
00119 }

HxVector HxVector::add const HxVector &    b const
 

Addition.

Equivalent to : a+b

00124 {
00125     return *this+b;
00126 }

HxVector HxVector::add const double    val const
 

Addition.

Equivalent to : a+val

00130 {
00131     return *this+val;
00132 }

HxVector HxVector::sub const HxVector &    b const
 

Subtraction.

Equivalent to : a-b

00136 {
00137     return *this-b;
00138 }

HxVector HxVector::sub const double    val const
 

Subtraction.

Equivalent to : a-val

00142 {
00143     return *this-val;
00144 }

HxVector HxVector::mul const HxVector &    b const
 

Multiplication.

Equivalent to : a*b

00148 {
00149     return *this*b;
00150 }

HxVector HxVector::mul const HxMatrix   m const
 

Multiplication.

Equivalent to : a*v

00160 {
00161     return *this*m;
00162 }

HxVector HxVector::mul const double    val const
 

Multiplication.

Equivalent to : a*val

00154 {
00155     return *this*val;
00156 }

HxVector HxVector::div const double    val const
 

Division.

Equivalent to : a/val

00166 {
00167     return *this/val;
00168 }

HxVector HxVector::sin   const
 

Apply sin to each element.

00172 {
00173     return map(::sin);
00174 }

HxVector HxVector::cos   const
 

Apply cos to each element.

00178 {
00179     return map(::cos);
00180 }

HxVector HxVector::tan   const
 

Apply tan to each element.

00184 {
00185     return map(::tan);
00186 }

HxVector HxVector::sinh   const
 

Apply sinh to each element.

00190 {
00191     return map(::sinh);
00192 }

HxVector HxVector::cosh   const
 

Apply cosh to each element.

00196 {
00197     return map(::cosh);
00198 }

HxVector HxVector::tanh   const
 

Apply tanh to each element.

00202 {
00203     return map(::tanh);
00204 }

HxVector HxVector::exp   const
 

Apply exp to each element.

00208 {
00209     return map(::exp);
00210 }

HxVector HxVector::log   const
 

Apply log to each element.

00214 {
00215     return map(::log);
00216 }

HxVector HxVector::sqrt   const
 

Apply sqrt to each element.

00220 {
00221     return map(::sqrt);
00222 }

HxVector HxVector::abs   const
 

Apply abs to each element.

00226 {
00227     return map(::fabs);
00228 }

HxVector HxVector::sgn   const
 

Apply sgn to each element.

00234 {
00235     return map(::sgn);
00236 }

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

Map f to each element of this.

00444 {
00445     HxVector m(*this);
00446     double* t = m._data;
00447     double* u = _data;
00448     int i = nElem();
00449     while (--i >= 0)
00450             *t++ = f(*u++);
00451     return m;
00452 }


Friends And Related Function Documentation

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

Multiplication.

00040 {
00041     if (a.nElem() != b.nElem()) {
00042         error("nonconformant HxVector * HxVector operands.");
00043         return 0;
00044     }
00045     double sum = 0;
00046     int i;
00047     for (i=0 ; i<a.nElem() ; i++)
00048         sum += a[i] * b[i];
00049     return sum;
00050 }

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

Multiplication.

00347 {
00348     HxVector m(b);
00349     double* t = m._data;
00350     double* u = b._data;
00351     int i = b.nElem();
00352     while (--i >= 0)
00353     *t++ = a * *u++;
00354     return m;
00355 }

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

Multiplication.

00335 {
00336     HxVector m(a);
00337     double* t = m._data;
00338     double* u = a._data;
00339     int i = a.nElem();
00340     while (--i >= 0)
00341         *t++ = *u++ * b;
00342     return m;
00343 }

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

Division.

00359 {
00360     HxVector m(a);
00361     double* t = m._data;
00362     double* u = a._data;
00363     int i = a.nElem();
00364     while (--i >= 0)
00365         *t++ = *u++ / b;
00366     return m;
00367 }

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

Division.

00371 {
00372     HxVector m(b);
00373     double* t = m._data;
00374     double* u = b._data;
00375     int i = b.nElem();
00376     while (--i >= 0)
00377         *t++ = a / *u++;
00378     return m;
00379 }

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

Addition.

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

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

Addition.

00383 {
00384     HxVector m(a);
00385     double* t = m._data;
00386     double* u = a._data;
00387     int i = a.nElem();
00388     while (--i >= 0)
00389         *t++ = *u++ + b;
00390     return m;
00391 }

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

Addition.

00395 {
00396     HxVector m(b);
00397     double* t = m._data;
00398     double* u = b._data;
00399     int i = b.nElem();
00400     while (--i >= 0)
00401         *t++ = a + *u++;
00402     return m;
00403 }

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

Subtraction.

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

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

Subtraction.

00407 {
00408     HxVector m(a);
00409     double* t = m._data;
00410     double* u = a._data;
00411     int i = a.nElem();
00412     while (--i >= 0)
00413         *t++ = *u++ - b;
00414     return m;
00415 }

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

Subtraction.

00419 {
00420     HxVector m(b);
00421     double* t = m._data;
00422     double* u = b._data;
00423     int i = b.nElem();
00424     while (--i >= 0)
00425         *t++ = a - *u++;
00426     return m;
00427 }

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

Equal.

00084 {
00085     if (a.nElem() != b.nElem())
00086         return 0;
00087     double *t = a._data;
00088     double *u = b._data;
00089     int i = a.nElem();
00090     while (--i >= 0) {
00091         if (fabs(*t++ - *u++) > HxMatrix_EPS)
00092             return 0;
00093     }
00094     return 1;
00095 }

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

Not equal.

00431 {
00432     return !(a == b);
00433 }


The documentation for this class was generated from the following files:
Generated on Mon Jan 27 15:49:12 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001