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

Make NDict (hopefully) lighter to import #342

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions fuse/utils/ndict.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import copy
import types
import numpy
import torch
from numpy import ndarray
from torch import Tensor
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -273,7 +273,7 @@ def pop(self, key: str) -> Any:
del self[key]
return res

def indices(self, indices: numpy.ndarray) -> dict:
def indices(self, indices: ndarray) -> dict:
"""
Extract the specified indices from each element in the dictionary (if possible)

Expand All @@ -286,7 +286,7 @@ def indices(self, indices: numpy.ndarray) -> dict:
for key in all_keys:
try:
value = self[key]
if isinstance(value, (numpy.ndarray, torch.Tensor)):
if isinstance(value, (ndarray, Tensor)):
new_value = value[indices]
elif isinstance(value, Sequence):
new_value = [item for i, item in enumerate(value) if indices[i]]
Expand Down
Loading