From 1688c45e3c3fc0a2055e1aba2a5be6f044f766e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 3 Jul 2019 17:58:46 +0200 Subject: [PATCH] [poincare] MatrixTranspose --- poincare/include/poincare/matrix.h | 2 +- poincare/src/matrix.cpp | 18 +++++++++--------- poincare/src/matrix_transpose.cpp | 23 +++++++++-------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 3bab7f8b1..071b0010a 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -77,10 +77,10 @@ public: // Inverse the array in-place. Array has to be given in the form array[row_index][column_index] template static int ArrayInverse(T * array, int numberOfRows, int numberOfColumns); static Matrix CreateIdentity(int dim); + Matrix createTranspose() const; #if MATRIX_EXACT_REDUCING Expression trace() const; Expression determinant() const; - Matrix transpose() const; /* createInverse can be called on any matrix reduce or not, approximate or not. */ Expression inverse(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; #endif diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index b26a9a00e..f3e43fe99 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -296,21 +296,21 @@ Matrix Matrix::CreateIdentity(int dim) { return matrix; } -#if 0 -#if MATRIX_EXACT_REDUCING -Matrix Matrix::transpose() const { - Matrix matrix(); - for (int i = 0; i < m_numberOfRows; i++) { - for (int j = 0; j < m_numberOfColumns; j++) { - matrix.addChildAtIndexInPlace(childAtIndex(i*m_numberOfRows+j), j*m_numberOfRows+i, j*m_numberOfRows+i); + +Matrix Matrix::createTranspose() const { + Matrix matrix = Matrix::Builder(); + for (int j = 0; j < numberOfColumns(); j++) { + for (int i = 0; i < numberOfRows(); i++) { + matrix.addChildAtIndexInPlace(const_cast(this)->matrixChild(i, j).clone(), matrix.numberOfChildren(), matrix.numberOfChildren()); } } // Intentionally swapping dimensions for transpose - matrix.setDimensions(m_numberOfColumns, m_numberOfRows); + matrix.setDimensions(numberOfColumns(), numberOfRows()); return matrix; } -Expression Matrix::inverse(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { +#if 0 +#if MATRIX_EXACT_REDUCINGExpression Matrix::inverse(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { if (m_numberOfRows != m_numberOfColumns) { return Undefined::Builder(); } diff --git a/poincare/src/matrix_transpose.cpp b/poincare/src/matrix_transpose.cpp index 2f9410b84..93201db97 100644 --- a/poincare/src/matrix_transpose.cpp +++ b/poincare/src/matrix_transpose.cpp @@ -46,22 +46,17 @@ Expression MatrixTranspose::shallowReduce() { } } Expression c = childAtIndex(0); -#if MATRIX_EXACT_REDUCING if (c.type() == ExpressionNode::Type::Matrix) { - Matrix transpose = static_cast(c).createTranspose(); - return transpose; + Expression result = static_cast(c).createTranspose(); + replaceWithInPlace(result); + return result; } - if (!c.recursivelyMatches(Expression::IsMatrix)) { - return c; - } - return *this; -#else - if (c.type() != ExpressionNode::Type::Matrix) { - replaceWithInPlace(c); - return c; - } - return *this; -#endif + /* TODO LEA + if (c.recursivelyMatches(Expression::IsMatrix)) { + return *this; + }*/ + replaceWithInPlace(c); + return c; } }