mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-10 18:17:31 +08:00
Don't throw away non-tensor objects in TensorDataclass (#2783)
* Don't throw away non-tensor objects in TensorDataclass * Update test_tensor_dataclass.py --------- Co-authored-by: Justin Kerr <justin.g.kerr@gmail.com>
This commit is contained in:
parent
f55bd04ca6
commit
99073eb187
@ -141,6 +141,8 @@ class TensorDataclass:
|
||||
new_dict[k] = v.broadcast_to(batch_shape)
|
||||
elif isinstance(v, Dict):
|
||||
new_dict[k] = self._broadcast_dict_fields(v, batch_shape)
|
||||
else:
|
||||
new_dict[k] = v
|
||||
return new_dict
|
||||
|
||||
def __getitem__(self: TensorDataclassT, indices) -> TensorDataclassT:
|
||||
|
||||
@ -179,6 +179,12 @@ def test_iter():
|
||||
assert batch.b.shape == (4, 5)
|
||||
|
||||
|
||||
def test_non_tensor():
|
||||
"""Test iterating over tensor dataclass"""
|
||||
# We shouldn't throw away non-dataclass values.
|
||||
assert DummyTensorDataclass(a=torch.ones((3, 10)), b={"k": 2}, c=None).b == {"k": 2} # type: ignore
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_init()
|
||||
test_broadcasting()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user