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

setting dtype of array in ti.func causes TypeError: Expect TensorType element for Ndarray with element_dim: 1 > 0 #7470

Closed
99991 opened this issue Mar 1, 2023 · 2 comments
Assignees

Comments

@99991
Copy link

99991 commented Mar 1, 2023

Describe the bug

It does not seem to be possible to set the dtype of ti.types.ndarray(dtype=vec3, ndim=1) in the signature of a ti.func to a vector type.

To Reproduce

import taichi as ti
ti.init()

vec3 = ti.types.vector(3, ti.f32)

@ti.func #                         vvvvvvvvvv-------------- Works without this part.
def child_func(a: ti.types.ndarray(dtype=vec3, ndim=1)):
    pass

@ti.kernel
def parent_func(x: ti.types.ndarray(dtype=vec3, ndim=1)):
    child_func(x)

arr = ti.ndarray(vec3, shape=(4))
parent_func(arr)

Log/Screenshots

$ python my_sample_code.py
[Taichi] version 1.4.1, llvm 15.0.4, commit e67c674e, linux, python 3.7.4
[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    parent_func(arr)
  File "/home/myusername/miniconda3/lib/python3.7/site-packages/taichi/lang/kernel_impl.py", line 976, in wrapped
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiCompilationError: 
File "test.py", line 12, in parent_func:
    child_func(x)
File "test.py", line 6, in child_func:
@ti.func
Traceback (most recent call last):
  File "/home/myusername/miniconda3/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer_utils.py", line 25, in __call__
    return method(ctx, node)
  File "/home/myusername/miniconda3/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer.py", line 652, in build_FunctionDef
    data.get_type())
  File "/home/myusername/miniconda3/lib/python3.7/site-packages/taichi/types/ndarray_type.py", line 112, in check_matched
    f"Expect TensorType element for Ndarray with element_dim: {self.dtype.ndim} > 0"
TypeError: Expect TensorType element for Ndarray with element_dim: 1 > 0

Additional comments

  • Scalar types instead of vec3 work, e.g. by replacing vec3 = ti.types.vector(3, ti.f32) with vec3 = ti.f32.
  • Not giving type information at all works, too.
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Mar 1, 2023
@erizmr erizmr moved this from Untriaged to Todo in Taichi Lang Mar 3, 2023
@ailzhang
Copy link
Contributor

ailzhang commented Mar 9, 2023

@99991 I've confirmed that this error exists in v1.4.1 and is fixed in master, would you minding giving nightly a try?

pip install -i https://pypi.taichi.graphics/simple/ taichi-nightly

@99991
Copy link
Author

99991 commented Mar 16, 2023

Works for me.

@99991 99991 closed this as completed Mar 16, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants