44
55import numpy as np
66import xarray as xr
7- from numba import njit
7+ from numba import njit , prange
88
99if TYPE_CHECKING :
1010 from uxarray .core .dataarray import UxDataArray
@@ -147,7 +147,7 @@ def _barycentric_weights(point_xyz, dual, data_size, source_grid):
147147 return all_weights , all_indices
148148
149149
150- @njit (cache = True )
150+ @njit (cache = True , parallel = True )
151151def _calculate_weights (
152152 valid_idxs ,
153153 point_xyz ,
@@ -160,8 +160,8 @@ def _calculate_weights(
160160 all_weights ,
161161 all_indices ,
162162):
163- for idx in valid_idxs :
164- fidx = int (face_indices [idx , 0 ])
163+ for idx in prange ( len ( valid_idxs )) :
164+ fidx = int (face_indices [valid_idxs [ idx ] , 0 ])
165165 nverts = int (n_nodes_per_face [fidx ])
166166
167167 polygon_xyz = np .zeros ((nverts , 3 ), dtype = np .float64 )
@@ -174,18 +174,18 @@ def _calculate_weights(
174174 polygon_face_indices [j ] = node
175175
176176 # snap check
177- match = _find_matching_node_index (polygon_xyz , point_xyz [idx ])
177+ match = _find_matching_node_index (polygon_xyz , point_xyz [valid_idxs [ idx ] ])
178178 if match [0 ] != - 1 :
179- all_weights [idx , 0 ] = 1.0
180- all_indices [idx , 0 ] = polygon_face_indices [match [0 ]]
179+ all_weights [valid_idxs [ idx ] , 0 ] = 1.0
180+ all_indices [valid_idxs [ idx ] , 0 ] = polygon_face_indices [match [0 ]]
181181 continue
182182
183183 weights , node_idxs = barycentric_coordinates_cartesian (
184- polygon_xyz , point_xyz [idx ]
184+ polygon_xyz , point_xyz [valid_idxs [ idx ] ]
185185 )
186186 for k in range (len (weights )):
187- all_weights [idx , k ] = weights [k ]
188- all_indices [idx , k ] = polygon_face_indices [node_idxs [k ]]
187+ all_weights [valid_idxs [ idx ] , k ] = weights [k ]
188+ all_indices [valid_idxs [ idx ] , k ] = polygon_face_indices [node_idxs [k ]]
189189
190190
191191@njit (cache = True )
0 commit comments