Skip to content

Commit 583e0aa

Browse files
committed
ENH: Make ValueIndices.to_list much more efficient
1 parent 4ba6a73 commit 583e0aa

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

nibabel/metasum.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,15 @@ def get_value(self, idx):
165165

166166
def to_list(self):
167167
'''Convert back to a list of values'''
168-
return [self.get_value(i) for i in range(self.n_input)]
168+
if self._const_val is not _NoValue:
169+
return [self._const_val] * self._n_input
170+
res = [_NoValue] * self._n_input
171+
for val, idx in self._unique_vals.items():
172+
res[idx] = val
173+
for val, ba in self._val_bitarrs.items():
174+
for idx in self._extract_indices(ba):
175+
res[idx] = val
176+
return res
169177

170178
def extend(self, values):
171179
'''Add more values to the end of any existing ones'''

0 commit comments

Comments
 (0)