Skip to content
Merged
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
7 changes: 6 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vortex-file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ vortex-scan = { workspace = true }
vortex-sequence = { workspace = true }
vortex-session = { workspace = true }
vortex-sparse = { workspace = true }
vortex-tensor = { workspace = true, optional = true }
vortex-utils = { workspace = true, features = ["dashmap"] }
vortex-zigzag = { workspace = true }
vortex-zstd = { workspace = true, optional = true }
Expand All @@ -79,6 +80,7 @@ tokio = [
zstd = ["dep:vortex-zstd", "vortex-btrblocks/zstd", "vortex-btrblocks/pco"]
# This feature enables unstable encodings for which we don't guarantee stability.
unstable_encodings = [
"dep:vortex-tensor",
"vortex-zstd?/unstable_encodings",
"vortex-btrblocks/unstable_encodings",
]
Expand Down
3 changes: 3 additions & 0 deletions vortex-file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,7 @@ pub fn register_default_encodings(session: &VortexSession) {
vortex_fastlanes::initialize(session);
vortex_runend::initialize(session);
vortex_sequence::initialize(session);

#[cfg(feature = "unstable_encodings")]
vortex_tensor::initialize(session);
}
5 changes: 4 additions & 1 deletion vortex-tensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ version = { workspace = true }
workspace = true

[dependencies]
vortex = { workspace = true }
vortex-array = { workspace = true }
vortex-error = { workspace = true }
vortex-session = { workspace = true }

itertools = { workspace = true }
num-traits = { workspace = true }
prost = { workspace = true }

[dev-dependencies]
rstest = { workspace = true }
vortex-buffer = { workspace = true }
2 changes: 2 additions & 0 deletions vortex-tensor/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,5 @@ pub fn vortex_tensor::vector::Vector::serialize_metadata(&self, _metadata: &Self
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>

pub fn vortex_tensor::vector::Vector::validate_dtype(ext_dtype: &vortex_array::dtype::extension::typed::ExtDType<Self>) -> vortex_error::VortexResult<()>

pub fn vortex_tensor::initialize(session: &vortex_session::VortexSession)
8 changes: 4 additions & 4 deletions vortex-tensor/src/fixed_shape/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use std::fmt;

use itertools::Either;
use vortex::error::VortexExpect;
use vortex::error::VortexResult;
use vortex::error::vortex_ensure;
use vortex::error::vortex_ensure_eq;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;

/// Metadata for a `FixedShapeTensor` extension type.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
6 changes: 3 additions & 3 deletions vortex-tensor/src/fixed_shape/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! Protobuf serialization for [`FixedShapeTensorMetadata`].

use prost::Message;
use vortex::error::VortexExpect;
use vortex::error::VortexResult;
use vortex::error::vortex_err;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_err;

use crate::fixed_shape::FixedShapeTensorMetadata;

Expand Down
22 changes: 11 additions & 11 deletions vortex-tensor/src/fixed_shape/vtable.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex::dtype::DType;
use vortex::dtype::extension::ExtDType;
use vortex::dtype::extension::ExtId;
use vortex::dtype::extension::ExtVTable;
use vortex::error::VortexResult;
use vortex::error::vortex_bail;
use vortex::error::vortex_ensure;
use vortex::error::vortex_ensure_eq;
use vortex::scalar::ScalarValue;
use vortex_array::dtype::DType;
use vortex_array::dtype::extension::ExtDType;
use vortex_array::dtype::extension::ExtId;
use vortex_array::dtype::extension::ExtVTable;
use vortex_array::scalar::ScalarValue;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;

use crate::fixed_shape::FixedShapeTensor;
use crate::fixed_shape::FixedShapeTensorMetadata;
Expand Down Expand Up @@ -77,8 +77,8 @@ impl ExtVTable for FixedShapeTensor {
#[cfg(test)]
mod tests {
use rstest::rstest;
use vortex::dtype::extension::ExtVTable;
use vortex::error::VortexResult;
use vortex_array::dtype::extension::ExtVTable;
use vortex_error::VortexResult;

use crate::fixed_shape::FixedShapeTensor;
use crate::fixed_shape::FixedShapeTensorMetadata;
Expand Down
17 changes: 17 additions & 0 deletions vortex-tensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
//! including unit vectors, spherical coordinates, and similarity measures such as cosine
//! similarity.

use vortex_array::dtype::session::DTypeSessionExt;
use vortex_array::scalar_fn::session::ScalarFnSessionExt;
use vortex_session::VortexSession;

use crate::fixed_shape::FixedShapeTensor;
use crate::scalar_fns::cosine_similarity::CosineSimilarity;
use crate::scalar_fns::l2_norm::L2Norm;
use crate::vector::Vector;

pub mod matcher;
pub mod scalar_fns;

Expand All @@ -14,3 +23,11 @@ pub mod vector;
pub mod encodings;

mod utils;

/// Registers the tensor extension dtypes and scalar functions with the given session.
pub fn initialize(session: &VortexSession) {
session.dtypes().register(Vector);
session.dtypes().register(FixedShapeTensor);
session.scalar_fns().register(CosineSimilarity);
session.scalar_fns().register(L2Norm);
}
4 changes: 2 additions & 2 deletions vortex-tensor/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

//! Matcher for tensor-like extension types.

use vortex::dtype::extension::ExtDTypeRef;
use vortex::dtype::extension::Matcher;
use vortex_array::dtype::extension::ExtDTypeRef;
use vortex_array::dtype::extension::Matcher;

use crate::fixed_shape::FixedShapeTensor;
use crate::fixed_shape::FixedShapeTensorMetadata;
Expand Down
47 changes: 24 additions & 23 deletions vortex-tensor/src/scalar_fns/cosine_similarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
use std::fmt::Formatter;

use num_traits::Float;
use vortex::array::ArrayRef;
use vortex::array::ExecutionCtx;
use vortex::array::IntoArray;
use vortex::array::arrays::PrimitiveArray;
use vortex::array::match_each_float_ptype;
use vortex::dtype::DType;
use vortex::dtype::NativePType;
use vortex::dtype::Nullability;
use vortex::error::VortexResult;
use vortex::error::vortex_ensure;
use vortex::error::vortex_err;
use vortex::expr::Expression;
use vortex::scalar_fn::Arity;
use vortex::scalar_fn::ChildName;
use vortex::scalar_fn::ExecutionArgs;
use vortex::scalar_fn::ScalarFnId;
use vortex::scalar_fn::ScalarFnVTable;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::dtype::DType;
use vortex_array::dtype::NativePType;
use vortex_array::dtype::Nullability;
use vortex_array::expr::Expression;
use vortex_array::expr::and;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar_fn::Arity;
use vortex_array::scalar_fn::ChildName;
use vortex_array::scalar_fn::ExecutionArgs;
use vortex_array::scalar_fn::ScalarFnId;
use vortex_array::scalar_fn::ScalarFnVTable;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;

use crate::matcher::AnyTensor;
use crate::scalar_fns::ApproxOptions;
Expand Down Expand Up @@ -156,7 +157,7 @@ impl ScalarFnVTable for CosineSimilarity {
let lhs_validity = expression.child(0).validity()?;
let rhs_validity = expression.child(1).validity()?;

Ok(Some(vortex::expr::and(lhs_validity, rhs_validity)))
Ok(Some(and(lhs_validity, rhs_validity)))
}

fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
Expand Down Expand Up @@ -188,11 +189,11 @@ fn cosine_similarity_row<T: Float + NativePType>(a: &[T], b: &[T]) -> T {
#[cfg(test)]
mod tests {
use rstest::rstest;
use vortex::array::ArrayRef;
use vortex::array::ToCanonical;
use vortex::array::arrays::ScalarFnArray;
use vortex::error::VortexResult;
use vortex::scalar_fn::ScalarFn;
use vortex_array::ArrayRef;
use vortex_array::ToCanonical;
use vortex_array::arrays::ScalarFnArray;
use vortex_array::scalar_fn::ScalarFn;
use vortex_error::VortexResult;

use crate::scalar_fns::ApproxOptions;
use crate::scalar_fns::cosine_similarity::CosineSimilarity;
Expand Down
45 changes: 23 additions & 22 deletions vortex-tensor/src/scalar_fns/l2_norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
use std::fmt::Formatter;

use num_traits::Float;
use vortex::array::ArrayRef;
use vortex::array::ExecutionCtx;
use vortex::array::IntoArray;
use vortex::array::arrays::PrimitiveArray;
use vortex::array::match_each_float_ptype;
use vortex::dtype::DType;
use vortex::dtype::NativePType;
use vortex::dtype::Nullability;
use vortex::error::VortexResult;
use vortex::error::vortex_ensure;
use vortex::error::vortex_err;
use vortex::expr::Expression;
use vortex::scalar_fn::Arity;
use vortex::scalar_fn::ChildName;
use vortex::scalar_fn::ExecutionArgs;
use vortex::scalar_fn::ScalarFnId;
use vortex::scalar_fn::ScalarFnVTable;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::dtype::DType;
use vortex_array::dtype::NativePType;
use vortex_array::dtype::Nullability;
use vortex_array::expr::Expression;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar_fn::Arity;
use vortex_array::scalar_fn::ChildName;
use vortex_array::scalar_fn::ExecutionArgs;
use vortex_array::scalar_fn::ScalarFnId;
use vortex_array::scalar_fn::ScalarFnVTable;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;

use crate::matcher::AnyTensor;
use crate::scalar_fns::ApproxOptions;
Expand Down Expand Up @@ -156,10 +156,11 @@ fn l2_norm_row<T: Float + NativePType>(v: &[T]) -> T {
#[cfg(test)]
mod tests {
use rstest::rstest;
use vortex::array::ToCanonical;
use vortex::array::arrays::ScalarFnArray;
use vortex::error::VortexResult;
use vortex::scalar_fn::ScalarFn;
use vortex_array::ArrayRef;
use vortex_array::ToCanonical;
use vortex_array::arrays::ScalarFnArray;
use vortex_array::scalar_fn::ScalarFn;
use vortex_error::VortexResult;

use crate::scalar_fns::ApproxOptions;
use crate::scalar_fns::l2_norm::L2Norm;
Expand All @@ -168,7 +169,7 @@ mod tests {
use crate::utils::test_helpers::vector_array;

/// Evaluates L2 norm on a tensor/vector array and returns the result as `Vec<f64>`.
fn eval_l2_norm(input: vortex::array::ArrayRef, len: usize) -> VortexResult<Vec<f64>> {
fn eval_l2_norm(input: ArrayRef, len: usize) -> VortexResult<Vec<f64>> {
let scalar_fn = ScalarFn::new(L2Norm, ApproxOptions::Exact).erased();
let result = ScalarFnArray::try_new(scalar_fn, vec![input], len)?;
let prim = result.as_array().to_primitive();
Expand Down
Loading
Loading