version
0.0.1
Defines the C++ API for MsPASS
|
Lightweight, simple matrix object. More...
#include <dmatrix.h>
Public Member Functions | |
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) |
dmatrix & | operator+= (const dmatrix &other) |
Add one matrix to another. More... | |
dmatrix & | operator-= (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 () |
Protected Attributes | |
std::vector< double > | ary |
size_t | length |
size_t | nrr |
size_t | ncc |
Friends | |
class | boost::serialization::access |
dmatrix | operator* (const dmatrix &A, const dmatrix &B) |
Procedure to multiply two matrices. This could be implemented with a dmatrix::operator but this was an existing procedure known to work that I didn't choose to mess with. Sizes must be compatible or an exception will be thrown. More... | |
dmatrix | operator* (const double &s, const dmatrix &A) noexcept |
Scale a matrix by a constant. More... | |
dmatrix | tr (const dmatrix &A) noexcept |
Transpose a matrix. More... | |
std::ostream & | operator<< (std::ostream &os, dmatrix &A) |
Text output operator. More... | |
Lightweight, simple matrix object.
This class defines a lightweight, simple double precision matrix. Provides basic matrix functionality. Note that elements of the matrix are stored internally in FORTRAN order but using C style indexing. That is, all indices begin at 0, not 1 and run to size - 1. Further, FORTRAN order means the elements are actually ordered in columns as in FORTRAN in a continuous, logical block of memory. This allow one to use the BLAS functions to access the elements of the matrix. As usual be warned this is useful for efficiency and speed, but completely circumvents the bounds checking used by methods in the object.
mspass::utility::dmatrix::dmatrix | ( | ) |
mspass::utility::dmatrix::dmatrix | ( | const size_t | nr, |
const size_t | nc | ||
) |
Basic constructor. Allocates space for nr x nc array and initializes to zeros.
nr | number of rows to allocate for this matrix. |
nc | number of columns to allocate for this matrix. |
mspass::utility::dmatrix::dmatrix | ( | const dmatrix & | other | ) |
mspass::utility::dmatrix::~dmatrix | ( | ) |
size_t mspass::utility::dmatrix::columns | ( | ) | const |
double mspass::utility::dmatrix::operator() | ( | const size_t | rowindex, |
const size_t | colindex | ||
) | const |
Indexing operator to fetch an array element.
Can also be used to set an element as a left hand side (e.g. A(2,4)=2.0;).
rowindex | row to fetch |
colindex | column to fetch. |
dmatrix_index_error | is thrown if request is out of range |
Operator to add two matrices.
This operator is similar to += but is the operator used in constructs like X=A+B. Like += other and this must be the same size or an exception will be thrown.
other | matrix to be added |
throws | a dmatrix_size_error if other and this are not the same size. |
Add one matrix to another.
Matrix addition is a standard operation but demands the two matrices to be added are the same size. Hence, an exception will happen if you use this operator with a size mismatch.
A | is the matrix to be added to this. |
throws | a dmatrix_size_error if other and this are not the same size. |
Operator to add two matrices.
This operator is similar to -= but is the operator used in constructs like X=A-B. Like -= other and this must be the same size or an exception will be thrown.
other | matrix to be added |
throws | a dmatrix_size_error if other and this are not the same size. |
Subtract one matrix to another.
Matrix subtraction is a standard operation but demands the two matrices to be added are the same size. Hence, an exception will happen if you use this operator with a size mismatch.
other | is the matrix to be subracted from to this. |
throws | a dmatrix_size_error if other and this are not the same size. |
size_t mspass::utility::dmatrix::rows | ( | ) | const |
vector< size_t > mspass::utility::dmatrix::size | ( | ) | const |
Return a vector with 2 elements giving the size.
This function returns an std::vector with 2 elements with size information. first component is rows, second is columns. This simulates the matlab size function.
void mspass::utility::dmatrix::zero | ( | ) |
Procedure to multiply two matrices. This could be implemented with a dmatrix::operator but this was an existing procedure known to work that I didn't choose to mess with. Sizes must be compatible or an exception will be thrown.
A | is the left matrix for the multiply. |
B | is the right matrix for the multiply. |
dmatrix_size_error | will be thrown if the columns in A are not equal to the rows in B. |
Scale a matrix by a constant.
This procedure will multiply all elements of a matrix by a constant. The linear algebra concept of scaling a matrix.
s | is the scaling factor |
A | is the matrix to be scaled |
|
friend |
Text output operator.
Output is ascii data written in the matrix layout. Note this can create huge lines and a lot of output for a large matrix so use carefully.
os | is the std::ostream to contain data. |
A | is the data to be written |
Transpose a matrix.
A standard matrix operation is to transpose a matrix (reversing rows and columns). This takes input A and returns A^T.
A | - matrix to transpose. |