-
Notifications
You must be signed in to change notification settings - Fork 84
Implementing PUT routine #582
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 30 commits
d4b6d69
4dd090a
fc6ebe7
1d87fd7
15db53e
d01e17c
48d1920
458f1a2
e67d0f3
5b8a301
dd5f0a3
ca965ed
6e05573
a821bf6
9ead87f
24cb096
ba0ec13
41e8406
4814b4c
5f64cad
d5c4414
9a8a3ca
c91042a
5d6c9fa
4ffae77
f8af1de
f5b92d3
c893ee5
9edae62
7f59b15
6a9545f
ed60e72
67aa0ad
88cca6d
92cf417
e489d56
d363758
58cd174
34fc00b
be9f556
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 |
---|---|---|
|
@@ -781,10 +781,16 @@ def _broadcast(self, shape: NdShape) -> Any: | |
|
||
return result | ||
|
||
def _convert_future_to_regionfield(self) -> DeferredArray: | ||
def _convert_future_to_regionfield( | ||
self, change_shape: bool = False | ||
) -> DeferredArray: | ||
if change_shape and self.shape == (): | ||
shape: NdShape = (1,) | ||
else: | ||
shape = self.shape | ||
store = self.context.create_store( | ||
self.dtype, | ||
shape=self.shape, | ||
shape=shape, | ||
optimize_scalar=False, | ||
) | ||
thunk_copy = DeferredArray( | ||
|
@@ -1660,6 +1666,60 @@ def _diag_helper( | |
|
||
task.execute() | ||
|
||
@auto_convert([1, 2]) | ||
def put(self, indices: Any, values: Any) -> None: | ||
|
||
if indices.base.kind == Future or indices.base.transformed: | ||
change_shape = indices.base.kind == Future | ||
indices = indices._convert_future_to_regionfield(change_shape) | ||
if values.base.kind == Future or values.base.transformed: | ||
change_shape = values.base.kind == Future | ||
values = values._convert_future_to_regionfield(change_shape) | ||
|
||
if self.base.kind == Future or self.base.transformed: | ||
manopapad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
change_shape = self.base.kind == Future | ||
self_tmp = self._convert_future_to_regionfield(change_shape) | ||
else: | ||
self_tmp = self | ||
|
||
assert indices.size == values.size | ||
|
||
# first, we create indirect array with PointN type that | ||
# (indices.size,) shape and is used to copy data from values | ||
# to the target ND array (self) | ||
N = self_tmp.ndim | ||
pointN_dtype = self.runtime.get_point_type(N) | ||
indirect = cast( | ||
DeferredArray, | ||
self.runtime.create_empty_thunk( | ||
shape=indices.shape, | ||
dtype=pointN_dtype, | ||
inputs=[indices], | ||
), | ||
) | ||
|
||
shape = self_tmp.shape | ||
task = self.context.create_task(CuNumericOpCode.WRAP) | ||
task.add_output(indirect.base) | ||
task.add_scalar_arg(shape, (ty.int64,)) | ||
task.add_scalar_arg(True, bool) # has_input | ||
task.add_input(indices.base) | ||
task.add_alignment(indices.base, indirect.base) | ||
task.throws_exception(IndexError) | ||
task.execute() | ||
if indirect.base.kind == Future: | ||
indirect = indirect._convert_future_to_regionfield() | ||
|
||
copy = self.context.create_copy() | ||
copy.set_target_indirect_out_of_range(False) | ||
copy.add_input(values.base) | ||
copy.add_target_indirect(indirect.base) | ||
copy.add_output(self_tmp.base) | ||
copy.execute() | ||
|
||
if self_tmp is not self: | ||
self.copy(self_tmp, deep=True) | ||
|
||
# Create an identity array with the ones offset from the diagonal by k | ||
def eye(self, k: int) -> None: | ||
assert self.ndim == 2 # Only 2-D arrays should be here | ||
|
@@ -2877,8 +2937,13 @@ def unary_op( | |
args: Any, | ||
multiout: Optional[Any] = None, | ||
) -> None: | ||
lhs = self.base | ||
rhs = src._broadcast(lhs.shape) | ||
|
||
if self.shape == () and self.size == src.size: | ||
lhs = self._broadcast(src.shape) | ||
rhs = src.base | ||
else: | ||
lhs = self.base | ||
rhs = src._broadcast(lhs.shape) | ||
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 added this logic for the case when 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. Is this still required? I just ran the test suite without this change and everything seems to be working. 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 don't think it is tested. I will add a test 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. Actually, I can't really test it on high level. I will revert the change since we are not using it |
||
|
||
task = self.context.create_auto_task(CuNumericOpCode.UNARY_OP) | ||
task.add_output(lhs) | ||
|
@@ -3334,9 +3399,11 @@ def unpackbits( | |
task.execute() | ||
|
||
@auto_convert([1]) | ||
def _wrap(self, src: Any, new_len: int) -> None: | ||
def _wrap(self, src: DeferredArray, new_len: int) -> None: | ||
src = self.runtime.to_deferred_array(src) | ||
manopapad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if src.base.kind == Future or src.base.transformed: | ||
src = src._convert_future_to_regionfield() | ||
change_shape = src.base.kind == Future | ||
src = src._convert_future_to_regionfield(change_shape) | ||
|
||
# first, we create indirect array with PointN type that | ||
# (len,) shape and is used to copy data from original array | ||
|
@@ -3355,6 +3422,7 @@ def _wrap(self, src: Any, new_len: int) -> None: | |
task = self.context.create_task(CuNumericOpCode.WRAP) | ||
task.add_output(indirect.base) | ||
task.add_scalar_arg(src.shape, (ty.int64,)) | ||
task.add_scalar_arg(False, bool) # has_input | ||
task.execute() | ||
|
||
copy = self.context.create_copy() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,5 +43,6 @@ Inserting data into arrays | |
:toctree: generated/ | ||
|
||
fill_diagonal | ||
put | ||
put_along_axis | ||
place |
Uh oh!
There was an error while loading. Please reload this page.