elisa.util.misc#

Miscellaneous helper functions.

set_suffix_config(unicode: bool = False, plain_subscript_template: str = '_%s', plain_superscript_template: str = '[%s]', latex_subscript_template: str = '_{%s}', latex_superscript_template: str = '^{%s}') None[source]#

Set suffix configuration.

Parameters:
  • unicode (bool) – If True, use unicode suffix. The default is False.

  • plain_subscript_template (str) – The template for plain subscript. The default is '_%s'.

  • plain_superscript_template (str) – The template for plain superscript. The default is '[%s]'.

  • latex_subscript_template (str) – The template for LaTeX subscript. The default is '_{%s}'.

  • latex_superscript_template (str) – The template for LaTeX superscript. The default is '^{%s}'.

add_suffix(strings: str | Sequence[str], suffix: str | Sequence[str], subscript: bool, unicode: bool | None = None, latex: bool = False, mathrm: bool = False) str | list[str][source]#

Add suffix to a sequence of strings.

Parameters:
  • strings (str | Sequence[str]) – The sequence of strings.

  • suffix (str | Sequence[str]) – The sequence of suffixes. The suffix format can be set by elisa.util.misc.set_suffix_config().

  • subscript (bool) – If True, add suffix as subscript, otherwise superscript. The default is True.

  • latex (bool) – If True, add suffix following LaTeX format. The default is False.

  • unicode (bool | None) – If True, add suffix with Unicode string. Defaults to elisa.util.misc.UNICODE_SUFFIX, which can be set by elisa.util.misc.set_suffix_config().

  • mathrm (bool) – If True, add suffix in mathrm when latex is True. The default is False.

Returns:

The strings with suffix added.

build_namespace(names: Sequence[str], latex: bool = False, prime: bool = False) dict[str, list[str | int]][source]#

Build a namespace from a sequence of names.

Parameters:
  • names (Sequence[str]) – A sequence of names.

  • latex (bool) – If True, names are assumed to be LaTeX strings. The default is False.

  • prime (bool) – If True, primes are used as suffix for duplicate names, otherwise a number is used. The default is False.

Returns:

A dict of non-duplicate names and suffixes in original name order.

define_fdjvp(fn: Callable[[Array, dict[str, Array]], Array], method: Literal['central', 'forward'] = 'central') Callable[[Array, dict[str, Array]], Array][source]#

Define JVP using finite differences.

get_unit_latex(unit: str, throw: bool = True) str[source]#

Get latex string of a unit.

Parameters:
  • unit (str) – The unit string.

  • throw (bool) – If True, raise ValueError if the unit is invalid. The default is True.

Returns:

The latex string of the unit.

make_pretty_table(fields: Sequence[str], rows: Sequence) PrettyTable[source]#

Make a prettytable.PrettyTable.

Parameters:
  • fields (Sequence[str]) – The names of fields.

  • rows (Sequence) – The sequence of data corresponding to the fields.

Returns:

The pretty table.

replace_string(value: T, mapping: dict[str, str]) T[source]#

Replace all strings in value appeared in mapping.

Parameters:
  • value (TypeVar(T)) – Object whose str value needs to be replaced.

  • mapping (dict[str, str]) – Mapping of str value to be replaced and replacement.

Returns:

Value of value replaced with mapping.

report_interval(vmid: float, vmin: float, vmax: float, precision: int = 2, min_exponent: int = 1, max_exponent: int = 2) str[source]#

Report parameter interval in \(\LaTeX\) format.

Parameters:
  • vmid (float) – The mid value.

  • vmin (float) – The lower bound.

  • vmax (float) – The upper bound.

  • precision (int) – The precision of the mid value. The default is 2.

  • min_exponent (int) – The minimum exponent to use scientific notation. The default is 1.

  • max_exponent (int) – The maximum exponent to use scientific notation. The default is 2.

Returns:

The interval in \(|LaTeX\) format.

progress_bar_factory(neval: int, ncores: int, init_str: str | None = None, run_str: str | None = None, update_rate: int = 50) Callable[[Callable], Callable][source]#

Add a progress bar to JAX fori_loop kernel, see [1] for details.

Parameters:
  • neval (int) – The total number of evaluations.

  • ncores (int) – The number of cores.

  • init_str (str | None) – The string displayed before progress bar when initialization.

  • run_str (str | None) – The string displayed before progress bar when run.

  • update_rate (int) – The update rate of the progress bar. The default is 50.

Returns:

Factory that adds a progress bar to function input.

References

to_native_byteorder(arr: ndarray) ndarray[source]#

Convert an array to native byte order.