INNER CODE UNIT · Rust

validate_queries_pooled

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

fn validate_queries_pooled(values: &[f32], dim: usize) -> PyResult<()> {
    if turbovec_core::validation_parallelizes(values.len()) {
        with_pool(|| validate_queries(values, dim))?
    } else {
        validate_queries(values, dim)
    }
}

/// Extract a bytes-like argument (`bytes` / `bytearray`) into an owned
/// buffer; see [`extract_f32_2d`] for the error-naming rationale. Owned
/// because the buffer must cross a GIL release (`py.detach`), where a
/// borrowed Python buffer would be mutable out from under us.
fn extract_bytes(name: &str, obj: &Bound<'_, PyAny>) -> PyResult<Vec<u8>> {
    if let Ok(b) = obj.cast::<PyBytes>() {
        return Ok(b.as_bytes().to_vec());
    }
    if let Ok(b) = obj.cast::<pyo3::types::PyByteArray>() {
        return Ok(b.to_vec());

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…