Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF-#6645: avoid label synchronization for dot operation #6644

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from 1 commit
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
35 changes: 26 additions & 9 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2231,14 +2231,6 @@ def dot(self, other, squeeze_self=None, squeeze_other=None):
else other.to_pandas()
)

def map_func(df, other=other, squeeze_self=squeeze_self): # pragma: no cover
"""Compute matrix multiplication of the passed frames."""
result = df.squeeze(axis=1).dot(other) if squeeze_self else df.dot(other)
if is_list_like(result):
return pandas.DataFrame(result)
else:
return pandas.DataFrame([result])

num_cols = other.shape[1] if len(other.shape) > 1 else 1
if len(self.columns) == 1:
new_index = (
Expand All @@ -2255,8 +2247,33 @@ def map_func(df, other=other, squeeze_self=squeeze_self): # pragma: no cover
new_columns = [MODIN_UNNAMED_SERIES_LABEL] if num_cols == 1 else None
axis = 1

align_index = isinstance(new_index, list) and new_index == [
anmyachev marked this conversation as resolved.
Show resolved Hide resolved
MODIN_UNNAMED_SERIES_LABEL
]
align_columns = new_columns == [MODIN_UNNAMED_SERIES_LABEL]

def map_func(df, other=other, squeeze_self=squeeze_self): # pragma: no cover
"""Compute matrix multiplication of the passed frames."""
result = df.squeeze(axis=1).dot(other) if squeeze_self else df.dot(other)

if is_list_like(result):
res = pandas.DataFrame(result)
else:
res = pandas.DataFrame([result])

# manual aligning with external index to avoid `sync_labels` overhead
if align_columns:
res.columns = [MODIN_UNNAMED_SERIES_LABEL]
if align_index:
res.index = [MODIN_UNNAMED_SERIES_LABEL]
return res

new_modin_frame = self._modin_frame.apply_full_axis(
axis, map_func, new_index=new_index, new_columns=new_columns
axis,
map_func,
new_index=new_index,
new_columns=new_columns,
sync_labels=False,
)
return self.__constructor__(new_modin_frame)

Expand Down
Loading