-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Implemented MaskedArray.dot #5709
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4522,6 +4522,26 @@ def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): | |
return D.astype(dtype).filled(0).sum(axis=None, out=out) | ||
trace.__doc__ = ndarray.trace.__doc__ | ||
|
||
def dot(self, other, out=None): | ||
am = ~getmaskarray(self) | ||
bm = ~getmaskarray(other) | ||
if out is None: | ||
d = np.dot(filled(self, 0), filled(other, 0)) | ||
m = ~np.dot(am, bm) | ||
if d.ndim == 0: | ||
d = np.asarray(d) | ||
r = d.view(get_masked_subclass(self, other)) | ||
r.__setmask__(m) | ||
return r | ||
d = self.filled(0).dot(other.filled(0), out._data) | ||
if out.mask.shape != d.shape: | ||
out._mask = numpy.empty(d.shape, MaskType) | ||
np.dot(am, bm, out._mask) | ||
np.logical_not(out._mask, out._mask) | ||
return out | ||
dot.__doc__ = ndarray.dot.__doc__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little worried the doc might get out of sync, but I think you've thought about that more than I have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not thought much about this, but what's good for trace above is good for dot. And if doc gets out of sync we will have a bigger problem because that would mean that the code got out of sync as well. What I would like to add, though is a section explaining mask handling. |
||
|
||
|
||
def sum(self, axis=None, dtype=None, out=None): | ||
""" | ||
Return the sum of the array elements over the given axis. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to test if out is a maskedarray (other functions do this):