From defbe3a4d7f72a62f6b3e8abaa76dfa96ec36669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 01/68] PIMathMatrix doc --- CMakeLists.txt.user | 1023 +++++++++++++++++++++++++++++++++ libs/main/math/pimathmatrix.h | 485 +++++++++++++++- tests/concurrent/testutil.h | 2 + 3 files changed, 1505 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..6d0aa1d3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1023 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + + + doc + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal + + 10 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 676a4486..783c1a6a 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -1,5 +1,7 @@ /*! \file pimathmatrix.h * \brief PIMathMatrix + * + * This file declare math matrix class, which performs various matrix operations */ /* PIP - Platform Independent Primitives @@ -54,12 +56,13 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); @@ -67,46 +70,302 @@ public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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" + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the X axis + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the X axis by the value "factor" + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Y axis by the value "factor" + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Z axis by the value "factor" + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} + + /** + * @brief Method which returns number of rows in matrix + * + * @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 + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -122,6 +381,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -159,6 +423,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -206,7 +475,19 @@ public: memcpy(m, mtmp.m, sizeof(Type) * Cols * Rows); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -321,6 +602,7 @@ class PIMathMatrix; #define PIMM_FOR_C(v) for (uint v = 0; v < _V2D::cols_; ++v) #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 template class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIVector2D _V2D; @@ -332,33 +614,199 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} + /** + * @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) _V2D::element(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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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_A(i) _V2D::mat[i] = v; return *this;} + + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} + + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); 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_A(i) if (_V2D::mat[i] != sm.mat[i]) 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_A(i) _V2D::mat[i] += sm.mat[i];} + + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= 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(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -374,6 +822,11 @@ public: return ret; } + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -387,6 +840,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -424,6 +882,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -478,7 +941,19 @@ public: PIVector2D::swap(mtmp); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 7c3c15c7..9df146ba 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,6 +3,7 @@ #include "pithread.h" #include +#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -57,4 +58,5 @@ public: } }; + #endif //AWRCANFLASHER_TESTUTIL_H From 4d03ba1210fc8e89dff4b20383fe696b21ce391d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:47 +0300 Subject: [PATCH 02/68] PIMathMatrix document --- CMakeLists.txt.user | 1023 ------------------------------------------- 1 file changed, 1023 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 6d0aa1d3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1023 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 0 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - - - doc - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal - - 10 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 9544d5ef0de2c39feb69f90062f9a15c48b231bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:23:54 +0300 Subject: [PATCH 03/68] Rotation remake --- libs/main/math/pimathmatrix.h | 20 +++++++-------- tests/concurrent/testutil.h | 2 -- tests/math/testpimathmatrixt.cpp | 44 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 783c1a6a..399afdd6 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -63,9 +63,9 @@ class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrixI; typedef PIMathVectorT _CMCol; typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} @@ -86,7 +86,7 @@ public: 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" + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix * @return rotated matrix @@ -94,7 +94,7 @@ public: static _CMatrix rotation(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the X axis + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the X axis * @return rotated matrix @@ -102,7 +102,7 @@ public: static _CMatrix rotationX(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Y axis + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Y axis * @return rotated matrix @@ -110,7 +110,7 @@ public: static _CMatrix rotationY(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Z axis + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Z axis * @return rotated matrix @@ -118,7 +118,7 @@ public: static _CMatrix rotationZ(double angle) {return _CMatrix();} /** - * @brief Scaling the matrix along the X axis by the value "factor" + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by X axis * @return rotated matrix @@ -126,7 +126,7 @@ public: static _CMatrix scaleX(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Y axis by the value "factor" + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by Y axis * @return rotated matrix @@ -134,7 +134,7 @@ public: static _CMatrix scaleY(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Z axis by the value "factor" + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix * * @param factor is the value of scaling by Z axis * @return rotated matrix diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 9df146ba..7c3c15c7 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,7 +3,6 @@ #include "pithread.h" #include -#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -58,5 +57,4 @@ public: } }; - #endif //AWRCANFLASHER_TESTUTIL_H diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 38976bf8..2d68d131 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -674,24 +674,6 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, rotation) -{ - double angle = 1.0; - bool b; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); - double c = cos(angle); - double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; @@ -726,6 +708,31 @@ TEST(PIMathMatrixT_Test, scaleY_two) ASSERT_TRUE(b); } +TEST(PIMathMatrixT_Test, rotation_2x2) +{ + double angle = 1.0; + bool b; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); + double c = cos(angle); + double s = sin(angle); + if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) + { + b = true; + } + else + { + b = false; + } + ASSERT_TRUE(b); +} + +TEST(PIMathMatrixT_Test, rotation_3x3) +{ + double angle = 1.0; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); + ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); +} + TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; @@ -831,3 +838,4 @@ TEST(PIMathMatrixT_Test, scaleZ_three) ASSERT_TRUE(b); } + From 8e7d7a54c419a7bc97ca960f660d0df17e222e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:50:41 +0300 Subject: [PATCH 04/68] space correction --- libs/main/math/pimathmatrix.h | 847 +++++++++++++++++----------------- 1 file changed, 427 insertions(+), 420 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 399afdd6..0be4325c 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -59,313 +59,320 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { //! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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 - */ + /** + * @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 - */ + /** + * @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 _CMatrix - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + /** + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} - /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} - /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} - /** - * @brief Method which returns number of rows in matrix - * - * @return type uint shows number of rows - */ + /** + * @brief Method which returns number of rows in matrix + * + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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" - */ + /** + * @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" - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -381,11 +388,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -423,11 +430,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -476,18 +483,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -614,199 +621,199 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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 Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} - /** - * @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 - */ + /** + * @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) _V2D::element(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 - */ + /** + * @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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 - */ + /** + * @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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 - */ + /** + * @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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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 - */ + /** + * @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_A(i) _V2D::mat[i] = v; return *this;} - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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 - */ + /** + * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + /** + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix is null, else false + */ bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); return *this;} - /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + /** + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true;} - /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + /** + * @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 - */ + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} - /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + /** + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -822,11 +829,11 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -840,11 +847,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -882,11 +889,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -942,18 +949,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; From f1a0a3ec4a787a15f894b018651ad0992b893f98 Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Thu, 3 Sep 2020 16:57:46 +0300 Subject: [PATCH 05/68] Fix code formatting & grammar mistakes --- libs/main/math/pimathmatrix.h | 1352 ++++++++++++++++++++------------- 1 file changed, 810 insertions(+), 542 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 0be4325c..80f1eaab 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -29,7 +29,6 @@ #include "pimathcomplex.h" - template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); @@ -37,11 +36,12 @@ inline bool _PIMathMatrixNullCompare(const T v) { } template<> -inline bool _PIMathMatrixNullCompare(const complexf v) { +inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } + template<> -inline bool _PIMathMatrixNullCompare(const complexd v) { +inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); } @@ -56,6 +56,7 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { @@ -67,313 +68,391 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - PIMathMatrixT() {resize(Rows, Cols);} - PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} + PIMathMatrixT() { resize(Rows, Cols); } - /** - * @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;} + PIMathMatrixT(const PIVector &val) { + resize(Rows, Cols); + int i = 0; + PIMM_FOR_I_WB(r, c) m[r][c] = val[i++]; + } - /** - * @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 С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 Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT + /** + * @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 +* + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ + static _CMatrix rotation(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ + static _CMatrix rotationX(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ + static _CMatrix rotationY(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ + static _CMatrix rotationZ(double angle) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ + static _CMatrix scaleX(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ + static _CMatrix scaleY(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ + static _CMatrix scaleZ(double factor) { return _CMatrix(); } + + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ + uint cols() const { return Cols; } + + /** + * @brief Method which returns number of rows in matrix * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ - static _CMatrix rotation(double angle) {return _CMatrix();} + * @return type uint shows number of rows + */ + uint rows() const { return Rows; } - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ - static _CMatrix rotationX(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ - static _CMatrix rotationY(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ - static _CMatrix rotationZ(double angle) {return _CMatrix();} + /** + * @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 Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ - static _CMatrix scaleX(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ - static _CMatrix scaleY(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ - static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @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 returns number of columns in matrix - * - * @return type uint shows number of columns - */ - uint cols() const {return Cols;} + /** + * @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 returns number of rows in matrix - * - * @return type uint shows number of rows - */ - uint rows() const {return Rows;} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return cols() == rows();} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -388,12 +467,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; return *this; @@ -419,7 +498,7 @@ public: for (uint k = i; k < Cols; ++k) smat.m[k][j] -= mul * smat.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -430,12 +509,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); bool ndet; @@ -462,7 +541,7 @@ public: for (uint k = 0; k < Cols; ++k) mtmp.m[k][j] -= mul * mtmp.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -483,39 +562,125 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrixI transposed() const { + _CMatrixI tm; + PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; + return tm; + } private: - void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;} + void resize(uint rows_, uint cols_, const Type &new_value = Type()) { + r_ = rows_; + c_ = cols_; + PIMM_FOR_WB(r, c) m[r][c] = new_value; + } + int c_, r_; Type m[Rows][Cols]; }; + #pragma pack(pop) -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<2u, 2u> tm; tm[0][0] = tm[1][1] = c; tm[0][1] = -s; tm[1][0] = s; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = factor; tm[1][1] = 1.; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = 1.; tm[1][1] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = tm[1][1] = c; + tm[0][1] = -s; + tm[1][0] = s; + return tm; +} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[0][0] = 1.; tm[1][1] = tm[2][2] = c; tm[2][1] = s; tm[1][2] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[1][1] = 1.; tm[0][0] = tm[2][2] = c; tm[2][0] = -s; tm[0][2] = s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[2][2] = 1.; tm[0][0] = tm[1][1] = c; tm[1][0] = s; tm[0][1] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) {PIMathMatrixT<3u, 3u> tm; tm[1][1] = tm[2][2] = 1.; tm[0][0] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[2][2] = 1.; tm[1][1] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = factor; + tm[1][1] = 1.; + return tm; +} + +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = 1.; + tm[1][1] = tm[2][2] = c; + tm[2][1] = s; + tm[1][2] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = 1.; + tm[0][0] = tm[2][2] = c; + tm[2][0] = -s; + tm[0][2] = s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[2][2] = 1.; + tm[0][0] = tm[1][1] = c; + tm[1][0] = s; + tm[0][1] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = tm[2][2] = 1.; + tm[0][0] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[2][2] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[1][1] = 1.; + tm[2][2] = factor; + return tm; +} #ifdef PIP_STD_IOSTREAM template @@ -523,12 +688,19 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT -inline PICout operator <<(PICout s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrixT &m) { + s << "{"; + PIMM_FOR_I(r, c) s << m[r][c]; + if (c < Cols - 1 || r < Rows - 1) s << ", "; } + if (r < Rows - 1) s << PICoutManipulators::NewLine << " "; } + s << "}"; + return s; +} /// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1} template -inline PIMathMatrixT operator *(const PIMathMatrixT & fm, - const PIMathMatrixT & sm) { +inline PIMathMatrixT operator*(const PIMathMatrixT &fm, + const PIMathMatrixT &sm) { PIMathMatrixT tm; Type t; for (uint j = 0; j < Rows0; ++j) { @@ -544,8 +716,8 @@ inline PIMathMatrixT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathMatrixT & fm, - const PIMathVectorT & sv) { +inline PIMathVectorT operator*(const PIMathMatrixT &fm, + const PIMathVectorT &sv) { PIMathVectorT tv; Type t; for (uint j = 0; j < Rows; ++j) { @@ -559,8 +731,8 @@ inline PIMathVectorT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathVectorT & sv, - const PIMathMatrixT & fm) { +inline PIMathVectorT operator*(const PIMathVectorT &sv, + const PIMathMatrixT &fm) { PIMathVectorT tv; Type t; for (uint j = 0; j < Cols; ++j) { @@ -574,7 +746,7 @@ inline PIMathVectorT operator *(const PIMathVectorT & sv /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrixT operator *(const Type & x, const PIMathMatrixT & v) { +inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; } @@ -612,209 +784,277 @@ class PIMathMatrix; //! \brief A class that works with matrix operations, the input data of which is the data type of the matrix template class PIP_EXPORT PIMathMatrix : public PIVector2D { - typedef PIVector2D _V2D; + typedef PIVector2D _V2D; typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type & f = Type()) {_V2D::resize(rows, cols, f);} - PIMathMatrix(const uint cols, const uint rows, const PIVector & val) {_V2D::resize(rows, cols); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} - PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} - PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ - static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} + PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { + _V2D::resize(rows, cols); + int i = 0; + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; + } - /** - * @brief Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + PIMathMatrix(const PIVector > &val) { + if (!val.isEmpty()) { + _V2D::resize(val.size(), val[0].size()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c]; + } + } - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} + PIMathMatrix(const PIVector2D &val) { + if (!val.isEmpty()) { + _V2D::resize(val.rows(), val.cols()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c); + } + } - /** - * @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) _V2D::element(i, index) = v[i]; return *this;} + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ + static _CMatrix identity(const uint cols, const uint rows) { + _CMatrix tm(cols, rows); + 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 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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this;} + /** + * @brief Creates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } - /** - * @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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} return *this;} + /** + * @brief Creates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } - /** - * @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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} return *this;} + /** + * @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) _V2D::element(i, index) = v[i]; + 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_A(i) _V2D::mat[i] = v; 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 _CMCol &v) { + PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; + return *this; + } - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return _V2D::cols_ == _V2D::rows_;} + /** + * @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 &swapCols(uint r0, uint r1) { + PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } + return *this; + } - /** - * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0)) return false; return true;} + /** + * @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 &swapRows(uint c0, uint c1) { + PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } + return *this; + } - /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix is null, else false - */ - bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} + /** + * @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_A(i) _V2D::mat[i] = v; + return *this; + } - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ - bool isValid() const {return !PIVector2D::isEmpty();} + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ + bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ - _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); return *this;} + /** + * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; + return true; + } - /** - * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) 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_A(i) if (_V2D::mat[i] != Type(0)) 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 Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ + bool isValid() const { return !PIVector2D::isEmpty(); } - /** - * @brief Addition assignment with matrix "sm" - * - * @param sm matrix for the addition assigment - */ - void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ + _CMatrix &operator=(const PIVector > &v) { + *this = _CMatrix(v); + return *this; + } - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ - void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + /** + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; + return true; + } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ - void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + /** + * @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 Division assignment with value "v" - * - * @param v value for the division assigment - */ - void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ + void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ - _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ + void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ - _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ + void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ - _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ + void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ - _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ + _CMatrix operator-() const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; + return tm; + } - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ - _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ + _CMatrix operator+(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; + return tm; + } - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ + _CMatrix operator-(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; + return tm; + } + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ + _CMatrix operator*(const Type &v) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] *= 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(*this); + PIMM_FOR_A(i) tm.mat[i] /= v; + return tm; + } + + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -829,12 +1069,12 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ - Type trace(bool * ok = 0) const { + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ + Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { if (ok != 0) *ok = false; @@ -847,12 +1087,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -878,7 +1118,7 @@ public: for (uint k = i; k < _V2D::cols_; ++k) smat.element(k, j) -= mul * smat.element(k, i); } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -889,12 +1129,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -926,7 +1166,7 @@ public: if (sv != 0) (*sv)[j] -= mul * (*sv)[i]; } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -949,19 +1189,27 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrix transposed() const { + _CMatrix tm(_V2D::rows_, _V2D::cols_); + PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); + return tm; + } }; @@ -971,18 +1219,36 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m #endif template -inline PICout operator <<(PICout s, const PIMathMatrix & m) {s << "Matrix{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrix &m) { + s << "Matrix{"; + for (uint r = 0; r < m.rows(); ++r) { + for (uint c = 0; c < m.cols(); ++c) { + s << m.element(r, c); + if (c < m.cols() - 1 || r < m.rows() - 1) s << ", "; + } + if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " "; + } + s << "}"; + return s; +} template -inline PIByteArray & operator <<(PIByteArray & s, const PIMathMatrix & v) {s << (const PIVector2D &)v; return s;} +inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { + s << (const PIVector2D &) v; + return s; +} + template -inline PIByteArray & operator >>(PIByteArray & s, PIMathMatrix & v) {s >> (PIVector2D &)v; return s;} +inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { + s >> (PIVector2D &) v; + return s; +} /// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0} template -inline PIMathMatrix operator *(const PIMathMatrix & fm, - const PIMathMatrix & sm) { +inline PIMathMatrix operator*(const PIMathMatrix &fm, + const PIMathMatrix &sm) { uint cr = fm.cols(), rows0 = fm.rows(), cols1 = sm.cols(); PIMathMatrix tm(cols1, rows0); if (fm.cols() != sm.rows()) return tm; @@ -1000,8 +1266,8 @@ inline PIMathMatrix operator *(const PIMathMatrix & fm, /// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows} template -inline PIMathVector operator *(const PIMathMatrix & fm, - const PIMathVector & sv) { +inline PIMathVector operator*(const PIMathMatrix &fm, + const PIMathVector &sv) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(r); if (c != sv.size()) return tv; @@ -1018,8 +1284,8 @@ inline PIMathVector operator *(const PIMathMatrix & fm, /// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols} template -inline PIMathVector operator *(const PIMathVector & sv, - const PIMathMatrix & fm) { +inline PIMathVector operator*(const PIMathVector &sv, + const PIMathMatrix &fm) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(c); Type t; @@ -1034,7 +1300,7 @@ inline PIMathVector operator *(const PIMathVector & sv, /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrix operator *(const Type & x, const PIMathMatrix & v) { +inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; } @@ -1042,9 +1308,11 @@ typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; template -PIMathMatrix > hermitian(const PIMathMatrix > & m) { +PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); - for (uint r = 0; r < ret.rows(); ++r) for (uint c = 0; c < ret.cols(); ++c) ret.element(r, c).imag(-(ret.element(r, c).imag())); + for (uint r = 0; r < ret.rows(); ++r) + for (uint c = 0; c < ret.cols(); ++c) + ret.element(r, c).imag(-(ret.element(r, c).imag())); return ret.transposed(); } From 05a32ccf1ac27ba33c66597065cdc1031a717a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:05:22 +0300 Subject: [PATCH 06/68] doc correction --- libs/main/math/pimathmatrix.h | 853 ++++++++++++++++++------------- tests/math/testpimathmatrix.cpp | 30 +- tests/math/testpimathmatrixt.cpp | 35 +- 3 files changed, 530 insertions(+), 388 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 80f1eaab..9a767dd5 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -28,18 +28,35 @@ #include "pimathvector.h" #include "pimathcomplex.h" - +/** +* @brief Inline funtion of compare with zero different types +* +* @param v is input parameter of type T +* @return true if zero, false if not zero +*/ template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); return (piAbs(v) < T(1E-200)); } +/** +* @brief Inline funtion of compare with zero colmplexf type +* +* @param v is input parameter of type colmplexf +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } +/** +* @brief Inline funtion of compare with zero complexd type +* +* @param v is input parameter of type colmplexd +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); @@ -68,8 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -77,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identitied matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -88,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -100,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT -* - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -177,11 +205,12 @@ public: 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 - */ + * @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 + * + * @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]; @@ -189,11 +218,12 @@ public: } /** - * @brief Method which returns the selected row in PIMathVectorT format - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -201,36 +231,39 @@ public: } /** - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -242,12 +275,13 @@ public: } /** - * @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 - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -259,140 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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" - */ + * @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 + * + * @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" - */ + * @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 + * + * @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 - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -400,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -412,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -424,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -436,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -448,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -468,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -510,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -563,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -574,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -687,6 +723,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrixT type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrixT &m) { s << "{"; @@ -698,6 +741,13 @@ inline PICout operator<<(PICout s, const PIMathMatrixT &m) { } /// 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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const PIMathMatrixT &fm, const PIMathMatrixT &sm) { @@ -715,6 +765,13 @@ inline PIMathMatrixT operator*(const PIMathMatrixT inline PIMathVectorT operator*(const PIMathMatrixT &fm, const PIMathVectorT &sv) { @@ -730,6 +787,13 @@ inline PIMathVectorT operator*(const PIMathMatrixT } /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVectorT operator*(const PIMathVectorT &sv, const PIMathMatrixT &fm) { @@ -745,6 +809,13 @@ inline PIMathVectorT operator*(const PIMathVectorT &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; @@ -788,14 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -803,6 +893,11 @@ public: } } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -810,191 +905,194 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - */ + * @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 + * + * @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) _V2D::element(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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(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 - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } 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 - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::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 - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1002,11 +1100,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1014,11 +1112,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1026,11 +1124,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1038,11 +1136,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1050,10 +1148,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1070,10 +1168,10 @@ public: } /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1088,10 +1186,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1130,10 +1228,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1190,10 +1288,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1201,10 +1299,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); @@ -1218,6 +1316,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m) {s << "{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrix type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrix &m) { s << "Matrix{"; @@ -1232,12 +1337,26 @@ inline PICout operator<<(PICout s, const PIMathMatrix &m) { return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise left PIByteArray +*/ template inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { s << (const PIVector2D &) v; return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise right PIByteArray +*/ template inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { s >> (PIVector2D &) v; @@ -1246,6 +1365,13 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const PIMathMatrix &fm, const PIMathMatrix &sm) { @@ -1265,6 +1391,13 @@ inline PIMathMatrix operator*(const PIMathMatrix &fm, } /// 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 +* +* @param fm first matrix multiplier +* @param sv second vector multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathMatrix &fm, const PIMathVector &sv) { @@ -1283,6 +1416,13 @@ inline PIMathVector operator*(const PIMathMatrix &fm, /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathVector &sv, const PIMathMatrix &fm) { @@ -1299,6 +1439,13 @@ inline PIMathVector operator*(const PIMathVector &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; @@ -1307,6 +1454,12 @@ inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; +/** +* @brief Searching hermitian matrix +* +* @param m conjugate transpose matrix +* @return result of the hermitian +*/ template PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 4eeccd0c..09992b89 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -34,24 +34,22 @@ bool cmpMatrixWithValue(PIMathMatrix matrix, double val) TEST(PIMathMatrix_Test, identity) { - PIMathMatrix origMatr; - PIMathMatrix matrix; - int i; - bool b; - matrix = origMatr.identity(3, 3); - for(i = 0; i < 3; i++) - { - if(matrix[i][i] == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix = PIMathMatrix::identity(3, 3); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + 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); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixRow) diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 2d68d131..0542332a 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -38,31 +38,22 @@ bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) TEST(PIMathMatrixT_Test, identity) { - PIMathMatrixT matr; - PIMathMatrixT matrix; - double d; - double i = 1.0; - bool a; - bool output; - matrix = matr.identity(); - d = matrix.determinant(); - uint j; - for(j = 0; j < cols; j++) - { - if(matrix.at(i, i) == 1.0) a = true; - else - { - a = false; - break; + auto matrix = PIMathMatrixT::identity(); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - if((i == d) && (a == true)){ - output = true; + 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); + } + } + } } - else{ - output = false; - } - ASSERT_TRUE(output); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, at) From 6d83790358488686b3d8d6b0aeb560f82025c0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:44:01 +0300 Subject: [PATCH 07/68] tab correction --- libs/main/math/pimathmatrix.h | 791 +++++++++++++++++----------------- 1 file changed, 395 insertions(+), 396 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 9a767dd5..fe1c6a66 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -85,19 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - /** - * @brief Constructor that calls the private resize method - * - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } - /** - * @brief Constructor that calls the private resize method - * - * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -105,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identity matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -116,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -128,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -205,12 +205,12 @@ public: uint rows() const { return Rows; } /** - * @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 - * - * @param index is the number of the selected column - * @return column in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -218,12 +218,12 @@ 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 - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -231,39 +231,39 @@ public: } /** - * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -275,13 +275,13 @@ 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 - * - * @param c0 is the number of the first selected column - * @param c1 is the number of the second selected column - * @return matrix type _CMatrix - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -293,142 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -436,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -448,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -460,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -472,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -484,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -504,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -546,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -599,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -610,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -859,33 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param f is type of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param val is PIVector of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector of PIVector, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -893,11 +893,11 @@ public: } } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector2D, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -905,194 +905,193 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 - * - * @param val is the vector type PIMathVector - * @return row matrix of every element that is equal to every element of the vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a column matrix of every element that is equal to every element of the vector - * - * @param val is the vector type PIMathVector - * @return column matrix of every element that is equal to every element of the vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - * - * @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 - */ + * @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 + * + * @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) _V2D::element(i, index) = v[i]; return *this; } /** - * @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 - * @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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this; } /** - * @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 - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; } - /** - * @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 - * - * @param c0 is the number of the first selected row - * @param c1 is the number of the second selected row - * @return matrix type _CMatrix - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } /** - * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros - * - * @return true if matrix is identity, else false - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix elements equal to zero, else false - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1100,11 +1099,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1112,11 +1111,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1124,11 +1123,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1136,11 +1135,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1148,10 +1147,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1168,10 +1167,10 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1186,10 +1185,10 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1228,10 +1227,10 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1288,10 +1287,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1299,10 +1298,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); From ab16bb3ce00e828362f468edbb8b95a029998ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:47:44 +0300 Subject: [PATCH 08/68] final tab correction --- libs/main/math/pimathmatrix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index fe1c6a66..8ab15e91 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -120,7 +120,7 @@ public: * * @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; @@ -965,7 +965,7 @@ public: * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; From 98f77d90cd7b63c8883ac0238c490c9ab1506314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 10:52:09 +0300 Subject: [PATCH 09/68] tests correction --- tests/math/testpimathmatrix.cpp | 82 +++++++++------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 09992b89..d2751587 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -54,106 +54,66 @@ TEST(PIMathMatrix_Test, identity) TEST(PIMathMatrix_Test, matrixRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixRow(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 5.0) + if(matrix[0][i] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixCol(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 5.0) + if(matrix[i][0] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); + auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 10.0) + if(matrix[i][0] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); + auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 10.0) + if(matrix[0][i] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, swapCols) @@ -758,4 +718,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} +} \ No newline at end of file From 58a132a3a50496aefb439d3d96a227479fa9fe0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 13:11:31 +0300 Subject: [PATCH 10/68] PIMathMatrix new tests version --- tests/math/testpimathmatrix.cpp | 517 +++++++++++--------------------- 1 file changed, 179 insertions(+), 338 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index d2751587..deeca9ca 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -1,33 +1,16 @@ #include "gtest/gtest.h" #include "pimathmatrix.h" -bool cmpMatrixWithValue(PIMathMatrix matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.element(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.element(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } @@ -57,10 +40,8 @@ TEST(PIMathMatrix_Test, matrixRow) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 3.0) { ASSERT_TRUE(false); } } @@ -72,10 +53,8 @@ TEST(PIMathMatrix_Test, matrixCol) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 3.0) { ASSERT_TRUE(false); } } @@ -89,10 +68,8 @@ TEST(PIMathMatrix_Test, setCol) auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 10.0) { ASSERT_TRUE(false); } } @@ -106,10 +83,8 @@ TEST(PIMathMatrix_Test, setRow) auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 10.0) { ASSERT_TRUE(false); } } @@ -139,25 +114,21 @@ TEST(PIMathMatrix_Test, swapCols) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(i, 0); a2[i] = matrix1.element(i, 1); a3[i] = matrix1.element(i, 2); } matrix1.swapCols(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(i, 0); b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); @@ -186,350 +157,218 @@ TEST(PIMathMatrix_Test, swapRows) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(0, i); a2[i] = matrix1.element(1, i); a3[i] = matrix1.element(2, i); } matrix1.swapRows(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(0, i); b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); } TEST(PIMathMatrix_Test, fill) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 5.0); + matrix.fill(7.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); +} + +TEST(PIMathMatrix_Test, isSquareTrue) +{ + PIMathMatrix matrix(3, 3, 1.0); + ASSERT_TRUE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isSquareFalse) +{ + PIMathMatrix matrix(2, 4, 1.0); + ASSERT_FALSE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isIdentityTrue) +{ + auto matrix = PIMathMatrix::identity(3, 3); + ASSERT_TRUE(matrix.isIdentity()); +} + +TEST(PIMathMatrix_Test, isIdentityFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isIdentity()); +} + + +TEST(PIMathMatrix_Test, isNullTrue) +{ + PIMathMatrix matrix(3, 3, 0.0); + ASSERT_TRUE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isNullFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isValidTrue) +{ + PIMathMatrix matrix(3, 3, 1.62); + ASSERT_TRUE(matrix.isValid()); +} + +TEST(PIMathMatrix_Test, isValidFalse) +{ PIMathMatrix matrix; - bool b; - matrix = origMatr.identity(3, 3); - matrix.fill(5.0); - b = cmpMatrixWithValue(matrix, 5.0); - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isSquare) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(4,3); - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isIdentity) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(3.932); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isNull) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(0.0); - matrix2.fill(3.932); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isValid) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - if((matrix1.isValid() == true) && (matrix2.isValid() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix.isValid()); } TEST(PIMathMatrix_Test, operator_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); + PIMathMatrix matrix1(3, 3, 5.72); + PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_Equal) +TEST(PIMathMatrix_Test, operator_EqualTrue) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 == matrix2) == true) && ((matrix1 == matrix3) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_Equal) +TEST(PIMathMatrix_Test, operator_EqualFalse) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 != matrix2) == false) && ((matrix1 != matrix3) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 1.0); + PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } TEST(PIMathMatrix_Test, operator_Division_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } TEST(PIMathMatrix_Test, operator_Addition) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3, 3); - matrix2 = origMatr.identity(3, 3); - origMatr.fill(8.0); - matrix1.fill(8.28); - origMatr = origMatr - matrix1; - matrix2.fill(-0.28); - if(origMatr == matrix2) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.0); + PIMathMatrix matrix2(3, 3, 5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } TEST(PIMathMatrix_Test, operator_Division) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinant) +TEST(PIMathMatrix_Test, determinantIfSquare) { - PIMathMatrix origMatr; double d; double i = 59.0; - PIMathMatrix matrix; + PIMathMatrix matrix(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -543,18 +382,23 @@ TEST(PIMathMatrix_Test, determinant) ASSERT_DOUBLE_EQ(d, i); } +TEST(PIMathMatrix_Test, determinantIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.determinant()); +} + TEST(PIMathMatrix_Test, trace) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -568,18 +412,23 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } +TEST(PIMathMatrix_Test, traceIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.trace()); +} + TEST(PIMathMatrix_Test, toUpperTriangular) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -600,19 +449,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -626,8 +473,6 @@ TEST(PIMathMatrix_Test, invert) matrix2 = matrix1; matrix2.invert(); d2 = matrix2.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -642,19 +487,17 @@ TEST(PIMathMatrix_Test, invert) TEST(PIMathMatrix_Test, inverted) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -668,8 +511,6 @@ TEST(PIMathMatrix_Test, inverted) matrix2 = matrix1; matrix1 = matrix2.invert(); d2 = matrix1.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix3 = matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -718,4 +559,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} \ No newline at end of file +} From f98874401f6b3100d6bcfa623595f898d4be6b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 15:27:09 +0300 Subject: [PATCH 11/68] testing another operations --- tests/math/testpimathmatrix.cpp | 80 ++++++++++++++++++++++++++++++++ tests/math/testpimathmatrixt.cpp | 73 +++++++++-------------------- 2 files changed, 101 insertions(+), 52 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index deeca9ca..ae3b46f3 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -35,6 +35,26 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } +TEST(PIMathMatrixT_Test, element) +{ + auto matrix = PIMathMatrix::identity(3, 3); + for(uint i = 0; i < 3; i++) { + if(matrix.element(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); + } + } + } + } + ASSERT_TRUE(true); +} + TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; @@ -560,3 +580,63 @@ TEST(PIMathMatrix_Test, transposed) } ASSERT_TRUE(b); } + +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathMatrix matrix2(2, 2, 2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); +} + +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + PIMathMatrix matrix1(3, 3, 1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} + +TEST(PIMathMatrixT_Test, hermitian) +{ + complex val; + complex res; + val.imag(1.0); + val.real(1.0); + PIMathMatrix> matrix(3, 3, val); + res.imag(-1.0); + res.real(1.0); + auto matr = hermitian(matrix); + for(uint i = 0; i < 3; i++) { + for(uint j = 0; j < 3; j++) { + if(matr.element(i, j) != res) { + ASSERT_TRUE(false); + } + } + } + ASSERT_TRUE(true); +} + diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 0542332a..6e4e0a45 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -4,38 +4,20 @@ const uint rows = 3; const uint cols = 3; -bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.at(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.at(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } - TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); @@ -58,26 +40,13 @@ TEST(PIMathMatrixT_Test, identity) TEST(PIMathMatrixT_Test, at) { - uint i; - bool b; - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1 = matr.identity(); - matrix2 = matr.identity(); - for(i = 0; i < rows; i++) - { - if(matrix1.at(i,i) == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix1 = PIMathMatrixT::identity(); + for(uint i = 0; i < rows; i++) { + if(matrix1.at(i,i) != 1.0) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, filled) { @@ -374,7 +343,7 @@ TEST(PIMathMatrixT_Test, operator_Assignment) bool b; matrix2.fill(6.72); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); + b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); ASSERT_TRUE(b); } @@ -444,7 +413,7 @@ TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); + b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); ASSERT_TRUE(b); } @@ -456,7 +425,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); + b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); ASSERT_TRUE(b); } @@ -466,7 +435,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) bool b; matrix1.fill(6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); + b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); ASSERT_TRUE(b); } @@ -476,7 +445,7 @@ TEST(PIMathMatrixT_Test, operator_Division_Assignment) bool b; matrix1.fill(6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); + b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); ASSERT_TRUE(b); } @@ -487,7 +456,7 @@ TEST(PIMathMatrixT_Test, operator_Addition) bool b; matrix1.fill(6.72); matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); + b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); ASSERT_TRUE(b); } @@ -498,7 +467,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction) bool b; matrix1.fill(6.0); matrix2.fill(5.0); - b = cmpMatrixWithValue(matrix1 - matrix2, 1.0); + b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); ASSERT_TRUE(b); } @@ -509,7 +478,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication) bool b; matrix1.fill(6.72); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); + b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Division) @@ -519,7 +488,7 @@ TEST(PIMathMatrixT_Test, operator_Division) bool b; matrix1.fill(6.72); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); + b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); ASSERT_TRUE(b); } @@ -721,7 +690,7 @@ TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); - ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } TEST(PIMathMatrixT_Test, rotationX) From 641633f6f0504d3094f617a3f48c654888e0e1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 16:56:04 +0300 Subject: [PATCH 12/68] overall PIMathMatrix tests correction --- tests/math/testpimathmatrix.cpp | 44 +-- tests/math/testpimathmatrixt.cpp | 584 +++++++++++-------------------- 2 files changed, 206 insertions(+), 422 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index ae3b46f3..2b045000 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -470,7 +470,6 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -494,21 +493,12 @@ TEST(PIMathMatrix_Test, invert) matrix2.invert(); d2 = matrix2.determinant(); matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, inverted) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -532,22 +522,13 @@ TEST(PIMathMatrix_Test, inverted) matrix1 = matrix2.invert(); d2 = matrix1.determinant(); matrix3 = matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; - bool b; PIMathMatrix matrix1; PIMathMatrix matrix2; PIMathMatrix matrix3; @@ -570,25 +551,17 @@ TEST(PIMathMatrix_Test, transposed) matrix2 = matrix1.transposed(); d2 = matrix2.determinant(); matrix3 = matrix2.transposed(); - if((d1 == d2) && (matrix1 == matrix3)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrixT_Test, matrixMultiplication) +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -601,7 +574,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -614,13 +587,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrixT_Test, hermitian) +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; @@ -639,4 +612,3 @@ TEST(PIMathMatrixT_Test, hermitian) } ASSERT_TRUE(true); } - diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 6e4e0a45..a006b3cd 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -50,21 +50,8 @@ TEST(PIMathMatrixT_Test, at) } TEST(PIMathMatrixT_Test, filled) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - PIMathVectorT vect; - double g = 1.0; - matrix2 = matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { - matrix1.at(j,i) = g; - } - } - ASSERT_TRUE(matrix2 == matrix1); + auto matr = PIMathMatrixT::filled(1.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } TEST(PIMathMatrixT_Test, cols) @@ -83,9 +70,7 @@ TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -96,28 +81,18 @@ TEST(PIMathMatrixT_Test, col) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.col(g); - for(i = 0; i < matr.cols(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.cols(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, row) -{ - PIMathMatrixT matr; +{ PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -128,19 +103,12 @@ TEST(PIMathMatrixT_Test, row) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.row(g); - for(i = 0; i < matr.rows(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.rows(); i++) { + if(matr.at(g, i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setCol) @@ -151,22 +119,13 @@ TEST(PIMathMatrixT_Test, setCol) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setCol(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setRow) @@ -177,33 +136,19 @@ TEST(PIMathMatrixT_Test, setRow) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setRow(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(g,i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -213,31 +158,23 @@ TEST(PIMathMatrixT_Test, swapCols) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.col(g1); - before_Vect2 = matr.col(g2); - matr.swapCols(g1,g2); - after_Vect1 = matr.col(g1); - after_Vect2 = matr.col(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.col(g1); + const PIMathVectorT before_Vect2 = matr.col(g2); + matr.swapCols(g1, g2); + const PIMathVectorT after_Vect1 = matr.col(g1); + const PIMathVectorT after_Vect2 = matr.col(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -247,20 +184,17 @@ TEST(PIMathMatrixT_Test, swapRows) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.row(g1); - before_Vect2 = matr.row(g2); - matr.swapRows(g1,g2); - after_Vect1 = matr.row(g1); - after_Vect2 = matr.row(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.row(g1); + const PIMathVectorT before_Vect2 = matr.row(g2); + matr.swapRows(g1, g2); + const PIMathVectorT after_Vect1 = matr.row(g1); + const PIMathVectorT after_Vect2 = matr.row(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, fill) @@ -269,231 +203,175 @@ TEST(PIMathMatrixT_Test, fill) PIMathMatrixT matrix1; double g = 1.0; matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { + for(uint i = 0; i < cols; i++) { + for(uint j = 0; j < rows; j++) { matrix1.at(j,i) = g; } } ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquare) +TEST(PIMathMatrixT_Test, isSquareTrue) { - PIMathMatrixT matr; PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isSquare()); +} + +TEST(PIMathMatrixT_Test, isSquareFalse) +{ const uint new_Cols = 4; PIMathMatrixT matrix2; - bool b; - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentity) +TEST(PIMathMatrixT_Test, isIdentityTrue) { - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1 = matr.identity(); - matrix2 = matr.filled(3.67); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNull) +TEST(PIMathMatrixT_Test, isIdentityFalse) +{ + auto matrix1 = PIMathMatrixT::filled(2.5); + ASSERT_FALSE(matrix1.isIdentity()); +} + +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2 = matr.filled(3.67); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE(matrix1.isNull()); +} + +TEST(PIMathMatrixT_Test, isNullFalse) +{ + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_FALSE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2.fill(6.72); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Equal) +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr == matrix1) == true) && ((matr == matrix2) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_Equal) +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - bool b; - PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr != matrix1) == false) && ((matr != matrix2) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(6.72) ; + auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(1.0); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.0); - matrix2.fill(5.0); - b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1*4.0; - b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1/4.0; - b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } - -TEST(PIMathMatrixT_Test, determinant) +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; @@ -511,6 +389,21 @@ TEST(PIMathMatrixT_Test, determinant) ASSERT_DOUBLE_EQ(i, d); } +TEST(PIMathMatrixT_Test, determinantIfNotSquare) +{ + PIMathMatrixT matr; + matr.at(0,0) = 3; + matr.at(0,1) = 6; + matr.at(0,2) = 8; + matr.at(1,0) = 2; + matr.at(1,1) = 1; + matr.at(1,2) = 4; + matr.at(2,0) = 6; + matr.at(2,1) = 2; + matr.at(2,2) = 5; + ASSERT_FALSE(matr.determinant()); +} + TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; @@ -518,8 +411,6 @@ TEST(PIMathMatrixT_Test, invert) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; - matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -535,15 +426,7 @@ TEST(PIMathMatrixT_Test, invert) d2 = matrix2.determinant(); matrix3 = matrix1; matrix1.invert(); - if((matrix1 == matrix3) && (d1 == 1/d2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } TEST(PIMathMatrixT_Test, inverted) @@ -553,7 +436,6 @@ TEST(PIMathMatrixT_Test, inverted) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -568,22 +450,13 @@ TEST(PIMathMatrixT_Test, inverted) d1 = matr.determinant(); d2 = matrix2.determinant(); matrix3 = matrix1.inverted(); - if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; - uint i; PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -596,7 +469,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) matr.at(2,2) = 5; matrix = matr.toUpperTriangular(); d1 = matrix.determinant(); - for(i = 0; i < cols; i++) + for(uint i = 0; i < cols; i++) { d2 = d2*matrix.at(i,i); } @@ -609,7 +482,6 @@ TEST(PIMathMatrixT_Test, transposed) PIMathMatrixT matrix2; PIMathMatrixT matr; double d1, d2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -623,67 +495,30 @@ TEST(PIMathMatrixT_Test, transposed) matrix1 = matr.transposed(); d2 = matrix1.determinant(); matrix2 = matrix1.transposed(); - if((d1 == d2) && (matr == matrix2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); - - if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); - - if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } TEST(PIMathMatrixT_Test, rotation_3x3) @@ -696,106 +531,83 @@ TEST(PIMathMatrixT_Test, rotation_3x3) TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); - - if((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); - - if((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); - - if((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); - if((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); - if((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); - if((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto matrix2 = PIMathMatrixT::filled(2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); +} +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 11.25) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 11.25) { + ASSERT_TRUE(false); + } + } +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} From 7acc2f6b2f1146942d157a1f2ece9da34605e03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:13:02 +0300 Subject: [PATCH 13/68] indentation in strings --- tests/math/testpimathmatrix.cpp | 150 +++++++++--------------------- tests/math/testpimathmatrixt.cpp | 154 +++++++++++-------------------- 2 files changed, 98 insertions(+), 206 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 2b045000..6f4e5ffa 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -2,8 +2,7 @@ #include "pimathmatrix.h" template -bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -15,8 +14,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) return b; } -TEST(PIMathMatrix_Test, identity) -{ +TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -35,8 +33,7 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, element) -{ +TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); for(uint i = 0; i < 3; i++) { if(matrix.element(i,i) != 1.0) { @@ -55,8 +52,7 @@ TEST(PIMathMatrixT_Test, element) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixRow) -{ +TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -68,8 +64,7 @@ TEST(PIMathMatrix_Test, matrixRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixCol) -{ +TEST(PIMathMatrix_Test, matrixCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -81,8 +76,7 @@ TEST(PIMathMatrix_Test, matrixCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setCol) -{ +TEST(PIMathMatrix_Test, setCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -96,8 +90,7 @@ TEST(PIMathMatrix_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setRow) -{ +TEST(PIMathMatrix_Test, setRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -111,15 +104,13 @@ TEST(PIMathMatrix_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, swapCols) -{ +TEST(PIMathMatrix_Test, swapCols) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -145,24 +136,16 @@ TEST(PIMathMatrix_Test, swapCols) b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, swapRows) -{ +TEST(PIMathMatrix_Test, swapRows) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -188,80 +171,63 @@ TEST(PIMathMatrix_Test, swapRows) b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, fill) -{ +TEST(PIMathMatrix_Test, fill) { PIMathMatrix matrix(3, 3, 5.0); matrix.fill(7.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); } -TEST(PIMathMatrix_Test, isSquareTrue) -{ +TEST(PIMathMatrix_Test, isSquareTrue) { PIMathMatrix matrix(3, 3, 1.0); ASSERT_TRUE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isSquareFalse) -{ +TEST(PIMathMatrix_Test, isSquareFalse) { PIMathMatrix matrix(2, 4, 1.0); ASSERT_FALSE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isIdentityTrue) -{ +TEST(PIMathMatrix_Test, isIdentityTrue) { auto matrix = PIMathMatrix::identity(3, 3); ASSERT_TRUE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isIdentityFalse) -{ +TEST(PIMathMatrix_Test, isIdentityFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isNullTrue) -{ +TEST(PIMathMatrix_Test, isNullTrue) { PIMathMatrix matrix(3, 3, 0.0); ASSERT_TRUE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isNullFalse) -{ +TEST(PIMathMatrix_Test, isNullFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isValidTrue) -{ +TEST(PIMathMatrix_Test, isValidTrue) { PIMathMatrix matrix(3, 3, 1.62); ASSERT_TRUE(matrix.isValid()); } -TEST(PIMathMatrix_Test, isValidFalse) -{ +TEST(PIMathMatrix_Test, isValidFalse) { PIMathMatrix matrix; ASSERT_FALSE(matrix.isValid()); } -TEST(PIMathMatrix_Test, operator_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Assignment) { PIMathMatrix matrix1(3, 3, 5.72); PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -275,8 +241,7 @@ TEST(PIMathMatrix_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -290,8 +255,7 @@ TEST(PIMathMatrix_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -305,8 +269,7 @@ TEST(PIMathMatrix_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -320,67 +283,58 @@ TEST(PIMathMatrix_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { PIMathMatrix matrix1(3, 3, 1.0); PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } -TEST(PIMathMatrix_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Division_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } -TEST(PIMathMatrix_Test, operator_Addition) -{ +TEST(PIMathMatrix_Test, operator_Addition) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction) -{ +TEST(PIMathMatrix_Test, operator_Subtraction) { PIMathMatrix matrix1(3, 3, 6.0); PIMathMatrix matrix2(3, 3, 5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication) -{ +TEST(PIMathMatrix_Test, operator_Multiplication) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } -TEST(PIMathMatrix_Test, operator_Division) -{ +TEST(PIMathMatrix_Test, operator_Division) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinantIfSquare) -{ +TEST(PIMathMatrix_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrix matrix(3, 3, 0.0); @@ -402,15 +356,13 @@ TEST(PIMathMatrix_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(d, i); } -TEST(PIMathMatrix_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrix_Test, determinantIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.determinant()); } -TEST(PIMathMatrix_Test, trace) -{ +TEST(PIMathMatrix_Test, trace) { PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; @@ -432,15 +384,13 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } -TEST(PIMathMatrix_Test, traceIfNotSquare) -{ +TEST(PIMathMatrix_Test, traceIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.trace()); } -TEST(PIMathMatrix_Test, toUpperTriangular) -{ +TEST(PIMathMatrix_Test, toUpperTriangular) { PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; @@ -467,8 +417,7 @@ TEST(PIMathMatrix_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrix_Test, invert) -{ +TEST(PIMathMatrix_Test, invert) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -496,8 +445,7 @@ TEST(PIMathMatrix_Test, invert) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, inverted) -{ +TEST(PIMathMatrix_Test, inverted) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -525,8 +473,7 @@ TEST(PIMathMatrix_Test, inverted) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, transposed) -{ +TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; PIMathMatrix matrix1; @@ -554,15 +501,13 @@ TEST(PIMathMatrix_Test, transposed) ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrix_Test, matrixMultiplication) -{ +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -574,8 +519,7 @@ TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -587,14 +531,12 @@ TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrix_Test, hermitian) -{ +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; val.imag(1.0); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index a006b3cd..52bb462e 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,8 +5,7 @@ const uint rows = 3; const uint cols = 3; template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -18,8 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } -TEST(PIMathMatrixT_Test, identity) -{ +TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -38,8 +36,7 @@ TEST(PIMathMatrixT_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, at) -{ +TEST(PIMathMatrixT_Test, at) { auto matrix1 = PIMathMatrixT::identity(); for(uint i = 0; i < rows; i++) { if(matrix1.at(i,i) != 1.0) { @@ -48,26 +45,22 @@ TEST(PIMathMatrixT_Test, at) } ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, filled) -{ +TEST(PIMathMatrixT_Test, filled) { auto matr = PIMathMatrixT::filled(1.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } -TEST(PIMathMatrixT_Test, cols) -{ +TEST(PIMathMatrixT_Test, cols) { PIMathMatrixT matr; ASSERT_EQ(cols,matr.cols()); } -TEST(PIMathMatrixT_Test, rows) -{ +TEST(PIMathMatrixT_Test, rows) { PIMathMatrixT matr; ASSERT_EQ(rows,matr.rows()); } -TEST(PIMathMatrixT_Test, col) -{ +TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; @@ -89,8 +82,8 @@ TEST(PIMathMatrixT_Test, col) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, row) -{ PIMathMatrixT matr; +TEST(PIMathMatrixT_Test, row) { + PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; matr.at(0,0) = 3; @@ -111,8 +104,7 @@ TEST(PIMathMatrixT_Test, row) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setCol) -{ +TEST(PIMathMatrixT_Test, setCol) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -128,8 +120,7 @@ TEST(PIMathMatrixT_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setRow) -{ +TEST(PIMathMatrixT_Test, setRow) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -145,8 +136,7 @@ TEST(PIMathMatrixT_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, swapCols) -{ +TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -171,8 +161,7 @@ TEST(PIMathMatrixT_Test, swapCols) } } -TEST(PIMathMatrixT_Test, swapRows) -{ +TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -197,8 +186,7 @@ TEST(PIMathMatrixT_Test, swapRows) } } -TEST(PIMathMatrixT_Test, fill) -{ +TEST(PIMathMatrixT_Test, fill) { PIMathMatrixT matr; PIMathMatrixT matrix1; double g = 1.0; @@ -211,53 +199,45 @@ TEST(PIMathMatrixT_Test, fill) ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquareTrue) -{ +TEST(PIMathMatrixT_Test, isSquareTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isSquare()); } -TEST(PIMathMatrixT_Test, isSquareFalse) -{ +TEST(PIMathMatrixT_Test, isSquareFalse) { const uint new_Cols = 4; PIMathMatrixT matrix2; ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentityTrue) -{ +TEST(PIMathMatrixT_Test, isIdentityTrue) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isIdentityFalse) -{ +TEST(PIMathMatrixT_Test, isIdentityFalse) { auto matrix1 = PIMathMatrixT::filled(2.5); ASSERT_FALSE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNullTrue) -{ +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, isNullFalse) -{ +TEST(PIMathMatrixT_Test, isNullFalse) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_FALSE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, operator_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -271,8 +251,7 @@ TEST(PIMathMatrixT_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -286,8 +265,7 @@ TEST(PIMathMatrixT_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -301,8 +279,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -316,63 +293,54 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { auto matrix1 = PIMathMatrixT::filled(1.0); auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } -TEST(PIMathMatrixT_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Division_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } -TEST(PIMathMatrixT_Test, operator_Addition) -{ +TEST(PIMathMatrixT_Test, operator_Addition) { auto matrix1 = PIMathMatrixT::filled(6.72); auto matrix2 = PIMathMatrixT::filled(8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction) { auto matrix1 = PIMathMatrixT::filled(6.0); auto matrix2 = PIMathMatrixT::filled(5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } -TEST(PIMathMatrixT_Test, operator_Division) -{ +TEST(PIMathMatrixT_Test, operator_Division) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } -TEST(PIMathMatrixT_Test, determinantIfSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrixT matr; @@ -389,8 +357,7 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(i, d); } -TEST(PIMathMatrixT_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfNotSquare) { PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -404,8 +371,7 @@ TEST(PIMathMatrixT_Test, determinantIfNotSquare) ASSERT_FALSE(matr.determinant()); } -TEST(PIMathMatrixT_Test, invert) -{ +TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -429,8 +395,7 @@ TEST(PIMathMatrixT_Test, invert) ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } -TEST(PIMathMatrixT_Test, inverted) -{ +TEST(PIMathMatrixT_Test, inverted) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -453,8 +418,7 @@ TEST(PIMathMatrixT_Test, inverted) ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrixT_Test, toUpperTriangular) -{ +TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; PIMathMatrixT matr; @@ -476,8 +440,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrixT_Test, transposed) -{ +TEST(PIMathMatrixT_Test, transposed) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matr; @@ -498,22 +461,19 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } -TEST(PIMathMatrixT_Test, scaleX_two) -{ +TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, scaleY_two) -{ +TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, rotation_2x2) -{ +TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); @@ -521,15 +481,13 @@ TEST(PIMathMatrixT_Test, rotation_2x2) ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } -TEST(PIMathMatrixT_Test, rotation_3x3) -{ +TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } -TEST(PIMathMatrixT_Test, rotationX) -{ +TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -537,8 +495,7 @@ TEST(PIMathMatrixT_Test, rotationX) ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } -TEST(PIMathMatrixT_Test, rotationY) -{ +TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -546,8 +503,7 @@ TEST(PIMathMatrixT_Test, rotationY) ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } -TEST(PIMathMatrixT_Test, rotationZ) -{ +TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -555,22 +511,19 @@ TEST(PIMathMatrixT_Test, rotationZ) ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } -TEST(PIMathMatrixT_Test, scaleX_three) -{ +TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleY_three) -{ +TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleZ_three) -{ +TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); @@ -583,8 +536,7 @@ TEST(PIMathMatrixT_Test, matrixMultiplication) ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -595,8 +547,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -606,8 +557,7 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) } } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } From 5bec25a6283dbe1505ffdac7bbf46bf26481f6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:16 +0300 Subject: [PATCH 14/68] bug fixes --- CMakeLists.txt.user | 1175 ++++++++++++++++++++++++++++++ tests/math/testpimathmatrix.cpp | 26 +- tests/math/testpimathmatrixt.cpp | 12 +- 3 files changed, 1194 insertions(+), 19 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..aed2b6b3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1175 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 6 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_concurrent_test + CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test + pip_concurrent_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_math_test + CMakeProjectManager.CMakeRunConfiguration.pip_math_test + pip_math_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal + + 12 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 6f4e5ffa..3dc1943a 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -16,18 +16,18 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); - 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){ + 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); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -35,11 +35,6 @@ TEST(PIMathMatrix_Test, identity) { TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); - for(uint i = 0; i < 3; i++) { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ if(i != j){ @@ -47,6 +42,11 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(false); } } + else { + if(matrix.element(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 52bb462e..d7f11563 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -19,11 +19,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::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){ @@ -31,6 +26,11 @@ TEST(PIMathMatrixT_Test, identity) { ASSERT_TRUE(false); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -293,7 +293,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { +TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; From 0ce6afa43ca9bc3762e3531d8bf1010e33375bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:39 +0300 Subject: [PATCH 15/68] bug fixes --- CMakeLists.txt.user | 1175 ------------------------------------------- 1 file changed, 1175 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index aed2b6b3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1175 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 6 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_concurrent_test - CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test - pip_concurrent_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_math_test - CMakeProjectManager.CMakeRunConfiguration.pip_math_test - pip_math_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal - - 12 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 3a4ac8badd6e61a6b5ad927ae4525288f3de8329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 16/68] add CMakeLists.txt.user to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 092160f1..22cc44b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.svn /doc/rtf _unsused +CMakeLists.txt.user \ No newline at end of file From 1646f1ada70bfb710413903dee1f0fe9dda68694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 17/68] PIMathMatrix doc --- CMakeLists.txt.user | 1023 +++++++++++++++++++++++++++++++++ libs/main/math/pimathmatrix.h | 485 +++++++++++++++- tests/concurrent/testutil.h | 2 + 3 files changed, 1505 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..6d0aa1d3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1023 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + + + doc + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal + + 10 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 676a4486..783c1a6a 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -1,5 +1,7 @@ /*! \file pimathmatrix.h * \brief PIMathMatrix + * + * This file declare math matrix class, which performs various matrix operations */ /* PIP - Platform Independent Primitives @@ -54,12 +56,13 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); @@ -67,46 +70,302 @@ public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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" + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the X axis + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the X axis by the value "factor" + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Y axis by the value "factor" + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Z axis by the value "factor" + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} + + /** + * @brief Method which returns number of rows in matrix + * + * @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 + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -122,6 +381,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -159,6 +423,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -206,7 +475,19 @@ public: memcpy(m, mtmp.m, sizeof(Type) * Cols * Rows); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -321,6 +602,7 @@ class PIMathMatrix; #define PIMM_FOR_C(v) for (uint v = 0; v < _V2D::cols_; ++v) #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 template class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIVector2D _V2D; @@ -332,33 +614,199 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} + /** + * @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) _V2D::element(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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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_A(i) _V2D::mat[i] = v; return *this;} + + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} + + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); 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_A(i) if (_V2D::mat[i] != sm.mat[i]) 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_A(i) _V2D::mat[i] += sm.mat[i];} + + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= 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(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -374,6 +822,11 @@ public: return ret; } + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -387,6 +840,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -424,6 +882,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -478,7 +941,19 @@ public: PIVector2D::swap(mtmp); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 7c3c15c7..9df146ba 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,6 +3,7 @@ #include "pithread.h" #include +#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -57,4 +58,5 @@ public: } }; + #endif //AWRCANFLASHER_TESTUTIL_H From 3f84598ec06e529d562fba7abc2c1622115e21a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:47 +0300 Subject: [PATCH 18/68] PIMathMatrix document --- CMakeLists.txt.user | 1023 ------------------------------------------- 1 file changed, 1023 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 6d0aa1d3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1023 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 0 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - - - doc - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal - - 10 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 14e13fa8c1583e2b989cd5ea19fd46695ccfb746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:23:54 +0300 Subject: [PATCH 19/68] Rotation remake --- libs/main/math/pimathmatrix.h | 20 +++++++-------- tests/concurrent/testutil.h | 2 -- tests/math/testpimathmatrixt.cpp | 44 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 783c1a6a..399afdd6 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -63,9 +63,9 @@ class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrixI; typedef PIMathVectorT _CMCol; typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} @@ -86,7 +86,7 @@ public: 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" + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix * @return rotated matrix @@ -94,7 +94,7 @@ public: static _CMatrix rotation(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the X axis + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the X axis * @return rotated matrix @@ -102,7 +102,7 @@ public: static _CMatrix rotationX(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Y axis + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Y axis * @return rotated matrix @@ -110,7 +110,7 @@ public: static _CMatrix rotationY(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Z axis + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Z axis * @return rotated matrix @@ -118,7 +118,7 @@ public: static _CMatrix rotationZ(double angle) {return _CMatrix();} /** - * @brief Scaling the matrix along the X axis by the value "factor" + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by X axis * @return rotated matrix @@ -126,7 +126,7 @@ public: static _CMatrix scaleX(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Y axis by the value "factor" + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by Y axis * @return rotated matrix @@ -134,7 +134,7 @@ public: static _CMatrix scaleY(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Z axis by the value "factor" + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix * * @param factor is the value of scaling by Z axis * @return rotated matrix diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 9df146ba..7c3c15c7 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,7 +3,6 @@ #include "pithread.h" #include -#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -58,5 +57,4 @@ public: } }; - #endif //AWRCANFLASHER_TESTUTIL_H diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 38976bf8..2d68d131 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -674,24 +674,6 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, rotation) -{ - double angle = 1.0; - bool b; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); - double c = cos(angle); - double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; @@ -726,6 +708,31 @@ TEST(PIMathMatrixT_Test, scaleY_two) ASSERT_TRUE(b); } +TEST(PIMathMatrixT_Test, rotation_2x2) +{ + double angle = 1.0; + bool b; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); + double c = cos(angle); + double s = sin(angle); + if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) + { + b = true; + } + else + { + b = false; + } + ASSERT_TRUE(b); +} + +TEST(PIMathMatrixT_Test, rotation_3x3) +{ + double angle = 1.0; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); + ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); +} + TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; @@ -831,3 +838,4 @@ TEST(PIMathMatrixT_Test, scaleZ_three) ASSERT_TRUE(b); } + From 33d1abd14c825e222b9554787fc916b301f0bb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:50:41 +0300 Subject: [PATCH 20/68] space correction --- libs/main/math/pimathmatrix.h | 847 +++++++++++++++++----------------- 1 file changed, 427 insertions(+), 420 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 399afdd6..0be4325c 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -59,313 +59,320 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { //! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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 - */ + /** + * @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 - */ + /** + * @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 _CMatrix - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + /** + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} - /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} - /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} - /** - * @brief Method which returns number of rows in matrix - * - * @return type uint shows number of rows - */ + /** + * @brief Method which returns number of rows in matrix + * + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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" - */ + /** + * @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" - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -381,11 +388,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -423,11 +430,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -476,18 +483,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -614,199 +621,199 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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 Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} - /** - * @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 - */ + /** + * @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) _V2D::element(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 - */ + /** + * @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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 - */ + /** + * @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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 - */ + /** + * @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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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 - */ + /** + * @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_A(i) _V2D::mat[i] = v; return *this;} - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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 - */ + /** + * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + /** + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix is null, else false + */ bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); return *this;} - /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + /** + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true;} - /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + /** + * @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 - */ + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} - /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + /** + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -822,11 +829,11 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -840,11 +847,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -882,11 +889,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -942,18 +949,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; From 740d38ccce8923a87dabfd61796e80d142634de5 Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Thu, 3 Sep 2020 16:57:46 +0300 Subject: [PATCH 21/68] Fix code formatting & grammar mistakes --- libs/main/math/pimathmatrix.h | 1352 ++++++++++++++++++++------------- 1 file changed, 810 insertions(+), 542 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 0be4325c..80f1eaab 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -29,7 +29,6 @@ #include "pimathcomplex.h" - template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); @@ -37,11 +36,12 @@ inline bool _PIMathMatrixNullCompare(const T v) { } template<> -inline bool _PIMathMatrixNullCompare(const complexf v) { +inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } + template<> -inline bool _PIMathMatrixNullCompare(const complexd v) { +inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); } @@ -56,6 +56,7 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { @@ -67,313 +68,391 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - PIMathMatrixT() {resize(Rows, Cols);} - PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} + PIMathMatrixT() { resize(Rows, Cols); } - /** - * @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;} + PIMathMatrixT(const PIVector &val) { + resize(Rows, Cols); + int i = 0; + PIMM_FOR_I_WB(r, c) m[r][c] = val[i++]; + } - /** - * @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 С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 Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT + /** + * @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 +* + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ + static _CMatrix rotation(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ + static _CMatrix rotationX(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ + static _CMatrix rotationY(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ + static _CMatrix rotationZ(double angle) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ + static _CMatrix scaleX(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ + static _CMatrix scaleY(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ + static _CMatrix scaleZ(double factor) { return _CMatrix(); } + + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ + uint cols() const { return Cols; } + + /** + * @brief Method which returns number of rows in matrix * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ - static _CMatrix rotation(double angle) {return _CMatrix();} + * @return type uint shows number of rows + */ + uint rows() const { return Rows; } - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ - static _CMatrix rotationX(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ - static _CMatrix rotationY(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ - static _CMatrix rotationZ(double angle) {return _CMatrix();} + /** + * @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 Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ - static _CMatrix scaleX(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ - static _CMatrix scaleY(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ - static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @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 returns number of columns in matrix - * - * @return type uint shows number of columns - */ - uint cols() const {return Cols;} + /** + * @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 returns number of rows in matrix - * - * @return type uint shows number of rows - */ - uint rows() const {return Rows;} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return cols() == rows();} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -388,12 +467,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; return *this; @@ -419,7 +498,7 @@ public: for (uint k = i; k < Cols; ++k) smat.m[k][j] -= mul * smat.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -430,12 +509,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); bool ndet; @@ -462,7 +541,7 @@ public: for (uint k = 0; k < Cols; ++k) mtmp.m[k][j] -= mul * mtmp.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -483,39 +562,125 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrixI transposed() const { + _CMatrixI tm; + PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; + return tm; + } private: - void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;} + void resize(uint rows_, uint cols_, const Type &new_value = Type()) { + r_ = rows_; + c_ = cols_; + PIMM_FOR_WB(r, c) m[r][c] = new_value; + } + int c_, r_; Type m[Rows][Cols]; }; + #pragma pack(pop) -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<2u, 2u> tm; tm[0][0] = tm[1][1] = c; tm[0][1] = -s; tm[1][0] = s; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = factor; tm[1][1] = 1.; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = 1.; tm[1][1] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = tm[1][1] = c; + tm[0][1] = -s; + tm[1][0] = s; + return tm; +} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[0][0] = 1.; tm[1][1] = tm[2][2] = c; tm[2][1] = s; tm[1][2] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[1][1] = 1.; tm[0][0] = tm[2][2] = c; tm[2][0] = -s; tm[0][2] = s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[2][2] = 1.; tm[0][0] = tm[1][1] = c; tm[1][0] = s; tm[0][1] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) {PIMathMatrixT<3u, 3u> tm; tm[1][1] = tm[2][2] = 1.; tm[0][0] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[2][2] = 1.; tm[1][1] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = factor; + tm[1][1] = 1.; + return tm; +} + +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = 1.; + tm[1][1] = tm[2][2] = c; + tm[2][1] = s; + tm[1][2] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = 1.; + tm[0][0] = tm[2][2] = c; + tm[2][0] = -s; + tm[0][2] = s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[2][2] = 1.; + tm[0][0] = tm[1][1] = c; + tm[1][0] = s; + tm[0][1] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = tm[2][2] = 1.; + tm[0][0] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[2][2] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[1][1] = 1.; + tm[2][2] = factor; + return tm; +} #ifdef PIP_STD_IOSTREAM template @@ -523,12 +688,19 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT -inline PICout operator <<(PICout s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrixT &m) { + s << "{"; + PIMM_FOR_I(r, c) s << m[r][c]; + if (c < Cols - 1 || r < Rows - 1) s << ", "; } + if (r < Rows - 1) s << PICoutManipulators::NewLine << " "; } + s << "}"; + return s; +} /// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1} template -inline PIMathMatrixT operator *(const PIMathMatrixT & fm, - const PIMathMatrixT & sm) { +inline PIMathMatrixT operator*(const PIMathMatrixT &fm, + const PIMathMatrixT &sm) { PIMathMatrixT tm; Type t; for (uint j = 0; j < Rows0; ++j) { @@ -544,8 +716,8 @@ inline PIMathMatrixT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathMatrixT & fm, - const PIMathVectorT & sv) { +inline PIMathVectorT operator*(const PIMathMatrixT &fm, + const PIMathVectorT &sv) { PIMathVectorT tv; Type t; for (uint j = 0; j < Rows; ++j) { @@ -559,8 +731,8 @@ inline PIMathVectorT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathVectorT & sv, - const PIMathMatrixT & fm) { +inline PIMathVectorT operator*(const PIMathVectorT &sv, + const PIMathMatrixT &fm) { PIMathVectorT tv; Type t; for (uint j = 0; j < Cols; ++j) { @@ -574,7 +746,7 @@ inline PIMathVectorT operator *(const PIMathVectorT & sv /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrixT operator *(const Type & x, const PIMathMatrixT & v) { +inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; } @@ -612,209 +784,277 @@ class PIMathMatrix; //! \brief A class that works with matrix operations, the input data of which is the data type of the matrix template class PIP_EXPORT PIMathMatrix : public PIVector2D { - typedef PIVector2D _V2D; + typedef PIVector2D _V2D; typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type & f = Type()) {_V2D::resize(rows, cols, f);} - PIMathMatrix(const uint cols, const uint rows, const PIVector & val) {_V2D::resize(rows, cols); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} - PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} - PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ - static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} + PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { + _V2D::resize(rows, cols); + int i = 0; + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; + } - /** - * @brief Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + PIMathMatrix(const PIVector > &val) { + if (!val.isEmpty()) { + _V2D::resize(val.size(), val[0].size()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c]; + } + } - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} + PIMathMatrix(const PIVector2D &val) { + if (!val.isEmpty()) { + _V2D::resize(val.rows(), val.cols()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c); + } + } - /** - * @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) _V2D::element(i, index) = v[i]; return *this;} + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ + static _CMatrix identity(const uint cols, const uint rows) { + _CMatrix tm(cols, rows); + 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 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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this;} + /** + * @brief Creates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } - /** - * @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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} return *this;} + /** + * @brief Creates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } - /** - * @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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} return *this;} + /** + * @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) _V2D::element(i, index) = v[i]; + 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_A(i) _V2D::mat[i] = v; 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 _CMCol &v) { + PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; + return *this; + } - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return _V2D::cols_ == _V2D::rows_;} + /** + * @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 &swapCols(uint r0, uint r1) { + PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } + return *this; + } - /** - * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0)) return false; return true;} + /** + * @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 &swapRows(uint c0, uint c1) { + PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } + return *this; + } - /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix is null, else false - */ - bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} + /** + * @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_A(i) _V2D::mat[i] = v; + return *this; + } - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ - bool isValid() const {return !PIVector2D::isEmpty();} + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ + bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ - _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); return *this;} + /** + * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; + return true; + } - /** - * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) 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_A(i) if (_V2D::mat[i] != Type(0)) 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 Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ + bool isValid() const { return !PIVector2D::isEmpty(); } - /** - * @brief Addition assignment with matrix "sm" - * - * @param sm matrix for the addition assigment - */ - void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ + _CMatrix &operator=(const PIVector > &v) { + *this = _CMatrix(v); + return *this; + } - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ - void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + /** + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; + return true; + } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ - void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + /** + * @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 Division assignment with value "v" - * - * @param v value for the division assigment - */ - void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ + void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ - _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ + void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ - _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ + void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ - _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ + void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ - _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ + _CMatrix operator-() const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; + return tm; + } - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ - _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ + _CMatrix operator+(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; + return tm; + } - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ + _CMatrix operator-(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; + return tm; + } + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ + _CMatrix operator*(const Type &v) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] *= 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(*this); + PIMM_FOR_A(i) tm.mat[i] /= v; + return tm; + } + + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -829,12 +1069,12 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ - Type trace(bool * ok = 0) const { + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ + Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { if (ok != 0) *ok = false; @@ -847,12 +1087,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -878,7 +1118,7 @@ public: for (uint k = i; k < _V2D::cols_; ++k) smat.element(k, j) -= mul * smat.element(k, i); } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -889,12 +1129,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -926,7 +1166,7 @@ public: if (sv != 0) (*sv)[j] -= mul * (*sv)[i]; } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -949,19 +1189,27 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrix transposed() const { + _CMatrix tm(_V2D::rows_, _V2D::cols_); + PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); + return tm; + } }; @@ -971,18 +1219,36 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m #endif template -inline PICout operator <<(PICout s, const PIMathMatrix & m) {s << "Matrix{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrix &m) { + s << "Matrix{"; + for (uint r = 0; r < m.rows(); ++r) { + for (uint c = 0; c < m.cols(); ++c) { + s << m.element(r, c); + if (c < m.cols() - 1 || r < m.rows() - 1) s << ", "; + } + if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " "; + } + s << "}"; + return s; +} template -inline PIByteArray & operator <<(PIByteArray & s, const PIMathMatrix & v) {s << (const PIVector2D &)v; return s;} +inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { + s << (const PIVector2D &) v; + return s; +} + template -inline PIByteArray & operator >>(PIByteArray & s, PIMathMatrix & v) {s >> (PIVector2D &)v; return s;} +inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { + s >> (PIVector2D &) v; + return s; +} /// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0} template -inline PIMathMatrix operator *(const PIMathMatrix & fm, - const PIMathMatrix & sm) { +inline PIMathMatrix operator*(const PIMathMatrix &fm, + const PIMathMatrix &sm) { uint cr = fm.cols(), rows0 = fm.rows(), cols1 = sm.cols(); PIMathMatrix tm(cols1, rows0); if (fm.cols() != sm.rows()) return tm; @@ -1000,8 +1266,8 @@ inline PIMathMatrix operator *(const PIMathMatrix & fm, /// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows} template -inline PIMathVector operator *(const PIMathMatrix & fm, - const PIMathVector & sv) { +inline PIMathVector operator*(const PIMathMatrix &fm, + const PIMathVector &sv) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(r); if (c != sv.size()) return tv; @@ -1018,8 +1284,8 @@ inline PIMathVector operator *(const PIMathMatrix & fm, /// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols} template -inline PIMathVector operator *(const PIMathVector & sv, - const PIMathMatrix & fm) { +inline PIMathVector operator*(const PIMathVector &sv, + const PIMathMatrix &fm) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(c); Type t; @@ -1034,7 +1300,7 @@ inline PIMathVector operator *(const PIMathVector & sv, /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrix operator *(const Type & x, const PIMathMatrix & v) { +inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; } @@ -1042,9 +1308,11 @@ typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; template -PIMathMatrix > hermitian(const PIMathMatrix > & m) { +PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); - for (uint r = 0; r < ret.rows(); ++r) for (uint c = 0; c < ret.cols(); ++c) ret.element(r, c).imag(-(ret.element(r, c).imag())); + for (uint r = 0; r < ret.rows(); ++r) + for (uint c = 0; c < ret.cols(); ++c) + ret.element(r, c).imag(-(ret.element(r, c).imag())); return ret.transposed(); } From 6e100e19f556ccd15a933b48bc45bf9f88e74b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:05:22 +0300 Subject: [PATCH 22/68] doc correction --- libs/main/math/pimathmatrix.h | 853 ++++++++++++++++++------------- tests/math/testpimathmatrix.cpp | 30 +- tests/math/testpimathmatrixt.cpp | 35 +- 3 files changed, 530 insertions(+), 388 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 80f1eaab..9a767dd5 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -28,18 +28,35 @@ #include "pimathvector.h" #include "pimathcomplex.h" - +/** +* @brief Inline funtion of compare with zero different types +* +* @param v is input parameter of type T +* @return true if zero, false if not zero +*/ template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); return (piAbs(v) < T(1E-200)); } +/** +* @brief Inline funtion of compare with zero colmplexf type +* +* @param v is input parameter of type colmplexf +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } +/** +* @brief Inline funtion of compare with zero complexd type +* +* @param v is input parameter of type colmplexd +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); @@ -68,8 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -77,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identitied matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -88,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -100,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT -* - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -177,11 +205,12 @@ public: 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 - */ + * @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 + * + * @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]; @@ -189,11 +218,12 @@ public: } /** - * @brief Method which returns the selected row in PIMathVectorT format - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -201,36 +231,39 @@ public: } /** - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -242,12 +275,13 @@ public: } /** - * @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 - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -259,140 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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" - */ + * @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 + * + * @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" - */ + * @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 + * + * @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 - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -400,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -412,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -424,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -436,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -448,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -468,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -510,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -563,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -574,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -687,6 +723,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrixT type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrixT &m) { s << "{"; @@ -698,6 +741,13 @@ inline PICout operator<<(PICout s, const PIMathMatrixT &m) { } /// 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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const PIMathMatrixT &fm, const PIMathMatrixT &sm) { @@ -715,6 +765,13 @@ inline PIMathMatrixT operator*(const PIMathMatrixT inline PIMathVectorT operator*(const PIMathMatrixT &fm, const PIMathVectorT &sv) { @@ -730,6 +787,13 @@ inline PIMathVectorT operator*(const PIMathMatrixT } /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVectorT operator*(const PIMathVectorT &sv, const PIMathMatrixT &fm) { @@ -745,6 +809,13 @@ inline PIMathVectorT operator*(const PIMathVectorT &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; @@ -788,14 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -803,6 +893,11 @@ public: } } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -810,191 +905,194 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - */ + * @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 + * + * @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) _V2D::element(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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(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 - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } 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 - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::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 - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1002,11 +1100,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1014,11 +1112,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1026,11 +1124,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1038,11 +1136,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1050,10 +1148,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1070,10 +1168,10 @@ public: } /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1088,10 +1186,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1130,10 +1228,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1190,10 +1288,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1201,10 +1299,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); @@ -1218,6 +1316,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m) {s << "{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrix type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrix &m) { s << "Matrix{"; @@ -1232,12 +1337,26 @@ inline PICout operator<<(PICout s, const PIMathMatrix &m) { return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise left PIByteArray +*/ template inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { s << (const PIVector2D &) v; return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise right PIByteArray +*/ template inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { s >> (PIVector2D &) v; @@ -1246,6 +1365,13 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const PIMathMatrix &fm, const PIMathMatrix &sm) { @@ -1265,6 +1391,13 @@ inline PIMathMatrix operator*(const PIMathMatrix &fm, } /// 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 +* +* @param fm first matrix multiplier +* @param sv second vector multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathMatrix &fm, const PIMathVector &sv) { @@ -1283,6 +1416,13 @@ inline PIMathVector operator*(const PIMathMatrix &fm, /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathVector &sv, const PIMathMatrix &fm) { @@ -1299,6 +1439,13 @@ inline PIMathVector operator*(const PIMathVector &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; @@ -1307,6 +1454,12 @@ inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; +/** +* @brief Searching hermitian matrix +* +* @param m conjugate transpose matrix +* @return result of the hermitian +*/ template PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 4eeccd0c..09992b89 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -34,24 +34,22 @@ bool cmpMatrixWithValue(PIMathMatrix matrix, double val) TEST(PIMathMatrix_Test, identity) { - PIMathMatrix origMatr; - PIMathMatrix matrix; - int i; - bool b; - matrix = origMatr.identity(3, 3); - for(i = 0; i < 3; i++) - { - if(matrix[i][i] == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix = PIMathMatrix::identity(3, 3); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + 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); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixRow) diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 2d68d131..0542332a 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -38,31 +38,22 @@ bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) TEST(PIMathMatrixT_Test, identity) { - PIMathMatrixT matr; - PIMathMatrixT matrix; - double d; - double i = 1.0; - bool a; - bool output; - matrix = matr.identity(); - d = matrix.determinant(); - uint j; - for(j = 0; j < cols; j++) - { - if(matrix.at(i, i) == 1.0) a = true; - else - { - a = false; - break; + auto matrix = PIMathMatrixT::identity(); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - if((i == d) && (a == true)){ - output = true; + 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); + } + } + } } - else{ - output = false; - } - ASSERT_TRUE(output); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, at) From 3092f4f45bbcbafb9abef12c1abe99959fbdb309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:44:01 +0300 Subject: [PATCH 23/68] tab correction --- libs/main/math/pimathmatrix.h | 791 +++++++++++++++++----------------- 1 file changed, 395 insertions(+), 396 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 9a767dd5..fe1c6a66 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -85,19 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - /** - * @brief Constructor that calls the private resize method - * - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } - /** - * @brief Constructor that calls the private resize method - * - * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -105,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identity matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -116,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -128,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -205,12 +205,12 @@ public: uint rows() const { return Rows; } /** - * @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 - * - * @param index is the number of the selected column - * @return column in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -218,12 +218,12 @@ 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 - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -231,39 +231,39 @@ public: } /** - * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -275,13 +275,13 @@ 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 - * - * @param c0 is the number of the first selected column - * @param c1 is the number of the second selected column - * @return matrix type _CMatrix - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -293,142 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -436,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -448,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -460,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -472,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -484,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -504,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -546,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -599,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -610,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -859,33 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param f is type of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param val is PIVector of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector of PIVector, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -893,11 +893,11 @@ public: } } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector2D, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -905,194 +905,193 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 - * - * @param val is the vector type PIMathVector - * @return row matrix of every element that is equal to every element of the vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a column matrix of every element that is equal to every element of the vector - * - * @param val is the vector type PIMathVector - * @return column matrix of every element that is equal to every element of the vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - * - * @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 - */ + * @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 + * + * @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) _V2D::element(i, index) = v[i]; return *this; } /** - * @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 - * @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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this; } /** - * @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 - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; } - /** - * @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 - * - * @param c0 is the number of the first selected row - * @param c1 is the number of the second selected row - * @return matrix type _CMatrix - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } /** - * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros - * - * @return true if matrix is identity, else false - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix elements equal to zero, else false - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1100,11 +1099,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1112,11 +1111,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1124,11 +1123,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1136,11 +1135,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1148,10 +1147,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1168,10 +1167,10 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1186,10 +1185,10 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1228,10 +1227,10 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1288,10 +1287,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1299,10 +1298,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); From 49507b4a84e32b9fb3d1813f3f59112386d2ddee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:47:44 +0300 Subject: [PATCH 24/68] final tab correction --- libs/main/math/pimathmatrix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index fe1c6a66..8ab15e91 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -120,7 +120,7 @@ public: * * @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; @@ -965,7 +965,7 @@ public: * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; From d25522482225397a3bd28819616e2680fd918e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 10:52:09 +0300 Subject: [PATCH 25/68] tests correction --- tests/math/testpimathmatrix.cpp | 82 +++++++++------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 09992b89..d2751587 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -54,106 +54,66 @@ TEST(PIMathMatrix_Test, identity) TEST(PIMathMatrix_Test, matrixRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixRow(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 5.0) + if(matrix[0][i] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixCol(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 5.0) + if(matrix[i][0] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); + auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 10.0) + if(matrix[i][0] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); + auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 10.0) + if(matrix[0][i] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, swapCols) @@ -758,4 +718,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} +} \ No newline at end of file From 7312fa9a3677c831c9cfaf406e61a06c4e6d7b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 13:11:31 +0300 Subject: [PATCH 26/68] PIMathMatrix new tests version --- tests/math/testpimathmatrix.cpp | 517 +++++++++++--------------------- 1 file changed, 179 insertions(+), 338 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index d2751587..deeca9ca 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -1,33 +1,16 @@ #include "gtest/gtest.h" #include "pimathmatrix.h" -bool cmpMatrixWithValue(PIMathMatrix matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.element(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.element(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } @@ -57,10 +40,8 @@ TEST(PIMathMatrix_Test, matrixRow) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 3.0) { ASSERT_TRUE(false); } } @@ -72,10 +53,8 @@ TEST(PIMathMatrix_Test, matrixCol) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 3.0) { ASSERT_TRUE(false); } } @@ -89,10 +68,8 @@ TEST(PIMathMatrix_Test, setCol) auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 10.0) { ASSERT_TRUE(false); } } @@ -106,10 +83,8 @@ TEST(PIMathMatrix_Test, setRow) auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 10.0) { ASSERT_TRUE(false); } } @@ -139,25 +114,21 @@ TEST(PIMathMatrix_Test, swapCols) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(i, 0); a2[i] = matrix1.element(i, 1); a3[i] = matrix1.element(i, 2); } matrix1.swapCols(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(i, 0); b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); @@ -186,350 +157,218 @@ TEST(PIMathMatrix_Test, swapRows) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(0, i); a2[i] = matrix1.element(1, i); a3[i] = matrix1.element(2, i); } matrix1.swapRows(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(0, i); b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); } TEST(PIMathMatrix_Test, fill) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 5.0); + matrix.fill(7.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); +} + +TEST(PIMathMatrix_Test, isSquareTrue) +{ + PIMathMatrix matrix(3, 3, 1.0); + ASSERT_TRUE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isSquareFalse) +{ + PIMathMatrix matrix(2, 4, 1.0); + ASSERT_FALSE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isIdentityTrue) +{ + auto matrix = PIMathMatrix::identity(3, 3); + ASSERT_TRUE(matrix.isIdentity()); +} + +TEST(PIMathMatrix_Test, isIdentityFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isIdentity()); +} + + +TEST(PIMathMatrix_Test, isNullTrue) +{ + PIMathMatrix matrix(3, 3, 0.0); + ASSERT_TRUE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isNullFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isValidTrue) +{ + PIMathMatrix matrix(3, 3, 1.62); + ASSERT_TRUE(matrix.isValid()); +} + +TEST(PIMathMatrix_Test, isValidFalse) +{ PIMathMatrix matrix; - bool b; - matrix = origMatr.identity(3, 3); - matrix.fill(5.0); - b = cmpMatrixWithValue(matrix, 5.0); - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isSquare) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(4,3); - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isIdentity) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(3.932); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isNull) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(0.0); - matrix2.fill(3.932); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isValid) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - if((matrix1.isValid() == true) && (matrix2.isValid() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix.isValid()); } TEST(PIMathMatrix_Test, operator_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); + PIMathMatrix matrix1(3, 3, 5.72); + PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_Equal) +TEST(PIMathMatrix_Test, operator_EqualTrue) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 == matrix2) == true) && ((matrix1 == matrix3) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_Equal) +TEST(PIMathMatrix_Test, operator_EqualFalse) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 != matrix2) == false) && ((matrix1 != matrix3) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 1.0); + PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } TEST(PIMathMatrix_Test, operator_Division_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } TEST(PIMathMatrix_Test, operator_Addition) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3, 3); - matrix2 = origMatr.identity(3, 3); - origMatr.fill(8.0); - matrix1.fill(8.28); - origMatr = origMatr - matrix1; - matrix2.fill(-0.28); - if(origMatr == matrix2) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.0); + PIMathMatrix matrix2(3, 3, 5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } TEST(PIMathMatrix_Test, operator_Division) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinant) +TEST(PIMathMatrix_Test, determinantIfSquare) { - PIMathMatrix origMatr; double d; double i = 59.0; - PIMathMatrix matrix; + PIMathMatrix matrix(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -543,18 +382,23 @@ TEST(PIMathMatrix_Test, determinant) ASSERT_DOUBLE_EQ(d, i); } +TEST(PIMathMatrix_Test, determinantIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.determinant()); +} + TEST(PIMathMatrix_Test, trace) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -568,18 +412,23 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } +TEST(PIMathMatrix_Test, traceIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.trace()); +} + TEST(PIMathMatrix_Test, toUpperTriangular) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -600,19 +449,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -626,8 +473,6 @@ TEST(PIMathMatrix_Test, invert) matrix2 = matrix1; matrix2.invert(); d2 = matrix2.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -642,19 +487,17 @@ TEST(PIMathMatrix_Test, invert) TEST(PIMathMatrix_Test, inverted) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -668,8 +511,6 @@ TEST(PIMathMatrix_Test, inverted) matrix2 = matrix1; matrix1 = matrix2.invert(); d2 = matrix1.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix3 = matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -718,4 +559,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} \ No newline at end of file +} From 43078903567fb4bcaff75110b8a67a5ba0d367f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 15:27:09 +0300 Subject: [PATCH 27/68] testing another operations --- tests/math/testpimathmatrix.cpp | 80 ++++++++++++++++++++++++++++++++ tests/math/testpimathmatrixt.cpp | 73 +++++++++-------------------- 2 files changed, 101 insertions(+), 52 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index deeca9ca..ae3b46f3 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -35,6 +35,26 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } +TEST(PIMathMatrixT_Test, element) +{ + auto matrix = PIMathMatrix::identity(3, 3); + for(uint i = 0; i < 3; i++) { + if(matrix.element(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); + } + } + } + } + ASSERT_TRUE(true); +} + TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; @@ -560,3 +580,63 @@ TEST(PIMathMatrix_Test, transposed) } ASSERT_TRUE(b); } + +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathMatrix matrix2(2, 2, 2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); +} + +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + PIMathMatrix matrix1(3, 3, 1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} + +TEST(PIMathMatrixT_Test, hermitian) +{ + complex val; + complex res; + val.imag(1.0); + val.real(1.0); + PIMathMatrix> matrix(3, 3, val); + res.imag(-1.0); + res.real(1.0); + auto matr = hermitian(matrix); + for(uint i = 0; i < 3; i++) { + for(uint j = 0; j < 3; j++) { + if(matr.element(i, j) != res) { + ASSERT_TRUE(false); + } + } + } + ASSERT_TRUE(true); +} + diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 0542332a..6e4e0a45 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -4,38 +4,20 @@ const uint rows = 3; const uint cols = 3; -bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.at(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.at(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } - TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); @@ -58,26 +40,13 @@ TEST(PIMathMatrixT_Test, identity) TEST(PIMathMatrixT_Test, at) { - uint i; - bool b; - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1 = matr.identity(); - matrix2 = matr.identity(); - for(i = 0; i < rows; i++) - { - if(matrix1.at(i,i) == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix1 = PIMathMatrixT::identity(); + for(uint i = 0; i < rows; i++) { + if(matrix1.at(i,i) != 1.0) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, filled) { @@ -374,7 +343,7 @@ TEST(PIMathMatrixT_Test, operator_Assignment) bool b; matrix2.fill(6.72); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); + b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); ASSERT_TRUE(b); } @@ -444,7 +413,7 @@ TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); + b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); ASSERT_TRUE(b); } @@ -456,7 +425,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); + b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); ASSERT_TRUE(b); } @@ -466,7 +435,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) bool b; matrix1.fill(6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); + b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); ASSERT_TRUE(b); } @@ -476,7 +445,7 @@ TEST(PIMathMatrixT_Test, operator_Division_Assignment) bool b; matrix1.fill(6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); + b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); ASSERT_TRUE(b); } @@ -487,7 +456,7 @@ TEST(PIMathMatrixT_Test, operator_Addition) bool b; matrix1.fill(6.72); matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); + b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); ASSERT_TRUE(b); } @@ -498,7 +467,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction) bool b; matrix1.fill(6.0); matrix2.fill(5.0); - b = cmpMatrixWithValue(matrix1 - matrix2, 1.0); + b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); ASSERT_TRUE(b); } @@ -509,7 +478,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication) bool b; matrix1.fill(6.72); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); + b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Division) @@ -519,7 +488,7 @@ TEST(PIMathMatrixT_Test, operator_Division) bool b; matrix1.fill(6.72); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); + b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); ASSERT_TRUE(b); } @@ -721,7 +690,7 @@ TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); - ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } TEST(PIMathMatrixT_Test, rotationX) From 7948028022633f99f60a21950fb3af92a381743f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=D0=B4=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=92=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 10 Sep 2020 17:48:28 +0300 Subject: [PATCH 28/68] string tests --- tests/CMakeLists.txt | 3 +- tests/core/pistringTest.cpp | 3008 +++++++++++++++++++++++++++++++++++ 2 files changed, 3010 insertions(+), 1 deletion(-) create mode 100644 tests/core/pistringTest.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bebb15da..49c4d1be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ macro(pip_test NAME LIBS) set(_target pip_${NAME}_test) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PIP_ROOT_BINARY_DIR}") add_executable(${_target} ${_CPPS} ${_HDRS}) - target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) + target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) add_test(NAME ${_target} COMMAND tests) add_custom_target(${_target}_perform ALL COMMAND ${_target}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY) @@ -17,3 +17,4 @@ endmacro() # Concurrent tests pip_test(concurrent "") pip_test(math "") +pip_test(core "") diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp new file mode 100644 index 00000000..26f5c97f --- /dev/null +++ b/tests/core/pistringTest.cpp @@ -0,0 +1,3008 @@ +#include "gtest/gtest.h" +#include "pistring.h" +#include "pistringlist.h" + +using namespace std; + +TEST(PIString_Tests, operator_concatenation_pichar){ + PIString str1 = "AB C"; + const PIChar str2 = " "; + str1 += str2; + ASSERT_STREQ(str1, "AB C "); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero1){ + PIString str1 = ""; + const PIChar str2 = "D"; + str1 += str2; + ASSERT_STREQ(str1, "D"); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero2){ + PIString str1 = "AB C"; + const PIChar str2 = ""; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero_zero){ + PIString str1; + const PIChar str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_char){ + PIString str1 = "AB C"; + const char *str2 = "D D "; + str1 += str2; + ASSERT_STREQ(str1, "AB CD D "); +} + +TEST(PIString_Tests, operator_concatenation_char_zero1){ + PIString str1 = ""; + const char *str2 = "D D "; + str1 += str2; + ASSERT_STREQ(str1, "D D "); +} + +TEST(PIString_Tests, operator_concatenation_char_zero2){ + PIString str1 = "AB C"; + const char *str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_char_zero_zero){ + PIString str1; + const char *str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_wchar){ + PIString str1= "AB C"; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_STREQ(str1, "AB CC"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero1){ + PIString str1 = ""; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_STREQ(str1, "C"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero2){ + PIString str1 = "AB C"; + wchar_t *str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero_zero){ + PIString str1; + wchar_t *str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_pistring){ + PIString str1 = "AB C"; + PIString str2 = " CD "; + str1 += str2; + ASSERT_STREQ(str1, "AB C CD "); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero1){ + PIString str1 = ""; + PIString str2 = "D DD"; + str1 += str2; + ASSERT_STREQ(str1, "D DD"); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero2){ + PIString str1 = "AB C"; + PIString str2 = ""; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){ + PIString str1; + PIString str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray){ + PIString str1 = "AB C"; + PIByteArray str2; + str2.append('g'); + str1 += str2; + ASSERT_STREQ(str1, "AB Cg"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){ + PIString str1 = ""; + PIByteArray str2; + str2.append('0'); + str1 += str2; + ASSERT_STREQ(str1, "0"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){ + PIString str1 = "AB C"; + PIByteArray str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){ + PIString str1; + PIByteArray str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, construct_pistring){ + PIString str1 = "New"; + ASSERT_STREQ(str1, PIString("New")); +} + +TEST(PIString_Tests, construct_pichar){ + PIChar str1 = 'n'; + ASSERT_STREQ("n", PIString(str1)); +} + +TEST(PIString_Tests, construct_char){ + char str1 = 'n'; + ASSERT_STREQ("n", PIString(str1)); +} + +TEST(PIString_Tests, construct_chars){ + char str1[] = "mew"; + ASSERT_STREQ("mew", PIString(str1)); +} + +TEST(PIString_Tests, construct_wchar_t){ + wchar_t str1[] = L"gav"; + ASSERT_STREQ("gav", PIString(str1)); +} + +TEST(PIString_Tests, construct_pibyte_array){ + PIByteArray str1; + str1.append('m'); + ASSERT_STREQ("m", PIString(str1)); +} + +TEST(PIString_Tests, construct_pichar_size){ + PIChar *str1 = new PIChar[3]; + str1[0] = 'n'; + str1[1] = 'e'; + str1[2] = 'w'; + ASSERT_STREQ("new", PIString(str1, 3)); +} + +TEST(PIString_Tests, construct_char_size){ + char str1[] = "good"; + ASSERT_STREQ("good", PIString(str1, 4)); +} + +TEST(PIString_Tests, construct_char_len){ + char str1 = 'n'; + ASSERT_STREQ("nnn", PIString(3, str1)); +} + +TEST(PIString_Tests, construct_pichar_len){ + PIChar str1 = 'n'; + ASSERT_STREQ("nnnnn", PIString(5, str1)); +} + +TEST(PIString_Tests, operator_pointer){ + PIString str1 = "testing"; + const char *point = str1.operator const char *(); + ASSERT_STREQ("testing", point); +} + +TEST(PIString_Tests, operator_symbol){ + PIString str1 = "testing"; + PIChar symbo = "i"; + ASSERT_EQ(symbo, str1[4]); +} + +TEST(PIString_Tests, operator_compare_pistring_true){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pistring_false){ + PIString str1 = "tes"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "p"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_char_true){ + PIString str1 = "test"; + char str2[] = "test"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_char_false){ + PIString str1 = "t"; + char str2[] = "test"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_encompare_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pistring_true){ + PIString str1 = "tes"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "p"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_char_false){ + PIString str1 = "test"; + char str2[] = "test"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_char_true){ + PIString str1 = "t"; + char str2[] = "test"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_less_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pistring_false_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_true){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_false_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_true){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_false){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_false_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_more_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str2 > str1); +} + +TEST(PIString_Tests, operator_more_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str2 > str1); +} + +TEST(PIString_Tests, operator_more_pistring_false_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_TRUE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_false){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_false_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_true){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_TRUE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_false){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_false_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_less_eq_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_pistring_true_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_true){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_true_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_true){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_false){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_true_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_more_eq_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str2 >= str1); +} + +TEST(PIString_Tests, operator_more_eq_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str2 >= str1); +} + +TEST(PIString_Tests, operator_more_eq_pistring_true_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_false){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_true_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_true){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_false){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_FALSE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_true_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_shift_pistring){ + PIString str1 = "shift"; + PIString str2 = " good"; + str1 << str2; + ASSERT_STREQ("shift good", str1); +} + +TEST(PIString_Tests, operator_shift_pichar){ + PIString str1 = "shif"; + PIChar str2 = 't'; + str1 << str2; + ASSERT_STREQ("shift", str1); +} + +TEST(PIString_Tests, operator_shift_char){ + PIString str1 = "shif"; + char str2[] = "t chat"; + str1 << str2; + ASSERT_STREQ("shift chat", str1); +} + +TEST(PIString_Tests, operator_shift_wchar_t){ + PIString str1 = "shif"; + wchar_t str2[] = L"t cc"; + str1 << str2; + ASSERT_STREQ("shift cc", str1); +} + +TEST(PIString_Tests, operator_shift_int){ + PIString str1 = "shift "; + int numb = -2147483648; + str1 << numb; + ASSERT_STREQ("shift -2147483648", str1); +} + +TEST(PIString_Tests, operator_shift_uint){ + PIString str1 = "shift "; + uint numb = 4294967295; + str1 << numb; + ASSERT_STREQ("shift 4294967295", str1); +} + +TEST(PIString_Tests, operator_shift_short){ + PIString str1 = "shift "; + short numb = -32768; + str1 << numb; + ASSERT_STREQ("shift -32768", str1); +} + +TEST(PIString_Tests, operator_shift_ushort){ + PIString str1 = "shift "; + ushort numb = 65535; + str1 << numb; + ASSERT_STREQ("shift 65535", str1); +} + +TEST(PIString_Tests, operator_shift_long){ + PIString str1 = "shift "; + long numb = -2147483648; + str1 << numb; + ASSERT_STREQ("shift -2147483648", str1); +} + +TEST(PIString_Tests, operator_shift_ulong){ + PIString str1 = "shift "; + ulong numb = 4294967295; + str1 << numb; + ASSERT_STREQ("shift 4294967295", str1); +} + +TEST(PIString_Tests, operator_shift_llong){ + PIString str1 = "shift "; + llong numb = -9223372036854775807; + str1 << numb; + ASSERT_STREQ("shift -9223372036854775807", str1); +} + +TEST(PIString_Tests, operator_shift_ullong){ + PIString str1 = "shift "; + ullong numb = 1844674407370955161; + str1 << numb; + ASSERT_STREQ("shift 1844674407370955161", str1); +} + +TEST(PIString_Tests, operator_shift_float){ + PIString str1 = "shift "; + float numb = -67.88999939; + str1 << numb; + ASSERT_STREQ("shift -67.88999939", str1); +} + +TEST(PIString_Tests, operator_shift_double){ + PIString str1 = "shift "; + double numb = 13.34300000; + str1 << numb; + + ASSERT_STREQ("shift 13.34300000", str1); +} + +TEST(PIString_Tests, prepend){ + PIString str1 = "idea"; + PIString str2 = "Good "; + str1.prepend(str2); + ASSERT_STREQ("Good idea", str1); +} + +TEST(PIString_Tests, append){ + PIString str1 = "Good"; + PIString str2 = " idea"; + str1.append(str2); + ASSERT_STREQ("Good idea", str1); +} + +TEST(PIString_Tests, mid){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("fo", str1.mid(10, 2)); +} + +TEST(PIString_Tests, mid_len_0){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.mid(10, 0)); +} + + +TEST(PIString_Tests, mid_start_more){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.mid(1000, 0)); +} + +TEST(PIString_Tests, mid_len_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, -2)); +} + +TEST(PIString_Tests, mid_len_more){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, 100)); +} + +TEST(PIString_Tests, subString){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, 46)); +} + +TEST(PIString_Tests, mid_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.mid(-10, 47)); +} + +TEST(PIString_Tests, subString_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Go", str1.mid(-10, 12)); +} + +TEST(PIString_Tests, left){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Go", str1.left(2)); +} + +TEST(PIString_Tests, left_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.left(-2)); +} + +TEST(PIString_Tests, right){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("44", str1.right(2)); +} + +TEST(PIString_Tests, right_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.right(-2)); +} + +TEST(PIString_Tests, cutMid){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good for new project 144", str1.cutMid(5,5)); +} + +TEST(PIString_Tests, cutMid_len_zero){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutMid(5,0)); +} + +TEST(PIString_Tests, cutMid_len_min){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good ", str1.cutMid(5,-2)); +} + +TEST(PIString_Tests, cutMid_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("ood idea for new project 144", str1.cutMid(-5, 6)); +} + +TEST(PIString_Tests, cutMid_zero){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutMid(-5, 5)); +} + +TEST(PIString_Tests, cutleft){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("od idea for new project 144", str1.cutLeft(2)); +} + +TEST(PIString_Tests, cutleft_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutLeft(-2)); +} + +TEST(PIString_Tests, cutright){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 1", str1.cutRight(2)); +} + +TEST(PIString_Tests, cutright_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutRight(-2)); +} + +TEST(PIString_Tests, trim){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("Good idea for new project 144", str1.trim()); +} + +TEST(PIString_Tests, trim_without){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.trim()); +} + +TEST(PIString_Tests, trim_link){ + PIString str1 = " Good idea for new project 144 "; + PIString &str2 = str1.trim(); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, trimmed){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); +} + +TEST(PIString_Tests, trimmed_without){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); +} + +TEST(PIString_Tests, replace){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin for new project 144 ", str1.replace(6,4, "thin")); +} + +TEST(PIString_Tests, replace_more){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin", str1.replace(6,100, "thin")); +} + +TEST(PIString_Tests, replace_link){ + PIString str1 = " Good idea for new project 144 "; + PIString &str2 = str1.replace(6,4, "thin"); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, replace_minus){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD idea for new project 144 ", str1.replace(0, 5, "BAD")); +} + +TEST(PIString_Tests, replace_zero){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin Good idea for new project 144 ", str1.replace(0, 0, "thin")); +} + +TEST(PIString_Tests, replace_all){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD", str1.replaced(0, 100, "BAD")); +} + +TEST(PIString_Tests, replaced){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin for new project 144 ", str1.replaced(6,4, "thin")); +} + +TEST(PIString_Tests, replaced_minus){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD idea for new project 144 ", str1.replaced(0, 5, "BAD")); +} + +TEST(PIString_Tests, replaced_zero){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin Good idea for new project 144 ", str1.replaced(0, 0, "thin")); +} + + +TEST(PIString_Tests, replaced_all){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin", str1.replaced(0, 100, "thin")); +} + +TEST(PIString_Tests, replace_str){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "bad", &ok); + ASSERT_STREQ(" bad idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replace_str_link){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString &str2 = str1.replace("Good", "bad", &ok); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, replace_str_zero){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("", "bad", &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, replace_str_true){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "bad", &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, replace_str_delete){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "", &ok); + ASSERT_STREQ(" idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replaced_str){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString str2 = str1.replaced("Good", "bad", &ok); + ASSERT_STREQ(" bad idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaced_str_zero){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replaced("", "bad", &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, replaced_str_true){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replaced("Good", "bad", &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, replaced_delete){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString str2 = str1.replaced("Good", "", &ok); + ASSERT_STREQ(" idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaceall){ + PIString str1 = " Good idea for new Good project 144 "; + str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str1); +} + +TEST(PIString_Tests, replaceall_no_find){ + PIString str1 = " Good idea for new Good project 144 "; + str1.replaceAll("God", "bad"); + ASSERT_STREQ(" Good idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replaceall_str){ + PIString str1 = " Good idea for new Good project 144 "; + PIString str2 = str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_str_no_find){ + PIString str1 = " Good idea for new Good project 144 "; + PIString str2 = str1.replaceAll("God", "bad"); + ASSERT_STREQ(" Good idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_link){ + PIString str1 = " Good idea for new Good project 144 "; + PIString &str2 = str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_link_change){ + PIString str1 = " Good idea for new Good project 144 "; + PIString &str2 = str1.replaceAll("Good", "bad"); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, repeat){ + PIString str1 = "string "; + PIString str2 = str1.repeat(6); + ASSERT_STREQ("string string string string string string ", str2); +} + +TEST(PIString_Tests, repeat_zero){ + PIString str1 = "string "; + PIString str2 = str1.repeat(0); + ASSERT_STREQ("string ", str2); +} + +TEST(PIString_Tests, repeat_link){ + PIString str1 = "string "; + PIString &str2 = str1.repeat(6); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, repeated){ + PIString str1 = "string "; + str1.repeat(6); + ASSERT_STREQ("string string string string string string ", str1); +} + +TEST(PIString_Tests, repeated_zero){ + PIString str1 = "string "; + str1.repeat(0); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_char){ + PIString str1 = "strng "; + char sym = 'i'; + str1.insert(3, sym); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_pichar){ + PIString str1 = "strng "; + PIChar sym = 'i'; + str1.insert(3, sym); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_pistring){ + PIString str1 = "string out"; + PIString str2 = " go"; + str1.insert(6, str2); + ASSERT_STREQ("string go out", str1); +} + +TEST(PIString_Tests, insert_chars){ + PIString str1 = "see boy"; + char str2[] = " big"; + str1.insert(3, str2); + ASSERT_STREQ("see big boy", str1); +} + +TEST(PIString_Tests, expandRightTo){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandRightTo(11, symbol); + ASSERT_STREQ("see boy xxx", str1); +} + +TEST(PIString_Tests, expandRightTo_null){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandRightTo(0, symbol); + ASSERT_STREQ("see boy ", str1); +} + +TEST(PIString_Tests, expandLeftTo){ + PIString str1 = " see boy"; + PIChar symbol = "x"; + str1.expandLeftTo(11, symbol); + ASSERT_STREQ("xxx see boy", str1); +} + +TEST(PIString_Tests, expandLeftTo_null){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandLeftTo(0, symbol); + ASSERT_STREQ("see boy ", str1); +} + +TEST(PIString_Tests, quote){ + PIString str1 = "see boy"; + PIChar symbol = " "; + str1.quote(symbol); + ASSERT_STREQ(" see boy ", str1); +} + +TEST(PIString_Tests, quote_link){ + PIString str1 = "see boy"; + PIChar symbol = " "; + PIString &str2 = str1.quote(symbol); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, quoted){ + PIString str1 = "see boy"; + PIChar symbol = " "; + PIString str2 = str1.quoted(symbol); + ASSERT_STREQ(" see boy ", str2); +} + +TEST(PIString_Tests, reverse){ + PIString str1 = "see boy"; + PIString &str2 = str1.reverse(); + ASSERT_STREQ("yob ees", str2); +} + +TEST(PIString_Tests, reverse_link){ + PIString str1 = "see boy"; + PIString &str2 = str1.reverse(); + str1 = "yes"; + ASSERT_STREQ("yes", str2); +} + +TEST(PIString_Tests, reversed){ + PIString str1 = "see boy"; + PIString str2 = str1.reversed(); + ASSERT_STREQ("yob ees", str2); +} + +TEST(PIString_Tests, elide){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(8, 1); + ASSERT_STREQ("BMSTU ..", str2); +} + +TEST(PIString_Tests, elide_small){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(2, 1); + ASSERT_STREQ("..", str2); +} + +TEST(PIString_Tests, elide_all){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(100, 1); + ASSERT_STREQ("BMSTU is best university in space", str2); +} + +TEST(PIString_Tests, elide_link){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(8, 1); + str1 = "space"; + ASSERT_STREQ("space", str2); +} + +TEST(PIString_Tests, elided){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.elided(8, 1); + ASSERT_STREQ("BMSTU ..", str2); +} + +TEST(PIString_Tests, takemid){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeMid(9, 4); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, takeleft){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeLeft(5); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeright){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRight(5); + ASSERT_STREQ("space", str2); +} + +TEST(PIString_Tests, takesymbol){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("B", str2); +} + +TEST(PIString_Tests, takesymbol_with_rubbish){ + PIString str1 = " \t \n \r BMSTU is best university in space"; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("B", str2); +} + +TEST(PIString_Tests, takesymbol_without){ + PIString str1 = " \t \n \r "; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeword){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeword_space){ + PIString str1 = " \r\n\tBMSTU is best university in space"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeword_without_word){ + PIString str1 = " \r\n\t"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takecword){ + PIString str1 = "_6 BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("_6", str2); +} + +TEST(PIString_Tests, takecword_space){ + PIString str1 = " \t\r\n_6 BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("_6", str2); +} + +TEST(PIString_Tests, takecword_space_w){ + PIString str1 = " \t\r\n BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takecword_not_cword){ + PIString str1 = " \t\r\n "; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeline){ + PIString str1 = "BMSTU is best\n university in space"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("BMSTU is best", str2); +} + +TEST(PIString_Tests, takeline_without){ + PIString str1 = "BMSTU is best"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeline_first){ + PIString str1 = "\nBMSTU is best"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takenumber){ + PIString str1 = "6.6"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("6.6", str2); +} + +TEST(PIString_Tests, takenumber_sign){ + PIString str1 = "-66"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("-66", str2); +} + +TEST(PIString_Tests, takenumber_suffix){ + PIString str1 = "66L"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("66L", str2); +} + +TEST(PIString_Tests, takerange){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i', ' '); + ASSERT_STREQ("MSTU is best un", str2); +} + +TEST(PIString_Tests, takerange_without_shield){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i'); + ASSERT_STREQ("MSTU ", str2); +} + +TEST(PIString_Tests, takerange_space){ + PIString str1 = " \t\r\nBMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i', ' '); + ASSERT_STREQ("MSTU is best un", str2); +} + +TEST(PIString_Tests, takerange_without_shield_space){ + PIString str1 = " \t\r\nBMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i'); + ASSERT_STREQ("MSTU ", str2); +} + +TEST(PIString_Tests, inBrackets){ + PIString str1 = "BMSTU is (best) university in space"; + PIString str2 = str1.inBrackets('(', ')'); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, inBrackets_end_start){ + PIString str1 = "BMSTU )is (best) university in space"; + PIString str2 = str1.inBrackets('(', ')'); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, inBrackets_without){ + PIString str1 = "BMSTU )is (best) university in space"; + PIString str2 = str1.inBrackets('0', '1'); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, lenghtascii){ + PIString str1 = "BMSTU is (best) university in space"; + int size = str1.lengthAscii(); + ASSERT_EQ(35, size); +} + +TEST(PIString_Tests, data){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.data(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataconsole){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataConsole(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataUTF8){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataUTF8(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataAScii){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataAscii(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, hash){ + const PIString str1 = "B"; + uint h = str1.hash(); + ASSERT_EQ(3912571919, h); +} + +TEST(PIString_Tests, toByteArray){ + const PIString str1 = "C"; + PIByteArray h = str1.toByteArray(); + ASSERT_EQ(67, h.at(0)); +} + +TEST(PIString_Tests, toUTF8){ + const PIString str1 = "C"; + PIByteArray h = str1.toUTF8(); + ASSERT_EQ(67, h.at(0)); +} + +TEST(PIString_Tests, tocharset){ + const PIString str1 = "B"; + PIByteArray h = str1.toCharset("c"); + ASSERT_EQ(66, h.at(0)); +} + +TEST(PIString_Tests, toUTF8_empty){ + PIString str1; + str1.toUTF8(); + ASSERT_EQ(0, str1.size()); +} + +TEST(PIString_Tests, tocharset_empty){ + PIString str1 = ""; + str1.toCharset("c"); + ASSERT_EQ(0, str1.size()); +} + +TEST(PIString_Tests, split){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split("best"); + ASSERT_STREQ(list[1], list[0]); +} + +TEST(PIString_Tests, split_empty){ + PIString str1 = ""; + PIStringList list = str1.split("best"); + ASSERT_EQ(0, list.size()); +} + +TEST(PIString_Tests, split_empty_delim){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split(""); + ASSERT_EQ(0, list.size()); +} + +TEST(PIString_Tests, split_not_delim){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split("tr"); + ASSERT_STREQ(list[0], " mirrow best mirrow "); +} + +TEST(PIString_Tests, toUpperCase){ + PIString str1 = " miRrow "; + PIString str2 = str1.toUpperCase(); + ASSERT_STREQ(" MIRROW ", str2); +} + +TEST(PIString_Tests, toLowerCase){ + PIString str1 = " MIrROW "; + PIString str2 = str1.toLowerCase(); + ASSERT_STREQ(" mirrow ", str2); +} + +TEST(PIString_Tests, toNativeDecimalPoints){ + PIString str1 = "4546,878"; + PIString str2 = str1.toNativeDecimalPoints(); + ASSERT_STREQ("4546.878", str2); +} + +TEST(PIString_Tests, contains_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = '\n'; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = '0'; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_picahr){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIChar s = 'i'; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_pichar_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIChar s = '0'; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_cahrs){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "BMSTU"; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "out"; + ASSERT_FALSE(str1.contains(s)); +} + + +TEST(PIString_Tests, contains_pistring){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString s = "univer"; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString s = "new"; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, find_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(6, str1.find(s)); +} + +TEST(PIString_Tests, find_char_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(18, str1.find(s, 7)); +} + +TEST(PIString_Tests, find_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'o'; + ASSERT_EQ(-1, str1.find(s)); +} + +TEST(PIString_Tests, find_chars){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "is"; + ASSERT_EQ(6, str1.find(str2)); +} + +TEST(PIString_Tests, find_chars_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "iv"; + ASSERT_EQ(18, str1.find(str2, 7)); +} + +TEST(PIString_Tests, find_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "ouc"; + ASSERT_EQ(-1, str1.find(s)); +} + +TEST(PIString_Tests, find_pistring){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "is"; + ASSERT_EQ(6, str1.find(str2)); +} + +TEST(PIString_Tests, find_pistring_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "iv"; + ASSERT_EQ(18, str1.find(str2, 7)); +} + +TEST(PIString_Tests, find_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "ouc"; + ASSERT_EQ(-1, str1.find(str2)); +} + +TEST(PIString_Tests, find_last_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(27, str1.findLast(s)); +} + +TEST(PIString_Tests, find_last_char_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(27, str1.findLast(s, 20)); +} + +TEST(PIString_Tests, find_last_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'o'; + ASSERT_EQ(-1, str1.findLast(s)); +} + +TEST(PIString_Tests, find_last_chars){ + PIString str1 = "BMSTU is (best) university in is space\n"; + char str2[] = "is"; + ASSERT_EQ(30, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_chars_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + char str2[] = "iv"; + ASSERT_EQ(30, str1.findLast(str2, 25)); +} + +TEST(PIString_Tests, find_last_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "ouc"; + ASSERT_EQ(-1, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_pistring){ + PIString str1 = "BMSTU is (best) university in is space\n"; + PIString str2 = "is"; + ASSERT_EQ(30, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_pistring_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "iv"; + ASSERT_EQ(30, str1.findLast(str2, 10)); +} + +TEST(PIString_Tests, find_last_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "ouc"; + ASSERT_EQ(-1, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_word){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findWord(str2)); +} + +TEST(PIString_Tests, find_word_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_space_before){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = " university"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_space_after){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university "; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_digit_before){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "_university"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_digit_after){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "university_"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "university"; + ASSERT_EQ(-1, str1.findWord(str2, 37)); +} + +TEST(PIString_Tests, find_cword){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findCWord(str2)); +} + +TEST(PIString_Tests, find_cword_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_space_before){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = " university"; + ASSERT_EQ(15, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_space_after){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university "; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_digit_before){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "_university"; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_digit_after){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "university_"; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "university"; + ASSERT_EQ(-1, str1.findCWord(str2, 37)); +} + +TEST(PIString_Tests, find_range){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + ASSERT_EQ(3, str1.findRange(start, end, "n", 1, len)); +} + +TEST(PIString_Tests, find_range_len){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + str1.findRange(start, end, "n", 1, len); + ASSERT_EQ(14, *len); +} + +TEST(PIString_Tests, find_range_len_without_shield){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + str1.findRange(start, end, "/", 1, len); + ASSERT_EQ(9, *len); +} + +TEST(PIString_Tests, find_range_start){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "g"; + PIChar end = "o"; + int *len; + str1.findRange(start, end, " ", 17, len); + ASSERT_EQ(9, *len); +} + +TEST(PIString_Tests, find_range_eq){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "v"; + int *len; + str1.findRange(start, end, "n", 1, len); + ASSERT_EQ(0, *len); +} + +TEST(PIString_Tests, find_range_trim){ + PIString str1 = " A very strong programmer wrote this code"; + PIChar start = "A"; + PIChar end = "v"; + int *len; + ASSERT_EQ(2, str1.findRange(start, end, "n", 0, len)); +} + +TEST(PIString_Tests, find_any){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(11, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_not){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "q"; + ASSERT_EQ(-1, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_start){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(15, str1.findAny(str2, 12)); +} + +TEST(PIString_Tests, find_any_chars){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(11, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_chars_not){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "q"; + ASSERT_EQ(-1, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_chars_start){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(15, str1.findAny(str2, 12)); +} + +TEST(PIString_Tests, find_any_last){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_not){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "q"; + ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_start){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 12)); +} + +TEST(PIString_Tests, find_any_last_chars){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_chars_not){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "q"; + ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_chars_start){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 12)); +} + +TEST(PIString_Tests, entries){ + PIString str1 = " A very strong programmer wrote this code"; + PIChar c = "A"; + ASSERT_EQ(1, str1.entries(c)); +} + +TEST(PIString_Tests, entries_char){ + PIString str1 = " A very strong programmer wrote this code"; + char c = 'A'; + ASSERT_EQ(1, str1.entries(c)); +} + +TEST(PIString_Tests, starts_with){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " A very"; + ASSERT_TRUE(str1.startsWith(str2)); +} + +TEST(PIString_Tests, starts_with_false){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " A veru"; + ASSERT_FALSE(str1.startsWith(str2)); +} + +TEST(PIString_Tests, ends_with){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " code"; + ASSERT_TRUE(str1.endsWith(str2)); +} + +TEST(PIString_Tests, ends_with_false){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "c code"; + ASSERT_FALSE(str1.endsWith(str2)); +} + +TEST(PIString_Tests, length){ + PIString str1 = " A very strong programmer wrote this code"; + ASSERT_EQ(41, str1.length()); +} + +TEST(PIString_Tests, is_empty_false){ + PIString str1 = " A very strong programmer wrote this code"; + ASSERT_FALSE(str1.isEmpty()); +} + +TEST(PIString_Tests, is_empty_true){ + PIString str1 = ""; + ASSERT_TRUE(str1.isEmpty()); +} + +TEST(PIString_Tests, to_bool){ + PIString str1 = "1"; + ASSERT_TRUE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_yes){ + PIString str1 = "yes"; + ASSERT_TRUE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_false){ + PIString str1 = "no"; + ASSERT_FALSE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_false_zero){ + PIString str1 = "0"; + ASSERT_FALSE(str1.toBool()); +} + +TEST(PIString_Tests, to_char){ + PIString str1 = "A very strong programmer wrote this code"; + ASSERT_EQ(65, str1.toChar()); +} + +TEST(PIString_Tests, to_short){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toShort(-1)); +} + +TEST(PIString_Tests, to_short_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toShort(-1)); +} + +TEST(PIString_Tests, to_short_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toShort(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_short_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toShort(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_short_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toShort(10, ok)); +} + +TEST(PIString_Tests, to_ushort){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toUShort(-1)); +} + +TEST(PIString_Tests, to_ushort_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toUShort(-1)); +} + +TEST(PIString_Tests, to_ushort_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toUShort(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ushort_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toUShort(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ushort_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(65529, str1.toUShort(10, ok)); +} + +TEST(PIString_Tests, to_int){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toInt(-1)); +} + +TEST(PIString_Tests, to_int_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toInt(-1)); +} + +TEST(PIString_Tests, to_int_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toInt(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_int_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toInt(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_int_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toShort(10, ok)); +} + +TEST(PIString_Tests, to_uint){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toUInt(-1)); +} + +TEST(PIString_Tests, to_uint_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toUInt(-1)); +} + +TEST(PIString_Tests, to_uint_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toUInt(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_uint_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toUInt(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_uint_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(4294967289, str1.toUInt(10, ok)); +} + +TEST(PIString_Tests, to_long){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toLong(-1)); +} + +TEST(PIString_Tests, to_long_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toLong(-1)); +} + +TEST(PIString_Tests, to_long_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_long_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_long_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toLong(10, ok)); +} + +TEST(PIString_Tests, to_ulong){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toULong(-1)); +} + +TEST(PIString_Tests, to_ulong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toULong(-1)); +} + +TEST(PIString_Tests, to_ulong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toULong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ulong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toULong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ulong_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(4294967289, str1.toULong(10, ok)); +} + +TEST(PIString_Tests, to_llong){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toLLong(-1)); +} + +TEST(PIString_Tests, to_llong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toLLong(-1)); +} + +TEST(PIString_Tests, to_llong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toLLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_llong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toLLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_llong_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toLLong(10, ok)); +} + +TEST(PIString_Tests, to_ullong){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toULLong(-1)); +} + +TEST(PIString_Tests, to_ullong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toULLong(-1)); +} + +TEST(PIString_Tests, to_ullong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toULLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ullong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toULLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ullong_neg){ + PIString str1 = "-7"; + bool *ok; + ullong f = 184467451609; + ASSERT_EQ(f, str1.toULLong(10, ok)); +} + +TEST(PIString_Tests, to_float){ + PIString str1 = "-7765,54"; + float f = -7765.54; + ASSERT_EQ(f, str1.toFloat()); +} + +TEST(PIString_Tests, to_double){ + PIString str1 = "-7765,54656"; + double f = -7765.54656; + ASSERT_EQ(f, str1.toDouble()); +} + +TEST(PIString_Tests, to_ldouble){ + PIString str1 = "-7765,54656"; + ldouble f = -7765.54656; + ASSERT_EQ(f, str1.toLDouble()); +} + +TEST(PIString_Tests, setNumber){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_zero){ + PIString str1 = " String"; + const short val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_false_base){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_true){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_false_base_str){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_base_minus){ + PIString str1 = " String"; + const short val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ushort){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ushort_true){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ushort_zero){ + PIString str1 = " String"; + const ushort val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ushort_false_base){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ushort_false_base_str){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ushort_base_minus){ + PIString str1 = " String"; + const ushort val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_int){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_int_zero){ + PIString str1 = " String"; + const int val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_int_false_base){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_int_true){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_int_false_base_str){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_int_base_minus){ + PIString str1 = " String"; + const int val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_uint){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_uint_true){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_uintt_zero){ + PIString str1 = " String"; + const uint val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_uint_false_base){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_uint_false_base_str){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_uint_base_minus){ + PIString str1 = " String"; + const uint val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_long){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_long_zero){ + PIString str1 = " String"; + const long val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_long_false_base){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_long_true){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_long_false_base_str){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_long_base_minus){ + PIString str1 = " String"; + const long val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ulong){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ulong_true){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ulong_zero){ + PIString str1 = " String"; + const ulong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ulong_false_base){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ulong_false_base_str){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ulong_base_minus){ + PIString str1 = " String"; + const ulong val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_llong){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_llong_zero){ + PIString str1 = " String"; + const llong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_llong_false_base){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_llong_true){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_llong_false_base_str){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_llong_base_minus){ + PIString str1 = " String"; + const llong val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ullong){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ullong_true){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ullong_zero){ + PIString str1 = " String"; + const ullong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ullong_false_base){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ullong_false_base_str){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ullong_base_minus){ + PIString str1 = " String"; + const ullong val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_float){ + PIString str1 = " String"; + const float val = 131.132; + str1.setNumber(val, 'f', 3); + ASSERT_STREQ("131.132", str1); +} + +TEST(PIString_Tests, setNumber_double){ + PIString str1 = " String"; + const double val = 131.1324334; + str1.setNumber(val, 'f', 7); + ASSERT_STREQ("131.1324334", str1); +} + +TEST(PIString_Tests, setNumber_ldouble){ + PIString str1 = " String"; + const ldouble val = 131.1324334; + str1.setNumber(val, 'f', 7); + ASSERT_STREQ("131.1324334", str1); +} + +TEST(PIString_Tests, setReadableSize){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1023 B", str1.setReadableSize(1023)); +} + +TEST(PIString_Tests, setReadableSize_kb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 kB", str1.setReadableSize(1024)); +} + +TEST(PIString_Tests, setReadableSize_mb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 MB", str1.setReadableSize(1024*1024)); +} + +TEST(PIString_Tests, setReadableSize_gb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 GB", str1.setReadableSize(1024*1024*1024)); +} + +TEST(PIString_Tests, setReadableSize_tb){ + PIString str1 = " ITELMA"; + llong val = 99999999999999; + ASSERT_STREQ("90.9 TB", str1.setReadableSize(val)); +} + +TEST(PIString_Tests, setReadableSize_pb){ + PIString str1 = " ITELMA"; + llong val = 999999999999999999; + ASSERT_STREQ("888.1 PB", str1.setReadableSize(val)); +} + +TEST(PIString_Tests, fromNumber){ + PIString str1 = " String"; + const short val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumberr_zero){ + PIString str1 = " String"; + const short val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_false_base){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_true){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_false_base_str){ + PIString str1 = " String"; + const short val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_base_minus){ + PIString str1 = " String"; + const short val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_true){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ushort_zero){ + PIString str1 = " String"; + const ushort val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_false_base){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ushort_false_base_str){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_base_minus){ + PIString str1 = " String"; + const ushort val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_int){ + PIString str1 = " String"; + const int val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_zero){ + PIString str1 = " String"; + const int val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_false_base){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_int_true){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_int_false_base_str){ + PIString str1 = " String"; + const int val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_base_minus){ + PIString str1 = " String"; + const int val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_true){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_uintt_zero){ + PIString str1 = " String"; + const uint val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_false_base){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_uint_false_base_str){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_base_minus){ + PIString str1 = " String"; + const uint val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_long){ + PIString str1 = " String"; + const long val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_zero){ + PIString str1 = " String"; + const long val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_false_base){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_long_true){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_long_false_base_str){ + PIString str1 = " String"; + const long val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_base_minus){ + PIString str1 = " String"; + const long val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_true){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ulong_zero){ + PIString str1 = " String"; + const ulong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_false_base){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ulong_false_base_str){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_base_minus){ + PIString str1 = " String"; + const ulong val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_zero){ + PIString str1 = " String"; + const llong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_false_base){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_llong_true){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_llong_false_base_str){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_base_minus){ + PIString str1 = " String"; + const llong val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_true){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ullong_zero){ + PIString str1 = " String"; + const ullong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_false_base){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ullong_false_base_str){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_base_minus){ + PIString str1 = " String"; + const ullong val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_float){ + PIString str1 = " String"; + const float val = 131.132; + ASSERT_STREQ("131.132", str1.fromNumber(val, 'f', 3)); +} + +TEST(PIString_Tests, fromNumber_double){ + PIString str1 = " String"; + const double val = 131.1324334; + ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); +} + +TEST(PIString_Tests, fromNumber_ldouble){ + PIString str1 = " String"; + const ldouble val = 131.1324334; + ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); +} + +TEST(PIString_Tests, fromBool_true){ + PIString str1; + bool val = true; + ASSERT_STREQ("true", str1.fromBool(val)); +} + +TEST(PIString_Tests, fromBool_false){ + PIString str1; + bool val = false; + ASSERT_STREQ("false", str1.fromBool(val)); +} + +TEST(PIString_Tests, from_Console){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromConsole(s)); +} + +TEST(PIString_Tests, from_System){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromSystem(s)); +} + +TEST(PIString_Tests, from_UTF8){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromUTF8(s)); +} + +TEST(PIString_Tests, from_UTF8_ba){ + PIString str1; + PIByteArray s; + s.append('t'); + s.append('r'); + s.append('u'); + s.append('e'); + ASSERT_STREQ("true", str1.fromUTF8(s)); +} + +TEST(PIString_Tests, from_Ascii){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromAscii(s)); +} + +TEST(PIString_Tests, from_Codepage){ + PIString str1 = "Nul"; + char s[] = "true"; + char c[] = "utf8"; + PIString str2 = str1.fromCodepage(s, c); + ASSERT_STREQ("true", str2); +} + +TEST(PIString_Tests, ReadableSize){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1023 B", str1.readableSize(1023)); +} + +TEST(PIString_Tests, readableSize_kb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 kB", str1.readableSize(1024)); +} + +TEST(PIString_Tests, readableSize_mb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 MB", str1.readableSize(1024*1024)); +} + +TEST(PIString_Tests, readableSize_gb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 GB", str1.readableSize(1024*1024*1024)); +} + +TEST(PIString_Tests, readableSize_tb){ + PIString str1 = " ITELMA"; + llong val = 99999999999999; + ASSERT_STREQ("90.9 TB", str1.readableSize(val)); +} + +TEST(PIString_Tests, readableSize_pb){ + PIString str1 = " ITELMA"; + llong val = 999999999999999999; + ASSERT_STREQ("888.1 PB", str1.readableSize(val)); +} + +TEST(PIString_Tests, removeAll_char){ + PIString str1 = "A very strong programmer wrote this code"; + char v = ' '; + ASSERT_STREQ("Averystrongprogrammerwrotethiscode", str1.removeAll(v)); +} + +TEST(PIString_Tests, removeAll_pistring){ + PIString str1 = "A very strong programmer wrote this code"; + PIString v = "very strong "; + ASSERT_STREQ("A programmer wrote this code", str1.removeAll(v)); +} + +TEST(PIString_Tests, operator_ba_pstr){ + PIString str1 = '1'; + PIByteArray s; + s << str1; + ASSERT_STREQ("010000003100", s.toHex()); +} + +TEST(PIString_Tests, operator_pstr_ba){ + PIString str1 = "1"; + PIByteArray s; + s.append('t'); + s.append('r'); + s.append('u'); + s.append('e'); + str1 << s; + ASSERT_STREQ("1true", str1); +} + +TEST(PIString_Tests, operator_plus_pstr_pstr){ + PIString str1 = "first "; + PIString str2 = "second"; + ASSERT_STREQ("first second", str1 + str2); +} + +TEST(PIString_Tests, operator_plus_pstr_chars){ + PIString str1 = "first "; + char str2[] = "second"; + ASSERT_STREQ("first second", str1 + str2); +} + +TEST(PIString_Tests, operator_plus_chars_pstr){ + PIString str1 = "first"; + char str2[] = "second "; + ASSERT_STREQ("second first", str2 + str1); +} + +TEST(PIString_Tests, versionCompare2){ //дописать + PIString str1 = "first"; + PIString str2 = "first 1"; + versionCompare(str1, str2, 0); + ASSERT_EQ(898448032, piHash(str1)); +} + +TEST(PIString_Tests, versionNormalize2){ //дописать + PIString str1 = "first"; + cout << versionNormalize(str1); + ASSERT_EQ(1, 1); +} + +TEST(PIString_Tests, piHash){ + PIString str1 = "first"; + ASSERT_EQ(898448032, piHash(str1)); +} + +TEST(PIString_Tests, piSwap){ + PIString str1 = "first"; + PIString str2 = "second"; + piSwap(str1, str2); + ASSERT_STREQ("first", str2); +} + +TEST(PIString_Tests, piSwap_sec){ + PIString str1 = "first"; + PIString str2 = "second"; + piSwap(str1, str2); + ASSERT_STREQ("second", str1); +} + + + + + + + + + + + From f72d4bcda4682f3d85e57cf8bc2bc29ab391e834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 16:56:04 +0300 Subject: [PATCH 29/68] overall PIMathMatrix tests correction --- tests/math/testpimathmatrix.cpp | 44 +-- tests/math/testpimathmatrixt.cpp | 584 +++++++++++-------------------- 2 files changed, 206 insertions(+), 422 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index ae3b46f3..2b045000 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -470,7 +470,6 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -494,21 +493,12 @@ TEST(PIMathMatrix_Test, invert) matrix2.invert(); d2 = matrix2.determinant(); matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, inverted) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -532,22 +522,13 @@ TEST(PIMathMatrix_Test, inverted) matrix1 = matrix2.invert(); d2 = matrix1.determinant(); matrix3 = matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; - bool b; PIMathMatrix matrix1; PIMathMatrix matrix2; PIMathMatrix matrix3; @@ -570,25 +551,17 @@ TEST(PIMathMatrix_Test, transposed) matrix2 = matrix1.transposed(); d2 = matrix2.determinant(); matrix3 = matrix2.transposed(); - if((d1 == d2) && (matrix1 == matrix3)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrixT_Test, matrixMultiplication) +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -601,7 +574,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -614,13 +587,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrixT_Test, hermitian) +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; @@ -639,4 +612,3 @@ TEST(PIMathMatrixT_Test, hermitian) } ASSERT_TRUE(true); } - diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 6e4e0a45..a006b3cd 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -50,21 +50,8 @@ TEST(PIMathMatrixT_Test, at) } TEST(PIMathMatrixT_Test, filled) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - PIMathVectorT vect; - double g = 1.0; - matrix2 = matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { - matrix1.at(j,i) = g; - } - } - ASSERT_TRUE(matrix2 == matrix1); + auto matr = PIMathMatrixT::filled(1.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } TEST(PIMathMatrixT_Test, cols) @@ -83,9 +70,7 @@ TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -96,28 +81,18 @@ TEST(PIMathMatrixT_Test, col) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.col(g); - for(i = 0; i < matr.cols(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.cols(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, row) -{ - PIMathMatrixT matr; +{ PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -128,19 +103,12 @@ TEST(PIMathMatrixT_Test, row) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.row(g); - for(i = 0; i < matr.rows(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.rows(); i++) { + if(matr.at(g, i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setCol) @@ -151,22 +119,13 @@ TEST(PIMathMatrixT_Test, setCol) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setCol(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setRow) @@ -177,33 +136,19 @@ TEST(PIMathMatrixT_Test, setRow) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setRow(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(g,i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -213,31 +158,23 @@ TEST(PIMathMatrixT_Test, swapCols) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.col(g1); - before_Vect2 = matr.col(g2); - matr.swapCols(g1,g2); - after_Vect1 = matr.col(g1); - after_Vect2 = matr.col(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.col(g1); + const PIMathVectorT before_Vect2 = matr.col(g2); + matr.swapCols(g1, g2); + const PIMathVectorT after_Vect1 = matr.col(g1); + const PIMathVectorT after_Vect2 = matr.col(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -247,20 +184,17 @@ TEST(PIMathMatrixT_Test, swapRows) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.row(g1); - before_Vect2 = matr.row(g2); - matr.swapRows(g1,g2); - after_Vect1 = matr.row(g1); - after_Vect2 = matr.row(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.row(g1); + const PIMathVectorT before_Vect2 = matr.row(g2); + matr.swapRows(g1, g2); + const PIMathVectorT after_Vect1 = matr.row(g1); + const PIMathVectorT after_Vect2 = matr.row(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, fill) @@ -269,231 +203,175 @@ TEST(PIMathMatrixT_Test, fill) PIMathMatrixT matrix1; double g = 1.0; matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { + for(uint i = 0; i < cols; i++) { + for(uint j = 0; j < rows; j++) { matrix1.at(j,i) = g; } } ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquare) +TEST(PIMathMatrixT_Test, isSquareTrue) { - PIMathMatrixT matr; PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isSquare()); +} + +TEST(PIMathMatrixT_Test, isSquareFalse) +{ const uint new_Cols = 4; PIMathMatrixT matrix2; - bool b; - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentity) +TEST(PIMathMatrixT_Test, isIdentityTrue) { - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1 = matr.identity(); - matrix2 = matr.filled(3.67); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNull) +TEST(PIMathMatrixT_Test, isIdentityFalse) +{ + auto matrix1 = PIMathMatrixT::filled(2.5); + ASSERT_FALSE(matrix1.isIdentity()); +} + +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2 = matr.filled(3.67); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE(matrix1.isNull()); +} + +TEST(PIMathMatrixT_Test, isNullFalse) +{ + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_FALSE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2.fill(6.72); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Equal) +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr == matrix1) == true) && ((matr == matrix2) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_Equal) +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - bool b; - PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr != matrix1) == false) && ((matr != matrix2) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(6.72) ; + auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(1.0); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.0); - matrix2.fill(5.0); - b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1*4.0; - b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1/4.0; - b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } - -TEST(PIMathMatrixT_Test, determinant) +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; @@ -511,6 +389,21 @@ TEST(PIMathMatrixT_Test, determinant) ASSERT_DOUBLE_EQ(i, d); } +TEST(PIMathMatrixT_Test, determinantIfNotSquare) +{ + PIMathMatrixT matr; + matr.at(0,0) = 3; + matr.at(0,1) = 6; + matr.at(0,2) = 8; + matr.at(1,0) = 2; + matr.at(1,1) = 1; + matr.at(1,2) = 4; + matr.at(2,0) = 6; + matr.at(2,1) = 2; + matr.at(2,2) = 5; + ASSERT_FALSE(matr.determinant()); +} + TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; @@ -518,8 +411,6 @@ TEST(PIMathMatrixT_Test, invert) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; - matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -535,15 +426,7 @@ TEST(PIMathMatrixT_Test, invert) d2 = matrix2.determinant(); matrix3 = matrix1; matrix1.invert(); - if((matrix1 == matrix3) && (d1 == 1/d2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } TEST(PIMathMatrixT_Test, inverted) @@ -553,7 +436,6 @@ TEST(PIMathMatrixT_Test, inverted) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -568,22 +450,13 @@ TEST(PIMathMatrixT_Test, inverted) d1 = matr.determinant(); d2 = matrix2.determinant(); matrix3 = matrix1.inverted(); - if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; - uint i; PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -596,7 +469,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) matr.at(2,2) = 5; matrix = matr.toUpperTriangular(); d1 = matrix.determinant(); - for(i = 0; i < cols; i++) + for(uint i = 0; i < cols; i++) { d2 = d2*matrix.at(i,i); } @@ -609,7 +482,6 @@ TEST(PIMathMatrixT_Test, transposed) PIMathMatrixT matrix2; PIMathMatrixT matr; double d1, d2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -623,67 +495,30 @@ TEST(PIMathMatrixT_Test, transposed) matrix1 = matr.transposed(); d2 = matrix1.determinant(); matrix2 = matrix1.transposed(); - if((d1 == d2) && (matr == matrix2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); - - if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); - - if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } TEST(PIMathMatrixT_Test, rotation_3x3) @@ -696,106 +531,83 @@ TEST(PIMathMatrixT_Test, rotation_3x3) TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); - - if((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); - - if((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); - - if((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); - if((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); - if((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); - if((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto matrix2 = PIMathMatrixT::filled(2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); +} +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 11.25) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 11.25) { + ASSERT_TRUE(false); + } + } +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} From 9505669780666870c5dcf5d0bd886c4ea02c866a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:13:02 +0300 Subject: [PATCH 30/68] indentation in strings --- tests/math/testpimathmatrix.cpp | 150 +++++++++--------------------- tests/math/testpimathmatrixt.cpp | 154 +++++++++++-------------------- 2 files changed, 98 insertions(+), 206 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 2b045000..6f4e5ffa 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -2,8 +2,7 @@ #include "pimathmatrix.h" template -bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -15,8 +14,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) return b; } -TEST(PIMathMatrix_Test, identity) -{ +TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -35,8 +33,7 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, element) -{ +TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); for(uint i = 0; i < 3; i++) { if(matrix.element(i,i) != 1.0) { @@ -55,8 +52,7 @@ TEST(PIMathMatrixT_Test, element) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixRow) -{ +TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -68,8 +64,7 @@ TEST(PIMathMatrix_Test, matrixRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixCol) -{ +TEST(PIMathMatrix_Test, matrixCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -81,8 +76,7 @@ TEST(PIMathMatrix_Test, matrixCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setCol) -{ +TEST(PIMathMatrix_Test, setCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -96,8 +90,7 @@ TEST(PIMathMatrix_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setRow) -{ +TEST(PIMathMatrix_Test, setRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -111,15 +104,13 @@ TEST(PIMathMatrix_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, swapCols) -{ +TEST(PIMathMatrix_Test, swapCols) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -145,24 +136,16 @@ TEST(PIMathMatrix_Test, swapCols) b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, swapRows) -{ +TEST(PIMathMatrix_Test, swapRows) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -188,80 +171,63 @@ TEST(PIMathMatrix_Test, swapRows) b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, fill) -{ +TEST(PIMathMatrix_Test, fill) { PIMathMatrix matrix(3, 3, 5.0); matrix.fill(7.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); } -TEST(PIMathMatrix_Test, isSquareTrue) -{ +TEST(PIMathMatrix_Test, isSquareTrue) { PIMathMatrix matrix(3, 3, 1.0); ASSERT_TRUE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isSquareFalse) -{ +TEST(PIMathMatrix_Test, isSquareFalse) { PIMathMatrix matrix(2, 4, 1.0); ASSERT_FALSE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isIdentityTrue) -{ +TEST(PIMathMatrix_Test, isIdentityTrue) { auto matrix = PIMathMatrix::identity(3, 3); ASSERT_TRUE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isIdentityFalse) -{ +TEST(PIMathMatrix_Test, isIdentityFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isNullTrue) -{ +TEST(PIMathMatrix_Test, isNullTrue) { PIMathMatrix matrix(3, 3, 0.0); ASSERT_TRUE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isNullFalse) -{ +TEST(PIMathMatrix_Test, isNullFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isValidTrue) -{ +TEST(PIMathMatrix_Test, isValidTrue) { PIMathMatrix matrix(3, 3, 1.62); ASSERT_TRUE(matrix.isValid()); } -TEST(PIMathMatrix_Test, isValidFalse) -{ +TEST(PIMathMatrix_Test, isValidFalse) { PIMathMatrix matrix; ASSERT_FALSE(matrix.isValid()); } -TEST(PIMathMatrix_Test, operator_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Assignment) { PIMathMatrix matrix1(3, 3, 5.72); PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -275,8 +241,7 @@ TEST(PIMathMatrix_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -290,8 +255,7 @@ TEST(PIMathMatrix_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -305,8 +269,7 @@ TEST(PIMathMatrix_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -320,67 +283,58 @@ TEST(PIMathMatrix_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { PIMathMatrix matrix1(3, 3, 1.0); PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } -TEST(PIMathMatrix_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Division_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } -TEST(PIMathMatrix_Test, operator_Addition) -{ +TEST(PIMathMatrix_Test, operator_Addition) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction) -{ +TEST(PIMathMatrix_Test, operator_Subtraction) { PIMathMatrix matrix1(3, 3, 6.0); PIMathMatrix matrix2(3, 3, 5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication) -{ +TEST(PIMathMatrix_Test, operator_Multiplication) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } -TEST(PIMathMatrix_Test, operator_Division) -{ +TEST(PIMathMatrix_Test, operator_Division) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinantIfSquare) -{ +TEST(PIMathMatrix_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrix matrix(3, 3, 0.0); @@ -402,15 +356,13 @@ TEST(PIMathMatrix_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(d, i); } -TEST(PIMathMatrix_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrix_Test, determinantIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.determinant()); } -TEST(PIMathMatrix_Test, trace) -{ +TEST(PIMathMatrix_Test, trace) { PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; @@ -432,15 +384,13 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } -TEST(PIMathMatrix_Test, traceIfNotSquare) -{ +TEST(PIMathMatrix_Test, traceIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.trace()); } -TEST(PIMathMatrix_Test, toUpperTriangular) -{ +TEST(PIMathMatrix_Test, toUpperTriangular) { PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; @@ -467,8 +417,7 @@ TEST(PIMathMatrix_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrix_Test, invert) -{ +TEST(PIMathMatrix_Test, invert) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -496,8 +445,7 @@ TEST(PIMathMatrix_Test, invert) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, inverted) -{ +TEST(PIMathMatrix_Test, inverted) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -525,8 +473,7 @@ TEST(PIMathMatrix_Test, inverted) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, transposed) -{ +TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; PIMathMatrix matrix1; @@ -554,15 +501,13 @@ TEST(PIMathMatrix_Test, transposed) ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrix_Test, matrixMultiplication) -{ +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -574,8 +519,7 @@ TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -587,14 +531,12 @@ TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrix_Test, hermitian) -{ +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; val.imag(1.0); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index a006b3cd..52bb462e 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,8 +5,7 @@ const uint rows = 3; const uint cols = 3; template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -18,8 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } -TEST(PIMathMatrixT_Test, identity) -{ +TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -38,8 +36,7 @@ TEST(PIMathMatrixT_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, at) -{ +TEST(PIMathMatrixT_Test, at) { auto matrix1 = PIMathMatrixT::identity(); for(uint i = 0; i < rows; i++) { if(matrix1.at(i,i) != 1.0) { @@ -48,26 +45,22 @@ TEST(PIMathMatrixT_Test, at) } ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, filled) -{ +TEST(PIMathMatrixT_Test, filled) { auto matr = PIMathMatrixT::filled(1.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } -TEST(PIMathMatrixT_Test, cols) -{ +TEST(PIMathMatrixT_Test, cols) { PIMathMatrixT matr; ASSERT_EQ(cols,matr.cols()); } -TEST(PIMathMatrixT_Test, rows) -{ +TEST(PIMathMatrixT_Test, rows) { PIMathMatrixT matr; ASSERT_EQ(rows,matr.rows()); } -TEST(PIMathMatrixT_Test, col) -{ +TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; @@ -89,8 +82,8 @@ TEST(PIMathMatrixT_Test, col) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, row) -{ PIMathMatrixT matr; +TEST(PIMathMatrixT_Test, row) { + PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; matr.at(0,0) = 3; @@ -111,8 +104,7 @@ TEST(PIMathMatrixT_Test, row) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setCol) -{ +TEST(PIMathMatrixT_Test, setCol) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -128,8 +120,7 @@ TEST(PIMathMatrixT_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setRow) -{ +TEST(PIMathMatrixT_Test, setRow) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -145,8 +136,7 @@ TEST(PIMathMatrixT_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, swapCols) -{ +TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -171,8 +161,7 @@ TEST(PIMathMatrixT_Test, swapCols) } } -TEST(PIMathMatrixT_Test, swapRows) -{ +TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -197,8 +186,7 @@ TEST(PIMathMatrixT_Test, swapRows) } } -TEST(PIMathMatrixT_Test, fill) -{ +TEST(PIMathMatrixT_Test, fill) { PIMathMatrixT matr; PIMathMatrixT matrix1; double g = 1.0; @@ -211,53 +199,45 @@ TEST(PIMathMatrixT_Test, fill) ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquareTrue) -{ +TEST(PIMathMatrixT_Test, isSquareTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isSquare()); } -TEST(PIMathMatrixT_Test, isSquareFalse) -{ +TEST(PIMathMatrixT_Test, isSquareFalse) { const uint new_Cols = 4; PIMathMatrixT matrix2; ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentityTrue) -{ +TEST(PIMathMatrixT_Test, isIdentityTrue) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isIdentityFalse) -{ +TEST(PIMathMatrixT_Test, isIdentityFalse) { auto matrix1 = PIMathMatrixT::filled(2.5); ASSERT_FALSE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNullTrue) -{ +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, isNullFalse) -{ +TEST(PIMathMatrixT_Test, isNullFalse) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_FALSE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, operator_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -271,8 +251,7 @@ TEST(PIMathMatrixT_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -286,8 +265,7 @@ TEST(PIMathMatrixT_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -301,8 +279,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -316,63 +293,54 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { auto matrix1 = PIMathMatrixT::filled(1.0); auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } -TEST(PIMathMatrixT_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Division_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } -TEST(PIMathMatrixT_Test, operator_Addition) -{ +TEST(PIMathMatrixT_Test, operator_Addition) { auto matrix1 = PIMathMatrixT::filled(6.72); auto matrix2 = PIMathMatrixT::filled(8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction) { auto matrix1 = PIMathMatrixT::filled(6.0); auto matrix2 = PIMathMatrixT::filled(5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } -TEST(PIMathMatrixT_Test, operator_Division) -{ +TEST(PIMathMatrixT_Test, operator_Division) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } -TEST(PIMathMatrixT_Test, determinantIfSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrixT matr; @@ -389,8 +357,7 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(i, d); } -TEST(PIMathMatrixT_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfNotSquare) { PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -404,8 +371,7 @@ TEST(PIMathMatrixT_Test, determinantIfNotSquare) ASSERT_FALSE(matr.determinant()); } -TEST(PIMathMatrixT_Test, invert) -{ +TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -429,8 +395,7 @@ TEST(PIMathMatrixT_Test, invert) ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } -TEST(PIMathMatrixT_Test, inverted) -{ +TEST(PIMathMatrixT_Test, inverted) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -453,8 +418,7 @@ TEST(PIMathMatrixT_Test, inverted) ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrixT_Test, toUpperTriangular) -{ +TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; PIMathMatrixT matr; @@ -476,8 +440,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrixT_Test, transposed) -{ +TEST(PIMathMatrixT_Test, transposed) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matr; @@ -498,22 +461,19 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } -TEST(PIMathMatrixT_Test, scaleX_two) -{ +TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, scaleY_two) -{ +TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, rotation_2x2) -{ +TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); @@ -521,15 +481,13 @@ TEST(PIMathMatrixT_Test, rotation_2x2) ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } -TEST(PIMathMatrixT_Test, rotation_3x3) -{ +TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } -TEST(PIMathMatrixT_Test, rotationX) -{ +TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -537,8 +495,7 @@ TEST(PIMathMatrixT_Test, rotationX) ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } -TEST(PIMathMatrixT_Test, rotationY) -{ +TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -546,8 +503,7 @@ TEST(PIMathMatrixT_Test, rotationY) ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } -TEST(PIMathMatrixT_Test, rotationZ) -{ +TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -555,22 +511,19 @@ TEST(PIMathMatrixT_Test, rotationZ) ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } -TEST(PIMathMatrixT_Test, scaleX_three) -{ +TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleY_three) -{ +TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleZ_three) -{ +TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); @@ -583,8 +536,7 @@ TEST(PIMathMatrixT_Test, matrixMultiplication) ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -595,8 +547,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -606,8 +557,7 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) } } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } From 04da5daa415bd452ec97dac6efebea29d01962f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:16 +0300 Subject: [PATCH 31/68] bug fixes --- CMakeLists.txt.user | 1175 ++++++++++++++++++++++++++++++ tests/math/testpimathmatrix.cpp | 26 +- tests/math/testpimathmatrixt.cpp | 12 +- 3 files changed, 1194 insertions(+), 19 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..aed2b6b3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1175 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 6 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_concurrent_test + CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test + pip_concurrent_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_math_test + CMakeProjectManager.CMakeRunConfiguration.pip_math_test + pip_math_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal + + 12 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 6f4e5ffa..3dc1943a 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -16,18 +16,18 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); - 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){ + 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); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -35,11 +35,6 @@ TEST(PIMathMatrix_Test, identity) { TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); - for(uint i = 0; i < 3; i++) { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ if(i != j){ @@ -47,6 +42,11 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(false); } } + else { + if(matrix.element(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 52bb462e..d7f11563 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -19,11 +19,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::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){ @@ -31,6 +26,11 @@ TEST(PIMathMatrixT_Test, identity) { ASSERT_TRUE(false); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -293,7 +293,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { +TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; From d5da2e7c7f4b0ecff895c3711e95ed1e604bc414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:39 +0300 Subject: [PATCH 32/68] bug fixes --- CMakeLists.txt.user | 1175 ------------------------------------------- 1 file changed, 1175 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index aed2b6b3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1175 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 6 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_concurrent_test - CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test - pip_concurrent_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_math_test - CMakeProjectManager.CMakeRunConfiguration.pip_math_test - pip_math_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal - - 12 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 6ba17c1122235c1d5f152d75282879e6af963802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 33/68] add CMakeLists.txt.user to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 092160f1..22cc44b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.svn /doc/rtf _unsused +CMakeLists.txt.user \ No newline at end of file From 608e09c9a0c4776498ae21b910d449ea84470775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 34/68] PIMathMatrix doc --- CMakeLists.txt.user | 1023 +++++++++++++++++++++++++++++++++ libs/main/math/pimathmatrix.h | 485 +++++++++++++++- tests/concurrent/testutil.h | 2 + 3 files changed, 1505 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..6d0aa1d3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1023 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + + + doc + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal + + 10 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 1f50bfab..09c7ed11 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -1,5 +1,7 @@ /*! \file pimathmatrix.h * \brief PIMathMatrix + * + * This file declare math matrix class, which performs various matrix operations */ /* PIP - Platform Independent Primitives @@ -54,12 +56,13 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); @@ -67,46 +70,302 @@ public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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" + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the X axis + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the X axis by the value "factor" + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Y axis by the value "factor" + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Z axis by the value "factor" + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} + + /** + * @brief Method which returns number of rows in matrix + * + * @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 + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -122,6 +381,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -159,6 +423,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -206,7 +475,19 @@ public: memcpy(m, mtmp.m, sizeof(Type) * Cols * Rows); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -321,6 +602,7 @@ class PIMathMatrix; #define PIMM_FOR_C(v) for (uint v = 0; v < _V2D::cols_; ++v) #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 template class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIVector2D _V2D; @@ -332,21 +614,117 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} + /** + * @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) _V2D::element(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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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_A(i) _V2D::mat[i] = v; return *this;} + + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} + + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); 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 { if(_V2D::mat.size() != sm.mat.size()) return false; @@ -356,17 +734,87 @@ public: } 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_A(i) _V2D::mat[i] += sm.mat[i];} + + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= 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(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -382,6 +830,11 @@ public: return ret; } + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -395,6 +848,11 @@ public: return ret; } + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -432,6 +890,11 @@ public: return *this; } + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -486,7 +949,19 @@ public: PIVector2D::swap(mtmp); return *this; } + + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 7c3c15c7..9df146ba 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,6 +3,7 @@ #include "pithread.h" #include +#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -57,4 +58,5 @@ public: } }; + #endif //AWRCANFLASHER_TESTUTIL_H From 781a1e75e2f8029c34d51309052cb7f9144ffa96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:47 +0300 Subject: [PATCH 35/68] PIMathMatrix document --- CMakeLists.txt.user | 1023 ------------------------------------------- 1 file changed, 1023 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 6d0aa1d3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1023 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 0 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - - - doc - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal - - 10 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 97a17a892db0e837a5d67b9873d2fbd3748f07c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:23:54 +0300 Subject: [PATCH 36/68] Rotation remake --- libs/main/math/pimathmatrix.h | 20 +++++++-------- tests/concurrent/testutil.h | 2 -- tests/math/testpimathmatrixt.cpp | 44 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 09c7ed11..7537791c 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -63,9 +63,9 @@ class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrixI; typedef PIMathVectorT _CMCol; typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} @@ -86,7 +86,7 @@ public: 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" + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix * @return rotated matrix @@ -94,7 +94,7 @@ public: static _CMatrix rotation(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the X axis + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the X axis * @return rotated matrix @@ -102,7 +102,7 @@ public: static _CMatrix rotationX(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Y axis + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Y axis * @return rotated matrix @@ -110,7 +110,7 @@ public: static _CMatrix rotationY(double angle) {return _CMatrix();} /** - * @brief Rotation of the matrix by an "angle" along the Z axis + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix * * @param angle is the angle of rotation of the matrix along the Z axis * @return rotated matrix @@ -118,7 +118,7 @@ public: static _CMatrix rotationZ(double angle) {return _CMatrix();} /** - * @brief Scaling the matrix along the X axis by the value "factor" + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by X axis * @return rotated matrix @@ -126,7 +126,7 @@ public: static _CMatrix scaleX(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Y axis by the value "factor" + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix * * @param factor is the value of scaling by Y axis * @return rotated matrix @@ -134,7 +134,7 @@ public: static _CMatrix scaleY(double factor) {return _CMatrix();} /** - * @brief Scaling the matrix along the Z axis by the value "factor" + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix * * @param factor is the value of scaling by Z axis * @return rotated matrix diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 9df146ba..7c3c15c7 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,7 +3,6 @@ #include "pithread.h" #include -#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -58,5 +57,4 @@ public: } }; - #endif //AWRCANFLASHER_TESTUTIL_H diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 38976bf8..2d68d131 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -674,24 +674,6 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, rotation) -{ - double angle = 1.0; - bool b; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); - double c = cos(angle); - double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; @@ -726,6 +708,31 @@ TEST(PIMathMatrixT_Test, scaleY_two) ASSERT_TRUE(b); } +TEST(PIMathMatrixT_Test, rotation_2x2) +{ + double angle = 1.0; + bool b; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); + double c = cos(angle); + double s = sin(angle); + if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) + { + b = true; + } + else + { + b = false; + } + ASSERT_TRUE(b); +} + +TEST(PIMathMatrixT_Test, rotation_3x3) +{ + double angle = 1.0; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); + ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); +} + TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; @@ -831,3 +838,4 @@ TEST(PIMathMatrixT_Test, scaleZ_three) ASSERT_TRUE(b); } + From 14a8c11a7199279bce480e329cc5bb898225fb09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:50:41 +0300 Subject: [PATCH 37/68] space correction --- libs/main/math/pimathmatrix.h | 830 +++++++++++++++++----------------- 1 file changed, 422 insertions(+), 408 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 7537791c..8e3830b1 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -59,313 +59,320 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { //! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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 - */ + /** + * @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 - */ + /** + * @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 _CMatrix - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + /** + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} - /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} - /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} - /** - * @brief Method which returns number of rows in matrix - * - * @return type uint shows number of rows - */ + /** + * @brief Method which returns number of rows in matrix + * + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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" - */ + /** + * @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" - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -381,11 +388,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -423,11 +430,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -476,18 +483,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} private: @@ -614,109 +621,109 @@ public: PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ + /** + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identitied matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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 Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} + /** + * @brief Сreates a matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ + static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ + /** + * @brief Сreates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return matrix identitied by vector + */ static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} - /** - * @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 - */ + /** + * @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) _V2D::element(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 - */ + /** + * @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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 - */ + /** + * @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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 - */ + /** + * @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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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 - */ + /** + * @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_A(i) _V2D::mat[i] = v; return *this;} - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const {return _V2D::cols_ == _V2D::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 - */ + /** + * @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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + /** + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix is null, else false + */ bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + /** + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const {return !PIVector2D::isEmpty();} - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); return *this;} /** @@ -741,80 +748,87 @@ public: * @param sm matrix for the compare * @return if matrices are not equal true, else false */ + + /** + * @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 - */ + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} - /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @param sm is matrix subtractor + * @return the result of matrix substraction + */ _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + /** + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { _CMatrix m(*this); bool k; @@ -830,11 +844,11 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ Type trace(bool * ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -848,11 +862,11 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ _CMatrix & toUpperTriangular(bool * ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -890,11 +904,11 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -950,18 +964,18 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} }; From a0c53bf689e4a682b6336cf3d0ca576a4c742ee0 Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Thu, 3 Sep 2020 16:57:46 +0300 Subject: [PATCH 38/68] Fix code formatting & grammar mistakes --- libs/main/math/pimathmatrix.h | 1383 +++++++++++++++++++-------------- 1 file changed, 818 insertions(+), 565 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 8e3830b1..80f1eaab 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -29,7 +29,6 @@ #include "pimathcomplex.h" - template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); @@ -37,11 +36,12 @@ inline bool _PIMathMatrixNullCompare(const T v) { } template<> -inline bool _PIMathMatrixNullCompare(const complexf v) { +inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } + template<> -inline bool _PIMathMatrixNullCompare(const complexd v) { +inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); } @@ -56,6 +56,7 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++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 template class PIP_EXPORT PIMathMatrixT { @@ -67,313 +68,391 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - PIMathMatrixT() {resize(Rows, Cols);} - PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} + PIMathMatrixT() { resize(Rows, Cols); } - /** - * @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;} + PIMathMatrixT(const PIVector &val) { + resize(Rows, Cols); + int i = 0; + PIMM_FOR_I_WB(r, c) m[r][c] = val[i++]; + } - /** - * @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 С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 Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT + /** + * @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 +* + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ + static _CMatrix rotation(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ + static _CMatrix rotationX(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ + static _CMatrix rotationY(double angle) { return _CMatrix(); } + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ + static _CMatrix rotationZ(double angle) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ + static _CMatrix scaleX(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ + static _CMatrix scaleY(double factor) { return _CMatrix(); } + + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ + static _CMatrix scaleZ(double factor) { return _CMatrix(); } + + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ + uint cols() const { return Cols; } + + /** + * @brief Method which returns number of rows in matrix * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ - static _CMatrix rotation(double angle) {return _CMatrix();} + * @return type uint shows number of rows + */ + uint rows() const { return Rows; } - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ - static _CMatrix rotationX(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ - static _CMatrix rotationY(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ - static _CMatrix rotationZ(double angle) {return _CMatrix();} + /** + * @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 Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ - static _CMatrix scaleX(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ - static _CMatrix scaleY(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ - static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @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 returns number of columns in matrix - * - * @return type uint shows number of columns - */ - uint cols() const {return Cols;} + /** + * @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 returns number of rows in matrix - * - * @return type uint shows number of rows - */ - uint rows() const {return Rows;} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return cols() == rows();} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -388,12 +467,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; return *this; @@ -419,7 +498,7 @@ public: for (uint k = i; k < Cols; ++k) smat.m[k][j] -= mul * smat.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -430,12 +509,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); bool ndet; @@ -462,7 +541,7 @@ public: for (uint k = 0; k < Cols; ++k) mtmp.m[k][j] -= mul * mtmp.m[k][i]; } if (i < Cols - 1) { - if (fabs(smat.m[i+1][i+1]) < Type(1E-200)) { + if (fabs(smat.m[i + 1][i + 1]) < Type(1E-200)) { if (ok != 0) *ok = false; return *this; } @@ -483,39 +562,125 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrixI transposed() const { + _CMatrixI tm; + PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; + return tm; + } private: - void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;} + void resize(uint rows_, uint cols_, const Type &new_value = Type()) { + r_ = rows_; + c_ = cols_; + PIMM_FOR_WB(r, c) m[r][c] = new_value; + } + int c_, r_; Type m[Rows][Cols]; }; + #pragma pack(pop) -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<2u, 2u> tm; tm[0][0] = tm[1][1] = c; tm[0][1] = -s; tm[1][0] = s; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = factor; tm[1][1] = 1.; return tm;} -template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = 1.; tm[1][1] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = tm[1][1] = c; + tm[0][1] = -s; + tm[1][0] = s; + return tm; +} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[0][0] = 1.; tm[1][1] = tm[2][2] = c; tm[2][1] = s; tm[1][2] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[1][1] = 1.; tm[0][0] = tm[2][2] = c; tm[2][0] = -s; tm[0][2] = s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[2][2] = 1.; tm[0][0] = tm[1][1] = c; tm[1][0] = s; tm[0][1] = -s; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) {PIMathMatrixT<3u, 3u> tm; tm[1][1] = tm[2][2] = 1.; tm[0][0] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[2][2] = 1.; tm[1][1] = factor; return tm;} -template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;} +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = factor; + tm[1][1] = 1.; + return tm; +} + +template<> +inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) { + PIMathMatrixT<2u, 2u> tm; + tm[0][0] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = 1.; + tm[1][1] = tm[2][2] = c; + tm[2][1] = s; + tm[1][2] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = 1.; + tm[0][0] = tm[2][2] = c; + tm[2][0] = -s; + tm[0][2] = s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) { + double c = cos(angle), s = sin(angle); + PIMathMatrixT<3u, 3u> tm; + tm[2][2] = 1.; + tm[0][0] = tm[1][1] = c; + tm[1][0] = s; + tm[0][1] = -s; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[1][1] = tm[2][2] = 1.; + tm[0][0] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[2][2] = 1.; + tm[1][1] = factor; + return tm; +} + +template<> +inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) { + PIMathMatrixT<3u, 3u> tm; + tm[0][0] = tm[1][1] = 1.; + tm[2][2] = factor; + return tm; +} #ifdef PIP_STD_IOSTREAM template @@ -523,12 +688,19 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT -inline PICout operator <<(PICout s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrixT &m) { + s << "{"; + PIMM_FOR_I(r, c) s << m[r][c]; + if (c < Cols - 1 || r < Rows - 1) s << ", "; } + if (r < Rows - 1) s << PICoutManipulators::NewLine << " "; } + s << "}"; + return s; +} /// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1} template -inline PIMathMatrixT operator *(const PIMathMatrixT & fm, - const PIMathMatrixT & sm) { +inline PIMathMatrixT operator*(const PIMathMatrixT &fm, + const PIMathMatrixT &sm) { PIMathMatrixT tm; Type t; for (uint j = 0; j < Rows0; ++j) { @@ -544,8 +716,8 @@ inline PIMathMatrixT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathMatrixT & fm, - const PIMathVectorT & sv) { +inline PIMathVectorT operator*(const PIMathMatrixT &fm, + const PIMathVectorT &sv) { PIMathVectorT tv; Type t; for (uint j = 0; j < Rows; ++j) { @@ -559,8 +731,8 @@ inline PIMathVectorT operator *(const PIMathMatrixT -inline PIMathVectorT operator *(const PIMathVectorT & sv, - const PIMathMatrixT & fm) { +inline PIMathVectorT operator*(const PIMathVectorT &sv, + const PIMathMatrixT &fm) { PIMathVectorT tv; Type t; for (uint j = 0; j < Cols; ++j) { @@ -574,7 +746,7 @@ inline PIMathVectorT operator *(const PIMathVectorT & sv /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrixT operator *(const Type & x, const PIMathMatrixT & v) { +inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; } @@ -612,224 +784,277 @@ class PIMathMatrix; //! \brief A class that works with matrix operations, the input data of which is the data type of the matrix template class PIP_EXPORT PIMathMatrix : public PIVector2D { - typedef PIVector2D _V2D; + typedef PIVector2D _V2D; typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type & f = Type()) {_V2D::resize(rows, cols, f);} - PIMathMatrix(const uint cols, const uint rows, const PIVector & val) {_V2D::resize(rows, cols); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} - PIMathMatrix(const PIVector > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} - PIMathMatrix(const PIVector2D & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} + PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identitied matrix of type PIMathMatrix - */ - static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); 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;} + PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { + _V2D::resize(rows, cols); + int i = 0; + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; + } - /** - * @brief Сreates a matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixRow(const PIMathVector & val) {return _CMatrix(val.size(), 1, val.toVector());} - - /** - * @brief Сreates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return matrix identitied by vector - */ - static _CMatrix matrixCol(const PIMathVector & val) {return _CMatrix(1, val.size(), val.toVector());} - - /** - * @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) _V2D::element(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 _CMCol & v) {PIMM_FOR_C(i) _V2D::element(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 & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} 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 & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} 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_A(i) _V2D::mat[i] = v; return *this;} - - /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return _V2D::cols_ == _V2D::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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} - - /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ - bool isValid() const {return !PIVector2D::isEmpty();} - - /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ - _CMatrix & operator =(const PIVector > & v) {*this = _CMatrix(v); 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 { - if(_V2D::mat.size() != sm.mat.size()) - return false; - PIMM_FOR_A(i) { - if (_V2D::mat[i] != sm.mat[i]) - return false; + PIMathMatrix(const PIVector > &val) { + if (!val.isEmpty()) { + _V2D::resize(val.size(), val[0].size()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c]; } + } + + PIMathMatrix(const PIVector2D &val) { + if (!val.isEmpty()) { + _V2D::resize(val.rows(), val.cols()); + PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c); + } + } + + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ + static _CMatrix identity(const uint cols, const uint rows) { + _CMatrix tm(cols, rows); + 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 matrix whose row equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } + + /** + * @brief Creates a matrix whose column equal to vector + * + * @param val is the vector type PIMathVector + * @return identity matrix by vector + */ + static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } + + /** + * @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) _V2D::element(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 _CMCol &v) { + PIMM_FOR_C(i) _V2D::element(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 &swapCols(uint r0, uint r1) { + PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } + 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 &swapRows(uint c0, uint c1) { + PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } + 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_A(i) _V2D::mat[i] = v; + return *this; + } + + /** + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ + bool isSquare() const { return _V2D::cols_ == _V2D::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(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } - /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + /** + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix is null, else false + */ + bool isNull() const { + PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) 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 Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ + bool isValid() const { return !PIVector2D::isEmpty(); } - /** - * @brief Addition assignment with matrix "sm" - * - * @param sm matrix for the addition assigment - */ - void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];} + /** + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ + _CMatrix &operator=(const PIVector > &v) { + *this = _CMatrix(v); + return *this; + } - /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ - void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];} + /** + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; + return true; + } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ - void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;} + /** + * @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 Division assignment with value "v" - * - * @param v value for the division assigment - */ - void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;} + /** + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ + void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ - _CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;} + /** + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ + void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ - _CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;} + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ + void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } - /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ - _CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;} + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ + void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ - _CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;} + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ + _CMatrix operator-() const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; + return tm; + } - /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ - _CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;} + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ + _CMatrix operator+(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; + return tm; + } - /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ + _CMatrix operator-(const _CMatrix &sm) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; + return tm; + } + + /** + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ + _CMatrix operator*(const Type &v) const { + _CMatrix tm(*this); + PIMM_FOR_A(i) tm.mat[i] *= 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(*this); + PIMM_FOR_A(i) tm.mat[i] /= v; + return tm; + } + + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); @@ -844,12 +1069,12 @@ public: return ret; } - /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ - Type trace(bool * ok = 0) const { + /** + * @brief Trace of the matrix is calculated + * + * @return matrix trace + */ + Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { if (ok != 0) *ok = false; @@ -862,12 +1087,12 @@ public: return ret; } - /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ - _CMatrix & toUpperTriangular(bool * ok = 0) { + /** + * @brief Transforming matrix to upper triangular + * + * @return transformed upper triangular matrix + */ + _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -893,7 +1118,7 @@ public: for (uint k = i; k < _V2D::cols_; ++k) smat.element(k, j) -= mul * smat.element(k, i); } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -904,12 +1129,12 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix & invert(bool * ok = 0, _CMCol * sv = 0) { + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; return *this; @@ -941,7 +1166,7 @@ public: if (sv != 0) (*sv)[j] -= mul * (*sv)[i]; } if (i < _V2D::cols_ - 1) { - if (_PIMathMatrixNullCompare(smat.element(i+1, i+1))) { + if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) { if (ok != 0) *ok = false; return *this; } @@ -964,19 +1189,27 @@ public: return *this; } - /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ - _CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;} + /** + * @brief Matrix inversion operation + * + * @return inverted matrix + */ + _CMatrix inverted(bool *ok = 0) const { + _CMatrix tm(*this); + tm.invert(ok); + return tm; + } - /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ - _CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} + /** + * @brief Matrix transposition operation + * + * @return transposed matrix + */ + _CMatrix transposed() const { + _CMatrix tm(_V2D::rows_, _V2D::cols_); + PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); + return tm; + } }; @@ -986,18 +1219,36 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m #endif template -inline PICout operator <<(PICout s, const PIMathMatrix & m) {s << "Matrix{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} +inline PICout operator<<(PICout s, const PIMathMatrix &m) { + s << "Matrix{"; + for (uint r = 0; r < m.rows(); ++r) { + for (uint c = 0; c < m.cols(); ++c) { + s << m.element(r, c); + if (c < m.cols() - 1 || r < m.rows() - 1) s << ", "; + } + if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " "; + } + s << "}"; + return s; +} template -inline PIByteArray & operator <<(PIByteArray & s, const PIMathMatrix & v) {s << (const PIVector2D &)v; return s;} +inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { + s << (const PIVector2D &) v; + return s; +} + template -inline PIByteArray & operator >>(PIByteArray & s, PIMathMatrix & v) {s >> (PIVector2D &)v; return s;} +inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { + s >> (PIVector2D &) v; + return s; +} /// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0} template -inline PIMathMatrix operator *(const PIMathMatrix & fm, - const PIMathMatrix & sm) { +inline PIMathMatrix operator*(const PIMathMatrix &fm, + const PIMathMatrix &sm) { uint cr = fm.cols(), rows0 = fm.rows(), cols1 = sm.cols(); PIMathMatrix tm(cols1, rows0); if (fm.cols() != sm.rows()) return tm; @@ -1015,8 +1266,8 @@ inline PIMathMatrix operator *(const PIMathMatrix & fm, /// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows} template -inline PIMathVector operator *(const PIMathMatrix & fm, - const PIMathVector & sv) { +inline PIMathVector operator*(const PIMathMatrix &fm, + const PIMathVector &sv) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(r); if (c != sv.size()) return tv; @@ -1033,8 +1284,8 @@ inline PIMathVector operator *(const PIMathMatrix & fm, /// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols} template -inline PIMathVector operator *(const PIMathVector & sv, - const PIMathMatrix & fm) { +inline PIMathVector operator*(const PIMathVector &sv, + const PIMathMatrix &fm) { uint c = fm.cols(), r = fm.rows(); PIMathVector tv(c); Type t; @@ -1049,7 +1300,7 @@ inline PIMathVector operator *(const PIMathVector & sv, /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} template -inline PIMathMatrix operator *(const Type & x, const PIMathMatrix & v) { +inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; } @@ -1057,9 +1308,11 @@ typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; template -PIMathMatrix > hermitian(const PIMathMatrix > & m) { +PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); - for (uint r = 0; r < ret.rows(); ++r) for (uint c = 0; c < ret.cols(); ++c) ret.element(r, c).imag(-(ret.element(r, c).imag())); + for (uint r = 0; r < ret.rows(); ++r) + for (uint c = 0; c < ret.cols(); ++c) + ret.element(r, c).imag(-(ret.element(r, c).imag())); return ret.transposed(); } From 012981baf7618fdd7f38b38110d918b0d5d4f03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:05:22 +0300 Subject: [PATCH 39/68] doc correction --- libs/main/math/pimathmatrix.h | 853 ++++++++++++++++++------------- tests/math/testpimathmatrix.cpp | 30 +- tests/math/testpimathmatrixt.cpp | 35 +- 3 files changed, 530 insertions(+), 388 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 80f1eaab..9a767dd5 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -28,18 +28,35 @@ #include "pimathvector.h" #include "pimathcomplex.h" - +/** +* @brief Inline funtion of compare with zero different types +* +* @param v is input parameter of type T +* @return true if zero, false if not zero +*/ template inline bool _PIMathMatrixNullCompare(const T v) { static_assert(std::is_floating_point::value, "Type must be floating point"); return (piAbs(v) < T(1E-200)); } +/** +* @brief Inline funtion of compare with zero colmplexf type +* +* @param v is input parameter of type colmplexf +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexf v) { return (abs(v) < float(1E-200)); } +/** +* @brief Inline funtion of compare with zero complexd type +* +* @param v is input parameter of type colmplexd +* @return true if zero, false if not zero +*/ template<> inline bool _PIMathMatrixNullCompare(const complexd v) { return (abs(v) < double(1E-200)); @@ -68,8 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -77,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identitied matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -88,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -100,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT -* - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -177,11 +205,12 @@ public: 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 - */ + * @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 + * + * @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]; @@ -189,11 +218,12 @@ public: } /** - * @brief Method which returns the selected row in PIMathVectorT format - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -201,36 +231,39 @@ public: } /** - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -242,12 +275,13 @@ public: } /** - * @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 - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -259,140 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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" - */ + * @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 + * + * @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" - */ + * @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 + * + * @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 - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -400,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -412,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -424,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -436,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -448,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -468,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -510,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -563,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -574,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -687,6 +723,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrixT type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrixT &m) { s << "{"; @@ -698,6 +741,13 @@ inline PICout operator<<(PICout s, const PIMathMatrixT &m) { } /// 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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const PIMathMatrixT &fm, const PIMathMatrixT &sm) { @@ -715,6 +765,13 @@ inline PIMathMatrixT operator*(const PIMathMatrixT inline PIMathVectorT operator*(const PIMathMatrixT &fm, const PIMathVectorT &sv) { @@ -730,6 +787,13 @@ inline PIMathVectorT operator*(const PIMathMatrixT } /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVectorT operator*(const PIMathVectorT &sv, const PIMathMatrixT &fm) { @@ -745,6 +809,13 @@ inline PIMathVectorT operator*(const PIMathVectorT &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrixT operator*(const Type &x, const PIMathMatrixT &v) { return v * x; @@ -788,14 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -803,6 +893,11 @@ public: } } + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -810,191 +905,194 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 matrix whose row equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a matrix whose column equal to vector - * - * @param val is the vector type PIMathVector - * @return identity matrix by vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - */ + * @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 + * + * @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) _V2D::element(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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(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 - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } 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 - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::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 - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(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 - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1002,11 +1100,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1014,11 +1112,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1026,11 +1124,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1038,11 +1136,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1050,10 +1148,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1070,10 +1168,10 @@ public: } /** - * @brief Trace of the matrix is calculated - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1088,10 +1186,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1130,10 +1228,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1190,10 +1288,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1201,10 +1299,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); @@ -1218,6 +1316,13 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m) {s << "{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << " ";} s << "}"; return s;} #endif +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PICout type +* @param m PIMathMatrix type +* @return bitwise left PICout +*/ template inline PICout operator<<(PICout s, const PIMathMatrix &m) { s << "Matrix{"; @@ -1232,12 +1337,26 @@ inline PICout operator<<(PICout s, const PIMathMatrix &m) { return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise left PIByteArray +*/ template inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { s << (const PIVector2D &) v; return s; } +/** +* @brief Add matrix "m" at the end of matrix and return reference to matrix +* +* @param s PIByteArray type +* @param v PIMathMatrix type +* @return bitwise right PIByteArray +*/ template inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { s >> (PIVector2D &) v; @@ -1246,6 +1365,13 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &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 +* +* @param fm first matrix multiplier +* @param sm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const PIMathMatrix &fm, const PIMathMatrix &sm) { @@ -1265,6 +1391,13 @@ inline PIMathMatrix operator*(const PIMathMatrix &fm, } /// 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 +* +* @param fm first matrix multiplier +* @param sv second vector multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathMatrix &fm, const PIMathVector &sv) { @@ -1283,6 +1416,13 @@ inline PIMathVector operator*(const PIMathMatrix &fm, /// 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 +* +* @param sv first vector multiplier +* @param fm second matrix multiplier +* @return vector that is the result of multiplication +*/ template inline PIMathVector operator*(const PIMathVector &sv, const PIMathMatrix &fm) { @@ -1299,6 +1439,13 @@ inline PIMathVector operator*(const PIMathVector &sv, } /// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} +/** +* @brief Multiplying value of type Type and matrix +* +* @param x first multiplier of type Type +* @param fm second matrix multiplier +* @return matrix that is the result of multiplication +*/ template inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) { return v * x; @@ -1307,6 +1454,12 @@ inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) typedef PIMathMatrix PIMathMatrixi; typedef PIMathMatrix PIMathMatrixd; +/** +* @brief Searching hermitian matrix +* +* @param m conjugate transpose matrix +* @return result of the hermitian +*/ template PIMathMatrix > hermitian(const PIMathMatrix > &m) { PIMathMatrix > ret(m); diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 4eeccd0c..09992b89 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -34,24 +34,22 @@ bool cmpMatrixWithValue(PIMathMatrix matrix, double val) TEST(PIMathMatrix_Test, identity) { - PIMathMatrix origMatr; - PIMathMatrix matrix; - int i; - bool b; - matrix = origMatr.identity(3, 3); - for(i = 0; i < 3; i++) - { - if(matrix[i][i] == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix = PIMathMatrix::identity(3, 3); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + 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); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixRow) diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 2d68d131..0542332a 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -38,31 +38,22 @@ bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) TEST(PIMathMatrixT_Test, identity) { - PIMathMatrixT matr; - PIMathMatrixT matrix; - double d; - double i = 1.0; - bool a; - bool output; - matrix = matr.identity(); - d = matrix.determinant(); - uint j; - for(j = 0; j < cols; j++) - { - if(matrix.at(i, i) == 1.0) a = true; - else - { - a = false; - break; + auto matrix = PIMathMatrixT::identity(); + for(int i = 0; i < 3; i++){ + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); } } - if((i == d) && (a == true)){ - output = true; + 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); + } + } + } } - else{ - output = false; - } - ASSERT_TRUE(output); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, at) From 247123194335d40a69892896bc348b8af8545c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:44:01 +0300 Subject: [PATCH 40/68] tab correction --- libs/main/math/pimathmatrix.h | 791 +++++++++++++++++----------------- 1 file changed, 395 insertions(+), 396 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 9a767dd5..fe1c6a66 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -85,19 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - /** - * @brief Constructor that calls the private resize method - * - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } - /** - * @brief Constructor that calls the private resize method - * - * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -105,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identity matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -116,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -128,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -205,12 +205,12 @@ public: uint rows() const { return Rows; } /** - * @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 - * - * @param index is the number of the selected column - * @return column in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -218,12 +218,12 @@ 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 - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -231,39 +231,39 @@ public: } /** - * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -275,13 +275,13 @@ 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 - * - * @param c0 is the number of the first selected column - * @param c1 is the number of the second selected column - * @return matrix type _CMatrix - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -293,142 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -436,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -448,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -460,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -472,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -484,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -504,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -546,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -599,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -610,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -859,33 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param f is type of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param val is PIVector of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector of PIVector, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -893,11 +893,11 @@ public: } } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector2D, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -905,194 +905,193 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 - * - * @param val is the vector type PIMathVector - * @return row matrix of every element that is equal to every element of the vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a column matrix of every element that is equal to every element of the vector - * - * @param val is the vector type PIMathVector - * @return column matrix of every element that is equal to every element of the vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - * - * @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 - */ + * @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 + * + * @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) _V2D::element(i, index) = v[i]; return *this; } /** - * @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 - * @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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this; } /** - * @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 - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; } - /** - * @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 - * - * @param c0 is the number of the first selected row - * @param c1 is the number of the second selected row - * @return matrix type _CMatrix - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } /** - * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros - * - * @return true if matrix is identity, else false - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix elements equal to zero, else false - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1100,11 +1099,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1112,11 +1111,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1124,11 +1123,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1136,11 +1135,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1148,10 +1147,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1168,10 +1167,10 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1186,10 +1185,10 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1228,10 +1227,10 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1288,10 +1287,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1299,10 +1298,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); From d003a2e7d8891d0e86192fbd034f1e18424ff69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:47:44 +0300 Subject: [PATCH 41/68] final tab correction --- libs/main/math/pimathmatrix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index fe1c6a66..8ab15e91 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -120,7 +120,7 @@ public: * * @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; @@ -965,7 +965,7 @@ public: * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; From 7a94de5af89232167c947991fb0adbe33aeaf87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 10:52:09 +0300 Subject: [PATCH 42/68] tests correction --- tests/math/testpimathmatrix.cpp | 82 +++++++++------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 09992b89..d2751587 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -54,106 +54,66 @@ TEST(PIMathMatrix_Test, identity) TEST(PIMathMatrix_Test, matrixRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixRow(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 5.0) + if(matrix[0][i] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); - for(i = 0; i < vector.size(); i++) + auto matrix = PIMathMatrix::matrixCol(vector); + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 5.0) + if(matrix[i][0] != 3.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setCol) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixCol(vector); + auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] == 10.0) + if(matrix[i][0] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setRow) { - PIMathMatrix origMatr; - PIMathMatrix matrix; PIMathVector vector; - uint i; - bool b; vector.resize(3, 3.0); - vector.fill(5.0); - matrix = origMatr.matrixRow(vector); + auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(i = 0; i < vector.size(); i++) + for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] == 10.0) + if(matrix[0][i] != 10.0) { - b = true; - } - else - { - b = false; - break; + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, swapCols) @@ -758,4 +718,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} +} \ No newline at end of file From ee6b026c6141023e3e26de459d1a9977f568678c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 13:11:31 +0300 Subject: [PATCH 43/68] PIMathMatrix new tests version --- tests/math/testpimathmatrix.cpp | 517 +++++++++++--------------------- 1 file changed, 179 insertions(+), 338 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index d2751587..deeca9ca 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -1,33 +1,16 @@ #include "gtest/gtest.h" #include "pimathmatrix.h" -bool cmpMatrixWithValue(PIMathMatrix matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.element(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.element(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } @@ -57,10 +40,8 @@ TEST(PIMathMatrix_Test, matrixRow) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 3.0) { ASSERT_TRUE(false); } } @@ -72,10 +53,8 @@ TEST(PIMathMatrix_Test, matrixCol) PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 3.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 3.0) { ASSERT_TRUE(false); } } @@ -89,10 +68,8 @@ TEST(PIMathMatrix_Test, setCol) auto matrix = PIMathMatrix::matrixCol(vector); vector.fill(10.0); matrix.setCol(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[i][0] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 10.0) { ASSERT_TRUE(false); } } @@ -106,10 +83,8 @@ TEST(PIMathMatrix_Test, setRow) auto matrix = PIMathMatrix::matrixRow(vector); vector.fill(10.0); matrix.setRow(0, vector); - for(uint i = 0; i < vector.size(); i++) - { - if(matrix[0][i] != 10.0) - { + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 10.0) { ASSERT_TRUE(false); } } @@ -139,25 +114,21 @@ TEST(PIMathMatrix_Test, swapCols) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(i, 0); a2[i] = matrix1.element(i, 1); a3[i] = matrix1.element(i, 2); } matrix1.swapCols(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(i, 0); b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); @@ -186,350 +157,218 @@ TEST(PIMathMatrix_Test, swapRows) vector.at(1) = 2.0; vector.at(2) = 5.0; matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(0, i); a2[i] = matrix1.element(1, i); a3[i] = matrix1.element(2, i); } matrix1.swapRows(i1, i2); - for(int i = 0; i < 3; i++) - { + for(int i = 0; i < 3; i++) { b1[i] = matrix1.element(0, i); b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) - { + if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { b = true; } - else - { + else { b = false; } ASSERT_TRUE(b); } TEST(PIMathMatrix_Test, fill) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 5.0); + matrix.fill(7.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); +} + +TEST(PIMathMatrix_Test, isSquareTrue) +{ + PIMathMatrix matrix(3, 3, 1.0); + ASSERT_TRUE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isSquareFalse) +{ + PIMathMatrix matrix(2, 4, 1.0); + ASSERT_FALSE(matrix.isSquare()); +} + +TEST(PIMathMatrix_Test, isIdentityTrue) +{ + auto matrix = PIMathMatrix::identity(3, 3); + ASSERT_TRUE(matrix.isIdentity()); +} + +TEST(PIMathMatrix_Test, isIdentityFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isIdentity()); +} + + +TEST(PIMathMatrix_Test, isNullTrue) +{ + PIMathMatrix matrix(3, 3, 0.0); + ASSERT_TRUE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isNullFalse) +{ + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isNull()); +} + +TEST(PIMathMatrix_Test, isValidTrue) +{ + PIMathMatrix matrix(3, 3, 1.62); + ASSERT_TRUE(matrix.isValid()); +} + +TEST(PIMathMatrix_Test, isValidFalse) +{ PIMathMatrix matrix; - bool b; - matrix = origMatr.identity(3, 3); - matrix.fill(5.0); - b = cmpMatrixWithValue(matrix, 5.0); - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isSquare) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(4,3); - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isIdentity) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(3.932); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isNull) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(0.0); - matrix2.fill(3.932); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); -} - -TEST(PIMathMatrix_Test, isValid) -{ - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - if((matrix1.isValid() == true) && (matrix2.isValid() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix.isValid()); } TEST(PIMathMatrix_Test, operator_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); + PIMathMatrix matrix1(3, 3, 5.72); + PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_Equal) +TEST(PIMathMatrix_Test, operator_EqualTrue) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 == matrix2) == true) && ((matrix1 == matrix3) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_Equal) +TEST(PIMathMatrix_Test, operator_EqualFalse) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix3 = origMatr.identity(3,3); - vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1.setCol(0, vector); - matrix2.setCol(0, vector); - matrix3.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; - matrix1.setCol(1, vector); - matrix2.setCol(1, vector); - matrix3.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; - matrix1.setCol(2, vector); - matrix2.setCol(2, vector); - vector.at(0) = 566.0; - vector.at(1) = 564.0; - vector.at(2) = 543.0; - matrix3.setCol(2, vector); - if(((matrix1 != matrix2) == false) && ((matrix1 != matrix3) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) +{ + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix2.fill(6.72); - matrix1.fill(1.0); + PIMathMatrix matrix1(3, 3, 1.0); + PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } TEST(PIMathMatrix_Test, operator_Division_Assignment) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - bool b; - matrix1 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } TEST(PIMathMatrix_Test, operator_Addition) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3, 3); - matrix2 = origMatr.identity(3, 3); - origMatr.fill(8.0); - matrix1.fill(8.28); - origMatr = origMatr - matrix1; - matrix2.fill(-0.28); - if(origMatr == matrix2) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + PIMathMatrix matrix1(3, 3, 6.0); + PIMathMatrix matrix2(3, 3, 5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } TEST(PIMathMatrix_Test, operator_Division) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - bool b; - matrix1 = origMatr.identity(3,3); - matrix2 = origMatr.identity(3,3); - matrix1.fill(6.72); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinant) +TEST(PIMathMatrix_Test, determinantIfSquare) { - PIMathMatrix origMatr; double d; double i = 59.0; - PIMathMatrix matrix; + PIMathMatrix matrix(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -543,18 +382,23 @@ TEST(PIMathMatrix_Test, determinant) ASSERT_DOUBLE_EQ(d, i); } +TEST(PIMathMatrix_Test, determinantIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.determinant()); +} + TEST(PIMathMatrix_Test, trace) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -568,18 +412,23 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } +TEST(PIMathMatrix_Test, traceIfNotSquare) +{ + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.trace()); +} + TEST(PIMathMatrix_Test, toUpperTriangular) { - PIMathMatrix origMatr; + PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; - PIMathMatrix matrix; PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix = origMatr.identity(3, 3); matrix.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -600,19 +449,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -626,8 +473,6 @@ TEST(PIMathMatrix_Test, invert) matrix2 = matrix1; matrix2.invert(); d2 = matrix2.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -642,19 +487,17 @@ TEST(PIMathMatrix_Test, invert) TEST(PIMathMatrix_Test, inverted) { - PIMathMatrix origMatr; double d1, d2; bool b; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathMatrix matrix4; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); vector.at(0) = 2.0; vector.at(1) = 1.0; @@ -668,8 +511,6 @@ TEST(PIMathMatrix_Test, inverted) matrix2 = matrix1; matrix1 = matrix2.invert(); d2 = matrix1.determinant(); - matrix3 = origMatr.identity(3, 3); - matrix4 = origMatr.identity(3, 3); matrix3 = matrix4.invert(); if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) { @@ -718,4 +559,4 @@ TEST(PIMathMatrix_Test, transposed) b = false; } ASSERT_TRUE(b); -} \ No newline at end of file +} From eab3317ae62738841e2a6d8bb2642279eeaeeb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 15:27:09 +0300 Subject: [PATCH 44/68] testing another operations --- tests/math/testpimathmatrix.cpp | 80 ++++++++++++++++++++++++++++++++ tests/math/testpimathmatrixt.cpp | 73 +++++++++-------------------- 2 files changed, 101 insertions(+), 52 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index deeca9ca..ae3b46f3 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -35,6 +35,26 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } +TEST(PIMathMatrixT_Test, element) +{ + auto matrix = PIMathMatrix::identity(3, 3); + for(uint i = 0; i < 3; i++) { + if(matrix.element(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); + } + } + } + } + ASSERT_TRUE(true); +} + TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; @@ -560,3 +580,63 @@ TEST(PIMathMatrix_Test, transposed) } ASSERT_TRUE(b); } + +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathMatrix matrix2(2, 2, 2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); +} + +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + PIMathMatrix matrix1(3, 3, 1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} + +TEST(PIMathMatrixT_Test, hermitian) +{ + complex val; + complex res; + val.imag(1.0); + val.real(1.0); + PIMathMatrix> matrix(3, 3, val); + res.imag(-1.0); + res.real(1.0); + auto matr = hermitian(matrix); + for(uint i = 0; i < 3; i++) { + for(uint j = 0; j < 3; j++) { + if(matr.element(i, j) != res) { + ASSERT_TRUE(false); + } + } + } + ASSERT_TRUE(true); +} + diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 0542332a..6e4e0a45 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -4,38 +4,20 @@ const uint rows = 3; const uint cols = 3; -bool cmpMatrixWithValue(PIMathMatrixT matrix, double val) +template +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { - int i = 0; - int j = 0; - int k = 0; - bool b; - while(i < 9) - { - if(k < 3) - { - if(matrix.at(j,k) == val) - { - b = true; - } - else - { + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.at(i, j) != val) { b = false; - break; - } - k++; - if(k == 3) - { - j++; - k = 0; } } - i++; } return b; } - TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); @@ -58,26 +40,13 @@ TEST(PIMathMatrixT_Test, identity) TEST(PIMathMatrixT_Test, at) { - uint i; - bool b; - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1 = matr.identity(); - matrix2 = matr.identity(); - for(i = 0; i < rows; i++) - { - if(matrix1.at(i,i) == 1.0) - { - b = true; - } - else - { - b = false; - break; + auto matrix1 = PIMathMatrixT::identity(); + for(uint i = 0; i < rows; i++) { + if(matrix1.at(i,i) != 1.0) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, filled) { @@ -374,7 +343,7 @@ TEST(PIMathMatrixT_Test, operator_Assignment) bool b; matrix2.fill(6.72); matrix1 = matrix2; - b = cmpMatrixWithValue(matrix1, 6.72); + b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); ASSERT_TRUE(b); } @@ -444,7 +413,7 @@ TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 += matrix2; - b = cmpMatrixWithValue(matrix1, 7.72); + b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); ASSERT_TRUE(b); } @@ -456,7 +425,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) matrix2.fill(6.72); matrix1.fill(1.0); matrix1 -= matrix2; - b = cmpMatrixWithValue(matrix1, -5.72); + b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); ASSERT_TRUE(b); } @@ -466,7 +435,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) bool b; matrix1.fill(6.72); matrix1 *= 2.0; - b = cmpMatrixWithValue(matrix1, 13.44); + b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); ASSERT_TRUE(b); } @@ -476,7 +445,7 @@ TEST(PIMathMatrixT_Test, operator_Division_Assignment) bool b; matrix1.fill(6.72); matrix1 /= 2.0; - b = cmpMatrixWithValue(matrix1, 3.36); + b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); ASSERT_TRUE(b); } @@ -487,7 +456,7 @@ TEST(PIMathMatrixT_Test, operator_Addition) bool b; matrix1.fill(6.72); matrix2.fill(8.28); - b = cmpMatrixWithValue(matrix1 + matrix2, 15.0); + b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); ASSERT_TRUE(b); } @@ -498,7 +467,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction) bool b; matrix1.fill(6.0); matrix2.fill(5.0); - b = cmpMatrixWithValue(matrix1 - matrix2, 1.0); + b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); ASSERT_TRUE(b); } @@ -509,7 +478,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication) bool b; matrix1.fill(6.72); matrix2 = matrix1*4.0; - b = cmpMatrixWithValue(matrix2, 26.88); + b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Division) @@ -519,7 +488,7 @@ TEST(PIMathMatrixT_Test, operator_Division) bool b; matrix1.fill(6.72); matrix2 = matrix1/4.0; - b = cmpMatrixWithValue(matrix2, 1.68); + b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); ASSERT_TRUE(b); } @@ -721,7 +690,7 @@ TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); - ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0)); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } TEST(PIMathMatrixT_Test, rotationX) From 88a147e0a1cbf41f4b7bb042c7e25f37675bf740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=D0=B4=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=92=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 10 Sep 2020 17:48:28 +0300 Subject: [PATCH 45/68] string tests --- tests/CMakeLists.txt | 3 +- tests/core/pistringTest.cpp | 3008 +++++++++++++++++++++++++++++++++++ 2 files changed, 3010 insertions(+), 1 deletion(-) create mode 100644 tests/core/pistringTest.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bebb15da..49c4d1be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ macro(pip_test NAME LIBS) set(_target pip_${NAME}_test) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PIP_ROOT_BINARY_DIR}") add_executable(${_target} ${_CPPS} ${_HDRS}) - target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) + target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) add_test(NAME ${_target} COMMAND tests) add_custom_target(${_target}_perform ALL COMMAND ${_target}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY) @@ -17,3 +17,4 @@ endmacro() # Concurrent tests pip_test(concurrent "") pip_test(math "") +pip_test(core "") diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp new file mode 100644 index 00000000..26f5c97f --- /dev/null +++ b/tests/core/pistringTest.cpp @@ -0,0 +1,3008 @@ +#include "gtest/gtest.h" +#include "pistring.h" +#include "pistringlist.h" + +using namespace std; + +TEST(PIString_Tests, operator_concatenation_pichar){ + PIString str1 = "AB C"; + const PIChar str2 = " "; + str1 += str2; + ASSERT_STREQ(str1, "AB C "); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero1){ + PIString str1 = ""; + const PIChar str2 = "D"; + str1 += str2; + ASSERT_STREQ(str1, "D"); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero2){ + PIString str1 = "AB C"; + const PIChar str2 = ""; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_pichar_zero_zero){ + PIString str1; + const PIChar str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_char){ + PIString str1 = "AB C"; + const char *str2 = "D D "; + str1 += str2; + ASSERT_STREQ(str1, "AB CD D "); +} + +TEST(PIString_Tests, operator_concatenation_char_zero1){ + PIString str1 = ""; + const char *str2 = "D D "; + str1 += str2; + ASSERT_STREQ(str1, "D D "); +} + +TEST(PIString_Tests, operator_concatenation_char_zero2){ + PIString str1 = "AB C"; + const char *str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_char_zero_zero){ + PIString str1; + const char *str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_wchar){ + PIString str1= "AB C"; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_STREQ(str1, "AB CC"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero1){ + PIString str1 = ""; + wchar_t str2[] = L"C"; + str1 += str2; + ASSERT_STREQ(str1, "C"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero2){ + PIString str1 = "AB C"; + wchar_t *str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_wchar_zero_zero){ + PIString str1; + wchar_t *str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_pistring){ + PIString str1 = "AB C"; + PIString str2 = " CD "; + str1 += str2; + ASSERT_STREQ(str1, "AB C CD "); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero1){ + PIString str1 = ""; + PIString str2 = "D DD"; + str1 += str2; + ASSERT_STREQ(str1, "D DD"); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero2){ + PIString str1 = "AB C"; + PIString str2 = ""; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){ + PIString str1; + PIString str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray){ + PIString str1 = "AB C"; + PIByteArray str2; + str2.append('g'); + str1 += str2; + ASSERT_STREQ(str1, "AB Cg"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){ + PIString str1 = ""; + PIByteArray str2; + str2.append('0'); + str1 += str2; + ASSERT_STREQ(str1, "0"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){ + PIString str1 = "AB C"; + PIByteArray str2; + str1 += str2; + ASSERT_STREQ(str1, "AB C"); +} + +TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){ + PIString str1; + PIByteArray str2; + str1 += str2; + ASSERT_STREQ(str1, ""); +} + +TEST(PIString_Tests, construct_pistring){ + PIString str1 = "New"; + ASSERT_STREQ(str1, PIString("New")); +} + +TEST(PIString_Tests, construct_pichar){ + PIChar str1 = 'n'; + ASSERT_STREQ("n", PIString(str1)); +} + +TEST(PIString_Tests, construct_char){ + char str1 = 'n'; + ASSERT_STREQ("n", PIString(str1)); +} + +TEST(PIString_Tests, construct_chars){ + char str1[] = "mew"; + ASSERT_STREQ("mew", PIString(str1)); +} + +TEST(PIString_Tests, construct_wchar_t){ + wchar_t str1[] = L"gav"; + ASSERT_STREQ("gav", PIString(str1)); +} + +TEST(PIString_Tests, construct_pibyte_array){ + PIByteArray str1; + str1.append('m'); + ASSERT_STREQ("m", PIString(str1)); +} + +TEST(PIString_Tests, construct_pichar_size){ + PIChar *str1 = new PIChar[3]; + str1[0] = 'n'; + str1[1] = 'e'; + str1[2] = 'w'; + ASSERT_STREQ("new", PIString(str1, 3)); +} + +TEST(PIString_Tests, construct_char_size){ + char str1[] = "good"; + ASSERT_STREQ("good", PIString(str1, 4)); +} + +TEST(PIString_Tests, construct_char_len){ + char str1 = 'n'; + ASSERT_STREQ("nnn", PIString(3, str1)); +} + +TEST(PIString_Tests, construct_pichar_len){ + PIChar str1 = 'n'; + ASSERT_STREQ("nnnnn", PIString(5, str1)); +} + +TEST(PIString_Tests, operator_pointer){ + PIString str1 = "testing"; + const char *point = str1.operator const char *(); + ASSERT_STREQ("testing", point); +} + +TEST(PIString_Tests, operator_symbol){ + PIString str1 = "testing"; + PIChar symbo = "i"; + ASSERT_EQ(symbo, str1[4]); +} + +TEST(PIString_Tests, operator_compare_pistring_true){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pistring_false){ + PIString str1 = "tes"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "p"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_char_true){ + PIString str1 = "test"; + char str2[] = "test"; + ASSERT_TRUE(str1 == str2); +} + +TEST(PIString_Tests, operator_compare_char_false){ + PIString str1 = "t"; + char str2[] = "test"; + ASSERT_FALSE(str1 == str2); +} + +TEST(PIString_Tests, operator_encompare_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pistring_true){ + PIString str1 = "tes"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "p"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_char_false){ + PIString str1 = "test"; + char str2[] = "test"; + ASSERT_FALSE(str1 != str2); +} + +TEST(PIString_Tests, operator_encompare_char_true){ + PIString str1 = "t"; + char str2[] = "test"; + ASSERT_TRUE(str1 != str2); +} + +TEST(PIString_Tests, operator_less_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pistring_false_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_true){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_pichar_false_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_true){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_TRUE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_false){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_less_char_false_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_FALSE(str1 < str2); +} + +TEST(PIString_Tests, operator_more_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str2 > str1); +} + +TEST(PIString_Tests, operator_more_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str2 > str1); +} + +TEST(PIString_Tests, operator_more_pistring_false_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_TRUE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_false){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_pichar_false_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_true){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_TRUE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_false){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_more_char_false_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_FALSE(str1 > str2); +} + +TEST(PIString_Tests, operator_less_eq_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_pistring_true_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_true){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_false){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_pichar_true_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_true){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_false){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_FALSE(str1 <= str2); +} + +TEST(PIString_Tests, operator_less_eq_char_true_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_TRUE(str1 <= str2); +} + +TEST(PIString_Tests, operator_more_eq_pistring_true){ + PIString str1 = "testin"; + PIString str2 = "testing"; + ASSERT_TRUE(str2 >= str1); +} + +TEST(PIString_Tests, operator_more_eq_pistring_false){ + PIString str1 = "testing"; + PIString str2 = "testin"; + ASSERT_FALSE(str2 >= str1); +} + +TEST(PIString_Tests, operator_more_eq_pistring_true_equal){ + PIString str1 = "testing"; + PIString str2 = "testing"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_true){ + PIString str1 = "t"; + PIChar str2 = "a"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_false){ + PIString str1 = "a"; + PIChar str2 = "t"; + ASSERT_FALSE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_pichar_true_equal){ + PIString str1 = "t"; + PIChar str2 = "t"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_true){ + PIString str1 = "t"; + char str2[] = "a"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_false){ + PIString str1 = "a"; + char str2[] = "t"; + ASSERT_FALSE(str1 >= str2); +} + +TEST(PIString_Tests, operator_more_eq_char_true_equal){ + PIString str1 = "t"; + char str2[] = "t"; + ASSERT_TRUE(str1 >= str2); +} + +TEST(PIString_Tests, operator_shift_pistring){ + PIString str1 = "shift"; + PIString str2 = " good"; + str1 << str2; + ASSERT_STREQ("shift good", str1); +} + +TEST(PIString_Tests, operator_shift_pichar){ + PIString str1 = "shif"; + PIChar str2 = 't'; + str1 << str2; + ASSERT_STREQ("shift", str1); +} + +TEST(PIString_Tests, operator_shift_char){ + PIString str1 = "shif"; + char str2[] = "t chat"; + str1 << str2; + ASSERT_STREQ("shift chat", str1); +} + +TEST(PIString_Tests, operator_shift_wchar_t){ + PIString str1 = "shif"; + wchar_t str2[] = L"t cc"; + str1 << str2; + ASSERT_STREQ("shift cc", str1); +} + +TEST(PIString_Tests, operator_shift_int){ + PIString str1 = "shift "; + int numb = -2147483648; + str1 << numb; + ASSERT_STREQ("shift -2147483648", str1); +} + +TEST(PIString_Tests, operator_shift_uint){ + PIString str1 = "shift "; + uint numb = 4294967295; + str1 << numb; + ASSERT_STREQ("shift 4294967295", str1); +} + +TEST(PIString_Tests, operator_shift_short){ + PIString str1 = "shift "; + short numb = -32768; + str1 << numb; + ASSERT_STREQ("shift -32768", str1); +} + +TEST(PIString_Tests, operator_shift_ushort){ + PIString str1 = "shift "; + ushort numb = 65535; + str1 << numb; + ASSERT_STREQ("shift 65535", str1); +} + +TEST(PIString_Tests, operator_shift_long){ + PIString str1 = "shift "; + long numb = -2147483648; + str1 << numb; + ASSERT_STREQ("shift -2147483648", str1); +} + +TEST(PIString_Tests, operator_shift_ulong){ + PIString str1 = "shift "; + ulong numb = 4294967295; + str1 << numb; + ASSERT_STREQ("shift 4294967295", str1); +} + +TEST(PIString_Tests, operator_shift_llong){ + PIString str1 = "shift "; + llong numb = -9223372036854775807; + str1 << numb; + ASSERT_STREQ("shift -9223372036854775807", str1); +} + +TEST(PIString_Tests, operator_shift_ullong){ + PIString str1 = "shift "; + ullong numb = 1844674407370955161; + str1 << numb; + ASSERT_STREQ("shift 1844674407370955161", str1); +} + +TEST(PIString_Tests, operator_shift_float){ + PIString str1 = "shift "; + float numb = -67.88999939; + str1 << numb; + ASSERT_STREQ("shift -67.88999939", str1); +} + +TEST(PIString_Tests, operator_shift_double){ + PIString str1 = "shift "; + double numb = 13.34300000; + str1 << numb; + + ASSERT_STREQ("shift 13.34300000", str1); +} + +TEST(PIString_Tests, prepend){ + PIString str1 = "idea"; + PIString str2 = "Good "; + str1.prepend(str2); + ASSERT_STREQ("Good idea", str1); +} + +TEST(PIString_Tests, append){ + PIString str1 = "Good"; + PIString str2 = " idea"; + str1.append(str2); + ASSERT_STREQ("Good idea", str1); +} + +TEST(PIString_Tests, mid){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("fo", str1.mid(10, 2)); +} + +TEST(PIString_Tests, mid_len_0){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.mid(10, 0)); +} + + +TEST(PIString_Tests, mid_start_more){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.mid(1000, 0)); +} + +TEST(PIString_Tests, mid_len_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, -2)); +} + +TEST(PIString_Tests, mid_len_more){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, 100)); +} + +TEST(PIString_Tests, subString){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("for new project 144", str1.mid(10, 46)); +} + +TEST(PIString_Tests, mid_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.mid(-10, 47)); +} + +TEST(PIString_Tests, subString_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Go", str1.mid(-10, 12)); +} + +TEST(PIString_Tests, left){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Go", str1.left(2)); +} + +TEST(PIString_Tests, left_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.left(-2)); +} + +TEST(PIString_Tests, right){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("44", str1.right(2)); +} + +TEST(PIString_Tests, right_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("", str1.right(-2)); +} + +TEST(PIString_Tests, cutMid){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good for new project 144", str1.cutMid(5,5)); +} + +TEST(PIString_Tests, cutMid_len_zero){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutMid(5,0)); +} + +TEST(PIString_Tests, cutMid_len_min){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good ", str1.cutMid(5,-2)); +} + +TEST(PIString_Tests, cutMid_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("ood idea for new project 144", str1.cutMid(-5, 6)); +} + +TEST(PIString_Tests, cutMid_zero){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutMid(-5, 5)); +} + +TEST(PIString_Tests, cutleft){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("od idea for new project 144", str1.cutLeft(2)); +} + +TEST(PIString_Tests, cutleft_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutLeft(-2)); +} + +TEST(PIString_Tests, cutright){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 1", str1.cutRight(2)); +} + +TEST(PIString_Tests, cutright_minus){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.cutRight(-2)); +} + +TEST(PIString_Tests, trim){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("Good idea for new project 144", str1.trim()); +} + +TEST(PIString_Tests, trim_without){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.trim()); +} + +TEST(PIString_Tests, trim_link){ + PIString str1 = " Good idea for new project 144 "; + PIString &str2 = str1.trim(); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, trimmed){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); +} + +TEST(PIString_Tests, trimmed_without){ + PIString str1 = "Good idea for new project 144"; + ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); +} + +TEST(PIString_Tests, replace){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin for new project 144 ", str1.replace(6,4, "thin")); +} + +TEST(PIString_Tests, replace_more){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin", str1.replace(6,100, "thin")); +} + +TEST(PIString_Tests, replace_link){ + PIString str1 = " Good idea for new project 144 "; + PIString &str2 = str1.replace(6,4, "thin"); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, replace_minus){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD idea for new project 144 ", str1.replace(0, 5, "BAD")); +} + +TEST(PIString_Tests, replace_zero){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin Good idea for new project 144 ", str1.replace(0, 0, "thin")); +} + +TEST(PIString_Tests, replace_all){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD", str1.replaced(0, 100, "BAD")); +} + +TEST(PIString_Tests, replaced){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ(" Good thin for new project 144 ", str1.replaced(6,4, "thin")); +} + +TEST(PIString_Tests, replaced_minus){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("BAD idea for new project 144 ", str1.replaced(0, 5, "BAD")); +} + +TEST(PIString_Tests, replaced_zero){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin Good idea for new project 144 ", str1.replaced(0, 0, "thin")); +} + + +TEST(PIString_Tests, replaced_all){ + PIString str1 = " Good idea for new project 144 "; + ASSERT_STREQ("thin", str1.replaced(0, 100, "thin")); +} + +TEST(PIString_Tests, replace_str){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "bad", &ok); + ASSERT_STREQ(" bad idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replace_str_link){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString &str2 = str1.replace("Good", "bad", &ok); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, replace_str_zero){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("", "bad", &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, replace_str_true){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "bad", &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, replace_str_delete){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replace("Good", "", &ok); + ASSERT_STREQ(" idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replaced_str){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString str2 = str1.replaced("Good", "bad", &ok); + ASSERT_STREQ(" bad idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaced_str_zero){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replaced("", "bad", &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, replaced_str_true){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + str1.replaced("Good", "bad", &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, replaced_delete){ + PIString str1 = " Good idea for new Good project 144 "; + bool ok = 1; + PIString str2 = str1.replaced("Good", "", &ok); + ASSERT_STREQ(" idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaceall){ + PIString str1 = " Good idea for new Good project 144 "; + str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str1); +} + +TEST(PIString_Tests, replaceall_no_find){ + PIString str1 = " Good idea for new Good project 144 "; + str1.replaceAll("God", "bad"); + ASSERT_STREQ(" Good idea for new Good project 144 ", str1); +} + +TEST(PIString_Tests, replaceall_str){ + PIString str1 = " Good idea for new Good project 144 "; + PIString str2 = str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_str_no_find){ + PIString str1 = " Good idea for new Good project 144 "; + PIString str2 = str1.replaceAll("God", "bad"); + ASSERT_STREQ(" Good idea for new Good project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_link){ + PIString str1 = " Good idea for new Good project 144 "; + PIString &str2 = str1.replaceAll("Good", "bad"); + ASSERT_STREQ(" bad idea for new bad project 144 ", str2); +} + +TEST(PIString_Tests, replaceall_link_change){ + PIString str1 = " Good idea for new Good project 144 "; + PIString &str2 = str1.replaceAll("Good", "bad"); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, repeat){ + PIString str1 = "string "; + PIString str2 = str1.repeat(6); + ASSERT_STREQ("string string string string string string ", str2); +} + +TEST(PIString_Tests, repeat_zero){ + PIString str1 = "string "; + PIString str2 = str1.repeat(0); + ASSERT_STREQ("string ", str2); +} + +TEST(PIString_Tests, repeat_link){ + PIString str1 = "string "; + PIString &str2 = str1.repeat(6); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, repeated){ + PIString str1 = "string "; + str1.repeat(6); + ASSERT_STREQ("string string string string string string ", str1); +} + +TEST(PIString_Tests, repeated_zero){ + PIString str1 = "string "; + str1.repeat(0); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_char){ + PIString str1 = "strng "; + char sym = 'i'; + str1.insert(3, sym); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_pichar){ + PIString str1 = "strng "; + PIChar sym = 'i'; + str1.insert(3, sym); + ASSERT_STREQ("string ", str1); +} + +TEST(PIString_Tests, insert_pistring){ + PIString str1 = "string out"; + PIString str2 = " go"; + str1.insert(6, str2); + ASSERT_STREQ("string go out", str1); +} + +TEST(PIString_Tests, insert_chars){ + PIString str1 = "see boy"; + char str2[] = " big"; + str1.insert(3, str2); + ASSERT_STREQ("see big boy", str1); +} + +TEST(PIString_Tests, expandRightTo){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandRightTo(11, symbol); + ASSERT_STREQ("see boy xxx", str1); +} + +TEST(PIString_Tests, expandRightTo_null){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandRightTo(0, symbol); + ASSERT_STREQ("see boy ", str1); +} + +TEST(PIString_Tests, expandLeftTo){ + PIString str1 = " see boy"; + PIChar symbol = "x"; + str1.expandLeftTo(11, symbol); + ASSERT_STREQ("xxx see boy", str1); +} + +TEST(PIString_Tests, expandLeftTo_null){ + PIString str1 = "see boy "; + PIChar symbol = "x"; + str1.expandLeftTo(0, symbol); + ASSERT_STREQ("see boy ", str1); +} + +TEST(PIString_Tests, quote){ + PIString str1 = "see boy"; + PIChar symbol = " "; + str1.quote(symbol); + ASSERT_STREQ(" see boy ", str1); +} + +TEST(PIString_Tests, quote_link){ + PIString str1 = "see boy"; + PIChar symbol = " "; + PIString &str2 = str1.quote(symbol); + str1 = "link"; + ASSERT_STREQ("link", str2); +} + +TEST(PIString_Tests, quoted){ + PIString str1 = "see boy"; + PIChar symbol = " "; + PIString str2 = str1.quoted(symbol); + ASSERT_STREQ(" see boy ", str2); +} + +TEST(PIString_Tests, reverse){ + PIString str1 = "see boy"; + PIString &str2 = str1.reverse(); + ASSERT_STREQ("yob ees", str2); +} + +TEST(PIString_Tests, reverse_link){ + PIString str1 = "see boy"; + PIString &str2 = str1.reverse(); + str1 = "yes"; + ASSERT_STREQ("yes", str2); +} + +TEST(PIString_Tests, reversed){ + PIString str1 = "see boy"; + PIString str2 = str1.reversed(); + ASSERT_STREQ("yob ees", str2); +} + +TEST(PIString_Tests, elide){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(8, 1); + ASSERT_STREQ("BMSTU ..", str2); +} + +TEST(PIString_Tests, elide_small){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(2, 1); + ASSERT_STREQ("..", str2); +} + +TEST(PIString_Tests, elide_all){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(100, 1); + ASSERT_STREQ("BMSTU is best university in space", str2); +} + +TEST(PIString_Tests, elide_link){ + PIString str1 = "BMSTU is best university in space"; + PIString &str2 = str1.elide(8, 1); + str1 = "space"; + ASSERT_STREQ("space", str2); +} + +TEST(PIString_Tests, elided){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.elided(8, 1); + ASSERT_STREQ("BMSTU ..", str2); +} + +TEST(PIString_Tests, takemid){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeMid(9, 4); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, takeleft){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeLeft(5); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeright){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRight(5); + ASSERT_STREQ("space", str2); +} + +TEST(PIString_Tests, takesymbol){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("B", str2); +} + +TEST(PIString_Tests, takesymbol_with_rubbish){ + PIString str1 = " \t \n \r BMSTU is best university in space"; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("B", str2); +} + +TEST(PIString_Tests, takesymbol_without){ + PIString str1 = " \t \n \r "; + PIString str2 = str1.takeSymbol(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeword){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeword_space){ + PIString str1 = " \r\n\tBMSTU is best university in space"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takeword_without_word){ + PIString str1 = " \r\n\t"; + PIString str2 = str1.takeWord(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takecword){ + PIString str1 = "_6 BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("_6", str2); +} + +TEST(PIString_Tests, takecword_space){ + PIString str1 = " \t\r\n_6 BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("_6", str2); +} + +TEST(PIString_Tests, takecword_space_w){ + PIString str1 = " \t\r\n BMSTU is best university in space"; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("BMSTU", str2); +} + +TEST(PIString_Tests, takecword_not_cword){ + PIString str1 = " \t\r\n "; + PIString str2 = str1.takeCWord(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeline){ + PIString str1 = "BMSTU is best\n university in space"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("BMSTU is best", str2); +} + +TEST(PIString_Tests, takeline_without){ + PIString str1 = "BMSTU is best"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takeline_first){ + PIString str1 = "\nBMSTU is best"; + PIString str2 = str1.takeLine(); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, takenumber){ + PIString str1 = "6.6"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("6.6", str2); +} + +TEST(PIString_Tests, takenumber_sign){ + PIString str1 = "-66"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("-66", str2); +} + +TEST(PIString_Tests, takenumber_suffix){ + PIString str1 = "66L"; + PIString str2 = str1.takeNumber(); + ASSERT_STREQ("66L", str2); +} + +TEST(PIString_Tests, takerange){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i', ' '); + ASSERT_STREQ("MSTU is best un", str2); +} + +TEST(PIString_Tests, takerange_without_shield){ + PIString str1 = "BMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i'); + ASSERT_STREQ("MSTU ", str2); +} + +TEST(PIString_Tests, takerange_space){ + PIString str1 = " \t\r\nBMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i', ' '); + ASSERT_STREQ("MSTU is best un", str2); +} + +TEST(PIString_Tests, takerange_without_shield_space){ + PIString str1 = " \t\r\nBMSTU is best university in space"; + PIString str2 = str1.takeRange('B', 'i'); + ASSERT_STREQ("MSTU ", str2); +} + +TEST(PIString_Tests, inBrackets){ + PIString str1 = "BMSTU is (best) university in space"; + PIString str2 = str1.inBrackets('(', ')'); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, inBrackets_end_start){ + PIString str1 = "BMSTU )is (best) university in space"; + PIString str2 = str1.inBrackets('(', ')'); + ASSERT_STREQ("best", str2); +} + +TEST(PIString_Tests, inBrackets_without){ + PIString str1 = "BMSTU )is (best) university in space"; + PIString str2 = str1.inBrackets('0', '1'); + ASSERT_STREQ("", str2); +} + +TEST(PIString_Tests, lenghtascii){ + PIString str1 = "BMSTU is (best) university in space"; + int size = str1.lengthAscii(); + ASSERT_EQ(35, size); +} + +TEST(PIString_Tests, data){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.data(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataconsole){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataConsole(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataUTF8){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataUTF8(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, dataAScii){ + PIString str1 = "BMSTU is (best) university in space\n"; + const char *data = str1.dataAscii(); + ASSERT_STREQ("BMSTU is (best) university in space\n", data); +} + +TEST(PIString_Tests, hash){ + const PIString str1 = "B"; + uint h = str1.hash(); + ASSERT_EQ(3912571919, h); +} + +TEST(PIString_Tests, toByteArray){ + const PIString str1 = "C"; + PIByteArray h = str1.toByteArray(); + ASSERT_EQ(67, h.at(0)); +} + +TEST(PIString_Tests, toUTF8){ + const PIString str1 = "C"; + PIByteArray h = str1.toUTF8(); + ASSERT_EQ(67, h.at(0)); +} + +TEST(PIString_Tests, tocharset){ + const PIString str1 = "B"; + PIByteArray h = str1.toCharset("c"); + ASSERT_EQ(66, h.at(0)); +} + +TEST(PIString_Tests, toUTF8_empty){ + PIString str1; + str1.toUTF8(); + ASSERT_EQ(0, str1.size()); +} + +TEST(PIString_Tests, tocharset_empty){ + PIString str1 = ""; + str1.toCharset("c"); + ASSERT_EQ(0, str1.size()); +} + +TEST(PIString_Tests, split){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split("best"); + ASSERT_STREQ(list[1], list[0]); +} + +TEST(PIString_Tests, split_empty){ + PIString str1 = ""; + PIStringList list = str1.split("best"); + ASSERT_EQ(0, list.size()); +} + +TEST(PIString_Tests, split_empty_delim){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split(""); + ASSERT_EQ(0, list.size()); +} + +TEST(PIString_Tests, split_not_delim){ + PIString str1 = " mirrow best mirrow "; + PIStringList list = str1.split("tr"); + ASSERT_STREQ(list[0], " mirrow best mirrow "); +} + +TEST(PIString_Tests, toUpperCase){ + PIString str1 = " miRrow "; + PIString str2 = str1.toUpperCase(); + ASSERT_STREQ(" MIRROW ", str2); +} + +TEST(PIString_Tests, toLowerCase){ + PIString str1 = " MIrROW "; + PIString str2 = str1.toLowerCase(); + ASSERT_STREQ(" mirrow ", str2); +} + +TEST(PIString_Tests, toNativeDecimalPoints){ + PIString str1 = "4546,878"; + PIString str2 = str1.toNativeDecimalPoints(); + ASSERT_STREQ("4546.878", str2); +} + +TEST(PIString_Tests, contains_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = '\n'; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = '0'; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_picahr){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIChar s = 'i'; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_pichar_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIChar s = '0'; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_cahrs){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "BMSTU"; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "out"; + ASSERT_FALSE(str1.contains(s)); +} + + +TEST(PIString_Tests, contains_pistring){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString s = "univer"; + ASSERT_TRUE(str1.contains(s)); +} + +TEST(PIString_Tests, contains_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString s = "new"; + ASSERT_FALSE(str1.contains(s)); +} + +TEST(PIString_Tests, find_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(6, str1.find(s)); +} + +TEST(PIString_Tests, find_char_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(18, str1.find(s, 7)); +} + +TEST(PIString_Tests, find_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'o'; + ASSERT_EQ(-1, str1.find(s)); +} + +TEST(PIString_Tests, find_chars){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "is"; + ASSERT_EQ(6, str1.find(str2)); +} + +TEST(PIString_Tests, find_chars_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "iv"; + ASSERT_EQ(18, str1.find(str2, 7)); +} + +TEST(PIString_Tests, find_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s[] = "ouc"; + ASSERT_EQ(-1, str1.find(s)); +} + +TEST(PIString_Tests, find_pistring){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "is"; + ASSERT_EQ(6, str1.find(str2)); +} + +TEST(PIString_Tests, find_pistring_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "iv"; + ASSERT_EQ(18, str1.find(str2, 7)); +} + +TEST(PIString_Tests, find_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "ouc"; + ASSERT_EQ(-1, str1.find(str2)); +} + +TEST(PIString_Tests, find_last_char){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(27, str1.findLast(s)); +} + +TEST(PIString_Tests, find_last_char_start){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'i'; + ASSERT_EQ(27, str1.findLast(s, 20)); +} + +TEST(PIString_Tests, find_last_char_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char s = 'o'; + ASSERT_EQ(-1, str1.findLast(s)); +} + +TEST(PIString_Tests, find_last_chars){ + PIString str1 = "BMSTU is (best) university in is space\n"; + char str2[] = "is"; + ASSERT_EQ(30, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_chars_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + char str2[] = "iv"; + ASSERT_EQ(30, str1.findLast(str2, 25)); +} + +TEST(PIString_Tests, find_last_chars_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + char str2[] = "ouc"; + ASSERT_EQ(-1, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_pistring){ + PIString str1 = "BMSTU is (best) university in is space\n"; + PIString str2 = "is"; + ASSERT_EQ(30, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_last_pistring_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "iv"; + ASSERT_EQ(30, str1.findLast(str2, 10)); +} + +TEST(PIString_Tests, find_last_pistring_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "ouc"; + ASSERT_EQ(-1, str1.findLast(str2)); +} + +TEST(PIString_Tests, find_word){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findWord(str2)); +} + +TEST(PIString_Tests, find_word_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_space_before){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = " university"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_space_after){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university "; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_digit_before){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "_university"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_digit_after){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "university_"; + ASSERT_EQ(-1, str1.findWord(str2, 10)); +} + +TEST(PIString_Tests, find_word_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "university"; + ASSERT_EQ(-1, str1.findWord(str2, 37)); +} + +TEST(PIString_Tests, find_cword){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findCWord(str2)); +} + +TEST(PIString_Tests, find_cword_start){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university"; + ASSERT_EQ(16, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_space_before){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = " university"; + ASSERT_EQ(15, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_space_after){ + PIString str1 = "BMSTU is (best) university in iv space\n"; + PIString str2 = "university "; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_digit_before){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "_university"; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_digit_after){ + PIString str1 = "BMSTU is (best) _university_ in iv space\n"; + PIString str2 = "university_"; + ASSERT_EQ(-1, str1.findCWord(str2, 10)); +} + +TEST(PIString_Tests, find_cword_false){ + PIString str1 = "BMSTU is (best) university in space\n"; + PIString str2 = "university"; + ASSERT_EQ(-1, str1.findCWord(str2, 37)); +} + +TEST(PIString_Tests, find_range){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + ASSERT_EQ(3, str1.findRange(start, end, "n", 1, len)); +} + +TEST(PIString_Tests, find_range_len){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + str1.findRange(start, end, "n", 1, len); + ASSERT_EQ(14, *len); +} + +TEST(PIString_Tests, find_range_len_without_shield){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "g"; + int *len; + str1.findRange(start, end, "/", 1, len); + ASSERT_EQ(9, *len); +} + +TEST(PIString_Tests, find_range_start){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "g"; + PIChar end = "o"; + int *len; + str1.findRange(start, end, " ", 17, len); + ASSERT_EQ(9, *len); +} + +TEST(PIString_Tests, find_range_eq){ + PIString str1 = "A very strong programmer wrote this code"; + PIChar start = "v"; + PIChar end = "v"; + int *len; + str1.findRange(start, end, "n", 1, len); + ASSERT_EQ(0, *len); +} + +TEST(PIString_Tests, find_range_trim){ + PIString str1 = " A very strong programmer wrote this code"; + PIChar start = "A"; + PIChar end = "v"; + int *len; + ASSERT_EQ(2, str1.findRange(start, end, "n", 0, len)); +} + +TEST(PIString_Tests, find_any){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(11, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_not){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "q"; + ASSERT_EQ(-1, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_start){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(15, str1.findAny(str2, 12)); +} + +TEST(PIString_Tests, find_any_chars){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(11, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_chars_not){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "q"; + ASSERT_EQ(-1, str1.findAny(str2, 0)); +} + +TEST(PIString_Tests, find_any_chars_start){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(15, str1.findAny(str2, 12)); +} + +TEST(PIString_Tests, find_any_last){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_not){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "q"; + ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_start){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 12)); +} + +TEST(PIString_Tests, find_any_last_chars){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_chars_not){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "q"; + ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); +} + +TEST(PIString_Tests, find_any_last_chars_start){ + PIString str1 = " A very strong programmer wrote this code"; + char str2[] = "doip"; + ASSERT_EQ(39, str1.findAnyLast(str2, 12)); +} + +TEST(PIString_Tests, entries){ + PIString str1 = " A very strong programmer wrote this code"; + PIChar c = "A"; + ASSERT_EQ(1, str1.entries(c)); +} + +TEST(PIString_Tests, entries_char){ + PIString str1 = " A very strong programmer wrote this code"; + char c = 'A'; + ASSERT_EQ(1, str1.entries(c)); +} + +TEST(PIString_Tests, starts_with){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " A very"; + ASSERT_TRUE(str1.startsWith(str2)); +} + +TEST(PIString_Tests, starts_with_false){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " A veru"; + ASSERT_FALSE(str1.startsWith(str2)); +} + +TEST(PIString_Tests, ends_with){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = " code"; + ASSERT_TRUE(str1.endsWith(str2)); +} + +TEST(PIString_Tests, ends_with_false){ + PIString str1 = " A very strong programmer wrote this code"; + PIString str2 = "c code"; + ASSERT_FALSE(str1.endsWith(str2)); +} + +TEST(PIString_Tests, length){ + PIString str1 = " A very strong programmer wrote this code"; + ASSERT_EQ(41, str1.length()); +} + +TEST(PIString_Tests, is_empty_false){ + PIString str1 = " A very strong programmer wrote this code"; + ASSERT_FALSE(str1.isEmpty()); +} + +TEST(PIString_Tests, is_empty_true){ + PIString str1 = ""; + ASSERT_TRUE(str1.isEmpty()); +} + +TEST(PIString_Tests, to_bool){ + PIString str1 = "1"; + ASSERT_TRUE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_yes){ + PIString str1 = "yes"; + ASSERT_TRUE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_false){ + PIString str1 = "no"; + ASSERT_FALSE(str1.toBool()); +} + +TEST(PIString_Tests, to_bool_false_zero){ + PIString str1 = "0"; + ASSERT_FALSE(str1.toBool()); +} + +TEST(PIString_Tests, to_char){ + PIString str1 = "A very strong programmer wrote this code"; + ASSERT_EQ(65, str1.toChar()); +} + +TEST(PIString_Tests, to_short){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toShort(-1)); +} + +TEST(PIString_Tests, to_short_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toShort(-1)); +} + +TEST(PIString_Tests, to_short_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toShort(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_short_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toShort(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_short_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toShort(10, ok)); +} + +TEST(PIString_Tests, to_ushort){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toUShort(-1)); +} + +TEST(PIString_Tests, to_ushort_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toUShort(-1)); +} + +TEST(PIString_Tests, to_ushort_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toUShort(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ushort_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toUShort(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ushort_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(65529, str1.toUShort(10, ok)); +} + +TEST(PIString_Tests, to_int){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toInt(-1)); +} + +TEST(PIString_Tests, to_int_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toInt(-1)); +} + +TEST(PIString_Tests, to_int_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toInt(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_int_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toInt(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_int_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toShort(10, ok)); +} + +TEST(PIString_Tests, to_uint){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toUInt(-1)); +} + +TEST(PIString_Tests, to_uint_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toUInt(-1)); +} + +TEST(PIString_Tests, to_uint_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toUInt(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_uint_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toUInt(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_uint_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(4294967289, str1.toUInt(10, ok)); +} + +TEST(PIString_Tests, to_long){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toLong(-1)); +} + +TEST(PIString_Tests, to_long_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toLong(-1)); +} + +TEST(PIString_Tests, to_long_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_long_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_long_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toLong(10, ok)); +} + +TEST(PIString_Tests, to_ulong){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toULong(-1)); +} + +TEST(PIString_Tests, to_ulong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toULong(-1)); +} + +TEST(PIString_Tests, to_ulong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toULong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ulong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toULong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ulong_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(4294967289, str1.toULong(10, ok)); +} + +TEST(PIString_Tests, to_llong){ + PIString str1 = "133"; + ASSERT_EQ(133, str1.toLLong(-1)); +} + +TEST(PIString_Tests, to_llong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toLLong(-1)); +} + +TEST(PIString_Tests, to_llong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toLLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_llong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toLLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_llong_neg){ + PIString str1 = "-7"; + bool *ok; + ASSERT_EQ(-7, str1.toLLong(10, ok)); +} + +TEST(PIString_Tests, to_ullong){ + PIString str1 = "133.1"; + ASSERT_EQ(133, str1.toULLong(-1)); +} + +TEST(PIString_Tests, to_ullong_0x){ + PIString str1 = "0x133"; + ASSERT_EQ(307, str1.toULLong(-1)); +} + +TEST(PIString_Tests, to_ullong_false){ + PIString str1 = "0x133"; + bool *ok; + str1.toULLong(1, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ullong_false_base){ + PIString str1 = "7"; + bool *ok; + str1.toULLong(6, ok); + ASSERT_FALSE(*ok); +} + +TEST(PIString_Tests, to_ullong_neg){ + PIString str1 = "-7"; + bool *ok; + ullong f = 184467451609; + ASSERT_EQ(f, str1.toULLong(10, ok)); +} + +TEST(PIString_Tests, to_float){ + PIString str1 = "-7765,54"; + float f = -7765.54; + ASSERT_EQ(f, str1.toFloat()); +} + +TEST(PIString_Tests, to_double){ + PIString str1 = "-7765,54656"; + double f = -7765.54656; + ASSERT_EQ(f, str1.toDouble()); +} + +TEST(PIString_Tests, to_ldouble){ + PIString str1 = "-7765,54656"; + ldouble f = -7765.54656; + ASSERT_EQ(f, str1.toLDouble()); +} + +TEST(PIString_Tests, setNumber){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_zero){ + PIString str1 = " String"; + const short val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_false_base){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_true){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_false_base_str){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_base_minus){ + PIString str1 = " String"; + const short val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ushort){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ushort_true){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ushort_zero){ + PIString str1 = " String"; + const ushort val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ushort_false_base){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ushort_false_base_str){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ushort_base_minus){ + PIString str1 = " String"; + const ushort val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_int){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_int_zero){ + PIString str1 = " String"; + const int val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_int_false_base){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_int_true){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_int_false_base_str){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_int_base_minus){ + PIString str1 = " String"; + const int val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_uint){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_uint_true){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_uintt_zero){ + PIString str1 = " String"; + const uint val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_uint_false_base){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_uint_false_base_str){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_uint_base_minus){ + PIString str1 = " String"; + const uint val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_long){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_long_zero){ + PIString str1 = " String"; + const long val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_long_false_base){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_long_true){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_long_false_base_str){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_long_base_minus){ + PIString str1 = " String"; + const long val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ulong){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ulong_true){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ulong_zero){ + PIString str1 = " String"; + const ulong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ulong_false_base){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ulong_false_base_str){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ulong_base_minus){ + PIString str1 = " String"; + const ulong val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_llong){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_llong_zero){ + PIString str1 = " String"; + const llong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_llong_false_base){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_llong_true){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_llong_false_base_str){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_llong_base_minus){ + PIString str1 = " String"; + const llong val = -10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("-A", str1); +} + +TEST(PIString_Tests, setNumber_ullong){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("131", str1); +} + +TEST(PIString_Tests, setNumber_ullong_true){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, setNumber_ullong_zero){ + PIString str1 = " String"; + const ullong val = 0; + bool ok; + str1.setNumber(val, 10, &ok); + ASSERT_STREQ("0", str1); +} + +TEST(PIString_Tests, setNumber_ullong_false_base){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, setNumber_ullong_false_base_str){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.setNumber(val, 1, &ok); + ASSERT_STREQ("", str1); +} + +TEST(PIString_Tests, setNumber_ullong_base_minus){ + PIString str1 = " String"; + const ullong val = 10; + bool ok; + str1.setNumber(val, 16, &ok); + ASSERT_STREQ("A", str1); +} + +TEST(PIString_Tests, setNumber_float){ + PIString str1 = " String"; + const float val = 131.132; + str1.setNumber(val, 'f', 3); + ASSERT_STREQ("131.132", str1); +} + +TEST(PIString_Tests, setNumber_double){ + PIString str1 = " String"; + const double val = 131.1324334; + str1.setNumber(val, 'f', 7); + ASSERT_STREQ("131.1324334", str1); +} + +TEST(PIString_Tests, setNumber_ldouble){ + PIString str1 = " String"; + const ldouble val = 131.1324334; + str1.setNumber(val, 'f', 7); + ASSERT_STREQ("131.1324334", str1); +} + +TEST(PIString_Tests, setReadableSize){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1023 B", str1.setReadableSize(1023)); +} + +TEST(PIString_Tests, setReadableSize_kb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 kB", str1.setReadableSize(1024)); +} + +TEST(PIString_Tests, setReadableSize_mb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 MB", str1.setReadableSize(1024*1024)); +} + +TEST(PIString_Tests, setReadableSize_gb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 GB", str1.setReadableSize(1024*1024*1024)); +} + +TEST(PIString_Tests, setReadableSize_tb){ + PIString str1 = " ITELMA"; + llong val = 99999999999999; + ASSERT_STREQ("90.9 TB", str1.setReadableSize(val)); +} + +TEST(PIString_Tests, setReadableSize_pb){ + PIString str1 = " ITELMA"; + llong val = 999999999999999999; + ASSERT_STREQ("888.1 PB", str1.setReadableSize(val)); +} + +TEST(PIString_Tests, fromNumber){ + PIString str1 = " String"; + const short val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumberr_zero){ + PIString str1 = " String"; + const short val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_false_base){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_true){ + PIString str1 = " String"; + const short val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_false_base_str){ + PIString str1 = " String"; + const short val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_base_minus){ + PIString str1 = " String"; + const short val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_true){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ushort_zero){ + PIString str1 = " String"; + const ushort val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_false_base){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ushort_false_base_str){ + PIString str1 = " String"; + const ushort val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ushort_base_minus){ + PIString str1 = " String"; + const ushort val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_int){ + PIString str1 = " String"; + const int val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_zero){ + PIString str1 = " String"; + const int val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_false_base){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_int_true){ + PIString str1 = " String"; + const int val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_int_false_base_str){ + PIString str1 = " String"; + const int val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_int_base_minus){ + PIString str1 = " String"; + const int val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_true){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_uintt_zero){ + PIString str1 = " String"; + const uint val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_false_base){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_uint_false_base_str){ + PIString str1 = " String"; + const uint val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_uint_base_minus){ + PIString str1 = " String"; + const uint val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_long){ + PIString str1 = " String"; + const long val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_zero){ + PIString str1 = " String"; + const long val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_false_base){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_long_true){ + PIString str1 = " String"; + const long val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_long_false_base_str){ + PIString str1 = " String"; + const long val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_long_base_minus){ + PIString str1 = " String"; + const long val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_true){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ulong_zero){ + PIString str1 = " String"; + const ulong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_false_base){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ulong_false_base_str){ + PIString str1 = " String"; + const ulong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ulong_base_minus){ + PIString str1 = " String"; + const ulong val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_zero){ + PIString str1 = " String"; + const llong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_false_base){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_llong_true){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_llong_false_base_str){ + PIString str1 = " String"; + const llong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_llong_base_minus){ + PIString str1 = " String"; + const llong val = -10; + bool ok; + ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_true){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.fromNumber(val, 10, &ok); + ASSERT_TRUE(ok); +} + +TEST(PIString_Tests, fromNumber_ullong_zero){ + PIString str1 = " String"; + const ullong val = 0; + bool ok; + ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_false_base){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + str1.fromNumber(val, 1, &ok); + ASSERT_FALSE(ok); +} + +TEST(PIString_Tests, fromNumber_ullong_false_base_str){ + PIString str1 = " String"; + const ullong val = 131; + bool ok; + ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); +} + +TEST(PIString_Tests, fromNumber_ullong_base_minus){ + PIString str1 = " String"; + const ullong val = 10; + bool ok; + ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); +} + +TEST(PIString_Tests, fromNumber_float){ + PIString str1 = " String"; + const float val = 131.132; + ASSERT_STREQ("131.132", str1.fromNumber(val, 'f', 3)); +} + +TEST(PIString_Tests, fromNumber_double){ + PIString str1 = " String"; + const double val = 131.1324334; + ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); +} + +TEST(PIString_Tests, fromNumber_ldouble){ + PIString str1 = " String"; + const ldouble val = 131.1324334; + ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); +} + +TEST(PIString_Tests, fromBool_true){ + PIString str1; + bool val = true; + ASSERT_STREQ("true", str1.fromBool(val)); +} + +TEST(PIString_Tests, fromBool_false){ + PIString str1; + bool val = false; + ASSERT_STREQ("false", str1.fromBool(val)); +} + +TEST(PIString_Tests, from_Console){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromConsole(s)); +} + +TEST(PIString_Tests, from_System){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromSystem(s)); +} + +TEST(PIString_Tests, from_UTF8){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromUTF8(s)); +} + +TEST(PIString_Tests, from_UTF8_ba){ + PIString str1; + PIByteArray s; + s.append('t'); + s.append('r'); + s.append('u'); + s.append('e'); + ASSERT_STREQ("true", str1.fromUTF8(s)); +} + +TEST(PIString_Tests, from_Ascii){ + PIString str1; + char s[] = "true boy"; + ASSERT_STREQ("true boy", str1.fromAscii(s)); +} + +TEST(PIString_Tests, from_Codepage){ + PIString str1 = "Nul"; + char s[] = "true"; + char c[] = "utf8"; + PIString str2 = str1.fromCodepage(s, c); + ASSERT_STREQ("true", str2); +} + +TEST(PIString_Tests, ReadableSize){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1023 B", str1.readableSize(1023)); +} + +TEST(PIString_Tests, readableSize_kb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 kB", str1.readableSize(1024)); +} + +TEST(PIString_Tests, readableSize_mb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 MB", str1.readableSize(1024*1024)); +} + +TEST(PIString_Tests, readableSize_gb){ + PIString str1 = " ITELMA"; + ASSERT_STREQ("1.0 GB", str1.readableSize(1024*1024*1024)); +} + +TEST(PIString_Tests, readableSize_tb){ + PIString str1 = " ITELMA"; + llong val = 99999999999999; + ASSERT_STREQ("90.9 TB", str1.readableSize(val)); +} + +TEST(PIString_Tests, readableSize_pb){ + PIString str1 = " ITELMA"; + llong val = 999999999999999999; + ASSERT_STREQ("888.1 PB", str1.readableSize(val)); +} + +TEST(PIString_Tests, removeAll_char){ + PIString str1 = "A very strong programmer wrote this code"; + char v = ' '; + ASSERT_STREQ("Averystrongprogrammerwrotethiscode", str1.removeAll(v)); +} + +TEST(PIString_Tests, removeAll_pistring){ + PIString str1 = "A very strong programmer wrote this code"; + PIString v = "very strong "; + ASSERT_STREQ("A programmer wrote this code", str1.removeAll(v)); +} + +TEST(PIString_Tests, operator_ba_pstr){ + PIString str1 = '1'; + PIByteArray s; + s << str1; + ASSERT_STREQ("010000003100", s.toHex()); +} + +TEST(PIString_Tests, operator_pstr_ba){ + PIString str1 = "1"; + PIByteArray s; + s.append('t'); + s.append('r'); + s.append('u'); + s.append('e'); + str1 << s; + ASSERT_STREQ("1true", str1); +} + +TEST(PIString_Tests, operator_plus_pstr_pstr){ + PIString str1 = "first "; + PIString str2 = "second"; + ASSERT_STREQ("first second", str1 + str2); +} + +TEST(PIString_Tests, operator_plus_pstr_chars){ + PIString str1 = "first "; + char str2[] = "second"; + ASSERT_STREQ("first second", str1 + str2); +} + +TEST(PIString_Tests, operator_plus_chars_pstr){ + PIString str1 = "first"; + char str2[] = "second "; + ASSERT_STREQ("second first", str2 + str1); +} + +TEST(PIString_Tests, versionCompare2){ //дописать + PIString str1 = "first"; + PIString str2 = "first 1"; + versionCompare(str1, str2, 0); + ASSERT_EQ(898448032, piHash(str1)); +} + +TEST(PIString_Tests, versionNormalize2){ //дописать + PIString str1 = "first"; + cout << versionNormalize(str1); + ASSERT_EQ(1, 1); +} + +TEST(PIString_Tests, piHash){ + PIString str1 = "first"; + ASSERT_EQ(898448032, piHash(str1)); +} + +TEST(PIString_Tests, piSwap){ + PIString str1 = "first"; + PIString str2 = "second"; + piSwap(str1, str2); + ASSERT_STREQ("first", str2); +} + +TEST(PIString_Tests, piSwap_sec){ + PIString str1 = "first"; + PIString str2 = "second"; + piSwap(str1, str2); + ASSERT_STREQ("second", str1); +} + + + + + + + + + + + From 2b2ad436f02e4c43ee89c8022e5f263959a3efe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 16:56:04 +0300 Subject: [PATCH 46/68] overall PIMathMatrix tests correction --- tests/math/testpimathmatrix.cpp | 44 +-- tests/math/testpimathmatrixt.cpp | 584 +++++++++++-------------------- 2 files changed, 206 insertions(+), 422 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index ae3b46f3..2b045000 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -470,7 +470,6 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -494,21 +493,12 @@ TEST(PIMathMatrix_Test, invert) matrix2.invert(); d2 = matrix2.determinant(); matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, inverted) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -532,22 +522,13 @@ TEST(PIMathMatrix_Test, inverted) matrix1 = matrix2.invert(); d2 = matrix1.determinant(); matrix3 = matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; - bool b; PIMathMatrix matrix1; PIMathMatrix matrix2; PIMathMatrix matrix3; @@ -570,25 +551,17 @@ TEST(PIMathMatrix_Test, transposed) matrix2 = matrix1.transposed(); d2 = matrix2.determinant(); matrix3 = matrix2.transposed(); - if((d1 == d2) && (matrix1 == matrix3)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrixT_Test, matrixMultiplication) +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -601,7 +574,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -614,13 +587,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrixT_Test, hermitian) +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; @@ -639,4 +612,3 @@ TEST(PIMathMatrixT_Test, hermitian) } ASSERT_TRUE(true); } - diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 6e4e0a45..a006b3cd 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -50,21 +50,8 @@ TEST(PIMathMatrixT_Test, at) } TEST(PIMathMatrixT_Test, filled) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - PIMathVectorT vect; - double g = 1.0; - matrix2 = matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { - matrix1.at(j,i) = g; - } - } - ASSERT_TRUE(matrix2 == matrix1); + auto matr = PIMathMatrixT::filled(1.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } TEST(PIMathMatrixT_Test, cols) @@ -83,9 +70,7 @@ TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -96,28 +81,18 @@ TEST(PIMathMatrixT_Test, col) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.col(g); - for(i = 0; i < matr.cols(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.cols(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, row) -{ - PIMathMatrixT matr; +{ PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -128,19 +103,12 @@ TEST(PIMathMatrixT_Test, row) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.row(g); - for(i = 0; i < matr.rows(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.rows(); i++) { + if(matr.at(g, i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setCol) @@ -151,22 +119,13 @@ TEST(PIMathMatrixT_Test, setCol) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setCol(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setRow) @@ -177,33 +136,19 @@ TEST(PIMathMatrixT_Test, setRow) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setRow(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(g,i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -213,31 +158,23 @@ TEST(PIMathMatrixT_Test, swapCols) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.col(g1); - before_Vect2 = matr.col(g2); - matr.swapCols(g1,g2); - after_Vect1 = matr.col(g1); - after_Vect2 = matr.col(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.col(g1); + const PIMathVectorT before_Vect2 = matr.col(g2); + matr.swapCols(g1, g2); + const PIMathVectorT after_Vect1 = matr.col(g1); + const PIMathVectorT after_Vect2 = matr.col(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -247,20 +184,17 @@ TEST(PIMathMatrixT_Test, swapRows) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.row(g1); - before_Vect2 = matr.row(g2); - matr.swapRows(g1,g2); - after_Vect1 = matr.row(g1); - after_Vect2 = matr.row(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.row(g1); + const PIMathVectorT before_Vect2 = matr.row(g2); + matr.swapRows(g1, g2); + const PIMathVectorT after_Vect1 = matr.row(g1); + const PIMathVectorT after_Vect2 = matr.row(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, fill) @@ -269,231 +203,175 @@ TEST(PIMathMatrixT_Test, fill) PIMathMatrixT matrix1; double g = 1.0; matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { + for(uint i = 0; i < cols; i++) { + for(uint j = 0; j < rows; j++) { matrix1.at(j,i) = g; } } ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquare) +TEST(PIMathMatrixT_Test, isSquareTrue) { - PIMathMatrixT matr; PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isSquare()); +} + +TEST(PIMathMatrixT_Test, isSquareFalse) +{ const uint new_Cols = 4; PIMathMatrixT matrix2; - bool b; - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentity) +TEST(PIMathMatrixT_Test, isIdentityTrue) { - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1 = matr.identity(); - matrix2 = matr.filled(3.67); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNull) +TEST(PIMathMatrixT_Test, isIdentityFalse) +{ + auto matrix1 = PIMathMatrixT::filled(2.5); + ASSERT_FALSE(matrix1.isIdentity()); +} + +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2 = matr.filled(3.67); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE(matrix1.isNull()); +} + +TEST(PIMathMatrixT_Test, isNullFalse) +{ + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_FALSE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2.fill(6.72); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Equal) +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr == matrix1) == true) && ((matr == matrix2) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_Equal) +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - bool b; - PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr != matrix1) == false) && ((matr != matrix2) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(6.72) ; + auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(1.0); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.0); - matrix2.fill(5.0); - b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1*4.0; - b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1/4.0; - b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } - -TEST(PIMathMatrixT_Test, determinant) +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; @@ -511,6 +389,21 @@ TEST(PIMathMatrixT_Test, determinant) ASSERT_DOUBLE_EQ(i, d); } +TEST(PIMathMatrixT_Test, determinantIfNotSquare) +{ + PIMathMatrixT matr; + matr.at(0,0) = 3; + matr.at(0,1) = 6; + matr.at(0,2) = 8; + matr.at(1,0) = 2; + matr.at(1,1) = 1; + matr.at(1,2) = 4; + matr.at(2,0) = 6; + matr.at(2,1) = 2; + matr.at(2,2) = 5; + ASSERT_FALSE(matr.determinant()); +} + TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; @@ -518,8 +411,6 @@ TEST(PIMathMatrixT_Test, invert) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; - matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -535,15 +426,7 @@ TEST(PIMathMatrixT_Test, invert) d2 = matrix2.determinant(); matrix3 = matrix1; matrix1.invert(); - if((matrix1 == matrix3) && (d1 == 1/d2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } TEST(PIMathMatrixT_Test, inverted) @@ -553,7 +436,6 @@ TEST(PIMathMatrixT_Test, inverted) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -568,22 +450,13 @@ TEST(PIMathMatrixT_Test, inverted) d1 = matr.determinant(); d2 = matrix2.determinant(); matrix3 = matrix1.inverted(); - if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; - uint i; PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -596,7 +469,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) matr.at(2,2) = 5; matrix = matr.toUpperTriangular(); d1 = matrix.determinant(); - for(i = 0; i < cols; i++) + for(uint i = 0; i < cols; i++) { d2 = d2*matrix.at(i,i); } @@ -609,7 +482,6 @@ TEST(PIMathMatrixT_Test, transposed) PIMathMatrixT matrix2; PIMathMatrixT matr; double d1, d2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -623,67 +495,30 @@ TEST(PIMathMatrixT_Test, transposed) matrix1 = matr.transposed(); d2 = matrix1.determinant(); matrix2 = matrix1.transposed(); - if((d1 == d2) && (matr == matrix2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); - - if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); - - if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } TEST(PIMathMatrixT_Test, rotation_3x3) @@ -696,106 +531,83 @@ TEST(PIMathMatrixT_Test, rotation_3x3) TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); - - if((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); - - if((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); - - if((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); - if((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); - if((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); - if((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto matrix2 = PIMathMatrixT::filled(2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); +} +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 11.25) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 11.25) { + ASSERT_TRUE(false); + } + } +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} From 9f6fa4cb8ef79657e4b2a14cea8cca226f9a1fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:13:02 +0300 Subject: [PATCH 47/68] indentation in strings --- tests/math/testpimathmatrix.cpp | 150 +++++++++--------------------- tests/math/testpimathmatrixt.cpp | 154 +++++++++++-------------------- 2 files changed, 98 insertions(+), 206 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 2b045000..6f4e5ffa 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -2,8 +2,7 @@ #include "pimathmatrix.h" template -bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -15,8 +14,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) return b; } -TEST(PIMathMatrix_Test, identity) -{ +TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -35,8 +33,7 @@ TEST(PIMathMatrix_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, element) -{ +TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); for(uint i = 0; i < 3; i++) { if(matrix.element(i,i) != 1.0) { @@ -55,8 +52,7 @@ TEST(PIMathMatrixT_Test, element) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixRow) -{ +TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -68,8 +64,7 @@ TEST(PIMathMatrix_Test, matrixRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixCol) -{ +TEST(PIMathMatrix_Test, matrixCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -81,8 +76,7 @@ TEST(PIMathMatrix_Test, matrixCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setCol) -{ +TEST(PIMathMatrix_Test, setCol) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixCol(vector); @@ -96,8 +90,7 @@ TEST(PIMathMatrix_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, setRow) -{ +TEST(PIMathMatrix_Test, setRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -111,15 +104,13 @@ TEST(PIMathMatrix_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, swapCols) -{ +TEST(PIMathMatrix_Test, swapCols) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -145,24 +136,16 @@ TEST(PIMathMatrix_Test, swapCols) b2[i] = matrix1.element(i, 1); b3[i] = matrix1.element(i, 2); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, swapRows) -{ +TEST(PIMathMatrix_Test, swapRows) { PIMathMatrix origMatr; PIMathMatrix matrix1; PIMathVector vector; uint i1 = 0; uint i2 = 1; double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; - bool b; vector.resize(3, 3.0); vector.at(0) = 3.0; vector.at(1) = 6.0; @@ -188,80 +171,63 @@ TEST(PIMathMatrix_Test, swapRows) b2[i] = matrix1.element(1, i); b3[i] = matrix1.element(2, i); } - if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) { - b = true; - } - else { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } -TEST(PIMathMatrix_Test, fill) -{ +TEST(PIMathMatrix_Test, fill) { PIMathMatrix matrix(3, 3, 5.0); matrix.fill(7.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); } -TEST(PIMathMatrix_Test, isSquareTrue) -{ +TEST(PIMathMatrix_Test, isSquareTrue) { PIMathMatrix matrix(3, 3, 1.0); ASSERT_TRUE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isSquareFalse) -{ +TEST(PIMathMatrix_Test, isSquareFalse) { PIMathMatrix matrix(2, 4, 1.0); ASSERT_FALSE(matrix.isSquare()); } -TEST(PIMathMatrix_Test, isIdentityTrue) -{ +TEST(PIMathMatrix_Test, isIdentityTrue) { auto matrix = PIMathMatrix::identity(3, 3); ASSERT_TRUE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isIdentityFalse) -{ +TEST(PIMathMatrix_Test, isIdentityFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isIdentity()); } -TEST(PIMathMatrix_Test, isNullTrue) -{ +TEST(PIMathMatrix_Test, isNullTrue) { PIMathMatrix matrix(3, 3, 0.0); ASSERT_TRUE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isNullFalse) -{ +TEST(PIMathMatrix_Test, isNullFalse) { PIMathMatrix matrix(3, 3, 5.0); ASSERT_FALSE(matrix.isNull()); } -TEST(PIMathMatrix_Test, isValidTrue) -{ +TEST(PIMathMatrix_Test, isValidTrue) { PIMathMatrix matrix(3, 3, 1.62); ASSERT_TRUE(matrix.isValid()); } -TEST(PIMathMatrix_Test, isValidFalse) -{ +TEST(PIMathMatrix_Test, isValidFalse) { PIMathMatrix matrix; ASSERT_FALSE(matrix.isValid()); } -TEST(PIMathMatrix_Test, operator_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Assignment) { PIMathMatrix matrix1(3, 3, 5.72); PIMathMatrix matrix2(3, 3, 7.12); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } -TEST(PIMathMatrix_Test, operator_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -275,8 +241,7 @@ TEST(PIMathMatrix_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -290,8 +255,7 @@ TEST(PIMathMatrix_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualTrue) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -305,8 +269,7 @@ TEST(PIMathMatrix_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrix_Test, operator_Not_EqualFalse) { PIMathMatrix matrix1(2, 2, 2.0); PIMathMatrix matrix2(2, 2, 2.0); matrix1.element(0, 0) = 5.1; @@ -320,67 +283,58 @@ TEST(PIMathMatrix_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrix_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 1.0); matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { PIMathMatrix matrix1(3, 3, 1.0); PIMathMatrix matrix2(3, 3, 6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } -TEST(PIMathMatrix_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrix_Test, operator_Division_Assignment) { PIMathMatrix matrix1(3, 3, 6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } -TEST(PIMathMatrix_Test, operator_Addition) -{ +TEST(PIMathMatrix_Test, operator_Addition) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } -TEST(PIMathMatrix_Test, operator_Subtraction) -{ +TEST(PIMathMatrix_Test, operator_Subtraction) { PIMathMatrix matrix1(3, 3, 6.0); PIMathMatrix matrix2(3, 3, 5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } -TEST(PIMathMatrix_Test, operator_Multiplication) -{ +TEST(PIMathMatrix_Test, operator_Multiplication) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1*4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } -TEST(PIMathMatrix_Test, operator_Division) -{ +TEST(PIMathMatrix_Test, operator_Division) { PIMathMatrix matrix1(3, 3, 6.72); PIMathMatrix matrix2(3, 3, 5.0); matrix2 = matrix1/4.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } -TEST(PIMathMatrix_Test, determinantIfSquare) -{ +TEST(PIMathMatrix_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrix matrix(3, 3, 0.0); @@ -402,15 +356,13 @@ TEST(PIMathMatrix_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(d, i); } -TEST(PIMathMatrix_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrix_Test, determinantIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.determinant()); } -TEST(PIMathMatrix_Test, trace) -{ +TEST(PIMathMatrix_Test, trace) { PIMathMatrix matrix(3, 3, 0.0); double t; double i = 9.0; @@ -432,15 +384,13 @@ TEST(PIMathMatrix_Test, trace) ASSERT_DOUBLE_EQ(t, i); } -TEST(PIMathMatrix_Test, traceIfNotSquare) -{ +TEST(PIMathMatrix_Test, traceIfNotSquare) { PIMathMatrix matrix(3, 5, 1.0); matrix.element(1,1) = 5.0; ASSERT_FALSE(matrix.trace()); } -TEST(PIMathMatrix_Test, toUpperTriangular) -{ +TEST(PIMathMatrix_Test, toUpperTriangular) { PIMathMatrix matrix(3, 3, 0.0); double d1, d2 = 1; int i; @@ -467,8 +417,7 @@ TEST(PIMathMatrix_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrix_Test, invert) -{ +TEST(PIMathMatrix_Test, invert) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -496,8 +445,7 @@ TEST(PIMathMatrix_Test, invert) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, inverted) -{ +TEST(PIMathMatrix_Test, inverted) { double d1, d2; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); @@ -525,8 +473,7 @@ TEST(PIMathMatrix_Test, inverted) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrix_Test, transposed) -{ +TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; PIMathMatrix matrix1; @@ -554,15 +501,13 @@ TEST(PIMathMatrix_Test, transposed) ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrix_Test, matrixMultiplication) -{ +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -574,8 +519,7 @@ TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -587,14 +531,12 @@ TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrix_Test, hermitian) -{ +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; val.imag(1.0); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index a006b3cd..52bb462e 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,8 +5,7 @@ const uint rows = 3; const uint cols = 3; template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -18,8 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } -TEST(PIMathMatrixT_Test, identity) -{ +TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -38,8 +36,7 @@ TEST(PIMathMatrixT_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, at) -{ +TEST(PIMathMatrixT_Test, at) { auto matrix1 = PIMathMatrixT::identity(); for(uint i = 0; i < rows; i++) { if(matrix1.at(i,i) != 1.0) { @@ -48,26 +45,22 @@ TEST(PIMathMatrixT_Test, at) } ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, filled) -{ +TEST(PIMathMatrixT_Test, filled) { auto matr = PIMathMatrixT::filled(1.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } -TEST(PIMathMatrixT_Test, cols) -{ +TEST(PIMathMatrixT_Test, cols) { PIMathMatrixT matr; ASSERT_EQ(cols,matr.cols()); } -TEST(PIMathMatrixT_Test, rows) -{ +TEST(PIMathMatrixT_Test, rows) { PIMathMatrixT matr; ASSERT_EQ(rows,matr.rows()); } -TEST(PIMathMatrixT_Test, col) -{ +TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; @@ -89,8 +82,8 @@ TEST(PIMathMatrixT_Test, col) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, row) -{ PIMathMatrixT matr; +TEST(PIMathMatrixT_Test, row) { + PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; matr.at(0,0) = 3; @@ -111,8 +104,7 @@ TEST(PIMathMatrixT_Test, row) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setCol) -{ +TEST(PIMathMatrixT_Test, setCol) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -128,8 +120,7 @@ TEST(PIMathMatrixT_Test, setCol) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, setRow) -{ +TEST(PIMathMatrixT_Test, setRow) { PIMathMatrixT matr; PIMathVectorT vect; vect.at(0) = 1.0; @@ -145,8 +136,7 @@ TEST(PIMathMatrixT_Test, setRow) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, swapCols) -{ +TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -171,8 +161,7 @@ TEST(PIMathMatrixT_Test, swapCols) } } -TEST(PIMathMatrixT_Test, swapRows) -{ +TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; int g1 = 1, g2 = 2; matr.at(0,0) = 3; @@ -197,8 +186,7 @@ TEST(PIMathMatrixT_Test, swapRows) } } -TEST(PIMathMatrixT_Test, fill) -{ +TEST(PIMathMatrixT_Test, fill) { PIMathMatrixT matr; PIMathMatrixT matrix1; double g = 1.0; @@ -211,53 +199,45 @@ TEST(PIMathMatrixT_Test, fill) ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquareTrue) -{ +TEST(PIMathMatrixT_Test, isSquareTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isSquare()); } -TEST(PIMathMatrixT_Test, isSquareFalse) -{ +TEST(PIMathMatrixT_Test, isSquareFalse) { const uint new_Cols = 4; PIMathMatrixT matrix2; ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentityTrue) -{ +TEST(PIMathMatrixT_Test, isIdentityTrue) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isIdentityFalse) -{ +TEST(PIMathMatrixT_Test, isIdentityFalse) { auto matrix1 = PIMathMatrixT::filled(2.5); ASSERT_FALSE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNullTrue) -{ +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; ASSERT_TRUE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, isNullFalse) -{ +TEST(PIMathMatrixT_Test, isNullFalse) { auto matrix1 = PIMathMatrixT::identity(); ASSERT_FALSE(matrix1.isNull()); } -TEST(PIMathMatrixT_Test, operator_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -271,8 +251,7 @@ TEST(PIMathMatrixT_Test, operator_EqualTrue) ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -286,8 +265,7 @@ TEST(PIMathMatrixT_Test, operator_EqualFalse) ASSERT_FALSE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -301,8 +279,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) ASSERT_TRUE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) -{ +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; matrix1.at(0, 0) = 5.1; @@ -316,63 +293,54 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) -{ +TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { auto matrix1 = PIMathMatrixT::filled(1.0); auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } -TEST(PIMathMatrixT_Test, operator_Division_Assignment) -{ +TEST(PIMathMatrixT_Test, operator_Division_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } -TEST(PIMathMatrixT_Test, operator_Addition) -{ +TEST(PIMathMatrixT_Test, operator_Addition) { auto matrix1 = PIMathMatrixT::filled(6.72); auto matrix2 = PIMathMatrixT::filled(8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction) { auto matrix1 = PIMathMatrixT::filled(6.0); auto matrix2 = PIMathMatrixT::filled(5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } -TEST(PIMathMatrixT_Test, operator_Division) -{ +TEST(PIMathMatrixT_Test, operator_Division) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } -TEST(PIMathMatrixT_Test, determinantIfSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrixT matr; @@ -389,8 +357,7 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) ASSERT_DOUBLE_EQ(i, d); } -TEST(PIMathMatrixT_Test, determinantIfNotSquare) -{ +TEST(PIMathMatrixT_Test, determinantIfNotSquare) { PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -404,8 +371,7 @@ TEST(PIMathMatrixT_Test, determinantIfNotSquare) ASSERT_FALSE(matr.determinant()); } -TEST(PIMathMatrixT_Test, invert) -{ +TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -429,8 +395,7 @@ TEST(PIMathMatrixT_Test, invert) ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } -TEST(PIMathMatrixT_Test, inverted) -{ +TEST(PIMathMatrixT_Test, inverted) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matrix3; @@ -453,8 +418,7 @@ TEST(PIMathMatrixT_Test, inverted) ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } -TEST(PIMathMatrixT_Test, toUpperTriangular) -{ +TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; PIMathMatrixT matr; @@ -476,8 +440,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) ASSERT_DOUBLE_EQ(d1, d2); } -TEST(PIMathMatrixT_Test, transposed) -{ +TEST(PIMathMatrixT_Test, transposed) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; PIMathMatrixT matr; @@ -498,22 +461,19 @@ TEST(PIMathMatrixT_Test, transposed) ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } -TEST(PIMathMatrixT_Test, scaleX_two) -{ +TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, scaleY_two) -{ +TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } -TEST(PIMathMatrixT_Test, rotation_2x2) -{ +TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); @@ -521,15 +481,13 @@ TEST(PIMathMatrixT_Test, rotation_2x2) ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } -TEST(PIMathMatrixT_Test, rotation_3x3) -{ +TEST(PIMathMatrixT_Test, rotation_3x3) { double angle = 1.0; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } -TEST(PIMathMatrixT_Test, rotationX) -{ +TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -537,8 +495,7 @@ TEST(PIMathMatrixT_Test, rotationX) ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } -TEST(PIMathMatrixT_Test, rotationY) -{ +TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -546,8 +503,7 @@ TEST(PIMathMatrixT_Test, rotationY) ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } -TEST(PIMathMatrixT_Test, rotationZ) -{ +TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; double c = cos(angle); double s = sin(angle); @@ -555,22 +511,19 @@ TEST(PIMathMatrixT_Test, rotationZ) ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } -TEST(PIMathMatrixT_Test, scaleX_three) -{ +TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleY_three) -{ +TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } -TEST(PIMathMatrixT_Test, scaleZ_three) -{ +TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); @@ -583,8 +536,7 @@ TEST(PIMathMatrixT_Test, matrixMultiplication) ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -595,8 +547,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); auto vector = PIMathVectorT::filled(2.5); for(uint i = 0; i < 2; i++) { @@ -606,8 +557,7 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) } } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) { auto matrix1 = PIMathMatrixT::filled(1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } From 8b5f80d6dc0b585415765d112e19be4bdffbebfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:16 +0300 Subject: [PATCH 48/68] bug fixes --- CMakeLists.txt.user | 1175 ++++++++++++++++++++++++++++++ tests/math/testpimathmatrix.cpp | 26 +- tests/math/testpimathmatrixt.cpp | 12 +- 3 files changed, 1194 insertions(+), 19 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..aed2b6b3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1175 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 6 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_concurrent_test + CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test + pip_concurrent_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_math_test + CMakeProjectManager.CMakeRunConfiguration.pip_math_test + pip_math_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal + + 12 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 6f4e5ffa..3dc1943a 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -16,18 +16,18 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { TEST(PIMathMatrix_Test, identity) { auto matrix = PIMathMatrix::identity(3, 3); - 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){ + 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); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -35,11 +35,6 @@ TEST(PIMathMatrix_Test, identity) { TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); - for(uint i = 0; i < 3; i++) { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ if(i != j){ @@ -47,6 +42,11 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(false); } } + else { + if(matrix.element(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 52bb462e..d7f11563 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -19,11 +19,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::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){ @@ -31,6 +26,11 @@ TEST(PIMathMatrixT_Test, identity) { ASSERT_TRUE(false); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); @@ -293,7 +293,7 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { ASSERT_FALSE(matrix1 != matrix2); } -TEST(PIMathMatrixT_Test, operator_Addition_ ssignment) { +TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; From d0e703751a348ac6bbf290964012eec90f7f90d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:39 +0300 Subject: [PATCH 49/68] bug fixes --- CMakeLists.txt.user | 1175 ------------------------------------------- 1 file changed, 1175 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index aed2b6b3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1175 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 6 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_concurrent_test - CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test - pip_concurrent_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_math_test - CMakeProjectManager.CMakeRunConfiguration.pip_math_test - pip_math_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal - - 12 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 604aa44e57e380b42979d960986980301da1b9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:02 +0300 Subject: [PATCH 50/68] PIMathMatrix doc --- CMakeLists.txt.user | 1023 +++++++++++++++++++++++++++++++++ libs/main/math/pimathmatrix.h | 8 +- tests/concurrent/testutil.h | 2 + 3 files changed, 1029 insertions(+), 4 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..6d0aa1d3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1023 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + + + doc + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal + + 10 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 8ab15e91..6f76fbe0 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -77,10 +77,10 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { //! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 7c3c15c7..9df146ba 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,6 +3,7 @@ #include "pithread.h" #include +#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -57,4 +58,5 @@ public: } }; + #endif //AWRCANFLASHER_TESTUTIL_H From 8b6a3563491e981c4a48fed0e6cf18838de84aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 13:54:47 +0300 Subject: [PATCH 51/68] PIMathMatrix document --- CMakeLists.txt.user | 1023 ------------------------------------------- 1 file changed, 1023 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 6d0aa1d3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1023 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 0 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - - - doc - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/pip_tests/build-pip-Desktop_Qt_5_12_7_MinGW_64_bit-Release/utils/piterminal - - 10 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 3a038ef50b93bca902b51ef879abbec0cfed6579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:23:54 +0300 Subject: [PATCH 52/68] Rotation remake --- libs/main/math/pimathmatrix.h | 309 +++++++++++++++++++++++++++++++++- tests/concurrent/testutil.h | 2 - 2 files changed, 306 insertions(+), 5 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 6f76fbe0..57493788 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -81,10 +81,11 @@ class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrixI; typedef PIMathVectorT _CMCol; typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: +<<<<<<< HEAD /** * @brief Constructor that calls the private resize method * @@ -489,6 +490,308 @@ public: * @return matrix determinant */ Type determinant(bool *ok = 0) const { +======= + PIMathMatrixT() {resize(Rows, Cols);} + PIMathMatrixT(const PIVector & 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 _CMatrix + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ + static _CMatrix rotation(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ + static _CMatrix rotationX(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ + static _CMatrix rotationY(double angle) {return _CMatrix();} + + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ + static _CMatrix rotationZ(double angle) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ + static _CMatrix scaleX(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ + static _CMatrix scaleY(double factor) {return _CMatrix();} + + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ + static _CMatrix scaleZ(double factor) {return _CMatrix();} + + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ + uint cols() const {return Cols;} + + /** + * @brief Method which returns number of rows in matrix + * + * @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 + * + * @return matrix determinant + */ + Type determinant(bool * ok = 0) const { +>>>>>>> 9544d5e... Rotation remake _CMatrix m(*this); bool k; Type ret = Type(0); diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 9df146ba..7c3c15c7 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -3,7 +3,6 @@ #include "pithread.h" #include -#include "pistring.h" /** * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests @@ -58,5 +57,4 @@ public: } }; - #endif //AWRCANFLASHER_TESTUTIL_H From 8163a68e036b6ccfec451fc96d0654d413974ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 3 Sep 2020 15:50:41 +0300 Subject: [PATCH 53/68] space correction --- libs/main/math/pimathmatrix.h | 468 +++++++++++++++++----------------- 1 file changed, 236 insertions(+), 232 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 57493788..5abb00eb 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -77,15 +77,14 @@ inline bool _PIMathMatrixNullCompare(const complexd v) { //! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix template class PIP_EXPORT PIMathMatrixT { - typedef PIMathMatrixT _CMatrix; - typedef PIMathMatrixT _CMatrixI; - typedef PIMathVectorT _CMCol; - typedef PIMathVectorT _CMRow; - static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Rows > 0, "Row count must be > 0"); - static_assert(Cols > 0, "Column count must be > 0"); + typedef PIMathMatrixT _CMatrix; + typedef PIMathMatrixT _CMatrixI; + typedef PIMathVectorT _CMCol; + typedef PIMathVectorT _CMRow; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: -<<<<<<< HEAD /** * @brief Constructor that calls the private resize method * @@ -490,308 +489,313 @@ public: * @return matrix determinant */ Type determinant(bool *ok = 0) const { -======= PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & 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 - */ + /** + * @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 - */ + /** + * @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 _CMatrix - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + /** + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) {return _CMatrix();} - /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, else return _CMatrix - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + /** + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) {return _CMatrix();} - /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) {return _CMatrix();} - /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, else return _CMatrix - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + /** + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) {return _CMatrix();} - /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + /** + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const {return Cols;} - /** - * @brief Method which returns number of rows in matrix - * - * @return type uint shows number of rows - */ + /** + * @brief Method which returns number of rows in matrix + * + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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" - */ + /** + * @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" - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - */ + /** + * @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 - * - * @return matrix determinant - */ + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool * ok = 0) const { ->>>>>>> 9544d5e... Rotation remake _CMatrix m(*this); bool k; Type ret = Type(0); From 42793522a409ef47141395af3670db6d280fcf00 Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Thu, 3 Sep 2020 16:57:46 +0300 Subject: [PATCH 54/68] Fix code formatting & grammar mistakes --- libs/main/math/pimathmatrix.h | 512 +++++++++++++++++----------------- 1 file changed, 254 insertions(+), 258 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 5abb00eb..d192d3e9 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -511,291 +511,287 @@ public: * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, * else return default construction of PIMathMatrixT * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ - static _CMatrix rotation(double angle) {return _CMatrix();} + * @return type uint shows number of rows + */ + uint rows() const { return Rows; } - /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ - static _CMatrix rotationX(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ - static _CMatrix rotationY(double angle) {return _CMatrix();} + /** + * @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 Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ - static _CMatrix rotationZ(double angle) {return _CMatrix();} + /** + * @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 Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ - static _CMatrix scaleX(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ - static _CMatrix scaleY(double factor) {return _CMatrix();} + /** + * @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 Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ - static _CMatrix scaleZ(double factor) {return _CMatrix();} + /** + * @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 returns number of columns in matrix - * - * @return type uint shows number of columns - */ - uint cols() const {return Cols;} + /** + * @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 returns number of rows in matrix - * - * @return type uint shows number of rows - */ - uint rows() const {return Rows;} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ - bool isSquare() const {return cols() == rows();} + /** + * @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 - * - * @return matrix determinant - */ - Type determinant(bool * ok = 0) const { + /** + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ + Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; Type ret = Type(0); From d59d60b1a730c49680713ef847b874420a5efb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:05:22 +0300 Subject: [PATCH 55/68] doc correction --- libs/main/math/pimathmatrix.h | 1094 +++++++++++------------------- tests/math/testpimathmatrixt.cpp | 21 + 2 files changed, 417 insertions(+), 698 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index d192d3e9..9a767dd5 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -85,19 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - /** - * @brief Constructor that calls the private resize method - * - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } - /** - * @brief Constructor that calls the private resize method - * - * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -105,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identity matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -116,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -128,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -205,12 +205,12 @@ public: uint rows() const { return Rows; } /** - * @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 - * - * @param index is the number of the selected column - * @return column in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -218,12 +218,12 @@ 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 - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -231,39 +231,39 @@ public: } /** - * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -275,13 +275,13 @@ 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 - * - * @param c0 is the number of the first selected column - * @param c1 is the number of the second selected column - * @return matrix type _CMatrix - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -293,142 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -436,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -448,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -460,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -472,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -484,313 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ - Type determinant(bool *ok = 0) const { - PIMathMatrixT() {resize(Rows, Cols);} - PIMathMatrixT(const PIVector & 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 - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -807,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -849,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -902,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -913,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -1162,33 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param f is type of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param val is PIVector of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector of PIVector, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -1196,11 +893,11 @@ public: } } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector2D, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -1208,193 +905,194 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 - * - * @param val is the vector type PIMathVector - * @return row matrix of every element that is equal to every element of the vector - */ + + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a column matrix of every element that is equal to every element of the vector - * - * @param val is the vector type PIMathVector - * @return column matrix of every element that is equal to every element of the vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - * - * @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 - */ + * @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 + * + * @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) _V2D::element(i, index) = v[i]; return *this; } /** - * @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 - * @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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this; } /** - * @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 - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; } - /** - * @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 - * - * @param c0 is the number of the first selected row - * @param c1 is the number of the second selected row - * @return matrix type _CMatrix - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } /** - * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros - * - * @return true if matrix is identity, else false - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix elements equal to zero, else false - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1402,11 +1100,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1414,11 +1112,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1426,11 +1124,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1438,11 +1136,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1450,10 +1148,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1470,10 +1168,10 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1488,10 +1186,10 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1530,10 +1228,10 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1590,10 +1288,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1601,10 +1299,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index d7f11563..2bdcf980 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -17,6 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } +<<<<<<< HEAD TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); for(int i = 0; i < 3; i++){ @@ -33,6 +34,26 @@ TEST(PIMathMatrixT_Test, identity) { } } } +======= + +TEST(PIMathMatrixT_Test, identity) +{ + auto matrix = PIMathMatrixT::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); } From 7a8ab669d6dc1b26aac1057be16a592aa83f2cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:44:01 +0300 Subject: [PATCH 56/68] tab correction --- libs/main/math/pimathmatrix.h | 791 +++++++++++++++++----------------- 1 file changed, 395 insertions(+), 396 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 9a767dd5..fe1c6a66 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -85,19 +85,19 @@ class PIP_EXPORT PIMathMatrixT { static_assert(Rows > 0, "Row count must be > 0"); static_assert(Cols > 0, "Column count must be > 0"); public: - /** - * @brief Constructor that calls the private resize method - * - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT() { resize(Rows, Cols); } - /** - * @brief Constructor that calls the private resize method - * - * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT - */ + /** + * @brief Constructor that calls the private resize method + * + * @param val is the PIVector with which the matrix is ​​filled + * @return identitied matrix of type PIMathMatrixT + */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); int i = 0; @@ -105,10 +105,10 @@ public: } /** - * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @return identity matrix of type PIMathMatrixT - */ + * @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @return identity 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)); @@ -116,11 +116,11 @@ public: } /** - * @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 - */ + * @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; @@ -128,73 +128,73 @@ public: } /** - * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix - * @return rotated matrix - */ + * @brief Rotation the matrix by an "angle". Works only with 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix + * @return rotated matrix + */ static _CMatrix rotation(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the X axis + * @return rotated matrix + */ static _CMatrix rotationX(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Y axis + * @return rotated matrix + */ static _CMatrix rotationY(double angle) { return _CMatrix(); } /** - * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix - */ + * @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param angle is the angle of rotation of the matrix along the Z axis + * @return rotated matrix + */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } /** - * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by X axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by X axis + * @return rotated matrix + */ static _CMatrix scaleX(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Y axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Y axis + * @return rotated matrix + */ static _CMatrix scaleY(double factor) { return _CMatrix(); } /** - * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, - * else return default construction of PIMathMatrixT - * - * @param factor is the value of scaling by Z axis - * @return rotated matrix - */ + * @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix, + * else return default construction of PIMathMatrixT + * + * @param factor is the value of scaling by Z axis + * @return rotated matrix + */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix - * - * @return type uint shows number of columns - */ + * @brief Method which returns number of columns in matrix + * + * @return type uint shows number of columns + */ uint cols() const { return Cols; } /** @@ -205,12 +205,12 @@ public: uint rows() const { return Rows; } /** - * @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 - * - * @param index is the number of the selected column - * @return column in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -218,12 +218,12 @@ 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 - * - * @param index is the number of the selected row - * @return row in PIMathVectorT format - */ + * @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 + * + * @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]; @@ -231,39 +231,39 @@ public: } /** - * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected column in matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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 - */ + * @brief Set the selected row in matrix + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @brief Method which changes selected rows in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -275,13 +275,13 @@ 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 - * - * @param c0 is the number of the first selected column - * @param c1 is the number of the second selected column - * @return matrix type _CMatrix - */ + * @brief Method which changes selected columns in a matrix. + * If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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) { @@ -293,142 +293,142 @@ public: } /** - * @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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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". - * If you enter an index out of the border of the matrix will be SEGFAULT - * - * @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" - */ + * @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 + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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. If you enter an index out of the border of the matrix will be SEGFAULT - * - * @param row is a row of necessary matrix - * @return matrix row pointer - */ + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix will be SEGFAULT + * + * @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 - */ + * @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 - */ + * @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 - */ + * @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 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 - */ + * @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 - */ + * @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 - */ + * @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 - */ + * @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]; @@ -436,11 +436,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @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]; @@ -448,11 +448,11 @@ public: } /** - * @brief Matrix substraction - * - * @param sm is matrix subtractor - * @return the result of matrix substraction - */ + * @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]; @@ -460,11 +460,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @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; @@ -472,11 +472,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @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; @@ -484,10 +484,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -504,10 +504,10 @@ public: } /** - * @brief Transforming matrix to upper triangular - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { if (ok != 0) *ok = false; @@ -546,10 +546,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); @@ -599,10 +599,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -610,10 +610,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrixI transposed() const { _CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; @@ -859,33 +859,33 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIMathMatrix _CMatrix; typedef PIMathVector _CMCol; public: - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param f is type of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param f is type of matrix elements + */ PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @param val is PIVector of matrix elements - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @param val is PIVector of matrix elements + */ PIMathMatrix(const uint cols, const uint rows, const PIVector &val) { _V2D::resize(rows, cols); int i = 0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++]; } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector of PIVector, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector of PIVector, which creates matrix + */ PIMathMatrix(const PIVector > &val) { if (!val.isEmpty()) { _V2D::resize(val.size(), val[0].size()); @@ -893,11 +893,11 @@ public: } } - /** - * @brief Constructor of class PIMathMatrix, which creates a matrix - * - * @param val is PIVector2D, which creates matrix - */ + /** + * @brief Constructor of class PIMathMatrix, which creates a matrix + * + * @param val is PIVector2D, which creates matrix + */ PIMathMatrix(const PIVector2D &val) { if (!val.isEmpty()) { _V2D::resize(val.rows(), val.cols()); @@ -905,194 +905,193 @@ public: } } - /** - * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros - * - * @param cols is number of matrix column uint type - * @param rows is number of matrix row uint type - * @return identity matrix of type PIMathMatrix - */ + /** + * @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros + * + * @param cols is number of matrix column uint type + * @param rows is number of matrix row uint type + * @return identity matrix of type PIMathMatrix + */ static _CMatrix identity(const uint cols, const uint rows) { _CMatrix tm(cols, rows); 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 - * - * @param val is the vector type PIMathVector - * @return row matrix of every element that is equal to every element of the vector - */ + /** + * @brief Creates a row matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return row matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixRow(const PIMathVector &val) { return _CMatrix(val.size(), 1, val.toVector()); } /** - * @brief Creates a column matrix of every element that is equal to every element of the vector - * - * @param val is the vector type PIMathVector - * @return column matrix of every element that is equal to every element of the vector - */ + * @brief Creates a column matrix of every element that is equal to every element of the vector + * + * @param val is the vector type PIMathVector + * @return column matrix of every element that is equal to every element of the vector + */ static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @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 - * - * @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 - */ + * @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 + * + * @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) _V2D::element(i, index) = v[i]; return *this; } /** - * @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 - * @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 - */ + * @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 + * @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 _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this; } /** - * @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 - * - * @param r0 is the number of the first selected row - * @param r1 is the number of the second selected row - * @return matrix type _CMatrix - */ + * @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 + * + * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; } - /** - * @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 - * - * @param c0 is the number of the first selected row - * @param c1 is the number of the second selected row - * @return matrix type _CMatrix - */ + /** + * @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 + * + * @param c0 is the number of the first selected row + * @param c1 is the number of the second selected row + * @return matrix type _CMatrix + */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } 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 - */ + * @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_A(i) _V2D::mat[i] = v; return *this; } /** - * @brief Method which checks if matrix is square - * - * @return true if matrix is square, else false - */ + * @brief Method which checks if matrix is square + * + * @return true if matrix is square, else false + */ bool isSquare() const { return _V2D::cols_ == _V2D::rows_; } /** - * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros - * - * @return true if matrix is identity, else false - */ + * @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros + * + * @return true if matrix is identity, else false + */ bool isIdentity() const { PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false; return true; } /** - * @brief Method which checks if every elements of matrix are zeros - * - * @return true if matrix elements equal to zero, else false - */ + * @brief Method which checks if every elements of matrix are zeros + * + * @return true if matrix elements equal to zero, else false + */ bool isNull() const { PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true; } /** - * @brief Method which checks if matrix is empty - * - * @return true if matrix is valid, else false - */ + * @brief Method which checks if matrix is empty + * + * @return true if matrix is valid, else false + */ bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" - * - * @param v matrix for the assigment - * @return matrix equal with v - */ + * @brief Matrix assignment to matrix "v" + * + * @param v matrix for the assigment + * @return matrix equal with v + */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); return *this; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are equal true, else false - */ + * @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_A(i) if (_V2D::mat[i] != sm.mat[i]) return false; return true; } /** - * @brief Compare with matrix "sm" - * - * @param sm matrix for the compare - * @return if matrices are not equal true, else false - */ + * @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 - */ + * @brief Addition assignment with matrix "sm" + * + * @param sm matrix for the addition assigment + */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" - * - * @param sm matrix for the subtraction assigment - */ + * @brief Subtraction assignment with matrix "sm" + * + * @param sm matrix for the subtraction assigment + */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } - /** - * @brief Multiplication assignment with value "v" - * - * @param v value for the multiplication assigment - */ + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" - * - * @param v value for the division assigment - */ + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; } - /** - * @brief Matrix substraction - * - * @return the result of matrix substraction - */ + /** + * @brief Matrix substraction + * + * @return the result of matrix substraction + */ _CMatrix operator-() const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; @@ -1100,11 +1099,11 @@ public: } /** - * @brief Matrix addition - * - * @param sm is matrix term - * @return the result of matrix addition - */ + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CMatrix operator+(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; @@ -1112,11 +1111,11 @@ public: } /** - * @brief Matrix subtraction - * - * @param sm is matrix subtractor - * @return the result of matrix subtraction - */ + * @brief Matrix subtraction + * + * @param sm is matrix subtractor + * @return the result of matrix subtraction + */ _CMatrix operator-(const _CMatrix &sm) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; @@ -1124,11 +1123,11 @@ public: } /** - * @brief Matrix multiplication - * - * @param v is value factor - * @return the result of matrix multiplication - */ + * @brief Matrix multiplication + * + * @param v is value factor + * @return the result of matrix multiplication + */ _CMatrix operator*(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; @@ -1136,11 +1135,11 @@ public: } /** - * @brief Matrix division - * - * @param v is value divider - * @return the result of matrix division - */ + * @brief Matrix division + * + * @param v is value divider + * @return the result of matrix division + */ _CMatrix operator/(const Type &v) const { _CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; @@ -1148,10 +1147,10 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix - * - * @return matrix determinant - */ + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * + * @return matrix determinant + */ Type determinant(bool *ok = 0) const { _CMatrix m(*this); bool k; @@ -1168,10 +1167,10 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix - * - * @return matrix trace - */ + * @brief Trace of the matrix is calculated. Works only with square matrix + * + * @return matrix trace + */ Type trace(bool *ok = 0) const { Type ret = Type(0); if (!isSquare()) { @@ -1186,10 +1185,10 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix - * - * @return copy of transformed upper triangular matrix - */ + * @brief Transforming matrix to upper triangular. Works only with square matrix + * + * @return copy of transformed upper triangular matrix + */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1228,10 +1227,10 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix - * - * @return copy of inverted matrix - */ + * @brief Matrix inversion operation. Works only with square matrix + * + * @return copy of inverted matrix + */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { if (ok != 0) *ok = false; @@ -1288,10 +1287,10 @@ public: } /** - * @brief Matrix inversion operation - * - * @return inverted matrix - */ + * @brief Matrix inversion operation + * + * @return inverted matrix + */ _CMatrix inverted(bool *ok = 0) const { _CMatrix tm(*this); tm.invert(ok); @@ -1299,10 +1298,10 @@ public: } /** - * @brief Matrix transposition operation - * - * @return transposed matrix - */ + * @brief Matrix transposition operation + * + * @return transposed matrix + */ _CMatrix transposed() const { _CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); From 9e52a78022314cd5527c77ea3a357363a6c02268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Tue, 8 Sep 2020 16:47:44 +0300 Subject: [PATCH 57/68] final tab correction --- libs/main/math/pimathmatrix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index fe1c6a66..8ab15e91 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -120,7 +120,7 @@ public: * * @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; @@ -965,7 +965,7 @@ public: * @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 &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } return *this; From 6b7594cc90e3156045f7b9f8170ad4501ffc86a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 15:27:09 +0300 Subject: [PATCH 58/68] testing another operations --- tests/math/testpimathmatrix.cpp | 83 ++++++++++++++++++++++++++++- tests/math/testpimathmatrixt.cpp | 90 ++++++++++++++++++-------------- 2 files changed, 132 insertions(+), 41 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 3dc1943a..a5e319f1 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -52,7 +52,28 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixRow) { +TEST(PIMathMatrixT_Test, element) +{ + auto matrix = PIMathMatrix::identity(3, 3); + for(uint i = 0; i < 3; i++) { + if(matrix.element(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); + } + } + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrix_Test, matrixRow) +{ PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -554,3 +575,63 @@ TEST(PIMathMatrix_Test, hermitian) { } ASSERT_TRUE(true); } + +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathMatrix matrix2(2, 2, 2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); +} + +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + PIMathMatrix matrix1(3, 3, 1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +} + +TEST(PIMathMatrixT_Test, hermitian) +{ + complex val; + complex res; + val.imag(1.0); + val.real(1.0); + PIMathMatrix> matrix(3, 3, val); + res.imag(-1.0); + res.real(1.0); + auto matr = hermitian(matrix); + for(uint i = 0; i < 3; i++) { + for(uint j = 0; j < 3; j++) { + if(matr.element(i, j) != res) { + ASSERT_TRUE(false); + } + } + } + ASSERT_TRUE(true); +} + diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 2bdcf980..0017f00f 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,7 +5,8 @@ const uint rows = 3; const uint cols = 3; template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) +{ bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -17,25 +18,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } -<<<<<<< HEAD -TEST(PIMathMatrixT_Test, identity) { - auto matrix = PIMathMatrixT::identity(); - 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); - } - } - else { - if(matrix[i][i] != 1.0){ - ASSERT_TRUE(false); - } - } - } - } -======= - TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); @@ -57,7 +39,8 @@ TEST(PIMathMatrixT_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, at) { +TEST(PIMathMatrixT_Test, at) +{ auto matrix1 = PIMathMatrixT::identity(); for(uint i = 0; i < rows; i++) { if(matrix1.at(i,i) != 1.0) { @@ -255,7 +238,8 @@ TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); + b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); + ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_EqualTrue) { @@ -318,47 +302,73 @@ TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); + b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); + ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { auto matrix1 = PIMathMatrixT::filled(1.0); auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); + b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); + ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); + b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); + ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); + b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); + ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, operator_Addition) { - auto matrix1 = PIMathMatrixT::filled(6.72); - auto matrix2 = PIMathMatrixT::filled(8.28); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); +TEST(PIMathMatrixT_Test, operator_Addition) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + bool b; + matrix1.fill(6.72); + matrix2.fill(8.28); + b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); + ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, operator_Subtraction) { - auto matrix1 = PIMathMatrixT::filled(6.0); - auto matrix2 = PIMathMatrixT::filled(5.0); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); +TEST(PIMathMatrixT_Test, operator_Subtraction) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + bool b; + matrix1.fill(6.0); + matrix2.fill(5.0); + b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); + ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, operator_Multiplication) { - auto matrix1 = PIMathMatrixT::filled(6.72); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); +TEST(PIMathMatrixT_Test, operator_Multiplication) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + bool b; + matrix1.fill(6.72); + matrix2 = matrix1*4.0; + b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); + ASSERT_TRUE(b); } -TEST(PIMathMatrixT_Test, operator_Division) { - auto matrix1 = PIMathMatrixT::filled(6.72); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); +TEST(PIMathMatrixT_Test, operator_Division) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + bool b; + matrix1.fill(6.72); + matrix2 = matrix1/4.0; + b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); + ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, determinantIfSquare) { From 05e935f55239e48dcf32b86e5e084093e1a1bd2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 16:56:04 +0300 Subject: [PATCH 59/68] overall PIMathMatrix tests correction --- tests/math/testpimathmatrix.cpp | 11 ++++--- tests/math/testpimathmatrixt.cpp | 50 +++++++++----------------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index a5e319f1..4f76af1f 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -576,14 +576,14 @@ TEST(PIMathMatrix_Test, hermitian) { ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, matrixMultiplication) +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -596,7 +596,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -609,13 +609,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrixT_Test, hermitian) +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; @@ -634,4 +634,3 @@ TEST(PIMathMatrixT_Test, hermitian) } ASSERT_TRUE(true); } - diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 0017f00f..e6979625 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -238,8 +238,7 @@ TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } TEST(PIMathMatrixT_Test, operator_EqualTrue) { @@ -310,65 +309,44 @@ TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { auto matrix1 = PIMathMatrixT::filled(1.0); auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.0); - matrix2.fill(5.0); - b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1*4.0; - b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1/4.0; - b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } TEST(PIMathMatrixT_Test, determinantIfSquare) { From 36fe9135dbc3d522a4ff4101b7070f335bfdc41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:13:02 +0300 Subject: [PATCH 60/68] indentation in strings --- tests/math/testpimathmatrix.cpp | 18 ++++++------------ tests/math/testpimathmatrixt.cpp | 21 +++++++-------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 4f76af1f..3d0e680e 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -52,8 +52,7 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, element) -{ +TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); for(uint i = 0; i < 3; i++) { if(matrix.element(i,i) != 1.0) { @@ -72,8 +71,7 @@ TEST(PIMathMatrixT_Test, element) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, matrixRow) -{ +TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; vector.resize(3, 3.0); auto matrix = PIMathMatrix::matrixRow(vector); @@ -583,8 +581,7 @@ TEST(PIMathMatrix_Test, matrixMultiplication) ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) -{ +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -596,8 +593,7 @@ TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; vector.resize(2, 2.5); @@ -609,14 +605,12 @@ TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrix_Test, valAndMatrixMultiplication) -{ +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrix_Test, hermitian) -{ +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; val.imag(1.0); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index e6979625..f60b99af 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,8 +5,7 @@ const uint rows = 3; const uint cols = 3; template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) -{ +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { @@ -18,8 +17,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val return b; } -TEST(PIMathMatrixT_Test, identity) -{ +TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); for(int i = 0; i < 3; i++){ if(matrix[i][i] != 1.0){ @@ -39,8 +37,7 @@ TEST(PIMathMatrixT_Test, identity) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, at) -{ +TEST(PIMathMatrixT_Test, at) { auto matrix1 = PIMathMatrixT::identity(); for(uint i = 0; i < rows; i++) { if(matrix1.at(i,i) != 1.0) { @@ -324,27 +321,23 @@ TEST(PIMathMatrixT_Test, operator_Division_Assignment) { ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } -TEST(PIMathMatrixT_Test, operator_Addition) -{ +TEST(PIMathMatrixT_Test, operator_Addition) { auto matrix1 = PIMathMatrixT::filled(6.72); auto matrix2 = PIMathMatrixT::filled(8.28); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Subtraction) -{ +TEST(PIMathMatrixT_Test, operator_Subtraction) { auto matrix1 = PIMathMatrixT::filled(6.0); auto matrix2 = PIMathMatrixT::filled(5.0); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } -TEST(PIMathMatrixT_Test, operator_Multiplication) -{ +TEST(PIMathMatrixT_Test, operator_Multiplication) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } -TEST(PIMathMatrixT_Test, operator_Division) -{ +TEST(PIMathMatrixT_Test, operator_Division) { auto matrix1 = PIMathMatrixT::filled(6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } From 2fa852a050c6a8f1c9b1f3ad166ff6351dd528a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:16 +0300 Subject: [PATCH 61/68] bug fixes --- CMakeLists.txt.user | 1175 ++++++++++++++++++++++++++++++ tests/math/testpimathmatrix.cpp | 10 +- tests/math/testpimathmatrixt.cpp | 10 +- 3 files changed, 1185 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 00000000..aed2b6b3 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,1175 @@ + + + + + + EnvironmentId + {590da41d-e68d-4f0d-9a90-bf433d6b70a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt MinGW 64-bit + Desktop Qt MinGW 64-bit + qt.qt5.5127.win64_mingw73_kit + 1 + 0 + 6 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + TESTS:BOOL=ON + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск с отладочной информацией + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск минимального размера + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deploy_tool + CMakeProjectManager.CMakeRunConfiguration.deploy_tool + deploy_tool + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picloud + CMakeProjectManager.CMakeRunConfiguration.picloud + picloud + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_concurrent_test + CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test + pip_concurrent_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_math_test + CMakeProjectManager.CMakeRunConfiguration.pip_math_test + pip_math_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + picrypt + CMakeProjectManager.CMakeRunConfiguration.picrypt + picrypt + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pift + CMakeProjectManager.CMakeRunConfiguration.pift + pift + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_cmg + CMakeProjectManager.CMakeRunConfiguration.pip_cmg + pip_cmg + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_rc + CMakeProjectManager.CMakeRunConfiguration.pip_rc + pip_rc + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_system_test + CMakeProjectManager.CMakeRunConfiguration.pip_system_test + pip_system_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pip_test + CMakeProjectManager.CMakeRunConfiguration.pip_test + pip_test + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + pisd + CMakeProjectManager.CMakeRunConfiguration.pisd + pisd + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + piterminal + CMakeProjectManager.CMakeRunConfiguration.piterminal + piterminal + + false + + false + true + true + false + false + true + + D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal + + 12 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 3d0e680e..1251b311 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -54,11 +54,6 @@ TEST(PIMathMatrixT_Test, element) { TEST(PIMathMatrixT_Test, element) { auto matrix = PIMathMatrix::identity(3, 3); - for(uint i = 0; i < 3; i++) { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ if(i != j){ @@ -66,6 +61,11 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(false); } } + else { + if(matrix.element(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } } } ASSERT_TRUE(true); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index f60b99af..db572942 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -19,11 +19,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::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){ @@ -31,6 +26,11 @@ TEST(PIMathMatrixT_Test, identity) { ASSERT_TRUE(false); } } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } } } >>>>>>> 05a32cc... doc correction From c7ebbe30c1aa7ddfd844a4f1c7d727a340e73bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 17:48:39 +0300 Subject: [PATCH 62/68] bug fixes --- CMakeLists.txt.user | 1175 ------------------------------------------- 1 file changed, 1175 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index aed2b6b3..00000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,1175 +0,0 @@ - - - - - - EnvironmentId - {590da41d-e68d-4f0d-9a90-bf433d6b70a5} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt MinGW 64-bit - Desktop Qt MinGW 64-bit - qt.qt5.5127.win64_mingw73_kit - 1 - 0 - 6 - - - CMAKE_BUILD_TYPE:STRING=Debug - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Debug - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - TESTS:BOOL=ON - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-RelWithDebInfo - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск с отладочной информацией - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} - CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} - QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} - - D:/build-pip-Desktop_Qt_MinGW_64_bit-MinSizeRel - - - - - all - - true - CMakeProjectManager.MakeStep - - 1 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - CMakeProjectManager.MakeStep - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск минимального размера - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - deploy_tool - CMakeProjectManager.CMakeRunConfiguration.deploy_tool - deploy_tool - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/deploy_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picloud - CMakeProjectManager.CMakeRunConfiguration.picloud - picloud - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/cloud_dispatcher - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_concurrent_test - CMakeProjectManager.CMakeRunConfiguration.pip_concurrent_test - pip_concurrent_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_math_test - CMakeProjectManager.CMakeRunConfiguration.pip_math_test - pip_math_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - picrypt - CMakeProjectManager.CMakeRunConfiguration.picrypt - picrypt - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/crypt_tool - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pift - CMakeProjectManager.CMakeRunConfiguration.pift - pift - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/udp_file_transfer - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_cmg - CMakeProjectManager.CMakeRunConfiguration.pip_cmg - pip_cmg - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/code_model_generator - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_rc - CMakeProjectManager.CMakeRunConfiguration.pip_rc - pip_rc - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/resources_compiler - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_system_test - CMakeProjectManager.CMakeRunConfiguration.pip_system_test - pip_system_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_test - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pip_test - CMakeProjectManager.CMakeRunConfiguration.pip_test - pip_test - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - pisd - CMakeProjectManager.CMakeRunConfiguration.pisd - pisd - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/system_daemon - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - piterminal - CMakeProjectManager.CMakeRunConfiguration.piterminal - piterminal - - false - - false - true - true - false - false - true - - D:/build-pip-Desktop_Qt_MinGW_64_bit-Release/utils/piterminal - - 12 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - From 53359ab286879267cbff16d62e18a62f2f2b2044 Mon Sep 17 00:00:00 2001 From: Gama Date: Tue, 15 Sep 2020 10:43:13 +0300 Subject: [PATCH 63/68] bug fixed second --- .gitignore | 2 +- tests/core/pistringTest.cpp | 206 +++++++++++++------------------ tests/math/testpimathmatrix.cpp | 74 ----------- tests/math/testpimathmatrixt.cpp | 4 +- 4 files changed, 90 insertions(+), 196 deletions(-) diff --git a/.gitignore b/.gitignore index 22cc44b5..0191619d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /.svn /doc/rtf _unsused -CMakeLists.txt.user \ No newline at end of file +*.user* \ No newline at end of file diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp index 26f5c97f..900b2cfd 100644 --- a/tests/core/pistringTest.cpp +++ b/tests/core/pistringTest.cpp @@ -46,20 +46,6 @@ TEST(PIString_Tests, operator_concatenation_char_zero1){ ASSERT_STREQ(str1, "D D "); } -TEST(PIString_Tests, operator_concatenation_char_zero2){ - PIString str1 = "AB C"; - const char *str2; - str1 += str2; - ASSERT_STREQ(str1, "AB C"); -} - -TEST(PIString_Tests, operator_concatenation_char_zero_zero){ - PIString str1; - const char *str2; - str1 += str2; - ASSERT_STREQ(str1, ""); -} - TEST(PIString_Tests, operator_concatenation_wchar){ PIString str1= "AB C"; wchar_t str2[] = L"C"; @@ -74,20 +60,6 @@ TEST(PIString_Tests, operator_concatenation_wchar_zero1){ ASSERT_STREQ(str1, "C"); } -TEST(PIString_Tests, operator_concatenation_wchar_zero2){ - PIString str1 = "AB C"; - wchar_t *str2; - str1 += str2; - ASSERT_STREQ(str1, "AB C"); -} - -TEST(PIString_Tests, operator_concatenation_wchar_zero_zero){ - PIString str1; - wchar_t *str2; - str1 += str2; - ASSERT_STREQ(str1, ""); -} - TEST(PIString_Tests, operator_concatenation_pistring){ PIString str1 = "AB C"; PIString str2 = " CD "; @@ -1287,6 +1259,13 @@ TEST(PIString_Tests, split){ ASSERT_STREQ(list[1], list[0]); } +TEST(PIString_Tests, split_sec){ + PIString str1 = " mirrow best detail "; + PIStringList list = str1.split("best"); + ASSERT_STREQ(" mirrow ", list[0]); + ASSERT_STREQ(list[1], " detail "); +} + TEST(PIString_Tests, split_empty){ PIString str1 = ""; PIStringList list = str1.split("best"); @@ -1568,52 +1547,51 @@ TEST(PIString_Tests, find_range){ PIString str1 = "A very strong programmer wrote this code"; PIChar start = "v"; PIChar end = "g"; - int *len; - ASSERT_EQ(3, str1.findRange(start, end, "n", 1, len)); + ASSERT_EQ(3, str1.findRange(start, end, "n", 1)); } TEST(PIString_Tests, find_range_len){ PIString str1 = "A very strong programmer wrote this code"; PIChar start = "v"; PIChar end = "g"; - int *len; - str1.findRange(start, end, "n", 1, len); - ASSERT_EQ(14, *len); + int len; + str1.findRange(start, end, "n", 1, &len); + ASSERT_EQ(14, len); } TEST(PIString_Tests, find_range_len_without_shield){ PIString str1 = "A very strong programmer wrote this code"; PIChar start = "v"; PIChar end = "g"; - int *len; - str1.findRange(start, end, "/", 1, len); - ASSERT_EQ(9, *len); + int len; + str1.findRange(start, end, "/", 1, &len); + ASSERT_EQ(9, len); } TEST(PIString_Tests, find_range_start){ PIString str1 = "A very strong programmer wrote this code"; PIChar start = "g"; PIChar end = "o"; - int *len; - str1.findRange(start, end, " ", 17, len); - ASSERT_EQ(9, *len); + int len; + str1.findRange(start, end, " ", 17, &len); + ASSERT_EQ(9, len); } TEST(PIString_Tests, find_range_eq){ PIString str1 = "A very strong programmer wrote this code"; PIChar start = "v"; PIChar end = "v"; - int *len; - str1.findRange(start, end, "n", 1, len); - ASSERT_EQ(0, *len); + int len; + str1.findRange(start, end, "n", 1, &len); + ASSERT_EQ(0, len); } TEST(PIString_Tests, find_range_trim){ PIString str1 = " A very strong programmer wrote this code"; PIChar start = "A"; PIChar end = "v"; - int *len; - ASSERT_EQ(2, str1.findRange(start, end, "n", 0, len)); + int len; + ASSERT_EQ(2, str1.findRange(start, end, "n", 0, &len)); } TEST(PIString_Tests, find_any){ @@ -1776,22 +1754,22 @@ TEST(PIString_Tests, to_short_0x){ TEST(PIString_Tests, to_short_false){ PIString str1 = "0x133"; - bool *ok; - str1.toShort(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toShort(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_short_false_base){ PIString str1 = "7"; - bool *ok; - str1.toShort(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toShort(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_short_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(-7, str1.toShort(10, ok)); + bool ok; + ASSERT_EQ(-7, str1.toShort(10, &ok)); } TEST(PIString_Tests, to_ushort){ @@ -1806,22 +1784,22 @@ TEST(PIString_Tests, to_ushort_0x){ TEST(PIString_Tests, to_ushort_false){ PIString str1 = "0x133"; - bool *ok; - str1.toUShort(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toUShort(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_ushort_false_base){ PIString str1 = "7"; - bool *ok; - str1.toUShort(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toUShort(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_ushort_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(65529, str1.toUShort(10, ok)); + bool ok; + ASSERT_EQ(65529, str1.toUShort(10, &ok)); } TEST(PIString_Tests, to_int){ @@ -1836,22 +1814,22 @@ TEST(PIString_Tests, to_int_0x){ TEST(PIString_Tests, to_int_false){ PIString str1 = "0x133"; - bool *ok; - str1.toInt(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toInt(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_int_false_base){ PIString str1 = "7"; - bool *ok; - str1.toInt(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toInt(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_int_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(-7, str1.toShort(10, ok)); + bool ok; + ASSERT_EQ(-7, str1.toShort(10, &ok)); } TEST(PIString_Tests, to_uint){ @@ -1866,22 +1844,22 @@ TEST(PIString_Tests, to_uint_0x){ TEST(PIString_Tests, to_uint_false){ PIString str1 = "0x133"; - bool *ok; - str1.toUInt(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toUInt(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_uint_false_base){ PIString str1 = "7"; - bool *ok; - str1.toUInt(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toUInt(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_uint_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(4294967289, str1.toUInt(10, ok)); + bool ok; + ASSERT_EQ(4294967289, str1.toUInt(10, &ok)); } TEST(PIString_Tests, to_long){ @@ -1896,22 +1874,22 @@ TEST(PIString_Tests, to_long_0x){ TEST(PIString_Tests, to_long_false){ PIString str1 = "0x133"; - bool *ok; - str1.toLong(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toLong(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_long_false_base){ PIString str1 = "7"; - bool *ok; - str1.toLong(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toLong(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_long_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(-7, str1.toLong(10, ok)); + bool ok; + ASSERT_EQ(-7, str1.toLong(10, &ok)); } TEST(PIString_Tests, to_ulong){ @@ -1926,22 +1904,22 @@ TEST(PIString_Tests, to_ulong_0x){ TEST(PIString_Tests, to_ulong_false){ PIString str1 = "0x133"; - bool *ok; - str1.toULong(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toULong(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_ulong_false_base){ PIString str1 = "7"; - bool *ok; - str1.toULong(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toULong(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_ulong_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(4294967289, str1.toULong(10, ok)); + bool ok; + ASSERT_EQ(4294967289, str1.toULong(10, &ok)); } TEST(PIString_Tests, to_llong){ @@ -1956,22 +1934,22 @@ TEST(PIString_Tests, to_llong_0x){ TEST(PIString_Tests, to_llong_false){ PIString str1 = "0x133"; - bool *ok; - str1.toLLong(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toLLong(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_llong_false_base){ PIString str1 = "7"; - bool *ok; - str1.toLLong(6, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toLLong(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_llong_neg){ PIString str1 = "-7"; - bool *ok; - ASSERT_EQ(-7, str1.toLLong(10, ok)); + bool ok; + ASSERT_EQ(-7, str1.toLLong(10, &ok)); } TEST(PIString_Tests, to_ullong){ @@ -1986,23 +1964,16 @@ TEST(PIString_Tests, to_ullong_0x){ TEST(PIString_Tests, to_ullong_false){ PIString str1 = "0x133"; - bool *ok; - str1.toULLong(1, ok); - ASSERT_FALSE(*ok); + bool ok; + str1.toULLong(1, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_ullong_false_base){ PIString str1 = "7"; - bool *ok; - str1.toULLong(6, ok); - ASSERT_FALSE(*ok); -} - -TEST(PIString_Tests, to_ullong_neg){ - PIString str1 = "-7"; - bool *ok; - ullong f = 184467451609; - ASSERT_EQ(f, str1.toULLong(10, ok)); + bool ok; + str1.toULLong(6, &ok); + ASSERT_FALSE(ok); } TEST(PIString_Tests, to_float){ @@ -2964,17 +2935,16 @@ TEST(PIString_Tests, operator_plus_chars_pstr){ ASSERT_STREQ("second first", str2 + str1); } -TEST(PIString_Tests, versionCompare2){ //дописать +TEST(PIString_Tests, versionCompare2){ //дописать PIString str1 = "first"; PIString str2 = "first 1"; versionCompare(str1, str2, 0); ASSERT_EQ(898448032, piHash(str1)); } -TEST(PIString_Tests, versionNormalize2){ //дописать - PIString str1 = "first"; - cout << versionNormalize(str1); - ASSERT_EQ(1, 1); +TEST(PIString_Tests, versionNormalize2){ + PIString str1 = "first second"; + ASSERT_STREQ("0.0_first second", versionNormalize(str1)); } TEST(PIString_Tests, piHash){ diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 1251b311..3dc1943a 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -52,25 +52,6 @@ TEST(PIMathMatrixT_Test, element) { ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, element) { - auto matrix = PIMathMatrix::identity(3, 3); - 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); - } - } - else { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } - } - } - ASSERT_TRUE(true); -} - TEST(PIMathMatrix_Test, matrixRow) { PIMathVector vector; vector.resize(3, 3.0); @@ -573,58 +554,3 @@ TEST(PIMathMatrix_Test, hermitian) { } ASSERT_TRUE(true); } - -TEST(PIMathMatrix_Test, matrixMultiplication) -{ - PIMathMatrix matrix1(2, 2, 1.5); - PIMathMatrix matrix2(2, 2, 2.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); -} - -TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { - PIMathMatrix matrix1(2, 2, 1.5); - PIMathVector vector; - vector.resize(2, 2.5); - for(uint i = 0; i < 2; i++) { - if((matrix1 * vector)[i] != 7.5) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); -} - -TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { - PIMathMatrix matrix1(2, 2, 1.5); - PIMathVector vector; - vector.resize(2, 2.5); - for(uint i = 0; i < 2; i++) { - if((vector * matrix1)[i] != 7.5) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); -} - -TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { - PIMathMatrix matrix1(3, 3, 1.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); -} - -TEST(PIMathMatrix_Test, hermitian) { - complex val; - complex res; - val.imag(1.0); - val.real(1.0); - PIMathMatrix> matrix(3, 3, val); - res.imag(-1.0); - res.real(1.0); - auto matr = hermitian(matrix); - for(uint i = 0; i < 3; i++) { - for(uint j = 0; j < 3; j++) { - if(matr.element(i, j) != res) { - ASSERT_TRUE(false); - } - } - } - ASSERT_TRUE(true); -} diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index db572942..d7f11563 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -33,7 +33,6 @@ TEST(PIMathMatrixT_Test, identity) { } } } ->>>>>>> 05a32cc... doc correction ASSERT_TRUE(true); } @@ -298,8 +297,7 @@ TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { auto matrix1 = PIMathMatrixT::filled(6.72) ; auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { From d19c6b1321369b50003372280792e17c4785dc69 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 15 Sep 2020 12:48:14 +0300 Subject: [PATCH 64/68] new docs --- libs/main/math/pimathmatrix.h | 78 +++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 8ab15e91..54a1904e 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -75,6 +75,9 @@ inline bool _PIMathMatrixNullCompare(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 class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _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 &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 operator*(const PIMathMatrixT operator*(const PIMathMatrixT 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 operator*(const PIMathVectorT &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 class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIVector2D _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 & 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 inline PICout operator<<(PICout s, const PIMathMatrix &m) { @@ -1337,11 +1348,11 @@ inline PICout operator<<(PICout s, const PIMathMatrix &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 inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { @@ -1350,11 +1361,11 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &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 inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { @@ -1363,9 +1374,8 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &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 operator*(const PIMathMatrix &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 operator*(const PIMathMatrix &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 operator*(const PIMathVector &sv, return tv; } -/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} /** * @brief Multiplying value of type Type and matrix * From 6a1b67a37427b1c4977933626aca7d312b91b21b Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 15 Sep 2020 14:50:19 +0300 Subject: [PATCH 65/68] bug fixes in docs --- libs/main/math/pimathmatrix.h | 70 ++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 54a1904e..eb12f17e 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -75,9 +75,10 @@ inline bool _PIMathMatrixNullCompare(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 +//! @tparam Rows rows number of matrix +//! @tparam Сols columns number of 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 class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrix; @@ -209,7 +210,7 @@ public: /** * @brief Method which returns the selected column in PIMathVectorT format. - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column * @return column in PIMathVectorT format @@ -222,7 +223,7 @@ public: /** * @brief Method which returns the selected row in PIMathVectorT format - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row * @return row in PIMathVectorT format @@ -235,7 +236,7 @@ public: /** * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column * @param v is a vector of the type _CMCol that needs to fill the column @@ -248,7 +249,7 @@ public: /** * @brief Set the selected row in matrix - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row * @param v is a vector of the type _CMCol that needs to fill the row @@ -261,7 +262,7 @@ public: /** * @brief Method which changes selected rows in a matrix. - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row @@ -279,7 +280,7 @@ public: /** * @brief Method which changes selected columns in a matrix. - * If you enter an index out of the border of the matrix behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param c0 is the number of the first selected column * @param c1 is the number of the second selected column @@ -335,7 +336,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 behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @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 @@ -345,7 +346,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 behavior will be undefined + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @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 @@ -354,7 +355,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 behavior will be undefined + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param row is a row of necessary matrix * @return matrix row pointer @@ -362,7 +363,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 behavior will be undefined + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param row is a row of necessary matrix * @return matrix row pointer @@ -487,7 +488,7 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix determinant @@ -508,7 +509,7 @@ public: } /** - * @brief Transforming matrix to upper triangular + * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of transformed upper triangular matrix @@ -551,7 +552,7 @@ public: } /** - * @brief Matrix inversion operation + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of inverted matrix @@ -605,7 +606,7 @@ public: } /** - * @brief Matrix inversion operation + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return inverted matrix @@ -617,7 +618,7 @@ public: } /** - * @brief Matrix transposition operation + * @brief Matrix transposition operation. Works only with square matrix, nonzero matrices and invertible matrix * * @return transposed matrix */ @@ -748,7 +749,7 @@ inline PICout operator<<(PICout s, const PIMathMatrixT &m) { } /** -* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix behavior will be undefined +* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param fm first matrix multiplier * @param sm second matrix multiplier @@ -771,7 +772,7 @@ inline PIMathMatrixT operator*(const PIMathMatrixT operator*(const PIMathMatrixT } /** -* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix behavior will be undefined +* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param sv first vector multiplier * @param fm second matrix multiplier @@ -856,7 +857,8 @@ 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 +//! @tparam There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /) +//! of the C++ language are implemented template class PIP_EXPORT PIMathMatrix : public PIVector2D { typedef PIVector2D _V2D; @@ -940,7 +942,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 behavior will be undefined + * or index larger than the number of columns otherwise there will be "undefined behavior" * * @param index is the number of the selected column * @param v is a vector of the type _CMCol that needs to fill the column @@ -953,7 +955,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 behavior will be undefined + * or index larger than the number of rows otherwise there will be "undefined behavior" * @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 @@ -965,7 +967,7 @@ public: /** * @brief Method which replace selected columns in a matrix. You cannot use an index larger than the number of columns, - * otherwise there behavior will be undefined + * otherwise there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row @@ -978,7 +980,7 @@ public: /** * @brief Method which replace selected rows in a matrix. You cannot use an index larger than the number of rows, - * otherwise there behavior will be undefined + * otherwise there will be "undefined behavior" * * @param c0 is the number of the first selected row * @param c1 is the number of the second selected row @@ -1152,7 +1154,7 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix + * @brief Determinant of the self matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix determinant @@ -1173,7 +1175,7 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix + * @brief Trace of the matrix is calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix trace @@ -1192,7 +1194,7 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix + * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of transformed upper triangular matrix @@ -1235,7 +1237,7 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @param sv is a vector multiplier @@ -1297,7 +1299,7 @@ public: } /** - * @brief Matrix inversion operation + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return inverted matrix @@ -1375,7 +1377,7 @@ inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { /** -* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix behavior will be undefined +* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param fm first matrix multiplier * @param sm second matrix multiplier @@ -1400,7 +1402,7 @@ inline PIMathMatrix operator*(const PIMathMatrix &fm, } /** -* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix behavior will be undefined +* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param fm first matrix multiplier * @param sv second vector multiplier @@ -1423,7 +1425,7 @@ inline PIMathVector operator*(const PIMathMatrix &fm, } /** -* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix behavior will be undefined +* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param sv first vector multiplier * @param fm second matrix multiplier From f73b7fb092f5e2ff27d306adbebf9dfb44c264e8 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 15 Sep 2020 14:53:28 +0300 Subject: [PATCH 66/68] tab correction --- libs/main/math/pimathmatrix.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index eb12f17e..3791a8ed 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -210,7 +210,7 @@ public: /** * @brief Method which returns the selected column in PIMathVectorT format. - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column * @return column in PIMathVectorT format @@ -223,7 +223,7 @@ public: /** * @brief Method which returns the selected row in PIMathVectorT format - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row * @return row in PIMathVectorT format @@ -236,7 +236,7 @@ public: /** * @brief Set the selected column in matrix. - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column * @param v is a vector of the type _CMCol that needs to fill the column @@ -249,7 +249,7 @@ public: /** * @brief Set the selected row in matrix - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row * @param v is a vector of the type _CMCol that needs to fill the row @@ -262,7 +262,7 @@ public: /** * @brief Method which changes selected rows in a matrix. - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row @@ -280,7 +280,7 @@ public: /** * @brief Method which changes selected columns in a matrix. - * If you enter an index out of the border of the matrix there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param c0 is the number of the first selected column * @param c1 is the number of the second selected column @@ -336,7 +336,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 there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @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 @@ -346,7 +346,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 there will be "undefined behavior" + * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @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 @@ -552,7 +552,7 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of inverted matrix @@ -606,7 +606,7 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return inverted matrix @@ -618,7 +618,7 @@ public: } /** - * @brief Matrix transposition operation. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Matrix transposition operation. Works only with square matrix, nonzero matrices and invertible matrix * * @return transposed matrix */ @@ -1154,7 +1154,7 @@ public: } /** - * @brief Determinant of the self matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Determinant of the self matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix determinant @@ -1175,7 +1175,7 @@ public: } /** - * @brief Trace of the matrix is calculated. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Trace of the matrix is calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix trace @@ -1194,7 +1194,7 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of transformed upper triangular matrix @@ -1237,7 +1237,7 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @param sv is a vector multiplier @@ -1299,7 +1299,7 @@ public: } /** - * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return inverted matrix From 4f731d72a6326ed37e9b3e679bad410bd7109444 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 15 Sep 2020 14:56:58 +0300 Subject: [PATCH 67/68] second tab correction --- libs/main/math/pimathmatrix.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 3791a8ed..897fe6ae 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -355,7 +355,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 there will be "undefined behavior" + * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param row is a row of necessary matrix * @return matrix row pointer @@ -363,7 +363,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 there will be "undefined behavior" + * @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param row is a row of necessary matrix * @return matrix row pointer @@ -488,7 +488,7 @@ public: } /** - * @brief Determinant of the matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Determinant of the matrix is ​​calculated. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return matrix determinant @@ -509,7 +509,7 @@ public: } /** - * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix + * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly * @return copy of transformed upper triangular matrix @@ -955,7 +955,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 "undefined behavior" + * or index larger than the number of rows otherwise there will be "undefined behavior" * @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 @@ -967,7 +967,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 "undefined behavior" + * otherwise there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row @@ -980,7 +980,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 "undefined behavior" + * otherwise there will be "undefined behavior" * * @param c0 is the number of the first selected row * @param c1 is the number of the second selected row From f9c1dbc6619aaf5ef48c2801fa6f05fae235c5ae Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 15 Sep 2020 15:39:17 +0300 Subject: [PATCH 68/68] bugzz --- .gitignore | 2 +- tests/CMakeLists.txt | 2 +- tests/math/testpimathmatrix.cpp | 3 +-- tests/math/testpimathmatrixt.cpp | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 0191619d..e47ef87b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /.svn /doc/rtf _unsused -*.user* \ No newline at end of file +CMakeLists.txt.user* \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 49c4d1be..68c51388 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ macro(pip_test NAME LIBS) set(_target pip_${NAME}_test) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PIP_ROOT_BINARY_DIR}") add_executable(${_target} ${_CPPS} ${_HDRS}) - target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) + target_link_libraries(${_target} pip ${LIBS} gtest_main gmock_main) add_test(NAME ${_target} COMMAND tests) add_custom_target(${_target}_perform ALL COMMAND ${_target}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index 3dc1943a..fb7109fb 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -1,8 +1,7 @@ #include "gtest/gtest.h" #include "pimathmatrix.h" -template -bool cmpSquareMatrixWithValue(PIMathMatrix matrix, Type val, int num) { +bool cmpSquareMatrixWithValue(PIMathMatrix matrix, double val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index d7f11563..df96a01c 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -4,8 +4,7 @@ const uint rows = 3; const uint cols = 3; -template -bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, Type val, int num) { +bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, double val, int num) { bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) {