FrankenNumPy

Docs/Numerics

Shared Memory and Views

UFuncArrayView provides NumPy-style shared-memory views with overlap detection:

UFuncArrayView {
    shape: Vec<usize>,
    buffer: Arc<RwLock<Vec<f64>>>,  // shared backing store
    offset: isize,                   // byte offset into buffer
    strides: Vec<isize>,             // per-dimension strides (can be negative)
    writable: bool,
    dtype: DType,
}

Memory overlap detection uses a two-tier approach:

  1. Fast path (may_share_memory): Checks whether the byte-offset spans of two views overlap. O(ndim) and conservative (may report false positives for non-contiguous views).
  2. Exact path (shares_memory): First checks Arc pointer equality (different backing buffers never share). If the same buffer, computes the actual set of accessed byte offsets (up to 200,000) and checks for intersection. Falls back to the fast path if offset collection exceeds the limit.

This supports safe in-place operations: if two views share memory, operations that read from one and write to the other use temporary copies to avoid data corruption.


This section in the README on GitHub