nvflare.app_common.decomposers.numpy_decomposers module¶
Decomposers for types from app_common and Machine Learning libraries.
- class Float32ScalarDecomposer[source]¶
Bases:
NumpyScalarDecomposer
- class Float64ScalarDecomposer[source]¶
Bases:
NumpyScalarDecomposer
- class Int32ScalarDecomposer[source]¶
Bases:
NumpyScalarDecomposer
- class Int64ScalarDecomposer[source]¶
Bases:
NumpyScalarDecomposer
- class NumpyArrayDecomposer[source]¶
Bases:
ViaFileDecomposer- dump_to_file(items: dict, path: str, fobs_ctx: dict)[source]¶
Dump the items to the file with the specified path
- Parameters:
items – a dict of items of target object type to be dumped to file
path – the path to the file.
fobs_ctx – FOBS Context
Returns: a tuple of (file name, meta info)
The “path” is a temporary file name. You should create the file with the specified name. However, some frameworks (e.g. numpy) may add a special suffix to the name. In this case, you must return the modified name.
The “items” is a dict of target objects. The dict contains all objects of the target type in one payload. The dict could be very big. You must create a file to contain all the objects.
- get_bytes_dot() int[source]¶
Get the Datum Object Type to be used for bytes datum
Returns: the DOT for bytes datum
- get_file_dot() int[source]¶
Get the Datum Object Type to be used for file ref datum
Returns: the DOT for file ref datum
- load_from_file(path: str, fobs_ctx: dict, meta: dict | None = None) Any[source]¶
Load target object items from the specified file
- Parameters:
path – the absolute path to the file to be loaded.
fobs_ctx – FOBS Context.
meta – meta info of the file.
Returns: a dict of target objects.
You must not delete the file after loading. Management of the file is done by the ViaFile class.
- native_decompose(target: ndarray, manager: DatumManager | None = None) bytes[source]¶
- native_recompose(data: bytes, manager: DatumManager | None = None) ndarray[source]¶
- class NumpyScalarDecomposer[source]¶
Bases:
Decomposer,ABCDecomposer base class for all numpy types with item method.
- decompose(target: Any, manager: DatumManager | None = None) Any[source]¶
Decompose the target into types supported by msgpack or classes with decomposers registered.
Msgpack supports primitives, bytes, memoryview, lists, dicts.
- Parameters:
target – The instance to be serialized
manager – Datum manager to store externalized datum
- Returns:
The decomposed serializable objects
- recompose(data: Any, manager: DatumManager | None = None) ndarray[source]¶
Reconstruct the object from decomposed components.
- Parameters:
data – The decomposed component
manager – Datum manager to internalize datum
- Returns:
The reconstructed object