plaid.utils.base

Base utilities.

Exceptions

NotAllowedError

Exception for not allowed usage.

ShapeError

Exception for badly shaped tensors.

DeprecatedError

Exception for deprecated methods.

Functions

generate_random_ASCII(→ str)

Generate a random ASCII string of the specified size.

safe_len(obj)

Safely return the length of an object, or 0 if the object has no length.

delegate_methods(to, methods)

Class decorator to forward specific methods from a delegate attribute.

Module Contents

generate_random_ASCII(size: int = 16) str[source]

Generate a random ASCII string of the specified size.

Parameters:

size (int, optional) – The length of the generated string. Defaults to 16.

Returns:

A random ASCII string of the specified size.

Return type:

str

safe_len(obj)[source]

Safely return the length of an object, or 0 if the object has no length.

Parameters:
  • obj (Any) – The object whose length is to be computed.

  • Returns

  • -------

  • int – The length of the object if it defines __len__, otherwise 0.

delegate_methods(to: str, methods: list[str])[source]

Class decorator to forward specific methods from a delegate attribute.

exception NotAllowedError[source]

Bases: Exception

Exception for not allowed usage.

Initialize self. See help(type(self)) for accurate signature.

exception ShapeError[source]

Bases: Exception

Exception for badly shaped tensors.

Initialize self. See help(type(self)) for accurate signature.

exception DeprecatedError[source]

Bases: Exception

Exception for deprecated methods.

Initialize self. See help(type(self)) for accurate signature.