Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Feb 7, 2025
1 parent d411d50 commit 82e5726
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/py/flwr/common/record/parametersrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ class Array:
data: bytes
A buffer of bytes containing the data.
Examples
--------
You can create an `Array` object from a NumPy `ndarray`:
>>> import numpy as np
>>>
>>> arr = Array(np.random.randn(3, 3))
Alternatively, you can create an `Array` object by specifying explicit values:
>>> arr = Array(
>>> dtype="float32",
>>> shape=[3, 3],
>>> stype="numpy.ndarray",
>>> data=b"serialized_data...",
>>> )
"""

dtype: str
Expand All @@ -83,7 +100,15 @@ def __init__( # pylint: disable=too-many-arguments, too-many-locals
stype: str | None = None,
data: bytes | None = None,
) -> None:
# Workaround to support multiple initialization signatures.
# This method validates and assigns the correct arguments,
# including keyword arguments such as dtype and shape.
# Supported initialization formats:
# 1. Array(dtype: str, shape: list[int], stype: str, data: bytes)
# 2. Array(ndarray: NDArray)

# Init all arguments
# If more than 4 positional arguments are provided, raise an error.
if len(args) > 4:
_raise_array_init_error()
all_args = [None] * 4
Expand Down

0 comments on commit 82e5726

Please sign in to comment.