Utils#

Collection of util functions.

enum DocEnum(value)[source]#

Enumeration with documentation of its members. Taken directly from stack overflow.

gini_coefficient(values: Iterable[int | float | mpq]) int | float | mpq[source]#

Returns the Gini coefficient of the vector of values given as argument.

Parameters:

values (Iterable[Numeric]) – A vector of values.

Returns:

The Gini coefficient.

Return type:

Numeric

mean_generator(generator: Iterable[int | float | mpq] | Iterable[tuple[int | float | mpq, int]]) int | float | mpq[source]#

Computes the mean of a sequence of numbers given as a generator. If the generator contains tuples, the first element is assumed to be the value and the second its multiplicity.

Parameters:

generator (Iterable[Numeric] | Iterable[tuple[Numeric, int]) – The generator.

Returns:

The mean of the values.

Return type:

Numeric

powerset(iterable: Iterable) Generator[source]#

Returns a generator of all the subsets of a given iterable.

Parameters:

iterable (Iterable) – An iterable.

Returns:

A generator of all the subsets of the iterable.

Return type:

Generator

round_cmp(a: int | float | mpq, b: int | float | mpq, precision: int = 6) int[source]#

Compares two numbers after rounding them to a specified precision.

Parameters:
  • a (Numeric) – The first number for comparison.

  • b (Numeric) – The second number for comparison.

  • precision (int, optional) – The number of decimal places to which the numbers should be rounded. Defaults to 6.

Returns:

A negative number if the rounded value of ‘a’ is less than the rounded value of ‘b’, 0 if they are approximately equal after rounding, a positive number if the rounded value of ‘a’ is greater than the rounded value of ‘b’.

Return type:

int

Numeric#

Type for numeric values. Is the union of int, float and mpq fractions (from the gumpy2 package).

alias of int | float | mpq