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,
)
#...
#....
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
Log/Screenshots
Additional comments A simple fix seems to set the offset to None in the
field
classmethod of Struct :