-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathmod.rs
More file actions
27 lines (22 loc) · 1.16 KB
/
mod.rs
File metadata and controls
27 lines (22 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Vector-side helpers: normalization, quantization, and physical storage layout.
pub(crate) mod normalize;
pub(crate) mod quantize;
pub(crate) mod storage;
use vortex_error::VortexResult;
use vortex_error::vortex_err;
/// Compute the padded SORF dimension for an original vector dimension.
///
/// The SORF transform requires a power-of-two width, so non-power-of-two input dimensions are
/// padded with zeros up to the next power of two. The padded dimension is stored implicitly via
/// [`TurboQuantMetadata::dimensions`](crate::TurboQuantMetadata) plus the codes child's
/// `FixedSizeList` width and recovered at decode time via this function. Returns an error when
/// the next power of two overflows the input integer type.
pub(crate) fn tq_padded_dim(dimensions: u32) -> VortexResult<usize> {
let padded_dim = dimensions
.checked_next_power_of_two()
.ok_or_else(|| vortex_err!("TurboQuant padded dimension overflow for {dimensions}"))?;
usize::try_from(padded_dim)
.map_err(|_| vortex_err!("TurboQuant padded dimension does not fit usize"))
}