tools¶
Benchmark¶
- onnx_array_api.ext_test_case.measure_time(stmt: Callable, context: Dict[str, Any] | None = None, repeat: int = 10, number: int = 50, div_by_number: bool = True, max_time: float | None = None) Dict[str, Any] [source]¶
Measures a statement and returns the results as a dictionary.
- Parameters:
stmt – string
context – variable to know in a dictionary
repeat – average over repeat experiment
number – number of executions in one row
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 onnx_array_api.ext_test_case import measure_time from math import cos res = measure_time(lambda: cos(0.5)) print(res)
>>>
{'average': np.float64(5.598762014415114e-06), 'deviation': np.float64(1.608986877207604e-05), 'min_exec': np.float64(2.292401040904224e-07), 'max_exec': np.float64(5.386835997342132e-05), 'repeat': 10, 'number': 50, 'ttime': np.float64(5.5987620144151144e-05), 'context_size': 64}
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.
Changed in version 0.4: Parameter max_time was added.
Manipulations¶
- onnx_array_api.tools.replace_constants.replace_initializer_by_constant_of_shape(onx, threshold=128, op_type='ConstantOfShape', domain='')[source]¶
Replaces initializers by nodes ConstantOfShape to reduce the size and still write a unit test.
- Parameters:
onx – ModelProto
threshold – every initializer under this threshold is not impacted
op_type – replace by this node
domain – replace by this domain
- Returns:
onx, modified ModelProto
Examples¶
Unit tests¶
- onnx_array_api.ext_test_case.ignore_warnings(warns: List[Warning]) Callable [source]¶
Catches warnings.
- Parameters:
warns – warnings to ignore
- class onnx_array_api.ext_test_case.ExtTestCase(methodName='runTest')[source]¶
- capture(fct: Callable)[source]¶
Runs a function and capture standard output and error.
- Parameters:
fct – function to run
- Returns:
result of fct, output, error