From b9e2d842d0a10c1b27d9cf4aaf53bc960fdc62fc Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 11 Jan 2025 22:21:13 -0600 Subject: [PATCH] refactor: simplify matrix inverse dimensions code --- public/dimensional_analysis.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/public/dimensional_analysis.py b/public/dimensional_analysis.py index 4d6e1254..7bce5a01 100644 --- a/public/dimensional_analysis.py +++ b/public/dimensional_analysis.py @@ -1017,18 +1017,12 @@ def ensure_inverse_dims(arg): row = [] rows.append(row) for j in range(arg.cols): - dim, _ = get_mathjs_units(cast(dict[Dimension, float], custom_get_dimensional_dependencies(cast(Expr, arg[j,i])))) - if dim == "": - row.append(S.Zero) - else: - row.append(cast(Expr, arg[j,i])**-1) - column_dims.setdefault(i, []).append(dim) - - column_checks = [] - for _, values in column_dims.items(): - column_checks.append(all([value == values[0] for value in values[1:]])) - - if not all(column_checks): + row.append(cast(Expr, arg[j,i])**-1) + column_dims.setdefault(i, []).append(arg[j,i]) + try: + for _, values in column_dims.items(): + ensure_dims_all_compatible(*values) + except TypeError: raise TypeError('Dimensions not consistent for matrix inverse') return Matrix(rows)