This commit is contained in:
2020-09-15 12:48:14 +03:00
parent 53359ab286
commit d19c6b1321

View File

@@ -75,6 +75,9 @@ inline bool _PIMathMatrixNullCompare<complexd>(const complexd v) {
#pragma pack(push, 1)
//! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix
//! @tparam Rows number of rows of matrix type uint
//! @tparam Сols number of columns of matrix type uint
//! @tparam Type is the data type of the matrix. There are can be basic C++ language data and different classes where the arithmetic operators of the C++ language are implemented
template<uint Rows, uint Cols = Rows, typename Type = double>
class PIP_EXPORT PIMathMatrixT {
typedef PIMathMatrixT<Rows, Cols, Type> _CMatrix;
@@ -206,7 +209,7 @@ public:
/**
* @brief Method which returns the selected column in PIMathVectorT format.
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param index is the number of the selected column
* @return column in PIMathVectorT format
@@ -219,7 +222,7 @@ public:
/**
* @brief Method which returns the selected row in PIMathVectorT format
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param index is the number of the selected row
* @return row in PIMathVectorT format
@@ -232,7 +235,7 @@ public:
/**
* @brief Set the selected column in matrix.
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param index is the number of the selected column
* @param v is a vector of the type _CMCol that needs to fill the column
@@ -245,7 +248,7 @@ public:
/**
* @brief Set the selected row in matrix
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param index is the number of the selected row
* @param v is a vector of the type _CMCol that needs to fill the row
@@ -258,7 +261,7 @@ public:
/**
* @brief Method which changes selected rows in a matrix.
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param r0 is the number of the first selected row
* @param r1 is the number of the second selected row
@@ -276,7 +279,7 @@ public:
/**
* @brief Method which changes selected columns in a matrix.
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @param c0 is the number of the first selected column
* @param c1 is the number of the second selected column
@@ -332,7 +335,7 @@ public:
/**
* @brief Full access to elements reference by row "row" and col "col".
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @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
@@ -342,7 +345,7 @@ public:
/**
* @brief Full access to element by row "row" and col "col".
* If you enter an index out of the border of the matrix will be SEGFAULT
* If you enter an index out of the border of the matrix behavior will be undefined
*
* @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
@@ -351,7 +354,7 @@ public:
Type at(uint row, uint col) const { return m[row][col]; }
/**
* @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param row is a row of necessary matrix
* @return matrix row pointer
@@ -359,7 +362,7 @@ public:
Type *operator[](uint row) { return m[row]; }
/**
* @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param row is a row of necessary matrix
* @return matrix row pointer
@@ -486,6 +489,7 @@ public:
/**
* @brief Determinant of the matrix is calculated
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return matrix determinant
*/
Type determinant(bool *ok = 0) const {
@@ -506,6 +510,7 @@ public:
/**
* @brief Transforming matrix to upper triangular
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return copy of transformed upper triangular matrix
*/
_CMatrix &toUpperTriangular(bool *ok = 0) {
@@ -548,6 +553,7 @@ public:
/**
* @brief Matrix inversion operation
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return copy of inverted matrix
*/
_CMatrix &invert(bool *ok = 0) {
@@ -601,6 +607,7 @@ public:
/**
* @brief Matrix inversion operation
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return inverted matrix
*/
_CMatrix inverted(bool *ok = 0) const {
@@ -740,9 +747,8 @@ inline PICout operator<<(PICout s, const PIMathMatrixT<Rows, Cols, Type> &m) {
return s;
}
/// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1}
/**
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param fm first matrix multiplier
* @param sm second matrix multiplier
@@ -764,9 +770,8 @@ inline PIMathMatrixT<Rows0, Cols1, Type> operator*(const PIMathMatrixT<Rows0, CR
return tm;
}
/// Multiply matrix {Rows x Cols} on vector {Cols}, result is vector {Rows}
/**
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param fm first matrix multiplier
* @param sv second vector multiplier
@@ -786,9 +791,8 @@ inline PIMathVectorT<Rows, Type> operator*(const PIMathMatrixT<Rows, Cols, Type>
return tv;
}
/// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols}
/**
* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param sv first vector multiplier
* @param fm second matrix multiplier
@@ -808,7 +812,6 @@ inline PIMathVectorT<Cols, Type> operator*(const PIMathVectorT<Rows, Type> &sv,
return tv;
}
/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows}
/**
* @brief Multiplying value of type Type and matrix
*
@@ -853,6 +856,7 @@ class PIMathMatrix;
#define PIMM_FOR_R(v) for (uint v = 0; v < _V2D::rows_; ++v)
//! \brief A class that works with matrix operations, the input data of which is the data type of the matrix
//! @tparam Type is the data type of the matrix. There are can be basic C++ language data and different classes where the arithmetic operators of the C++ language are implemented
template<typename Type>
class PIP_EXPORT PIMathMatrix : public PIVector2D<Type> {
typedef PIVector2D<Type> _V2D;
@@ -917,6 +921,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
*
@@ -935,7 +940,7 @@ public:
/**
* @brief Set the selected column in matrix. If there are more elements of the vector than elements in the column of the matrix
* or index larger than the number of columns otherwise there will be a SEGFAULT
* or index larger than the number of columns otherwise there behavior will be undefined
*
* @param index is the number of the selected column
* @param v is a vector of the type _CMCol that needs to fill the column
@@ -948,7 +953,7 @@ public:
/**
* @brief Set the selected row in matrix. If there are more elements of the vector than elements in the row of the matrix,
* or index larger than the number of rows otherwise there will be a SEGFAULT
* or index larger than the number of rows otherwise there behavior will be undefined
* @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
@@ -960,7 +965,7 @@ public:
/**
* @brief Method which replace selected columns in a matrix. You cannot use an index larger than the number of columns,
* otherwise there will be a SEGFAULT
* otherwise there behavior will be undefined
*
* @param r0 is the number of the first selected row
* @param r1 is the number of the second selected row
@@ -973,7 +978,7 @@ public:
/**
* @brief Method which replace selected rows in a matrix. You cannot use an index larger than the number of rows,
* otherwise there will be a SEGFAULT
* otherwise there behavior will be undefined
*
* @param c0 is the number of the first selected row
* @param c1 is the number of the second selected row
@@ -1149,6 +1154,7 @@ public:
/**
* @brief Determinant of the matrix is calculated. Works only with square matrix
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return matrix determinant
*/
Type determinant(bool *ok = 0) const {
@@ -1169,6 +1175,7 @@ public:
/**
* @brief Trace of the matrix is calculated. Works only with square matrix
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return matrix trace
*/
Type trace(bool *ok = 0) const {
@@ -1187,6 +1194,7 @@ public:
/**
* @brief Transforming matrix to upper triangular. Works only with square matrix
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return copy of transformed upper triangular matrix
*/
_CMatrix &toUpperTriangular(bool *ok = 0) {
@@ -1229,6 +1237,8 @@ public:
/**
* @brief Matrix inversion operation. Works only with square matrix
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @param sv is a vector multiplier
* @return copy of inverted matrix
*/
_CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) {
@@ -1289,6 +1299,7 @@ public:
/**
* @brief Matrix inversion operation
*
* @param ok is a parameter with which we can find out if the method worked correctly
* @return inverted matrix
*/
_CMatrix inverted(bool *ok = 0) const {
@@ -1316,11 +1327,11 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m
#endif
/**
* @brief Add matrix "m" at the end of matrix and return reference to matrix
* @brief Inline operator for outputting the matrix to the console
*
* @param s PICout type
* @param m PIMathMatrix type
* @return bitwise left PICout
* @param the matrix type PIMathMatrix that we print to the console
* @return PIMathMatrix printed to the console
*/
template<typename Type>
inline PICout operator<<(PICout s, const PIMathMatrix<Type> &m) {
@@ -1337,11 +1348,11 @@ inline PICout operator<<(PICout s, const PIMathMatrix<Type> &m) {
}
/**
* @brief Add matrix "m" at the end of matrix and return reference to matrix
* @brief Inline operator for serializing a matrix into a PIByteArray
*
* @param s PIByteArray type
* @param v PIMathMatrix type
* @return bitwise left PIByteArray
* @return PIBiteArray serialized PIMathMatrix
*/
template<typename Type>
inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
@@ -1350,11 +1361,11 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
}
/**
* @brief Add matrix "m" at the end of matrix and return reference to matrix
* @brief Inline operator to deserialize matrix from PIByteArray
*
* @param s PIByteArray type
* @param v PIMathMatrix type
* @return bitwise right PIByteArray
* @return PIMathMatrix deserialized from PIByteArray
*/
template<typename Type>
inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix<Type> &v) {
@@ -1363,9 +1374,8 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix<Type> &v) {
}
/// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0}
/**
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param fm first matrix multiplier
* @param sm second matrix multiplier
@@ -1389,9 +1399,8 @@ inline PIMathMatrix<Type> operator*(const PIMathMatrix<Type> &fm,
return tm;
}
/// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows}
/**
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param fm first matrix multiplier
* @param sv second vector multiplier
@@ -1413,10 +1422,8 @@ inline PIMathVector<Type> operator*(const PIMathMatrix<Type> &fm,
return tv;
}
/// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols}
/**
* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix will be SEGFAULT
* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix behavior will be undefined
*
* @param sv first vector multiplier
* @param fm second matrix multiplier
@@ -1437,7 +1444,6 @@ inline PIMathVector<Type> operator*(const PIMathVector<Type> &sv,
return tv;
}
/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows}
/**
* @brief Multiplying value of type Type and matrix
*