-
Notifications
You must be signed in to change notification settings - Fork 247
Open
Description
For pyopencl.array.Array I get wrong results for binary operations such as adding if the memory layout differs for both arguments. Say, "A" is a C-contiguous, and "AF" is F-contiguous, then adding A+AF gives unexpected results. See this notebook for an example (tested with PyOpenCL 2022.3.1)
import numpy as np
import pyopencl as cl
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
import pyopencl.array as cla# create simple numpy array 'a'
a = np.zeros((2,2))
a[0,1] = 1
aarray([[0., 1.],
[0., 0.]])
# with different memory layout
af = np.asarray(a, order='F')
afarray([[0., 1.],
[0., 0.]])
a + afarray([[0., 2.],
[0., 0.]])
A = cla.to_device(queue, a)
AF = cla.to_device(queue, af)A, AF(cl.Array([[0., 1.],
[0., 0.]]),
cl.Array([[0., 1.],
[0., 0.]]))
# bug: A + AF gives different result than a + aF
B = A + AF
Bcl.Array([[0., 1.],
[1., 0.]])
Is this intended to work? Looking quickly at the source code, I could not see that the strides are taken into account. It seems that the underlying arrays are added in memory order.
Thanks
Gregor
Metadata
Metadata
Assignees
Labels
No labels