Skip to content
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

[bug] c+=123 will not modify linked array but c[:]+=123 will #40

Open
3togo opened this issue Aug 25, 2022 · 3 comments
Open

[bug] c+=123 will not modify linked array but c[:]+=123 will #40

3togo opened this issue Aug 25, 2022 · 3 comments

Comments

@3togo
Copy link

3togo commented Aug 25, 2022

assume arrayfire array a is linked to asnumpy array b
and c = b.d_array

b*=2 will modify c
c+=123 will not modify b
but
c[:] += 123 will modify b

for details, you could refer to the code below.

import arrayfire as af
import afnumpy as afn

def ndarray_(s):
return afn.ndarray(s.shape, dtype=afn.pu.typemap(s.dtype()), af_array=s)

a = af.range(10) + 99
#b = afn.array(a) # a is copied to b
b = ndarray_(a) # a is linked to b
c = b.d_array
c[0] = af.log(c[0])
print(a)
print(b) # b is linked to c
print(c)
b *= 2
print(a)
print(b) # b is linked to c
print(c)
c[:] += 123
print(a)
print(b) # b is linked to c
print(c)
c += 123
print(a)
print(b) # b is linked to c
print(c)

@FilipeMaia
Copy link
Owner

Why do you consider this a bug?
You are modifying arrayfire-python arrays, and they do not follow numpy syntax.

If they were afnumpy arrays then I could understand your expectation.

@3togo
Copy link
Author

3togo commented Aug 26, 2022

b *= 2 ==> modifying through the pointer
b +=2 ==> not modifying through the pointer
not consistent

@FilipeMaia
Copy link
Owner

Where do you do b += 2?
You do c += 123. That's modifying an arrayfire array, which is not an afnumpy array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants