Skip to content

Commit 1fb6c19

Browse files
committed
IPython LaTeX output only generated for small systems
StateSpace._repr_latex_ now returns None for systems whose size is greater than new config variable statesp.latex_maxsize. System size is the largest dimension of the partitioned system matrix. statesp.latex_maxsize is 10.
1 parent 8299ebb commit 1fb6c19

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

control/statesp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
'statesp.remove_useless_states': False,
7676
'statesp.latex_num_format': '.3g',
7777
'statesp.latex_repr_type': 'partitioned',
78+
'statesp.latex_maxsize': 10,
7879
}
7980

8081

@@ -517,19 +518,26 @@ def fmt_matrix(matrix, name):
517518
def _repr_latex_(self):
518519
"""LaTeX representation of state-space model
519520
520-
Output is controlled by config options statesp.latex_repr_type
521-
and statesp.latex_num_format.
521+
Output is controlled by config options statesp.latex_repr_type,
522+
statesp.latex_num_format, and statesp.latex_maxsize.
522523
523524
The output is primarily intended for Jupyter notebooks, which
524525
use MathJax to render the LaTeX, and the results may look odd
525526
when processed by a 'conventional' LaTeX system.
526527
528+
527529
Returns
528530
-------
529-
s : string with LaTeX representation of model
531+
532+
s : string with LaTeX representation of model, or None if
533+
either matrix dimension is greater than
534+
statesp.latex_maxsize
530535
531536
"""
532-
if config.defaults['statesp.latex_repr_type'] == 'partitioned':
537+
syssize = self.nstates + max(self.noutputs, self.ninputs)
538+
if syssize > config.defaults['statesp.latex_maxsize']:
539+
return None
540+
elif config.defaults['statesp.latex_repr_type'] == 'partitioned':
533541
return self._latex_partitioned()
534542
elif config.defaults['statesp.latex_repr_type'] == 'separate':
535543
return self._latex_separate()

control/tests/statesp_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,29 @@ def test_xferfcn_ndarray_precedence(op, tf, arr):
10631063
ss = ct.tf2ss(tf)
10641064
result = op(arr, ss)
10651065
assert isinstance(result, ct.StateSpace)
1066+
1067+
1068+
def test_latex_repr_testsize(editsdefaults):
1069+
# _repr_latex_ returns None when size > maxsize
1070+
from control import set_defaults
1071+
1072+
maxsize = defaults['statesp.latex_maxsize']
1073+
nstates = maxsize // 2
1074+
ninputs = maxsize - nstates
1075+
noutputs = ninputs
1076+
1077+
assert nstates > 0
1078+
assert ninputs > 0
1079+
1080+
g = rss(nstates, ninputs, noutputs)
1081+
assert isinstance(g._repr_latex_(), str)
1082+
1083+
set_defaults('statesp', latex_maxsize=maxsize - 1)
1084+
assert g._repr_latex_() is None
1085+
1086+
set_defaults('statesp', latex_maxsize=-1)
1087+
assert g._repr_latex_() is None
1088+
1089+
gstatic = ss([], [], [], 1)
1090+
assert gstatic._repr_latex_() is None
1091+

0 commit comments

Comments
 (0)