10000 Merge pull request #607 from roryyorke/rory/statesp-latex-maxsize · python-control/python-control@e81f648 · GitHub
[go: up one dir, main page]

Skip to content

Commit e81f648

Browse files
authored
Merge pull request #607 from roryyorke/rory/statesp-latex-maxsize
IPython LaTeX output only generated for small systems
2 parents d1f3bca + 1fb6c19 commit e81f648

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

@@ -526,19 +527,26 @@ def _latex_dt(self):
526527
def _repr_latex_(self):
527528
"""LaTeX representation of state-space model
528529
529-
Output is controlled by config options statesp.latex_repr_type
530-
and statesp.latex_num_format.
530+
Output is controlled by config options statesp.latex_repr_type,
531+
statesp.latex_num_format, and statesp.latex_maxsize.
531532
532533
The output is primarily intended for Jupyter notebooks, which
533534
use MathJax to render the LaTeX, and the results may look odd
534535
when processed by a 'conventional' LaTeX system.
535536
537+
536538
Returns
537539
-------
538-
s : string with LaTeX representation of model
540+
541+
s : string with LaTeX representation of model, or None if
542+
either matrix dimension is greater than
543+
statesp.latex_maxsize
539544
540545
"""
541-
if config.defaults['statesp.latex_repr_type'] == 'partitioned':
546+
syssize = self.nstates + max(self.noutputs, self.ninputs)
547+
if syssize > config.defaults['statesp.latex_maxsize']:
548+
return None
549+
elif config.defaults['statesp.latex_repr_type'] == 'partitioned':
542550
return self._latex_partitioned()
543551
elif config.defaults['statesp.latex_repr_type'] == 'separate':
544552
return self._latex_separate()

control/tests/statesp_test.py

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

0 commit comments

Comments
 (0)
0