Skip to content

Attributing and assigning to a ndarray #8492

@fccoelho

Description

@fccoelho

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion on using Taichi

    Type

    No type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions