INNER CODE UNIT · Rust

extract_bool_1d

RyanCodrai/turbovec · turbovec-python/src/lib.rs:79

fn extract_bool_1d<'py>(
    name: &str,
    obj: &Bound<'py, PyAny>,
) -> PyResult<PyReadonlyArray1<'py, bool>> {
    obj.extract()
        .map_err(|_| array_type_err(name, "1-D bool", obj))
}

/// Copy a validated 1-D numpy `bool` mask into a `Vec<bool>` by reading
/// its raw bytes.
///
/// numpy stores `bool_` in one byte and does **not** constrain that byte
/// to 0 or 1, and it treats every non-zero byte as true. Such a buffer
/// is reachable from ordinary numpy — `np.frombuffer(buf, dtype=bool)`
/// over arbitrary bytes, `np.uint8` data through `.view(bool)`, or even
/// an uninitialised `np.empty(n, dtype=bool)` — so this needs no
/// deliberate byte-forging. A Rust `bool` may only ever hold 0 or 1, so
/// forming *any* `&bool`, `&[bool]` or `ArrayView<bool>` over one is

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…