diff --git a/control/statesp.py b/control/statesp.py index c12583111..653ea062a 100644 --- a/control/statesp.py +++ b/control/statesp.py @@ -75,6 +75,7 @@ 'statesp.remove_useless_states': False, 'statesp.latex_num_format': '.3g', 'statesp.latex_repr_type': 'partitioned', + 'statesp.latex_maxsize': 10, } @@ -517,19 +518,26 @@ def fmt_matrix(matrix, name): def _repr_latex_(self): """LaTeX representation of state-space model - Output is controlled by config options statesp.latex_repr_type - and statesp.latex_num_format. + Output is controlled by config options statesp.latex_repr_type, + statesp.latex_num_format, and statesp.latex_maxsize. The output is primarily intended for Jupyter notebooks, which use MathJax to render the LaTeX, and the results may look odd when processed by a 'conventional' LaTeX system. + Returns ------- - s : string with LaTeX representation of model + + s : string with LaTeX representation of model, or None if + either matrix dimension is greater than + statesp.latex_maxsize """ - if config.defaults['statesp.latex_repr_type'] == 'partitioned': + syssize = self.nstates + max(self.noutputs, self.ninputs) + if syssize > config.defaults['statesp.latex_maxsize']: + return None + elif config.defaults['statesp.latex_repr_type'] == 'partitioned': return self._latex_partitioned() elif config.defaults['statesp.latex_repr_type'] == 'separate': return self._latex_separate() diff --git a/control/tests/statesp_test.py b/control/tests/statesp_test.py index 71e7cc4bc..459b2306f 100644 --- a/control/tests/statesp_test.py +++ b/control/tests/statesp_test.py @@ -1063,3 +1063,29 @@ def test_xferfcn_ndarray_precedence(op, tf, arr): ss = ct.tf2ss(tf) result = op(arr, ss) assert isinstance(result, ct.StateSpace) + + +def test_latex_repr_testsize(editsdefaults): + # _repr_latex_ returns None when size > maxsize + from control import set_defaults + + maxsize = defaults['statesp.latex_maxsize'] + nstates = maxsize // 2 + ninputs = maxsize - nstates + noutputs = ninputs + + assert nstates > 0 + assert ninputs > 0 + + g = rss(nstates, ninputs, noutputs) + assert isinstance(g._repr_latex_(), str) + + set_defaults('statesp', latex_maxsize=maxsize - 1) + assert g._repr_latex_() is None + + set_defaults('statesp', latex_maxsize=-1) + assert g._repr_latex_() is None + + gstatic = ss([], [], [], 1) + assert gstatic._repr_latex_() is None + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy