onnx_extended.ext_test_case¶
Various helpers to help develop the package.
ExtTestCase¶
- class onnx_extended.ext_test_case.ExtTestCase(methodName='runTest')[source]¶
- assertAlmostEqual(expected: ndarray, value: ndarray, atol: float = 0, rtol: float = 0)[source]¶
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically compare almost equal.
- assertIns(sub: Tuple[Any, ...], s: str)[source]¶
Checks that one of the substrings in sub is part of s.
- assertNotAlmostEqual(expected: ndarray, value: ndarray, atol: float = 0, rtol: float = 0)[source]¶
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
- capture(fct: Callable) Tuple[Any, str, str] [source]¶
Runs a function and capture standard output and error.
- Parameters:
fct – function to run
- Returns:
result of fct, output, error
- classmethod tearDownClass()[source]¶
Hook method for deconstructing the class fixture after running all tests in the class.
- tryCall(fct: Callable, msg: str | None = None, none_if: str | None = None) Any | None [source]¶
Calls the function, catch any error.
- Parameters:
fct – function to call
msg – error message to display if failing
none_if – returns None if this substring is found in the error message
- Returns:
output of fct
ignore_warnings¶
measure_time¶
- onnx_extended.ext_test_case.measure_time(stmt: str | Callable, context: Dict[str, Any] | None = None, repeat: int = 10, number: int = 50, warmup: int = 1, div_by_number: bool = True, max_time: float | None = None) Dict[str, str | int | float] [source]¶
Measures a statement and returns the results as a dictionary.
- Parameters:
stmt – string or callable
context – variable to know in a dictionary
repeat – average over repeat experiment
number – number of executions in one row
warmup – number of iteration to do before starting the real measurement
div_by_number – divide by the number of executions
max_time – execute the statement until the total goes beyond this time (approximatively), repeat is ignored, div_by_number must be set to True
- Returns:
dictionary
<<<
from pprint import pprint from math import cos from onnx_extended.ext_test_case import measure_time res = measure_time(lambda: cos(0.5)) pprint(res)
>>>
{'average': 1.028000406222418e-07, 'context_size': 64, 'deviation': 3.3144496694490024e-08, 'max_exec': 2.0199993741698563e-07, 'min_exec': 8.999995770864189e-08, 'number': 50, 'repeat': 10, 'ttime': 1.028000406222418e-06, 'warmup_time': 4.3000036384910345e-06}
See Timer.repeat for a better understanding of parameter repeat and number. The function returns a duration corresponding to number times the execution of the main statement.