Skip to content

Commit 05faeb2

Browse files
committed
Reshape
1 parent a7cc672 commit 05faeb2

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/mdio/core/grid.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,24 @@ def build_map(self, index_headers: HeaderArray) -> None:
134134
# Process headers in batches
135135
for start in range(0, total_live_traces, batch_size):
136136
end = min(start + batch_size, total_live_traces)
137-
live_dim_indices = []
138-
139-
# Compute indices for the batch
140-
for dim in self.dims[:-1]:
141-
dim_hdr = index_headers[dim.name][start:end]
142-
indices = np.searchsorted(dim, dim_hdr).astype(np.uint32)
143-
live_dim_indices.append(indices)
144-
live_dim_indices = tuple(live_dim_indices)
145-
146-
# Assign trace indices
147-
trace_indices = np.arange(start, end, dtype=np.uint64)
148-
# Compute flat indices for lower-memory scatter assignment
149-
flat_indices = np.ravel_multi_index(live_dim_indices, live_shape)
150-
flat_map = self.map.reshape(-1)
137+
138+
# 1) build your per-dimension index arrays
139+
live_dim_indices = [
140+
np.searchsorted(dim, index_headers[dim.name][start:end])
141+
.astype(np.uint32)
142+
for dim in self.dims[:-1]
143+
]
144+
145+
# 2) flatten to 1D indices
146+
flat_idx = np.ravel_multi_index(tuple(live_dim_indices), dims=self.map.shape)
147+
148+
# 3) write into flattened views
149+
flat_map = self.map.reshape(-1)
151150
flat_mask = self.live_mask.reshape(-1)
152-
# Use 1-D fancy indexing (no broadcast) for assignment
153-
flat_map.vindex[flat_indices] = trace_indices
154-
flat_mask.vindex[flat_indices] = True
151+
trace_indices = np.arange(start, end, dtype=flat_map.dtype)
152+
153+
flat_map[flat_idx] = trace_indices
154+
flat_mask[flat_idx] = True
155155

156156

157157
class GridSerializer(Serializer):

0 commit comments

Comments
 (0)