onebone.utils
onebone.utils.slicing
- onebone.utils.slicing.slice_along_axis(arr: ndarray, s: slice, axis: int) ndarray
Slice the values of the array within a certain range on the axis.
- Parameters
arr (numpy.ndarray) – Input array.
s (slice) – Range on the axis.
axis (int) – Axis
- Returns
arr_out (numpy.ndarray) – Sliced input array.
onebone.utils.timer
Timer function.
Author: Kangwhi Kim
Contact: kangwhi.kim@onepredict.com
- class onebone.utils.timer.Timer(logger: Optional[Logger] = None)
Bases:
object
Check the elapsed time of the function.
Note
Use it as a function decorator.
- Parameters
logger (logging.Logger, default=None) – A logger.
- Returns
wrapper (function) – Wrapper function. When logger is not None, the debug level message is delivered to the logger within the wrapper function. But, when logger is None, the message is delivered to the print function.
Examples
>>> import logging >>> import time >>> from onebone.utils import Timer
Create a logger.
>>> logger = logging.getLogger(__name__) >>> logger.setLevel(logging.DEBUG) >>> stream_handler = logging.StreamHandler() >>> logger.addHandler(stream_handler)
Add the Timer Decorator to the function.
>>> @Timer(logger) >>> def timer_test(): start = time.time() time.sleep(1) duration = time.time() - start return duration
Run the function.
>>> timer_test()