From 1fb6c19d605825c2990dabebf9adf9e841c40c01 Mon Sep 17 00:00:00 2001 From: Rory Yorke Date: Sun, 11 Apr 2021 13:18:59 +0200 Subject: [PATCH] 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. --- control/statesp.py | 16 ++++++++++++---- control/tests/statesp_test.py | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) 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