Skip to content

Commit 2c4f4bb

Browse files
prevent unused vars in jacobians (#239)
* prevent unused vars in jacobians
1 parent cb5d1b9 commit 2c4f4bb

File tree

6 files changed

+2476
-8
lines changed

6 files changed

+2476
-8
lines changed

RELEASE.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Release 0.9.6
2-
- This release fixes a bug printing large integers, in some environments: Large numbers such as 8.034023767017109e+27 whch were actually ints would be printed as an the int 8034023767017108950029959168 and then the C++ compiler would complain as that's more than the maximum int value. This has been fixed by only printing ints as ints if they are `MIN_INT < number < MAX_INT` else we print them as a float (and we get the sceintific notation).
3-
4-
# Release 0.9.6 (yanked)
1+
# Release 0.9.8
2+
- Fixed an issue with unused variables appearing in common terms in jacobians.
3+
- Fixes a bug printing large integers, in some environments: Large numbers such as 8.034023767017109e+27 whch were actually ints would be printed as an the int 8034023767017108950029959168 and then the C++ compiler would complain as that's more than the maximum int value. This has been fixed by only printing ints as ints if they are `MIN_INT < number < MAX_INT` else we print them as a float (and we get the sceintific notation).
54
- Fixed tests to pass with sympy 1.10 and required latest cellmlmanip, which also workes with sympy1.10. Updated sympy requirement to be >=1.9, < 1.11
6-
- This release was yanked due to a bug printing large integers
75

86
# Release 0.9.5
97
- Corrected a type in the generated output for `--rush-larsen-c`

chaste_codegen/_jacobian.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,25 @@ def format_jacobian(jacobian_equations, jacobian_matrix, printer, print_rhs,
5151
assert isinstance(printer, Printer), 'Expecting printer to be a cellmlmanip.printer.Printer'
5252
assert callable(print_rhs), 'Expecting print_rhs to be a callable'
5353

54-
equations = [{'lhs': printer.doprint(eq[0]), 'rhs': print_rhs(eq[0], eq[1]), 'sympy_lhs': eq[0],
55-
'sympy_rhs': eq[1]} for eq in jacobian_equations]
54+
symbols_used = set()
5655
rows, cols = jacobian_matrix.shape
5756
jacobian = []
5857
for i in range(cols if swap_inner_outer_index else rows):
5958
for j in range(rows if swap_inner_outer_index else cols):
6059
matrix_entry = jacobian_matrix[j, i] if swap_inner_outer_index else jacobian_matrix[i, j]
6160
if not skip_0_entries or matrix_entry != 0:
61+
symbols_used.update(matrix_entry.free_symbols)
6262
jacobian.append({'i': j if swap_inner_outer_index else i, 'j': i if swap_inner_outer_index else j,
6363
'entry': printer.doprint(matrix_entry)})
64+
65+
num_symbols = 0
66+
while num_symbols != len(symbols_used):
67+
num_symbols = len(symbols_used)
68+
for eq in jacobian_equations:
69+
if eq[0] in symbols_used:
70+
symbols_used.update(eq[1].free_symbols)
71+
72+
equations = [{'lhs': printer.doprint(eq[0]), 'rhs': print_rhs(eq[0], eq[1]), 'sympy_lhs': eq[0],
73+
'sympy_rhs': eq[1]} for eq in jacobian_equations if eq[0] in symbols_used]
74+
6475
return equations, jacobian

0 commit comments

Comments
 (0)