utils

This module provides some functions that may be useful in other modules.

class AttrDict[source]

Bases: dict

array_split(data, batch=None)[source]

Split a data array. batch is the number of data in a row.

check_positive_definite(m)[source]

check if matrix m is postive definite

>>> check_positive_definite([[1.0,0.0],[0.0, 0.1]])
True
>>> check_positive_definite([[1.0,0.0],[1.0,-0.1]])
eigvalues:  [-0.1  1. ]
False
deep_iter(base, deep=1)[source]
deep_ordered_iter(base, deep=1)[source]
deep_ordered_range(size, deep=1, start=0)[source]
error_print(x, err=None)[source]

It returns a format string “value +/- error”. The precision is modified according to err

Parameters
  • x – Value

  • err – Error

Returns

String

flatten_dict_data(data, fun=<built-in method format of str object>)[source]

Flatten nested dictionary data into one layer dictionary.

Returns

Dictionary

flatten_np_data(data)
is_complex(x)[source]

If x is of type complex, it returns True.

load_config_file(name)[source]

Load config file such as Resonances.yml.

Parameters

name – File name. Either yml file or json file.

Returns

Dictionary read from the file.

pprint(dicts)[source]

Print dictionary using json format.

print_dic(dic)[source]

Another way to print dictionary.

std_periodic_var(p, mid=0.0, pi=3.141592653589793)[source]

Transform a periodic variable into its range.

>>> std_periodic_var(math.pi)
-3.1415...
>>> std_periodic_var(2*math.pi + 0.01)
0.0...
Parameters
  • p – Value

  • mid – The middle value

  • pi – Half-range

Returns

The transformed value

std_polar(rho, phi)[source]

To standardize a polar variable. By standard form, it means \(\rho>0, -\pi<\phi<\pi\).

Parameters
  • rho – Real number

  • phi – Real number

Returns

rho, phi

time_print(f)[source]

It provides a wrapper to print the time cost on a process.

tuple_table(fit_frac)[source]