Versatile#

For versatile utility.

check_black()[source]#

Check if black is installed or not.

Returns:

  • (bool) – installed ?

check_latex()[source]#

Check if LaTeX is installed or not.

Returns:

  • (bool) – installed ?

check_qtdraw()[source]#

Check if qtdraw is installed or not.

Returns:

  • (bool) – installed ?

deep_update(d, u)[source]#

Update dict with deepcopy.

Parameters:
  • d (dict) – dict to update (inplace).

  • u (dict) – additional dict.

do_black(w_dir, ext='.py')[source]#

Execute black for Python file.

Parameters:
  • w_dir (str) – directory.

  • ext (str, optional) – extention.

normalize_vector(vec, tol=1e-11)[source]#

Normalize vector (sympy or complex/float).

Parameters:
  • vec (array-like) – list of vectors.

  • tol (float, optional) – absolute norm tolerance for float.

Returns:

  • (ndaray) – normalized vector.

progress_bar_done(length=50, label='')[source]#

Finalize progress bar.

Parameters:
  • length (int, optional) – width.

  • label (str, optional) – prefix.

progress_bar_step(length=50, label='')[source]#

Show progress bar.

Parameters:
  • length (int, optional) – width.

  • label (str, optional) – prefix.

read_dict(filename, r_dir=None)[source]#

Read dict.

Parameters:
  • filename (str) – file name.

  • r_dir (str, optional) – directory to read, if None, cwd is used.

Returns:

  • (dict) – read dict.

read_dict_file(data, topdir=None, verbose=False)[source]#

Read dict file or dict.

Parameters:
  • data (str or dict) – filename or dict.

  • topdir (str, optional) – top directory.

  • verbose (bool, optional) – verbose ?

Returns:

  • (dict) – dict[var, data_dict].

Note

  • if topdir is None, current directory is used.

replace(a, s)[source]#

Replace expression (exchange among variables is ok).

Parameters:
  • a (ndarray) – array.

  • s (dict) – dict for substitution.

Returns:

  • (ndarray) – replaced array.

setup_logging(level=20)[source]#

Setup logging.

Parameters:

level (int, optional) – log level.

str_to_sympy(s, check_var=None, check_shape=None, rational=True, subs=None, **assumptions)[source]#

Convert a string to a sympy.

Parameters:
  • s (str) – a string.

  • check_var (list, optional) – variables to accept, None (all).

  • check_shape (tuple, optional) – shape, (), (n,), (n,m), …

  • rational (bool, optional) – use rational number ?

  • subs (dict, optional) – replace dict for local variables.

  • **assumptions (dict, optional) – common assumptions for all variables.

Returns:

  • (ndarray) – (list of) sympy.

Notes

  • if format error occurs, raise ValueError.

  • if s cannot be converted to a sympy, raise ValueError.

time_stamp()[source]#

Get current time stamp.

Returns:

  • (str) – time stamp.

timer(name=None, verbose=True)[source]#
to_latex(a, style='scalar')[source]#

convert list to latex list.

Parameters:
  • a (array-like) – list of sympy.

  • style (str, optional) – style, “scalar/vector/matrix”.

Returns:

  • (ndarray or str) – (list of) LaTeX string without “$”.

write_dict(dic, filename, var=None, comment='', w_dir=None)[source]#

Write dict.

Parameters:
  • dic (dict) – dict to write.

  • filename (str) – file name.

  • var (str, optional) – dict variable, if None, filename is used.

  • comment (str, optional) – comment.

  • w_dir (str, optional) – directory to write, if None, cwd is used.