Skip to content

Instantly share code, notes, and snippets.

@kvchen
Created December 3, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvchen/6403c2c80d0610ee22aef9a6cb8adaaf to your computer and use it in GitHub Desktop.
Save kvchen/6403c2c80d0610ee22aef9a6cb8adaaf to your computer and use it in GitHub Desktop.
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