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

Taichi ndarray element assignment not working #8560

Open
agravier opened this issue Jul 10, 2024 · 0 comments
Open

Taichi ndarray element assignment not working #8560

agravier opened this issue Jul 10, 2024 · 0 comments

Comments

@agravier
Copy link

Describe the bug
When I assign a scalar to an ndarray, it sometimes doesn't work!

To Reproduce

import taichi as ti

ti.init(arch=ti.gpu)

g = ti.ndarray(ti.int8, shape=(11, 5))
g.fill(1)
g[1, 2] = 2
assert g[1, 2] == 2

Log/Screenshots

$ python tests/ndarray_weird_behaviour.py
[Taichi] version 1.7.1, llvm 15.0.7, commit 0f143b2f, osx, python 3.10.9
[Taichi] Starting on arch=metal
Traceback (most recent call last):
  File "/Users/agravier/projects/perso/arc/archi/tests/ndarray_weird_behaviour.py", line 9, in <module>
    assert g[1, 2] == 2
AssertionError

Additional comments

In a more complex program, the behaviour is affected by other operations. For instance, this works:

from itertools import product
import taichi as ti

ti.init(arch=ti.gpu)

g = ti.ndarray(ti.int8, shape=(11, 5))
g.fill(1)
for i, j in product(range(11), range(5)):
    g[i, j] = i*j+1

print(g.to_numpy())

assert g[1, 2] == 3

Moreover, this one works too (!):

import taichi as ti

ti.init(arch=ti.gpu)

g = ti.ndarray(ti.int8, shape=(11, 5))
g.fill(1)
g[1, 2] = 2
g[1, 2] = 2
assert g[1, 2] == 2

I suspect that it's sometimes the first assignment that fails.

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

No branches or pull requests

1 participant