MsPASS C++ API  2.4.4.dev122+gb075c5a7b
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
mspass::utility::dvector Class Reference

A vector compatible with dmatrix objects. More...

#include <dmatrix.h>

Inheritance diagram for mspass::utility::dvector:
Collaboration diagram for mspass::utility::dvector:

Public Member Functions

 dvector ()
 dvector (size_t nrv)
 dvector (const dvector &other)
dvector & operator= (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)
dmatrix & operator= (const dmatrix &other)
void swap (dmatrix &other) noexcept
bool storage_is_consistent () const noexcept
dmatrix & operator+= (const dmatrix &other)
 Add one matrix to another.
dmatrix & operator-= (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
 Get a pointer to the location of a matrix component.
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.

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

References mspass::utility::dmatrix::dmatrix().

◆ dvector() [2/3]

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

Create a (zero initialized) vector of length nrv.

312: dmatrix(nrv, 1) {};

References mspass::utility::dmatrix::dmatrix().

◆ 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}
size_t nrr
Definition dmatrix.h:287
size_t ncc
Definition dmatrix.h:289
std::vector< double > ary
Definition dmatrix.h:283
size_t length
Definition dmatrix.h:285

References mspass::utility::dmatrix::ary, dvector(), mspass::utility::dmatrix::length, mspass::utility::dmatrix::ncc, and mspass::utility::dmatrix::nrr.

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}

References mspass::utility::dmatrix::ary, and mspass::utility::dmatrix::nrr.

◆ 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}

References mspass::utility::dmatrix::ary, dvector(), mspass::utility::dmatrix::length, mspass::utility::dmatrix::ncc, and mspass::utility::dmatrix::nrr.

◆ 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 left in multiply
x- vector on right 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 = A.rows();
242 size_t ncx1 = A.columns();
243 size_t nrb = const_cast<dvector &>(x).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 &>(A).get_address(i, 0), nrx1,
249 const_cast<dvector &>(x).get_address(0, 0), 1);
250 return prod;
251}
size_t rows() const
Definition dmatrix.cc:215
double * get_address(size_t r, size_t c) const
Get a pointer to the location of a matrix component.
Definition dmatrix.cc:72
dvector()
Definition dmatrix.h:310

References mspass::utility::dmatrix::columns(), mspass::utility::dmatrix::dmatrix(), dvector(), mspass::utility::dmatrix::get_address(), operator*, and mspass::utility::dmatrix::rows().


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