From c1c280762f703f3598ae2e9917a610736796188b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 3 May 2019 15:51:43 +0200 Subject: [PATCH] [regression] Add an assertion on the number of entries of matrices used in models --- apps/regression/model/model.cpp | 1 + poincare/include/poincare/matrix.h | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/regression/model/model.cpp b/apps/regression/model/model.cpp index 3b287687d..eb90bb77e 100644 --- a/apps/regression/model/model.cpp +++ b/apps/regression/model/model.cpp @@ -170,6 +170,7 @@ int Model::solveLinearSystem(double * solutions, double * coefficients, double * for (int i = 0; i < n * n; i++) { coefficientsSave[i] = coefficients[i]; } + assert(k_maxNumberOfCoefficients < Matrix::k_maxNumberOfCoefficients); int inverseResult = Matrix::ArrayInverse(coefficients, n, n); int numberOfMatrixModifications = 0; while (inverseResult < 0 && numberOfMatrixModifications < k_maxMatrixInversionFixIterations) { diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index b015b81de..d042bc939 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -84,10 +84,9 @@ public: /* 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 -private: // TODO: find another solution for inverse and determinant (avoid capping the matrix) static constexpr int k_maxNumberOfCoefficients = 100; - +private: MatrixNode * node() const { return static_cast(Expression::node()); } void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); } void setNumberOfColumns(int columns) { assert(columns >= 0); node()->setNumberOfColumns(columns); }