#include <linalg.h>
Inherits matrixview< T >< T >, and Matrix< T >< T >.
Inheritance diagram for DenseMatrix< T >:
Public Member Functions | |
void | initialize (const datablock< T > *db, const itype e[2], const itype r[2], const itype o[2]) |
virtual bool | Valid () const |
Should return TRUE if and only if the view has been properly initialized. Doesn't check parameters for sanity! | |
virtual datablock< T > * | GetDataBlock () const |
Each dataview is attached to a datablock; this should give access to it. Only usable from derived classes (i.e., views). | |
virtual itype | Dimensionality () const |
Should return the number of indices required to define an element in this view. | |
virtual itype | Range (itype i) const |
Should return the virtual range of index i . | |
virtual bool | Is1DCompatible () const |
Should return TRUE if and only if this view provides 1-D strided access. | |
virtual bool | Is2DCompatible () const |
Should return TRUE if and only if this view provides 2-D semi-contiguous strided access. | |
virtual T * | Get1DRep (itype &n_elements, itype &r_stride) const |
virtual T * | Get2DRep (itype &n_series, itype &series_size, itype &series_extent) const |
virtual T & | item (itype index) const |
virtual T & | element (itype *iarr) const |
virtual T & | element (itype i1,...) const |
virtual void | PrettyPrint (std::ostream &os=std::cout) const |
virtual void | DataPrint (std::ostream &os=std::cout) const |
virtual void | OwnData (bool copyflag) |
virtual void | FillFromStream (std::istream &is, bool clear=true) |
virtual void | InitFromStream (std::istream &is) |
matrixview< T > | GetSubMatrixView (interval sub_R, interval sub_C) const |
vectorview< T > | GetRowVectorView (itype r) const |
vectorview< T > | GetColumnVectorView (itype c) const |
T & | operator() (itype i) const |
virtual void | Fill (T val) |
void | SetSize (itype s1, itype s2, bool copyflag) |
virtual void | print (std::ostream &os=std::cout) const |
Prettyprints the Matrix to a stream, but without justification. | |
Constructors and destructors | |
DenseMatrix () | |
Default constructor: constructs a null matrix with size 0x0. | |
DenseMatrix (itype r, itype c) | |
Standard constructor: constructs a matrix linked to a fresh datablock of the specified size. | |
DenseMatrix (itype r, itype c, T array[]) | |
Initializing constructor: constructs a matrix linked to a new datablock of the specified size, and initializes from the specified pointer. | |
DenseMatrix (const matrixview< T > &other) | |
Semi-copy constructor: constructs a copy of another matrixview<T>. | |
DenseMatrix (const DenseMatrix< T > &other) | |
Copy constructor: constructs a copy of another DenseMatrix<T>. | |
template<class T2> | |
DenseMatrix (const Matrix< T2 > &other) | |
Cross-type copy constructor; constructs a copy of a DenseMatrix<T2> that contains a different type of data. Requires that T2 be implicitly convertible to T! | |
virtual | ~DenseMatrix () |
Destructor; does nothing. | |
Overridden base class methods | |
virtual DenseVector< T > | Rowvector (itype r) |
Returns a DenseVector<T> referring to a single row of this matrix. Changes to the returned vector will affect this matrix! | |
virtual DenseVector< T > | Columnvector (itype c) |
Returns a DenseVector<T> referring to a single column of this matrix. Changes to the returned vector will affect this matrix! | |
virtual DenseMatrix< T > | Submatrix (interval ri, interval ci) |
Returns a DenseMatrix<T> referring to a submatrix of this matrix. Changes to the returned matrix will affect this matrix! | |
virtual const DenseVector< T > | Rowvector (itype r) const |
Returns a [const] DenseVector<T> referring to a single row of this matrix. | |
virtual const DenseVector< T > | Columnvector (itype c) const |
Returns a [const] DenseVector<T> referring to a single column of this matrix. | |
virtual const DenseMatrix< T > | Submatrix (interval ri, interval ci) const |
Returns a [const] DenseMatrix<T> referring to a submatrix of this matrix. | |
DenseMatrix< T > | copy () const |
Creates a copy of this matrix and return it. The copy has a separate datablock. | |
virtual itype | Rows () const |
Returns the number of rows in this matrix. Overrides an abstract Matrix<T> method. | |
virtual itype | Columns () const |
Returns the number of columns in this matrix. Overrides an abstract Matrix<T> method. | |
virtual itype | Size () const |
Returns the total number of [potentially] nonzero elements in this matrix. Overrides an abstract Matrix<T> method. | |
virtual T & | operator() (itype r, itype c) |
Returns a reference to a particular element of this matrix. Overrides an abstract Matrix<T> method. | |
virtual T | operator() (itype r, itype c) const |
Returns the value of a particular element of this matrix. Overrides an abstract Matrix<T> method. | |
virtual void | print (std::ostream os=std::cout) const |
Prints this matrix to an output stream. Overrides an abstract Matrix<T> method. | |
New methods | |
bool | isSquare () const |
Returns true if and only if the matrix is square. | |
bool | isSymmetric () const |
Returns true if and only if for all ![]() ![]() | |
bool | isHermitian () const |
Returns true if and only if for all ![]() ![]() | |
T | Trace () const |
Returns the trace of this matrix: ![]() | |
DenseMatrix< T > & | AddOuterProduct (const DenseVector< T > &v1, const DenseVector< T > &v2, T scalar=1) |
Adds the outer product of v1 and v2 , multiplied by scalar , to this matrix, and returns a reference to the result. | |
DenseMatrix< T > & | AddAdjointOuterProduct (const DenseVector< T > &v1, const DenseVector< T > &v2, T scalar=1) |
Adds the adjoint outer product of v1 and v2 , multiplied by scalar , to this matrix, and returns a reference to the result. | |
DenseMatrix< typename linalg_traits< T >::conjugate_type > & | Conjugate () |
Conjugates this matrix in place, and returns a reference to the result. | |
linalg_traits< T >::norm_type | Norm () |
Return the squared 2-norm of this matrix, ![]() | |
linalg_traits< T >::abs_type | Abs () |
Return the squared 2-norm of this matrix, ![]() | |
DenseMatrix< T > & | Normalize () |
Normalize this matrix, so that Abs() and Norm() will return 1, and return a reference to the result. | |
In-place operators | |
Note: matrix *= not included because of left-right ambiguity. | |
DenseMatrix< T > & | operator= (const Matrix< T > &other) |
Assignment operator: sets this matrix equal to other . I believe (6/03/06) that this is not done lazily. We need to figure out a way to do lazy assignment when appropriate! | |
DenseMatrix< T > & | operator+= (const Matrix< T > &other) |
Addition-in-place operator: adds other to this vector, in place. | |
DenseMatrix< T > & | operator-= (const Matrix< T > &other) |
Subtraction-in-place operator: adds other to this vector, in place. | |
DenseMatrix< T > & | operator= (const DenseMatrix< T > &other) |
Assignment operator: sets this matrix equal to other . | |
DenseMatrix< T > & | operator+= (const DenseMatrix< T > &other) |
Addition-in-place operator: adds other to this vector, in place. | |
DenseMatrix< T > & | operator-= (const DenseMatrix< T > &other) |
Subtraction-in-place operator: adds other to this vector, in place. | |
DenseMatrix< T > & | operator *= (T scalar) |
Scalar-multiplication-in-place operator: multiplies this vector by scalar , in place. | |
DenseMatrix< T > & | operator/= (T scalar) |
Scalar-division-in-place operator: divides this vector by scalar , in place. | |
Protected Member Functions | |
void | CreateSubMatrixView (interval sub_R, interval sub_C, matrixview< T > &sm) const |
void | CreateRowVectorView (itype r, vectorview< T > &rv) const |
void | CreateColumnVectorView (itype c, vectorview< T > &cv) const |
Together with DenseVector<T>, one of the two central classes of LinAlg. A DenseMatrix<T> supports all the basic linear algebraic operations. DenseMatrices of type double
and complex
use BLAS routines for extra speed, and also support additional operations such as eigenfactoring.
|
Semi-copy constructor: constructs a copy of another matrixview<T>.
The standard copy-constructor for matrixview<T> is a shallow copy -- it adds a reference to |
|
Copy constructor: constructs a copy of another DenseMatrix<T>. A copy constructor MUST be defined, otherwise g++ supplies a stupid one. |
|
Prints this matrix to an output stream. Overrides an abstract Matrix<T> method. print() overrides Matrix<T>::print to use matrixview<T>'s output method. |
|
Adds the outer product of
The outer product of |
|
Adds the adjoint outer product of
The adjoint outer product of |
|
Conjugates this matrix in place, and returns a reference to the result. Note that conjugate() will cause a compile-time error if T != conjugate_type<T> |
|
Normalize this matrix, so that Abs() and Norm() will return 1, and return a reference to the result. Normalize will not make sense unless abs_type<T> is implicitly convertible to T. |
|
Should return TRUE if and only if this view provides 1-D strided access.
In other words, the data elements must be evenly spaced -- spacing of 1 means contiguous. There must exist a Implements dataview_interface< T >. |
|
Should return TRUE if and only if this view provides 2-D semi-contiguous strided access.
In other words, the data must be arranged in evenly spaced blocks, e.g. as blocks of length L followed by gaps of length K-L. There must exist a Implements dataview_interface< T >. |
|
If the view is 1D compatible, should provide its 1D representation in n_elements and stride, and the returned pointer. See Is1DCompatible(). Using the notation defined there, this function should:
Implements dataview_interface< T >. |
|
If the view is 2D compatible, should provide its 2D representation in n_series, series_range, series_extent, and the returned pointer. See Is2DCompatible(). Using the notation defined there, this function should:
Implements dataview_interface< T >. |
|
Should return a unique element corresponding to index, as long as index is in [0...Size()-1]. If the view has a 1DRep or 2DRep, then the ordering of the elements must agree with the ordering in that representation. Otherwise, there are no ordering requirements. Every element in the view must be accessible through this function, for some index in [0...Size()-1]. Implements dataview_interface< T >. |
|
Should return a unique element corresponding to the set of indices iarr. iarr must contain Dimensionality() indices, and iarr[i] must be in [0...Range(i)-1]. if Dimensionality() = 1, this function must agree with item( iarr[0] ). If the view has a 2DRep, the ordering must agree with it. Implements dataview_interface< T >. |
|
Should return a unique element corresponding to the first Dimensionality() parameters passed. This function must behave identically to element( itype* iarr ) when Dimensionality() parameters are given. Extra parameters must be ignored. Behavior is undefined when insufficient parameters given. Implements dataview_interface< T >. |
|
Should print the elements of the view to os, formatted for human reading. The exact format of printing is flexible -- it should be maximally readable for users. Implements dataview_interface< T >. |
|
Should print the elements of the view, arranged in columnar form, to os. Unlike PrettyPrint(), DataPrint should follow a fairly strict format.
Implements dataview_interface< T >. |
|
Ensures that the view has sole access to its datablock, by creating a virgin copy if necessary. The purpose of OwnData() is to permit the view to ensure that it has sole control of the data that it references, possibly resizing it. Note that there is no way to tell who "owns" a block of data -- it is possible, although not explicitly supported through data_view, to identify how many views on a given datablock exist, but none of them have special "owner" rights. Thus, OwnData simply initializes new data and discards the old data. Note that the old data is copied only if copying is explicitly requested, since that can be slow. Also, it is permitted for a view to ignore this call IF-AND-ONLY-IF the reference count for its datablock is 1, meaning it already owns it. Implements dataview_interface< T >. |
|
Should read in elements from a tabular data stream, and fill this view with them. The FillFromStream() function is the input version of DataPrint(). It should read from a tabular data stream, where the format is simply T's separated by whitespace, with a newline for each end- of-series. Thus, a 2D dataset will have single newlines after each series, while a 3D dataset will have 2D blocks separated by double newlines. FillFromStream() maintains the current dimensions of the view, but replaces as much data as possible with that obtained from the stream. If clear = TRUE, then it will set all elements not specified by the stream to 0. See also InitFromStream(). Implements dataview_interface< T >. |
|
Should reconstruct this view (changing size if necessary) to hold elements read in from a tabular data stream. InitFromStream should read from a tabular data stream, where the format is simply T's separated by whitespace, with a newline for each end- of-series. Thus, a 2D dataset will have single newlines after each series, while a 3D dataset will have 2D blocks separated by double newlines. It then resizes the view to be just large enough to hold all that data, and fills it with the data read in. Elements not specified in the input stream will be set to zero. See also FillFromStream(). Implements dataview_interface< T >. |