-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix in vectorized item assignment #1746
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
9eafe36
2aff4ce
22c1295
dc135cd
b1dd0f0
c74c828
8e6e2e0
aef3d56
f10ecf4
d482f80
c2b5ac3
84e5e6f
2011140
6906eeb
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 |
---|---|---|
|
@@ -637,17 +637,22 @@ def __setitem__(self, key, value): | |
""" | ||
dims, index_tuple, new_order = self._broadcast_indexes(key) | ||
|
||
if isinstance(value, Variable): | ||
value = value.set_dims(dims).data | ||
|
||
if new_order: | ||
value = duck_array_ops.asarray(value) | ||
if not isinstance(value, Variable): | ||
value = as_compatible_data(value) | ||
if value.ndim > len(dims): | ||
raise ValueError( | ||
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. Do we still need this special case error message now that we call set_dims below? 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 think |
||
'shape mismatch: value array of shape %s could not be' | ||
'broadcast to indexing result with %s dimensions' | ||
% (value.shape, len(dims))) | ||
if value.ndim == 0: | ||
value = Variable((), value) | ||
else: | ||
value = Variable(dims[-value.ndim:], value) | ||
# broadcast to become assignable | ||
value = value.set_dims(dims).data | ||
|
||
if new_order: | ||
value = duck_array_ops.asarray(value) | ||
value = value[(len(dims) - value.ndim) * (np.newaxis,) + | ||
(Ellipsis,)] | ||
value = np.moveaxis(value, new_order, range(len(new_order))) | ||
|
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.
Do we need to check that coordinates are consistent on the
key
?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.
This is done a few lines above,
obj = self[key]
, where in.isel
we check the coordinates in thekey
.But I am wondering this unnecessary indexing, though I think this implementation is the simplest.
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.
Hmm. This could indeed be a significant performance hit. That said, I'm OK leaving this for now, with a TODO note to optimize it later.