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

Struct field with offset crashes #8554

Open
VirgileUniv opened this issue Jun 28, 2024 · 0 comments
Open

Struct field with offset crashes #8554

VirgileUniv opened this issue Jun 28, 2024 · 0 comments

Comments

@VirgileUniv
Copy link

Describe the bug
when instaciating a taichi.Struct.field with shape and offset, taichi raise an exception error "shape cannot be None when offset is set"

To Reproduce

import taichi as ti
ti.init()

struct_field = ti.Struct.field(
    {"a": float}, 
    shape=(5,), 
    offset=(-1,)
)

Log/Screenshots

$ python .\sanboxxx.py
[Taichi] version 1.7.1, llvm 15.0.1, commit 0f143b2f, win, python 3.10.9
[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\sanboxxx.py", line 4, in <module>
    struct_field = ti.Struct.field(
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\util.py", line 334, in wrapped
    return func(*args, **kwargs)
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\struct.py", line 305, in field
    field_dict[key] = impl.field(
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\util.py", line 334, in wrapped
    return func(*args, **kwargs)
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\impl.py", line 814, in field
    return _field(dtype, *args, **kwargs)
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\util.py", line 334, in wrapped
    return func(*args, **kwargs)
  File "C:\Users\MEEEE\Documents\M2_stage\internship-virgile-taichi\env\lib\site-packages\taichi\lang\impl.py", line 733, in _field
    raise TaichiSyntaxError("shape cannot be None when offset is set")
taichi.lang.exception.TaichiSyntaxError: shape cannot be None when offset is set

Additional comments
A simple fix seems to set the offset to None in the field classmethod of Struct :

class Struct:
    #...
    def field(
        #...
    ):
        #...
        for key, dtype in members.items():
            #...
            field_dict[key] = dtype.field(
                shape=None,
                name=field_name,
                offset=offset, ## <-- offset=None seems to make it work
                needs_grad=needs_grad,
                needs_dual=needs_dual,
            )
            #...
        #....
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