Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rust/cuvs/src/dlpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl IntoDtype for f64 {
}
}

impl IntoDtype for i8 {
fn ffi_dtype() -> ffi::DLDataType {
ffi::DLDataType { code: ffi::DLDataTypeCode::kDLInt as _, bits: 8, lanes: 1 }
}
}

impl IntoDtype for i32 {
fn ffi_dtype() -> ffi::DLDataType {
ffi::DLDataType { code: ffi::DLDataTypeCode::kDLInt as _, bits: 32, lanes: 1 }
Expand Down
1 change: 1 addition & 0 deletions rust/cuvs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod dlpack;
mod error;
pub mod ivf_flat;
pub mod ivf_pq;
pub mod preprocessing;
mod resources;
pub mod vamana;

Expand Down
11 changes: 11 additions & 0 deletions rust/cuvs/src/preprocessing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

//! Preprocessing utilities for cuVS datasets.
//!
//! Currently this exposes the [`quantize`] module, which provides quantizers
//! that compress floating-point datasets into more compact representations.

pub mod quantize;
54 changes: 54 additions & 0 deletions rust/cuvs/src/preprocessing/quantize/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

//! Dataset quantizers.
//!
//! Quantizers compress a floating-point dataset into a more compact
//! representation. The [`scalar`] quantizer maps an interval of the input
//! float range onto the full range of an 8-bit integer.
//!
//! The binary and product (PQ) quantizers exposed by the cuVS C API are not
//! yet wrapped in Rust; they are intended to be added in follow-up
//! contributions.
//!
//! Example:
//! ```
//! use cuvs::preprocessing::quantize::scalar::{Quantizer, ScalarQuantizerParams};
//! use cuvs::{ManagedTensor, Resources, Result};
//!
//! use ndarray_rand::rand_distr::Uniform;
//! use ndarray_rand::RandomExt;
//!
//! fn scalar_quantize_example() -> Result<()> {
//! let res = Resources::new()?;
//!
//! // Create a new random dataset to quantize
//! let n_rows = 1024;
//! let n_cols = 16;
//! let dataset =
//! ndarray::Array::<f32, _>::random((n_rows, n_cols), Uniform::new(0., 1.0));
//! let dataset_device = ManagedTensor::from(&dataset).to_device(&res)?;
//!
//! // Train a scalar quantizer on the dataset
//! let params = ScalarQuantizerParams::new()?;
//! let quantizer = Quantizer::train(&res, &params, &dataset_device)?;
//!
//! // Quantize the dataset into int8
//! let mut quantized_host = ndarray::Array::<i8, _>::zeros((n_rows, n_cols));
//! let quantized = ManagedTensor::from(&quantized_host).to_device(&res)?;
//! quantizer.transform(&res, &dataset_device, &quantized)?;
//! quantized.to_host(&res, &mut quantized_host)?;
//!
//! // Reconstruct an approximation of the original f32 dataset
//! let mut reconstructed_host = ndarray::Array::<f32, _>::zeros((n_rows, n_cols));
//! let reconstructed = ManagedTensor::from(&reconstructed_host).to_device(&res)?;
//! quantizer.inverse_transform(&res, &quantized, &reconstructed)?;
//! reconstructed.to_host(&res, &mut reconstructed_host)?;
//!
//! Ok(())
//! }
//! ```

pub mod scalar;
Loading
Loading