fix math/pimathmatrix.h

This commit is contained in:
2020-06-02 13:05:35 +03:00
parent 988ebac3b7
commit a01c3144f3
2 changed files with 26 additions and 18 deletions

View File

@@ -117,19 +117,27 @@ PIKbdListener kbd(0, 0, false);
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
PIMathMatrixd m = PIMathMatrixd::identity(3,3); PIMathMatrixd m2(3,3); m2.fill(5);
m*=33; PIMathVectord v(3); v.fill(4);
piCout << m; //m.fill(7);
PIMathMatrixd m2; piCout << v*m2;
m2 = m; m2.resize(3,5, 99); //piCout << m1*m2.transposed();
piCout << m2; // PIMathMatrixd m2;
m2 = m; m2.resize(5,3, 88); // m2 = m; m2.resize(3,5, 99);
piCout << m2; // piCout << m2;
m2 = m; m2.resize(4,9, 77); // m2 = m; m2.resize(5,3, 88);
piCout << m2; // piCout << m2;
m2 = m; m2.resize(2,2, 66); // m2 = m; m2.resize(4,9, 77);
piCout << m2; // piCout << m2;
m2 = m; m2.resize(2,8, 66); // m2 = m; m2.resize(2,2, 66);
piCout << m2; // piCout << m2;
// m2 = m; m2.resize(2,8, 66);
// piCout << m2;
// piCout << m.transposed() << m.transposed()*m;
// piCout << "zzzzzzzz";
PIMathMatrixT<3u, 3u, double> n1 = PIMathMatrixT<3u, 3u, double>::filled(5);
PIMathMatrixT<1u, 3u, double> n2 = PIMathMatrixT<1u, 3u, double>::filled(4);
piCout << n2*n1;
// piCout << n.transposed() << n.transposed()*n;
return 0; return 0;
} }

View File

@@ -328,10 +328,10 @@ class PIP_EXPORT PIMathMatrix : public PIVector2D<Type> {
typedef PIMathMatrix<Type> _CMatrix; typedef PIMathMatrix<Type> _CMatrix;
typedef PIMathVector<Type> _CMCol; typedef PIMathVector<Type> _CMCol;
public: public:
PIMathMatrix(const uint cols = 0, const uint rows = 0) {_V2D::resize(cols, rows);} 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<Type> & val) {_V2D::resize(cols, rows); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];} PIMathMatrix(const uint cols, const uint rows, const PIVector<Type> & val) {_V2D::resize(rows, cols); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];}
PIMathMatrix(const PIVector<PIVector<Type> > & val) {if(!val.isEmpty()) {_V2D::resize(val[0].size(), val.size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}} PIMathMatrix(const PIVector<PIVector<Type> > & 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<Type> & val) {if(!val.isEmpty()) {_V2D::resize(val.cols(), val.rows()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}} PIMathMatrix(const PIVector2D<Type> & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}}
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 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<Type> & val) {return _CMatrix(val.size(), 1, val.toVector());} static _CMatrix matrixRow(const PIMathVector<Type> & val) {return _CMatrix(val.size(), 1, val.toVector());}