INNER CODE UNIT · Rust

bytes

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

    let bytes = unsafe { std::slice::from_raw_parts(arr.data() as *const u8, n) };
    Ok(bytes.iter().map(|&b| b != 0).collect())
}

/// Whether `obj` is integer-valued: a Python `int` of any magnitude, or
/// any object (numpy scalar, `__index__` implementor) that converts to
/// one. Used to pick a range error over a type error once the fast-path
/// fixed-width extraction has failed.
fn is_py_int(obj: &Bound<'_, PyAny>) -> bool {
    obj.extract::<i128>().is_ok() || obj.is_instance_of::<pyo3::types::PyInt>()
}

/// `str()` of an argument, for error messages.
fn int_repr(obj: &Bound<'_, PyAny>) -> String {
    obj.str()
        .map(|s| s.to_string())
        .unwrap_or_else(|_| "<unprintable>".to_string())
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…