Skip to content

Commit

Permalink
Merge branch 'main' into brent/ruff_output_format
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi authored Jan 19, 2024
2 parents b587e54 + 99073eb commit b71cc69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nerfstudio/utils/tensor_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def _broadcast_dict_fields(self, dict_: Dict, batch_shape) -> Dict:
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:
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/test_tensor_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b71cc69

Please sign in to comment.