version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
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.
 
dmatrixoperator-= (const dmatrix &other)
 Subtract one matrix to another.
 
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.
 
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.

276: 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.

278: dmatrix(nrv, 1) {};

◆ dvector() [3/3]

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

Copy constructor.

228 {
229 ncc = 1;
230 nrr = other.nrr;
231 length = other.length;
232 ary = other.ary;
233}

Member Function Documentation

◆ operator()()

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

Extract component rowindex.

234 {
235 if (rowindex >= nrr)
236 throw dmatrix_index_error(nrr, 1, rowindex, 1);
237 return (ary[rowindex]);
238}

◆ operator=()

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

Standard assignment operator.

219 {
220 if (this != &other) {
221 ncc = 1;
222 nrr = other.nrr;
223 length = other.length;
224 ary = other.ary;
225 }
226 return *this;
227}

Friends And Related Symbol 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.
239 {
240 size_t i;
241 size_t nrx1 = x1.rows();
242 size_t ncx1 = x1.columns();
243 size_t nrb = const_cast<dvector &>(b).rows();
244 if (ncx1 != nrb)
245 throw dmatrix_size_error(nrx1, ncx1, nrb, 1);
246 dvector prod(nrx1);
247 for (i = 0; i < nrx1; i++)
248 prod(i) = ddot(nrb, const_cast<dmatrix &>(x1).get_address(i, 0), nrx1,
249 const_cast<dvector &>(b).get_address(0, 0), 1);
250 return prod;
251}
size_t rows() const
Definition dmatrix.cc:215
dvector()
Definition dmatrix.h:276

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