pub fn with_execution_policy<R>(
policy: ExecutionPolicy,
operation: impl FnOnce() -> R,
) -> RExpand description
Execute operation under an explicit strided-kernel execution policy.
Nested scopes combine conservatively: sequential execution dominates and
nested Rayon budgets use the smaller limit. The previous policy is restored
even if operation panics.
The contract covers strided operations and their library-owned fanout. It
does not turn Rayon worker-local state into task-local state. In particular,
callbacks should not invoke Rayon scheduling or yielding APIs if they depend
on isolation from unrelated work; see ExecutionPolicy for details.
ยงExamples
use strided_kernel::{
map_into, with_execution_policy, ExecutionPolicy, StridedArray,
};
let source = StridedArray::<f64>::from_fn_col_major(&[3], |index| index[0] as f64);
let mut destination = StridedArray::<f64>::col_major(&[3]);
with_execution_policy(ExecutionPolicy::Sequential, || {
map_into(&mut destination.view_mut(), &source.view(), |value| value + 1.0)
.unwrap();
});
assert_eq!(destination.into_data(), vec![1.0, 2.0, 3.0]);