@@ -500,10 +500,6 @@ def _row_nanmean(bands: list[NDArray[np.float64]]) -> NDArray[np.float64]:
500500 )
501501 sample_size = grid .shape [0 ]
502502 k = eval_vec .size
503- position = np .tile (
504- np .repeat (np .asarray (["l" , "m" , "u" ], dtype = object ), sample_size ), k
505- )
506- ids = np .repeat (np .arange (k ), 3 * sample_size )
507503 for band in h_s :
508504 steps = np .array ([_dydx_step (column , ev , float (band )) for ev in eval_vec ])
509505 blocks : list [NDArray [np .float64 ]] = []
@@ -573,19 +569,16 @@ def reduce(parts: list[NDArray[np.float64]]) -> dict[str, NDArray[np.float64]]:
573569 block = parts [main_chunk_idx [bi ]]
574570 if vector_branch :
575571 k = steps .size
576- f = np .empty (k )
577- s = np .empty (k )
578- for g in range (k ):
579- lo = np .mean (block [(position == "l" ) & (ids == g )])
580- mid = np .mean (block [(position == "m" ) & (ids == g )])
581- up = np .mean (block [(position == "u" ) & (ids == g )])
582- h = steps [g ]
583- if np .isfinite (h ) and h != 0.0 :
584- f [g ] = (up - lo ) / (2.0 * h )
585- s [g ] = (up - 2.0 * mid + lo ) / (h ** 2 )
586- else :
587- f [g ] = np .nan
588- s [g ] = np .nan
572+ means = np .mean (block .reshape (k , 3 , sample_size ), axis = 2 )
573+ lo = means [:, 0 ]
574+ mid = means [:, 1 ]
575+ up = means [:, 2 ]
576+ finite = np .isfinite (steps ) & (steps != 0.0 )
577+ with np .errstate (invalid = "ignore" , divide = "ignore" ):
578+ f = (up - lo ) / (2.0 * steps )
579+ s = (up - 2.0 * mid + lo ) / (steps ** 2 )
580+ f = np .where (finite , f , np .nan )
581+ s = np .where (finite , s , np .nan )
589582 else :
590583 n_eval = steps .size
591584 lo = block [:n_eval ]
0 commit comments