Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions docarray/array/mixins/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ def apply(self: 'T', *args, **kwargs) -> 'T':
# noqa: DAR201
:return: a new :class:`DocumentArray`
"""
from ... import DocumentArray

new_da = DocumentArray(self.map(*args, **kwargs))
self.clear()
self.extend(new_da)
for doc in self.map(*args, **kwargs):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use batch_map would be efficient for some backends?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, interesting thought, that could be true. especially when the afterward da[d.id] = d is IO bounded https://docarray.jina.ai/fundamentals/documentarray/parallelization/#use-map-batch-to-overlap-cpu-and-network-time

@alaeddine-13 you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it's better to use it for apply_batch not apply.
I have applied the same logic for apply_batch, can you check ?

self[doc.id] = doc
return self

def map(
Expand Down Expand Up @@ -157,13 +154,8 @@ def apply_batch(self: 'T', *args, **kwargs) -> 'T':
# noqa: DAR201
:return: a new :class:`DocumentArray`
"""
from ... import DocumentArray

new_da = DocumentArray()
for _b in self.map_batch(*args, **kwargs):
new_da.extend(_b)
self.clear()
self.extend(new_da)
self[[doc.id for doc in _b]] = _b
return self

def map_batch(
Expand Down