version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | Friends | List of all members
mspass::utility::dvector Class Reference

A vector compatible with dmatrix objects. More...

#include <dmatrix.h>

Inheritance diagram for mspass::utility::dvector:
mspass::utility::dmatrix

Public Member Functions

 dvector ()
 
 dvector (size_t nrv)
 
 dvector (const dvector &other)
 
dvectoroperator= (const dvector &other)
 
double & operator() (size_t rowindex)
 
- Public Member Functions inherited from mspass::utility::dmatrix
 dmatrix ()
 
 dmatrix (const size_t nr, const size_t nc)
 
 dmatrix (const dmatrix &other)
 
 ~dmatrix ()
 
double operator() (const size_t rowindex, const size_t colindex) const
 
double & operator() (size_t r, size_t c)
 
dmatrixoperator= (const dmatrix &other)
 
dmatrixoperator+= (const dmatrix &other)
 Add one matrix to another. More...
 
dmatrixoperator-= (const dmatrix &other)
 Subtract one matrix to another. More...
 
dmatrix operator+ (const dmatrix &other) const
 
dmatrix operator- (const dmatrix &other) const
 
dmatrix operator* (double s) const noexcept
 
double * get_address (size_t r, size_t c) const
 
size_t rows () const
 
size_t columns () const
 
std::vector< size_t > size () const
 Return a vector with 2 elements giving the size. More...
 
void zero ()
 

Friends

dvector operator* (const dmatrix &A, const dvector &x)
 

Additional Inherited Members

- Protected Attributes inherited from mspass::utility::dmatrix
std::vector< double > ary
 
size_t length
 
size_t nrr
 
size_t ncc
 

Detailed Description

A vector compatible with dmatrix objects.

A vector is a special case of a matrix with one row or column. In this implementation, however, it always means a column vector. Hence, it is possible to multiply a vector x and a matrix A as Ax provided they are compatible sizes. This differs from matlab where row and columns vectors are sometimes used interchangably.

Constructor & Destructor Documentation

◆ dvector() [1/3]

mspass::utility::dvector::dvector ( )
inline

Default constructor creates an empty vector.

270 :dmatrix(){};
dmatrix()
Definition: dmatrix.cc:8

◆ dvector() [2/3]

mspass::utility::dvector::dvector ( size_t  nrv)
inline

Create a (zero initialized) vector of length nrv.

272 : dmatrix(nrv,1){};

◆ dvector() [3/3]

mspass::utility::dvector::dvector ( const dvector other)

Copy constructor.

250 {
251  ncc=1;
252  nrr=other.nrr;
253  length=other.length;
254  ary=other.ary;
255 }

Member Function Documentation

◆ operator()()

double & mspass::utility::dvector::operator() ( size_t  rowindex)

Extract component rowindex.

257 {
258  if (rowindex>=nrr)
259  throw dmatrix_index_error(nrr,1,rowindex,1);
260  return (ary[rowindex]);
261 }

◆ operator=()

dvector & mspass::utility::dvector::operator= ( const dvector other)

Standard assignment operator.

239 {
240  if(this != &other)
241  {
242  ncc=1;
243  nrr=other.nrr;
244  length=other.length;
245  ary=other.ary;
246  }
247  return *this;
248 }

Friends And Related Function Documentation

◆ operator*

dvector operator* ( const dmatrix A,
const dvector x 
)
friend

Matrix vector multiple operator.

This operator is used for constructs like y=Ax where x is a vector and A is a matrix. y is the returned vector.

Parameters
A- matrix on right in multiply
x- vector on left of multiply operation
Returns
product A*x
Exceptions
dmatrix_size_errorthrown if size of A and x do not match.
263 {
264  size_t i;
265  size_t nrx1=x1.rows();
266  size_t ncx1=x1.columns();
267  size_t nrb=const_cast<dvector&>(b).rows();
268  if(ncx1!=nrb)
269  throw dmatrix_size_error(nrx1, ncx1, nrb, 1);
270  dvector prod(nrx1);
271  for(i=0;i<nrx1;i++)
272  prod(i)=ddot(nrb,
273  const_cast<dmatrix&>(x1).get_address(i,0),nrx1,
274  const_cast<dvector&>(b).get_address(0,0),1);
275  return prod;
276 }
size_t rows() const
Definition: dmatrix.cc:228
dvector()
Definition: dmatrix.h:270

The documentation for this class was generated from the following files: