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

Attributing and assigning to a ndarray #8492

Open
fccoelho opened this issue Mar 19, 2024 · 2 comments
Open

Attributing and assigning to a ndarray #8492

fccoelho opened this issue Mar 19, 2024 · 2 comments
Labels
question Question on using Taichi

Comments

@fccoelho
Copy link

Here is the problematic code:

import numpy as np
import taichi as ti
import copy

ti.init(arch=ti.cpu,default_ip=ti.i32, default_fp=ti.f32)

@ti.data_oriented
class Test:
    def __init__(self, ini):
        self.ini = ti.ndarray(shape=(10,), dtype=ti.i32)
        self.ini.from_numpy(ini)

    @ti.kernel
    def run(self):
        ini = self.ini
        print(ini)

if __name__ == '__main__':
    ini = np.arange(10)
    test = Test(ini)
    test.run()
    print(test.ini.to_numpy())

In it, I am simply trying to create a copy of self.ini in side a kernel function.

I get the following stack trace:

Invalid constant scalar data type: <class 'taichi.lang._ndarray.ScalarNdarray'>

If instead I try to attribute to the ndarray within the kernel function,

self.ini[5] = 100

I get the following error:

AssertionError: __getitem__ cannot be called in Taichi-scope

What am I doing wrong?

@fccoelho fccoelho added the question Question on using Taichi label Mar 19, 2024
@bobcao3
Copy link
Collaborator

bobcao3 commented Mar 19, 2024

Ndarrays can not be captured through self / data oriented at this moment

@fccoelho
Copy link
Author

Yes, I managed to work around this by using ti.field defining my "temp" variable in the constructor and filling it with the values of self.ini in a for loop in my kernel function (aargh).

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

No branches or pull requests

2 participants