Skip to content

Commit 631d938

Browse files
Make if_positive keep strides of then_ if known. (#523)
* Make if_positive keep strides of then_ if known. The previous version of `if_positive` always returns a C-ordered array even if `then_` is not C-ordered. This breaks artificial viscosity in Mirgecom when an array context uses a Fortran style data layout. This change makes the output have the same strides as `then_` if the shape of `then_` is known, otherwise it defaults to use the same layout as `criterion`. * Increment version * Resolve Flake8 failures * Use more idiomatic != in shape comparison Co-authored-by: Andreas Klöckner <[email protected]>
1 parent 796c704 commit 631d938

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pyopencl/array.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,9 +2863,19 @@ def if_positive(criterion, then_, else_, out=None, queue=None):
28632863
raise AssertionError()
28642864

28652865
if out is None:
2866-
out = empty(
2867-
criterion.queue, criterion.shape, then_.dtype,
2868-
allocator=criterion.allocator)
2866+
2867+
if then_.shape != ():
2868+
out = empty_like(
2869+
then_, criterion.queue, allocator=criterion.allocator)
2870+
else:
2871+
# Use same strides as criterion
2872+
cr_byte_strides = np.array(criterion.strides, dtype=np.int64)
2873+
cr_item_strides = cr_byte_strides // criterion.dtype.itemsize
2874+
out_strides = tuple(cr_item_strides*then_.dtype.itemsize)
2875+
2876+
out = Array(criterion.queue, criterion.shape, then_.dtype,
2877+
allocator=criterion.allocator,
2878+
strides=out_strides)
28692879

28702880
event1 = _if_positive(out, criterion, then_, else_, queue=queue)
28712881
out.add_event(event1)

pyopencl/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (2021, 2, 9)
1+
VERSION = (2021, 2, 10)
22
VERSION_STATUS = ""
33
VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS

0 commit comments

Comments
 (0)