Skip to content

Commit

Permalink
fix performance issue with slow listcomp on regrid indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
grantbuster committed Jun 5, 2024
1 parent 54b7176 commit 5b765eb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sup3r/utilities/regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ def __call__(self, data):
data = data.reshape((data.shape[0] * data.shape[1], -1))
msg = 'Input data must be 2D (spatial, temporal)'
assert len(data.shape) == 2, msg
vals = [
data[np.array(self.indices), i][np.newaxis]
for i in range(data.shape[-1])
]
vals = np.concatenate(vals, axis=0)
return np.einsum('ijk,jk->ij', vals, self.weights).T

vals = data[np.array(self.indices), :] # index to (space, 4, time)
vals = np.transpose(vals, (2, 0, 1)) # shuffle to (time, space, 4)

out = np.einsum('ijk,jk->ij', vals, self.weights).T
return out


class WindRegridder(Regridder):
Expand Down

0 comments on commit 5b765eb

Please sign in to comment.