Skip to content

Commit ce7b6ad

Browse files
committed
o Pass n_face to _calculate_weights function to avoid the len() function call entirely in the Numba-compiled loop
1 parent 58f7e5e commit ce7b6ad

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

uxarray/remap/bilinear.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def _barycentric_weights(point_xyz, dual, data_size, source_grid):
140140
dual.node_z.values,
141141
dual.face_node_connectivity.values,
142142
dual.n_nodes_per_face.values,
143+
dual.n_face,
143144
all_weights,
144145
all_indices,
145146
)
@@ -157,13 +158,14 @@ def _calculate_weights(
157158
z,
158159
face_node_conn,
159160
n_nodes_per_face,
161+
n_faces,
160162
all_weights,
161163
all_indices,
162164
):
163165
for idx in prange(len(valid_idxs)):
164166
fidx = int(face_indices[valid_idxs[idx], 0])
165-
# bounds check
166-
if fidx < 0 or fidx >= len(n_nodes_per_face):
167+
# bounds check: ensure face index is within valid range (0 to n_faces-1)
168+
if fidx < 0 or fidx >= n_faces:
167169
continue
168170
nverts = int(n_nodes_per_face[fidx])
169171
polygon_xyz = np.zeros((nverts, 3), dtype=np.float64)

0 commit comments

Comments
 (0)