doc correction

This commit is contained in:
Шишов Максим Денисович
2020-09-08 16:05:22 +03:00
committed by Gama
parent 42793522a4
commit d59d60b1a7
2 changed files with 417 additions and 698 deletions

View File

@@ -483,309 +483,6 @@ public:
return tm;
}
/**
* @brief Determinant of the matrix is calculated
*
* @return matrix determinant
*/
Type determinant(bool *ok = 0) const {
PIMathMatrixT() {resize(Rows, Cols);}
PIMathMatrixT(const PIVector<Type> & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];}
/**
* @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros
*
* @return identitied matrix of type PIMathMatrixT
*/
static _CMatrix identity() {_CMatrix tm = _CMatrix(); PIMM_FOR_WB(r, c) tm.m[r][c] = (c == r ? Type(1) : Type(0)); return tm;}
/**
* @brief Creates a matrix that is filled with elements
*
* @param v is a parameter the type and value of which is selected and later filled into the matrix
* @return filled matrix of type PIMathMatrixT
*/
static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;}
/**
* @brief Rotation the matrix by an "angle". Works only with 2x2 matrix,
* else return default construction of PIMathMatrixT
*
* @return type uint shows number of rows
*/
uint rows() const { return Rows; }
/**
* @brief Method which returns the selected column in PIMathVectorT format
*
* @param index is the number of the selected column
* @return column in PIMathVectorT format
*/
_CMCol col(uint index) {
_CMCol tv;
PIMM_FOR_R(i) tv[i] = m[i][index];
return tv;
}
/**
* @brief Method which returns the selected row in PIMathVectorT format
*
* @param index is the number of the selected row
* @return row in PIMathVectorT format
*/
_CMRow row(uint index) {
_CMRow tv;
PIMM_FOR_C(i) tv[i] = m[index][i];
return tv;
}
/**
* @brief Set the selected column in matrix
*
* @param index is the number of the selected column
* @param v is a vector of the type _CMCol that needs to fill the column
* @return matrix type _CMatrix
*/
_CMatrix &setCol(uint index, const _CMCol &v) {
PIMM_FOR_R(i) m[i][index] = v[i];
return *this;
}
/**
* @brief Set the selected row in matrix
*
* @param index is the number of the selected row
* @param v is a vector of the type _CMCol that needs to fill the row
* @return matrix type _CMatrix
*/
_CMatrix &setRow(uint index, const _CMRow &v) {
PIMM_FOR_C(i) m[index][i] = v[i];
return *this;
}
/**
* @brief Method which changes selected rows in a matrix
*
* @param r0 is the number of the first selected row
* @param r1 is the number of the second selected row
* @return matrix type _CMatrix
*/
_CMatrix &swapRows(uint r0, uint r1) {
Type t;
PIMM_FOR_C(i) {
t = m[r0][i];
m[r0][i] = m[r1][i];
m[r1][i] = t;
}
return *this;
}
/**
* @brief Method which changes selected columns in a matrix
*
* @param c0 is the number of the first selected column
* @param c1 is the number of the second selected column
* @return matrix type _CMatrix
*/
_CMatrix &swapCols(uint c0, uint c1) {
Type t;
PIMM_FOR_R(i) {
t = m[i][c0];
m[i][c0] = m[i][c1];
m[i][c1] = t;
}
return *this;
}
/**
* @brief Method which fills the matrix with selected value
*
* @param v is a parameter the type and value of which is selected and later filled into the matrix
* @return filled matrix type _CMatrix
*/
_CMatrix &fill(const Type &v) {
PIMM_FOR_WB(r, c) m[r][c] = v;
return *this;
}
/**
* @brief Method which checks if matrix is square
*
* @return true if matrix is square, else false
*/
bool isSquare() const { return cols() == rows(); }
/**
* @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros
*
* @return true if matrix is identitied, else false
*/
bool isIdentity() const {
PIMM_FOR_WB(r, c) if ((c == r) ? m[r][c] != Type(1) : m[r][c] != Type(0)) return false;
return true;
}
/**
* @brief Method which checks if every elements of matrix are zeros
*
* @return true if matrix is null, else false
*/
bool isNull() const {
PIMM_FOR_WB(r, c) if (m[r][c] != Type(0)) return false;
return true;
}
/**
* @brief Full access to elements reference by row "row" and col "col"
*
* @param row is a parameter that shows the row number of the matrix of the selected element
* @param col is a parameter that shows the column number of the matrix of the selected element
* @return reference to element of matrix by row "row" and col "col"
*/
Type &at(uint row, uint col) { return m[row][col]; }
/**
* @brief Full access to element by row "row" and col "col"
*
* @param row is a parameter that shows the row number of the matrix of the selected element
* @param col is a parameter that shows the column number of the matrix of the selected element
* @return element of matrix by row "row" and col "col"
*/
Type at(uint row, uint col) const { return m[row][col]; }
/**
* @brief Full access to the matrix row pointer
*
* @param row is a row of necessary matrix
* @return matrix row pointer
*/
Type *operator[](uint row) { return m[row]; }
/**
* @brief Read-only access to the matrix row pointer
*
* @param row is a row of necessary matrix
* @return matrix row pointer
*/
const Type *operator[](uint row) const { return m[row]; }
/**
* @brief Matrix assignment to matrix "sm"
*
* @param sm matrix for the assigment
* @return matrix equal with sm
*/
_CMatrix &operator=(const _CMatrix &sm) {
memcpy(m, sm.m, sizeof(Type) * Cols * Rows);
return *this;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are equal true, else false
*/
bool operator==(const _CMatrix &sm) const {
PIMM_FOR_WB(r, c) if (m[r][c] != sm.m[r][c]) return false;
return true;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are not equal true, else false
*/
bool operator!=(const _CMatrix &sm) const { return !(*this == sm); }
/**
* @brief Addition assignment with matrix "sm"
*
* @param sm matrix for the addition assigment
*/
void operator+=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] += sm.m[r][c]; }
/**
* @brief Subtraction assignment with matrix "sm"
*
* @param sm matrix for the subtraction assigment
*/
void operator-=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c]; }
/**
* @brief Multiplication assignment with value "v"
*
* @param v value for the multiplication assigment
*/
void operator*=(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] *= v; }
/**
* @brief Division assignment with value "v"
*
* @param v value for the division assigment
*/
void operator/=(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] /= v; }
/**
* @brief Matrix substraction
*
* @return the result of matrix substraction
*/
_CMatrix operator-() const {
_CMatrix tm;
PIMM_FOR_WB(r, c) tm.m[r][c] = -m[r][c];
return tm;
}
/**
* @brief Matrix addition
*
* @param sm is matrix term
* @return the result of matrix addition
*/
_CMatrix operator+(const _CMatrix &sm) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] += sm.m[r][c];
return tm;
}
/**
* @brief Matrix substraction
*
* @param sm is matrix subtractor
* @return the result of matrix substraction
*/
_CMatrix operator-(const _CMatrix &sm) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] -= sm.m[r][c];
return tm;
}
/**
* @brief Matrix multiplication
*
* @param v is value factor
* @return the result of matrix multiplication
*/
_CMatrix operator*(const Type &v) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] *= v;
return tm;
}
/**
* @brief Matrix division
*
* @param v is value divider
* @return the result of matrix division
*/
_CMatrix operator/(const Type &v) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] /= v;
return tm;
}
/**
* @brief Determinant of the matrix is calculated
*
@@ -1220,6 +917,7 @@ public:
for (uint r = 0; r < rows; ++r) for (uint c = 0; c < cols; ++c) tm.element(r, c) = (c == r ? Type(1) : Type(0));
return tm;
}
/**
* @brief Creates a row matrix of every element that is equal to every element of the vector
*

View File

@@ -17,6 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, Type val
return b;
}
<<<<<<< HEAD
TEST(PIMathMatrixT_Test, identity) {
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
for(int i = 0; i < 3; i++){
@@ -33,6 +34,26 @@ TEST(PIMathMatrixT_Test, identity) {
}
}
}
=======
TEST(PIMathMatrixT_Test, identity)
{
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
for(int i = 0; i < 3; i++){
if(matrix[i][i] != 1.0){
ASSERT_TRUE(false);
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(i != j){
if(matrix[i][j] != 0.0){
ASSERT_TRUE(false);
}
}
}
}
>>>>>>> 05a32cc... doc correction
ASSERT_TRUE(true);
}