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

bug: fixed StackedDistributedArray.norm to work with cupy arrays #119

Merged
merged 1 commit into from
Nov 26, 2024
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
15 changes: 8 additions & 7 deletions pylops_mpi/DistributedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,21 +818,22 @@ def norm(self, ord: Optional[int] = None):
ord : :obj:`int`, optional
Order of the norm.
"""
norms = np.array([distarray.norm(ord) for distarray in self.distarrays])
ncp = get_module(self.distarrays[0].engine)
norms = ncp.array([distarray.norm(ord) for distarray in self.distarrays])
ord = 2 if ord is None else ord
if ord in ['fro', 'nuc']:
raise ValueError(f"norm-{ord} not possible for vectors")
elif ord == 0:
# Count non-zero then sum reduction
norm = np.sum(norms)
elif ord == np.inf:
norm = ncp.sum(norms)
elif ord == ncp.inf:
# Calculate max followed by max reduction
norm = np.max(norms)
elif ord == -np.inf:
norm = ncp.max(norms)
elif ord == -ncp.inf:
# Calculate min followed by max reduction
norm = np.min(norms)
norm = ncp.min(norms)
else:
norm = np.power(np.sum(np.power(norms, ord)), 1. / ord)
norm = ncp.power(ncp.sum(ncp.power(norms, ord)), 1. / ord)
return norm

def conj(self):
Expand Down
Loading