DSL_Dmatrix

<< Click to Display Table of Contents >>

Navigation:  Reference Manual > Arrays and matrices >

DSL_Dmatrix

Header file: dmatrix.h


DSL_Dmatrix();

The default constructor, creates an empty matrix without any dimensions.


DSL_Dmatrix(const DSL_intArray &dims);
DSL_Dmatrix(std::initializer_list<int> dims);

Use specified dimensions to create a matrix. The elements of the matrix are not initialized.


DSL_Dmatrix(const DSL_Dmatrix &mtx);

Copy constructor.


DSL_Dmatrix& operator=(const DSL_Dmatrix &mtx);

Assignment operator.


double &operator[](int index);

double operator[](int index) const;

double &Subscript(int index);

double Subscript(int index) const;

Access to matrix elements with a linear index.


double &operator[](const DSL_intArray &coords);

double operator[](const DSL_intArray &coords) const;

double &Subscript(DSL_intArray &coords);

double Subscript(DSL_intArray &coords) const;

Access to matrix elements using multidimensional coordinates.


double &operator[](const int * const * indirectCoords);

double operator[](const int * const * indirectCoords) const;

Access to matrix elements using indirect multidimensional coordinates.


int IndexToCoordinates(int index, DSL_intArray &coords) const;

Converts a linear index to multidimensional coordinates. Returns DSL_OKAY on success, or an error code on failure.


int CoordinatesToIndex(const int *coords) const;

int CoordinatesToIndex(DSL_intArray &coords) const;

int CoordinatesToIndex(const int * const * indirectCoords) const;

Converts multidimensional coordinates to linear index. Returns a converted index, or a negative error code on failure.


int NextCoordinates(DSL_intArray &coords) const;

Modifies the specified multidimensional coordinates to be the equivalent of the next linear index. Returns DSL_OKAY on success, or an error code on failure. Specifying the coordinates representing the last element of the matrix will cause an error code to be returned (as there is no next element).


int PrevCoordinates(DSL_intArray &coords) const;

Modifies the specified multidimensional coordinates to be the equivalent of the next linear index. Returns DSL_OKAY on success, or an error code on failure. Specifying the coordinates representing the first element of the matrix will cause an error code to be returned (as there is no previous element).


DSL_doubleArray& GetItems();

const DSL_doubleArray& GetItems() const;

Returns reference to a linear buffer containing the elements of the matrix.


const double* Ptr(int idx) const;

const double* Ptr(const DSL_intArray& coords) const;

Returns a pointer to the element of the matrix. Does not check for invalid inputs.


const DSL_intArray& GetDimensions() const;

Returns the dimensions of a matrix.


const DSL_intArray& GetPreProduct() const;

Returns reference to the pre-product array, which is useful for converting between linear and multidimensional coordinates.


int GetNumberOfDimensions() const;

Returns the number of dimensions of the matrix.


int GetLastDimension() const;

Returns the index of the last dimension of the matrix (not the size of the last dimension - call GetSizeOfLastDimension for that).


int GetSizeOfDimension(int dimIdx) const;

Returns the size of the specified matrix dimension, or negative error code if the index of the dimension is invalid.


int GetSizeOfLastDimension() const;

Returns the size of the last dimension of the matrix.


int GetSize() const;

Returns the total size of the matrix (which is a product of all dimensions).


int Sum(const DSL_Dmatrix &a, const DSL_Dmatrix &b);

Adds two matrices and stores the result in this matrix. The matrix must have dimensions compatible with both operands, or the method returns an error. Returns DSL_OKAY on success.


int Subtract(const DSL_Dmatrix &a, const DSL_Dmatrix &b);

Subtracts two matrices and stores the result in this matrix. The matrix must have dimensions compatible with both operands, or  the method returns an error. Returns DSL_OKAY on success.


int Add(const DSL_Dmatrix &m);

Adds the specified matrix to this matrix. The matrix must have dimensions compatible with both operands, or  the method returns an error. Returns DSL_OKAY on success.


int Add(double x);

Adds a scalar value to all elements in the matrix. Returns DSL_OKAY.


int Multiply(double x);

Multiplies all elements in the matrix by a scalar value. Returns DSL_OKAY.


int Multiply(DSL_doubleArray &v);

Multiplies each element of the matrix with coordinates (a,b,c,...,z=N) by the Nth element of vector v.


int FillWith(double x);

Fills the matrix with a specified scalar value.


int FillFrom(const DSL_Dmatrix& src);

Copies elements from the source matrix. Returns a negative error code if the dimensions of the source matrix are not compatible, or DSL_OKAY on success.


int FillFrom(const DSL_doubleArray& src);

int FillFrom(const std::vector<double>& src);
int FillFrom(std::initializer_list<double> src);

Copies an element from the specified linear buffer source. Returns a negative error code if the size of the source buffer is not equal to the size of the matrix, or DSL_OKAY on success.


void FillFrom(const double* src);

Copies elements from the specified linear buffer source.


int AddDimension(int dimSize);

Adds a dimension with a specified size.


int AddDimensions(const DSL_intArray &newDimensions);

Adds multiple dimensions with specified sizes.


int InsertDimension(int dimIdx, int dimSize);

Inserts a dimension with a specified size at a specified index.


int RemoveDimension(int dimIdx);

Removes the specified dimension. Uses the original elements with the coordinate value of zero at dimIdx.


int RemoveDimension(int dimIdx, int elemIdx);

Removes the specified dimension. Uses the original elements with the coordinate value of elemIdx at dimIdx.


int SetSingleDimension(int dimSize);

Sets the number of dimensions to one, and the size of the single dimension to dimSize.


int Setup(const DSL_intArray& dims);

int Setup(const int* dims, int dimCount);

Resets the contents of the matrix by setting new dimensions.


void Clear();

Removes all content from the matrix by setting the number of dimensions to zero.


void Swap(DSL_Dmatrix &mtx);

Swaps two matrices.


bool operator==(const DSL_Dmatrix& lhs, const DSL_Dmatrix& rhs);

bool operator!=(const DSL_Dmatrix& lhs, const DSL_Dmatrix& rhs);

Non-member function operator== returns true if the matrices have the same dimensions,  and each element in lhs is equal to the corresponding element in rhs. operator!= calls operator== and performs the negation on the result.