-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Documentation
Copy link
Description
Issue Description
The autodiff documentation references a Tensor constructor API that does not exist in the current SlangPy implementation.
Documentation Reference
Source:
slangpy/docs/src/autodiff/autodiff.rst
Line 29 in 147a6f1
| x = spy.Tensor.numpy(device, np.array([1, 2, 3, 4], dtype=np.float32)).with_grads() |
The documentation shows:
result = spy.Tensor(device, element_type=module.float, shape=(4,))
module.polynomial(a=2, b=8, c=-1, x=x, _result=result)Actual API
The actual Tensor.__init__ signature is:
(self, storage: 'Buffer', dtype: 'SlangType', shape: 'TShapeOrTuple', strides: 'Optional[TShapeOrTuple]' = None, offset: 'int' = 0, grad_in: 'Optional[Tensor]' = None, grad_out: 'Optional[Tensor]' = None)Issues:
- No
element_typeparameter exists - it should bedtype - Constructor requires
storageas first parameter, notdevice - The constructor is low-level and not intended for typical usage
Correct Approach
Users should use factory methods instead:
# Correct way to pre-allocate a tensor
result = spy.Tensor.empty(device, shape=(4,), dtype=module.float)
module.polynomial(a=2, b=8, c=-1, x=x, _result=result)Or use the string-based approach:
result: spy.Tensor = module.polynomial(a=2, b=8, c=-1, x=x, _result="tensor")Related Discussion
Discord thread: https://discord.com/channels/1303735196696445038/1305995870046650368/1422744660593344643
Suggested Fix
Update the documentation to show one of these correct patterns:
spy.Tensor.empty(device, shape=..., dtype=...)spy.Tensor.zeros(device, shape=..., dtype=...)- Or keep using the
_result="tensor"string approach which works fine
Environment
- Checked against current SlangPy installation
- All factory methods (
empty,zeros,from_numpy) consistently usedtype, notelement_type