Skip to content

Commit 886aefc

Browse files
authored
Invert thevortex-tensor dependency (#7271)
## Summary We want to start using the tensor types, but as very unstable encodings and types. This PR makes `vortex-tensor` a dependency of both `vortex` and `vortex-file`, gated under the `unstable_encodings` flag (technically there are also unstable types and expressions here too bet that isn't that important). This will let us write unstable types and encodings (like Vectors with TurboQuant) to files easily. ## API Changes The dependency direction has changed. ## Testing N/A Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent f782a6e commit 886aefc

15 files changed

Lines changed: 153 additions & 116 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vortex-file/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ vortex-scan = { workspace = true }
5454
vortex-sequence = { workspace = true }
5555
vortex-session = { workspace = true }
5656
vortex-sparse = { workspace = true }
57+
vortex-tensor = { workspace = true, optional = true }
5758
vortex-utils = { workspace = true, features = ["dashmap"] }
5859
vortex-zigzag = { workspace = true }
5960
vortex-zstd = { workspace = true, optional = true }
@@ -79,6 +80,7 @@ tokio = [
7980
zstd = ["dep:vortex-zstd", "vortex-btrblocks/zstd", "vortex-btrblocks/pco"]
8081
# This feature enables unstable encodings for which we don't guarantee stability.
8182
unstable_encodings = [
83+
"dep:vortex-tensor",
8284
"vortex-zstd?/unstable_encodings",
8385
"vortex-btrblocks/unstable_encodings",
8486
]

vortex-file/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,7 @@ pub fn register_default_encodings(session: &VortexSession) {
178178
vortex_fastlanes::initialize(session);
179179
vortex_runend::initialize(session);
180180
vortex_sequence::initialize(session);
181+
182+
#[cfg(feature = "unstable_encodings")]
183+
vortex_tensor::initialize(session);
181184
}

vortex-tensor/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ version = { workspace = true }
1717
workspace = true
1818

1919
[dependencies]
20-
vortex = { workspace = true }
20+
vortex-array = { workspace = true }
21+
vortex-error = { workspace = true }
22+
vortex-session = { workspace = true }
2123

2224
itertools = { workspace = true }
2325
num-traits = { workspace = true }
2426
prost = { workspace = true }
2527

2628
[dev-dependencies]
2729
rstest = { workspace = true }
30+
vortex-buffer = { workspace = true }

vortex-tensor/public-api.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,5 @@ pub fn vortex_tensor::vector::Vector::serialize_metadata(&self, _metadata: &Self
259259
pub fn vortex_tensor::vector::Vector::unpack_native<'a>(_ext_dtype: &'a vortex_array::dtype::extension::typed::ExtDType<Self>, storage_value: &'a vortex_array::scalar::scalar_value::ScalarValue) -> vortex_error::VortexResult<Self::NativeValue>
260260

261261
pub fn vortex_tensor::vector::Vector::validate_dtype(ext_dtype: &vortex_array::dtype::extension::typed::ExtDType<Self>) -> vortex_error::VortexResult<()>
262+
263+
pub fn vortex_tensor::initialize(session: &vortex_session::VortexSession)

vortex-tensor/src/fixed_shape/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use std::fmt;
55

66
use itertools::Either;
7-
use vortex::error::VortexExpect;
8-
use vortex::error::VortexResult;
9-
use vortex::error::vortex_ensure;
10-
use vortex::error::vortex_ensure_eq;
7+
use vortex_error::VortexExpect;
8+
use vortex_error::VortexResult;
9+
use vortex_error::vortex_ensure;
10+
use vortex_error::vortex_ensure_eq;
1111

1212
/// Metadata for a `FixedShapeTensor` extension type.
1313
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

vortex-tensor/src/fixed_shape/proto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
//! Protobuf serialization for [`FixedShapeTensorMetadata`].
55
66
use prost::Message;
7-
use vortex::error::VortexExpect;
8-
use vortex::error::VortexResult;
9-
use vortex::error::vortex_err;
7+
use vortex_error::VortexExpect;
8+
use vortex_error::VortexResult;
9+
use vortex_error::vortex_err;
1010

1111
use crate::fixed_shape::FixedShapeTensorMetadata;
1212

vortex-tensor/src/fixed_shape/vtable.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex::dtype::DType;
5-
use vortex::dtype::extension::ExtDType;
6-
use vortex::dtype::extension::ExtId;
7-
use vortex::dtype::extension::ExtVTable;
8-
use vortex::error::VortexResult;
9-
use vortex::error::vortex_bail;
10-
use vortex::error::vortex_ensure;
11-
use vortex::error::vortex_ensure_eq;
12-
use vortex::scalar::ScalarValue;
4+
use vortex_array::dtype::DType;
5+
use vortex_array::dtype::extension::ExtDType;
6+
use vortex_array::dtype::extension::ExtId;
7+
use vortex_array::dtype::extension::ExtVTable;
8+
use vortex_array::scalar::ScalarValue;
9+
use vortex_error::VortexResult;
10+
use vortex_error::vortex_bail;
11+
use vortex_error::vortex_ensure;
12+
use vortex_error::vortex_ensure_eq;
1313

1414
use crate::fixed_shape::FixedShapeTensor;
1515
use crate::fixed_shape::FixedShapeTensorMetadata;
@@ -77,8 +77,8 @@ impl ExtVTable for FixedShapeTensor {
7777
#[cfg(test)]
7878
mod tests {
7979
use rstest::rstest;
80-
use vortex::dtype::extension::ExtVTable;
81-
use vortex::error::VortexResult;
80+
use vortex_array::dtype::extension::ExtVTable;
81+
use vortex_error::VortexResult;
8282

8383
use crate::fixed_shape::FixedShapeTensor;
8484
use crate::fixed_shape::FixedShapeTensorMetadata;

vortex-tensor/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
//! including unit vectors, spherical coordinates, and similarity measures such as cosine
66
//! similarity.
77
8+
use vortex_array::dtype::session::DTypeSessionExt;
9+
use vortex_array::scalar_fn::session::ScalarFnSessionExt;
10+
use vortex_session::VortexSession;
11+
12+
use crate::fixed_shape::FixedShapeTensor;
13+
use crate::scalar_fns::cosine_similarity::CosineSimilarity;
14+
use crate::scalar_fns::l2_norm::L2Norm;
15+
use crate::vector::Vector;
16+
817
pub mod matcher;
918
pub mod scalar_fns;
1019

@@ -14,3 +23,11 @@ pub mod vector;
1423
pub mod encodings;
1524

1625
mod utils;
26+
27+
/// Registers the tensor extension dtypes and scalar functions with the given session.
28+
pub fn initialize(session: &VortexSession) {
29+
session.dtypes().register(Vector);
30+
session.dtypes().register(FixedShapeTensor);
31+
session.scalar_fns().register(CosineSimilarity);
32+
session.scalar_fns().register(L2Norm);
33+
}

vortex-tensor/src/matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
//! Matcher for tensor-like extension types.
55
6-
use vortex::dtype::extension::ExtDTypeRef;
7-
use vortex::dtype::extension::Matcher;
6+
use vortex_array::dtype::extension::ExtDTypeRef;
7+
use vortex_array::dtype::extension::Matcher;
88

99
use crate::fixed_shape::FixedShapeTensor;
1010
use crate::fixed_shape::FixedShapeTensorMetadata;

0 commit comments

Comments
 (0)