Skip to content

Commit

Permalink
Improve efficiency of special data unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjarrett committed Jul 8, 2024
1 parent 33b9937 commit d76eea3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions armi/bookkeeping/db/jaggedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,19 @@ def unpack(self):
List of numpy arrays with varying dimensions (i.e., jagged arrays)
"""
unpackedJaggedData: List[Optional[np.ndarray]] = []
for offset, shape in zip(self.offsets, self.shapes):
unpackedJaggedData.append(
np.ndarray(shape, dtype=self.dtype, buffer=self.flattenedArray[offset:])
)

for i in self.nones:
unpackedJaggedData.insert(i, None)
numElements = len(self.offsets) + len(self.nones)
j = 0 # non-None element counter
for i in range(numElements):
if i in self.nones:
unpackedJaggedData.append(None)
else:
unpackedJaggedData.append(
np.ndarray(
self.shapes[j],
dtype=self.dtype,
buffer=self.flattenedArray[self.offsets[j] :],
)
)
j += 1

return unpackedJaggedData

0 comments on commit d76eea3

Please sign in to comment.