Classes | |
class | Compressed |
Compression and Serialization. More... | |
class | FreeOnException |
Functions | |
def | version (version_str) |
def | find_in_dict (name, mapping, index=None) |
def | unique_list (sequence) |
def | default_value (value, default) |
def | unpack_args (args, num) |
def | is_dimension_dynamic (dim) |
Shapes. More... | |
def | num_dynamic_dimensions (shape) |
def | is_shape_dynamic (shape) |
def | is_valid_shape_override (new_shape, original_shape) |
def | override_dynamic_shape (shape) |
def | shapes_match (shape0, shape1) |
def | volume (obj) |
def | is_empty_shape (shape) |
def | is_compressed (obj) |
def | compress (obj) |
def | decompress (compressed) |
def | pickle_load (path) |
def | pickle_save (path, obj) |
def | send_on_queue (queue, obj) |
def | try_send_on_queue (queue, obj) |
def | receive_on_queue (queue, timeout=None) |
def | try_receive_on_queue (queue, timeout=None) |
def | try_call (func, *args, **kwargs) |
def | insert_suffix (path, suffix) |
File creation. More... | |
def | lazy_write (contents, path, mode="wb") |
def | try_match_shape (arr, shape) |
def | str_from_module_info (module, name=None) |
def | log_module_info (module, name=None, severity=G_LOGGER.VERBOSE) |
def | str_from_layer (prefix, index, name, op, input_info, output_info) |
def | indent_block (block, level=1) |
Variables | |
dictionary | NP_TYPE_FROM_STR = {np.dtype(dtype).name: np.dtype(dtype) for dtype in np.sctypeDict.values()} |
dictionary | STR_FROM_NP_TYPE = {dtype: name for name, dtype in NP_TYPE_FROM_STR.items()} |
int | PIPE_MAX_SEND_BYTES = 1 << 31 |
def polygraphy.util.misc.version | ( | version_str | ) |
def polygraphy.util.misc.find_in_dict | ( | name, | |
mapping, | |||
index = None |
|||
) |
Attempts to partially match keys in a dictionary. Checks for exact matches and substring matches, falling back to index based matching. Args: name (str): The key to search for. mapping (dict): The dictionary to search in. index (int): An index to fall back to if the key could not be found by name. Returns: str: The key found in the dict, or None if it could not be found.
def polygraphy.util.misc.unique_list | ( | sequence | ) |
Creates a list without duplicate elements, preserving order. Args: sequence (Sequence): The sequence to make unique Returns: list: A list containing the same elements as sequence, in the same order, but without duplicates.
def polygraphy.util.misc.default_value | ( | value, | |
default | |||
) |
Returns a specified default value if the provided value is None. Args: value (object): The value. default (object): The default value to use if value is None. Returns: object: Either value, or the default.
def polygraphy.util.misc.unpack_args | ( | args, | |
num | |||
) |
Extracts the specified number of arguments from a tuple, padding with `None` if the tuple length is insufficient. Args: args (Tuple[object]): The tuple of arguments num (int): The number of elements desired. Returns: Tuple[object]: A tuple containing `num` arguments, padded with `None` if `len(args) < num`
def polygraphy.util.misc.is_dimension_dynamic | ( | dim | ) |
Shapes.
def polygraphy.util.misc.num_dynamic_dimensions | ( | shape | ) |
def polygraphy.util.misc.is_shape_dynamic | ( | shape | ) |
def polygraphy.util.misc.is_valid_shape_override | ( | new_shape, | |
original_shape | |||
) |
def polygraphy.util.misc.override_dynamic_shape | ( | shape | ) |
def polygraphy.util.misc.shapes_match | ( | shape0, | |
shape1 | |||
) |
def polygraphy.util.misc.volume | ( | obj | ) |
def polygraphy.util.misc.is_empty_shape | ( | shape | ) |
def polygraphy.util.misc.is_compressed | ( | obj | ) |
def polygraphy.util.misc.compress | ( | obj | ) |
def polygraphy.util.misc.decompress | ( | compressed | ) |
def polygraphy.util.misc.pickle_load | ( | path | ) |
def polygraphy.util.misc.pickle_save | ( | path, | |
obj | |||
) |
def polygraphy.util.misc.send_on_queue | ( | queue, | |
obj | |||
) |
def polygraphy.util.misc.try_send_on_queue | ( | queue, | |
obj | |||
) |
Attempts to send an object over the queue, compressing it if needed. In the event the object cannot be sent, sends `None` instead. Args: queue (queue.Queue): The queue to send the object over. obj (object): The object to send.
def polygraphy.util.misc.receive_on_queue | ( | queue, | |
timeout = None |
|||
) |
def polygraphy.util.misc.try_receive_on_queue | ( | queue, | |
timeout = None |
|||
) |
def polygraphy.util.misc.try_call | ( | func, | |
* | args, | ||
** | kwargs | ||
) |
Attempts to invoke a function with arguments. If `func` is not callable, then returns `func` The second return value of this function indicates whether the argument was a callable.
def polygraphy.util.misc.insert_suffix | ( | path, | |
suffix | |||
) |
File creation.
Inserts the provided suffix into the given path, before any file extensions. Returns: str: The path, with suffix inserted, or None if no path was provided.
def polygraphy.util.misc.lazy_write | ( | contents, | |
path, | |||
mode = "wb" |
|||
) |
Writes a file to the specified path. Args: contents (Callable() -> bytes): Either a bytes-like object that can be written to disk, or a callable which will return such an object. path (str): The path to write to. mode(str): The mode to use when writing. Defaults to "wb". Returns: str: The complete file path, or `None` if nothing was written.
def polygraphy.util.misc.try_match_shape | ( | arr, | |
shape | |||
) |
Attempts to permute or reshape the array so its shape matches the specified shape. This is a no-op if the array is already the correct shape. Args: arr (numpy.ndarray): The array to reshape. shape (Tuple[int]): The shape to use. May contain at most 1 dynamic dimension. Returns: numpy.ndarray: The reshaped array.
def polygraphy.util.misc.str_from_module_info | ( | module, | |
name = None |
|||
) |
def polygraphy.util.misc.log_module_info | ( | module, | |
name = None , |
|||
severity = G_LOGGER.VERBOSE |
|||
) |
def polygraphy.util.misc.str_from_layer | ( | prefix, | |
index, | |||
name, | |||
op, | |||
input_info, | |||
output_info | |||
) |
def polygraphy.util.misc.indent_block | ( | block, | |
level = 1 |
|||
) |
Indents the provided block of text. Args: block (str): The text to indent. level (int): The number of tabs to indent with. Returns: str: The indented block.
dictionary polygraphy.util.misc.NP_TYPE_FROM_STR = {np.dtype(dtype).name: np.dtype(dtype) for dtype in np.sctypeDict.values()} |
dictionary polygraphy.util.misc.STR_FROM_NP_TYPE = {dtype: name for name, dtype in NP_TYPE_FROM_STR.items()} |
int polygraphy.util.misc.PIPE_MAX_SEND_BYTES = 1 << 31 |