gdpc.utils¶
Various generic utilities.
- clamp(x: ComparableT, minimum: ComparableT, maximum: ComparableT) ComparableT¶
Clamps
xto the range [minimum,maximum]
-
normalized(a: ndarray[tuple[int, ...], dtype[Any]], order: int =
2, axis: int =-1)¶ Normalizes
ausing the L<order> norm.If
axisis specified, normalizes along that axis.
- withRetries(function: ~typing.Callable[[], ~gdpc.utils.T], exceptionType: ~typing.Type[Exception] = <class 'Exception'>, retries: int = 1, onRetry: ~typing.Callable[[Exception, int], None] = <function <lambda>>, reRaise: bool = True) T | None¶
Retries
functionup toretriestimes if an exception occurs.Before retrying, calls
onRetry(<last exception>, <remaining retries>). The default callback sleeps for one second.If the retries have ran out and
reRaiseisTrue, the last exception is re-raised.
- class OrderedByLookupDict¶
Dict ordered from least to most recently looked-up key
Unless
maxSizeis 0, the dict size is limited tomaxSizeby evicting the least recently looked-up key when full.- __getitem__(key: KT) VT¶
Return self[key].
- __setitem__(key: KT, value: VT)¶
Set self[key] to value.
-
__orig_bases__ =
(typing.OrderedDict[~KT, ~VT], typing.Generic[~KT, ~VT])¶
-
visualizeMaps(*arrays: ndarray[tuple[int, ...], dtype[Any]], title: str =
'', normalize: bool =True) None¶ Deprecated
This function is deprecated and will be removed in a future version of GDPC.
It was only used by the now-removed
visualize_map.pyexample, and its removal will allow us to remove the OpenCV dependency.Visualizes one or multiple 2D numpy arrays.
-
rotateSequence(sequence: Sequence[T], n: int =
1) Generator[T, None, None]¶ Rotates a sequence of elements by n positions.
- Args:
sequence (Sequence): The sequence of elements to rotate. n (int, optional): The number of positions to rotate the sequence by. Defaults to 1.
- Yields:
Generator[Any, Any, None]: The rotated sequence of elements.