BlockLayout2D.to_dense: require floats when the layout has holes
Holes are filled with NaN, which bool/str silently mangled and integers rejected with a conversion error. Sparse layouts now raise a clear ValueError for non-floating arrays; full layouts keep any dtype. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
aecee19c19
commit
cc64abcafe
@@ -319,14 +319,18 @@ class BlockLayout2D:
|
||||
return blocked
|
||||
|
||||
def to_dense(self, blocked):
|
||||
"""Unpack owner cores only; halo contents are ignored, holes are NaN."""
|
||||
"""Unpack owner cores only; halo contents are ignored, holes are NaN.
|
||||
|
||||
Full layouts accept any dtype; layouts with holes require floats.
|
||||
"""
|
||||
blocked = self._check_blocked(blocked)
|
||||
flat = blocked.reshape(self.nblocks, NQ, -1)
|
||||
owned = self.owned.ravel()
|
||||
if not owned.all() and not np.issubdtype(blocked.dtype, np.floating):
|
||||
raise ValueError("a layout with holes unpacks floating arrays only (holes are NaN)")
|
||||
ob, oc = np.divmod(self.owner.ravel()[owned].astype(np.intp), flat.shape[2])
|
||||
dense = np.empty((NQ, owned.size), dtype=blocked.dtype)
|
||||
if not owned.all(): # full layouts keep any dtype; holes need a float NaN
|
||||
dense[:, ~owned] = np.nan
|
||||
dense[:, ~owned] = np.nan
|
||||
dense[:, owned] = flat[ob, :, oc].T
|
||||
return dense.reshape(NQ, *self.shape)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user