Skip to content
Merged
Prev Previous commit
Next Next commit
small cleanup
  • Loading branch information
tristan-deep authored and wesselvannierop committed Nov 10, 2026
commit 97e6228b8264a3a18e80e7f6830aaf160d389636
18 changes: 6 additions & 12 deletions zea/func/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,12 @@ def simple_map(function, elements):
if keras.backend.backend() == "numpy":

def vectorized_map(function, elements):
"""Fixes keras.ops.vectorized_map in numpy backend with multiple outputs."""
if not isinstance(elements, (list, tuple)):
return np.stack([function(x) for x in elements])
else:
batch_size = elements[0].shape[0]
output_store = []
for index in range(batch_size):
output_store.append(function([x[index] for x in elements]))
if isinstance(output_store[0], (list, tuple)):
return [np.stack(tensors) for tensors in zip(*output_store)]
else:
return np.stack(output_store)
"""Fixes keras.ops.vectorized_map in numpy backend with multiple outputs.

Only used by `_map`, which passes and returns a tuple of tensors.
"""
outputs = [function([x[i] for x in elements]) for i in range(elements[0].shape[0])]
return [np.stack(tensors) for tensors in zip(*outputs)]
else:
vectorized_map = ops.vectorized_map

Expand Down
5 changes: 2 additions & 3 deletions zea/ops/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def __init__(
operations: List[Operation],
argnames: List[str] | str,
in_axes: List[Union[int, None]] | int = 0,
out_axes: List[Union[int, None]] | int = 0,
out_axes: int = 0,
chunks: int | None = None,
batch_size: int | None = None,
**kwargs,
Expand All @@ -1108,8 +1108,7 @@ def __init__(
Can also be a single string if only one argument is mapped over.
in_axes (int or list): Axes to map over for each argument.
If a single int is provided, it is used for all arguments.
out_axes (int or list): Axes to map over for each output.
If a single int is provided, it is used for all outputs.
out_axes (int): Axis of the output to map over.
chunks (int, optional): Number of chunks to split the input data into.
If None, no chunking is performed. Mutually exclusive with ``batch_size``.
batch_size (int, optional): Size of batches to process at once.
Expand Down