From 123c6a8a7a5ce9386f5cc19c86b4bbb74f211eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 4 Jul 2019 14:23:49 +0200 Subject: [PATCH] [poincare] Matrix::rowCanonize uses context's Target --- poincare/include/poincare/matrix.h | 2 +- poincare/src/matrix.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index a460c6e60..5b49d0d53 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -92,7 +92,7 @@ private: void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); } void setNumberOfColumns(int columns) { assert(columns >= 0); node()->setNumberOfColumns(columns); } /* rowCanonize turns a matrix in its reduced row echelon form. */ - Matrix rowCanonize(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Matrix rowCanonize(ExpressionNode::ReductionContext reductionContext); // Row canonize the array in place template static void ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, T * c = nullptr); }; diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index a51a263b7..c0c148494 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -114,7 +114,8 @@ void Matrix::addChildrenAsRowInPlace(TreeHandle t, int i) { int Matrix::rank(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool inPlace) { Matrix m = inPlace ? *this : clone().convert(); - m = m.rowCanonize(context, complexFormat, angleUnit); + ExpressionNode::ReductionContext systemReductionContext = ExpressionNode::ReductionContext(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::System); + m = m.rowCanonize(systemReductionContext); int rank = m.numberOfRows(); int i = rank-1; while (i >= 0) { @@ -166,11 +167,10 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) { return 0; } -Matrix Matrix::rowCanonize(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { +Matrix Matrix::rowCanonize(ExpressionNode::ReductionContext reductionContext) { Expression::SetInterruption(false); // The matrix children have to be reduced to be able to spot 0 - ExpressionNode::ReductionContext systemReductionContext = ExpressionNode::ReductionContext(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::System); - deepReduceChildren(systemReductionContext); + deepReduceChildren(reductionContext); int m = numberOfRows(); int n = numberOfColumns(); @@ -200,7 +200,7 @@ Matrix Matrix::rowCanonize(Context * context, Preferences::ComplexFormat complex Expression opHJ = matrixChild(h, j); Expression newOpHJ = Division::Builder(opHJ, divisor.clone()); replaceChildAtIndexInPlace(h*n+j, newOpHJ); - newOpHJ = newOpHJ.shallowReduce(systemReductionContext); + newOpHJ = newOpHJ.shallowReduce(reductionContext); } replaceChildInPlace(divisor, Rational::Builder(1)); @@ -212,8 +212,8 @@ Matrix Matrix::rowCanonize(Context * context, Preferences::ComplexFormat complex Expression opIJ = matrixChild(i, j); Expression newOpIJ = Subtraction::Builder(opIJ, Multiplication::Builder(matrixChild(h, j).clone(), factor.clone())); replaceChildAtIndexInPlace(i*n+j, newOpIJ); - newOpIJ.childAtIndex(1).shallowReduce(systemReductionContext); - newOpIJ = newOpIJ.shallowReduce(systemReductionContext); + newOpIJ.childAtIndex(1).shallowReduce(reductionContext); + newOpIJ = newOpIJ.shallowReduce(reductionContext); } replaceChildAtIndexInPlace(i*n+k, Rational::Builder(0)); } @@ -317,7 +317,7 @@ Expression Matrix::createInverse(ExpressionNode::ReductionContext reductionConte } } matrixAI.setDimensions(dim, 2*dim); - matrixAI = matrixAI.rowCanonize(reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()); + matrixAI = matrixAI.rowCanonize(reductionContext); // Check inversibility for (int i = 0; i < dim; i++) { if (!matrixAI.matrixChild(i, i).isRationalOne()) {