Skip to main content

Module writeback

Module writeback 

Source
Expand description

WRITEBACKIFCOPY-style writeback guard for non-contiguous out destinations (#370).

NumPy uses NPY_ARRAY_WRITEBACKIFCOPY to allow ufuncs to operate on a contiguous scratch when the user-supplied out= is not contiguous, then write the scratch back to the original on success. This module provides the same pattern as a Rust scope guard:

use ferray_core::writeback::WritebackGuard;

let mut target: Array<f64, Ix2> = ...;  // possibly non-contiguous
let mut guard = WritebackGuard::new(&mut target)?;
run_kernel(guard.scratch_mut());
guard.commit()?;  // writes scratch back into target; without commit
                   // the scratch is discarded and target is untouched.

On a contiguous target the guard’s scratch is the target buffer (no copy on construction, no writeback on commit). On a non-contiguous target the scratch is a fresh contiguous allocation.

Structs§

WritebackGuard
RAII writeback guard for safe out-parameter mutation.