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:
unicodebool, optional

If True, use unicode suffix. The default is False.

plain_subscript_templatestr, optional

The template for plain subscript. The default is '_%s'.

plain_superscript_templatestr, optional

The template for plain superscript. The default is '[%s]'.

latex_subscript_templatestr, optional

The template for LaTeX subscript. The default is '_{%s}'.

latex_superscript_templatestr, optional

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:
stringssequence of str

The sequence of strings.

suffixsequence of str

The sequence of suffixes. The suffix format can be set by elisa.util.misc.set_suffix_config().

subscriptbool, optional

If True, add suffix as subscript, otherwise superscript. The default is True.

latexbool, optional

If True, add suffix following LaTeX format. The default is False.

unicodebool, optional

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().

mathrmbool, optional

If True, add suffix in mathrm when latex is True. The default is False.

Returns:
str or list of str

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:
namessequence of str

A sequence of names.

latexbool, optional

If True, names are assumed to be LaTeX strings. The default is False.

primebool, optional

If True, primes are used as suffix for duplicate names, otherwise a number is used. The default is False.

Returns:
namespace: dict

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:
unitstr

The unit string.

throwbool, optional

If True, raise ValueError if the unit is invalid. The default is True.

Returns:
str

The latex string of the unit.

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

Make a prettytable.PrettyTable.

Parameters:
fieldssequence of str

The names of fields.

rowssequence

The sequence of data corresponding to the fields.

Returns:
tablePrettyTable

The pretty table.

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

Replace all strings in value appeared in mapping.

Parameters:
valuestr, iterable or mapping

Object whose str value needs to be replaced.

mappingdict

Mapping of str value to be replaced and replacement.

Returns:
replacediterable or mapping

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:
vmidfloat

The mid value.

vminfloat

The lower bound.

vmaxfloat

The upper bound.

precisionint, optional

The precision of the mid value. The default is 2.

min_exponentint, optional

The minimum exponent to use scientific notation. The default is 1.

max_exponentint, optional

The maximum exponent to use scientific notation. The default is 2.

Returns:
str

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:
nevalint

The total number of evaluations.

ncoresint

The number of cores.

init_strstr, optional

The string displayed before progress bar when initialization.

run_strstr, optional

The string displayed before progress bar when run.

update_rateint, optional

The update rate of the progress bar. The default is 50.

Returns:
progress_bar_fori_loopcallable()

Factory that adds a progress bar to function input.

References

to_native_byteorder(arr: ndarray) ndarray[source]#

Convert an array to native byte order.