Created
December 3, 2016 17:25
-
-
Save kvchen/6403c2c80d0610ee22aef9a6cb8adaaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assemble(self): | |
"""Assemble an array on this node from a distributed array of object IDs.""" | |
first_block = ray.get(self.objectids[(0,) * self.ndim]) | |
dtype = first_block.dtype | |
result = np.zeros(self.shape, dtype=dtype) | |
indices = np.ndindex(*self.num_blocks) | |
# Fetch all the blocks asynchronously | |
blocks = ray.get([self.objectids[idx] for idx in indices]) | |
for idx, block in zip(indices, blocks): | |
lower = DistArray.compute_block_lower(idx, self.shape) | |
upper = DistArray.compute_block_upper(idx, self.shape) | |
result[[slice(l, u) for (l, u) in zip(lower, upper)]] = block | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment