Skip to content

Commit dacda20

Browse files
committed
clean up vortex-tensor
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 4135209 commit dacda20

File tree

24 files changed

+644
-875
lines changed

24 files changed

+644
-875
lines changed

vortex-array/public-api.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21546,6 +21546,8 @@ pub fn vortex_array::Array<vortex_array::arrays::Extension>::new(ext_dtype: vort
2154621546

2154721547
pub fn vortex_array::Array<vortex_array::arrays::Extension>::try_new(ext_dtype: vortex_array::dtype::extension::ExtDTypeRef, storage_array: vortex_array::ArrayRef) -> vortex_error::VortexResult<Self>
2154821548

21549+
pub fn vortex_array::Array<vortex_array::arrays::Extension>::try_new_from_vtable<V: vortex_array::dtype::extension::ExtVTable>(vtable: V, metadata: <V as vortex_array::dtype::extension::ExtVTable>::Metadata, storage_array: vortex_array::ArrayRef) -> vortex_error::VortexResult<Self>
21550+
2154921551
impl vortex_array::Array<vortex_array::arrays::Filter>
2155021552

2155121553
pub fn vortex_array::Array<vortex_array::arrays::Filter>::new(array: vortex_array::ArrayRef, mask: vortex_mask::Mask) -> Self

vortex-array/src/arrays/extension/array.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use crate::array::ArrayParts;
1313
use crate::array::TypedArrayRef;
1414
use crate::arrays::Extension;
1515
use crate::dtype::DType;
16+
use crate::dtype::extension::ExtDType;
1617
use crate::dtype::extension::ExtDTypeRef;
18+
use crate::dtype::extension::ExtVTable;
1719

1820
/// The backing storage array for this extension array.
1921
pub(super) const STORAGE_SLOT: usize = 0;
@@ -163,4 +165,17 @@ impl Array<Extension> {
163165
)
164166
})
165167
}
168+
169+
/// Creates a new [`ExtensionArray`](crate::arrays::ExtensionArray) from a vtable, metadata, and
170+
/// a storage array.
171+
pub fn try_new_from_vtable<V: ExtVTable>(
172+
vtable: V,
173+
metadata: V::Metadata,
174+
storage_array: ArrayRef,
175+
) -> VortexResult<Self> {
176+
let ext_dtype =
177+
ExtDType::<V>::try_with_vtable(vtable, metadata, storage_array.dtype().clone())?
178+
.erased();
179+
Self::try_new(ext_dtype, storage_array)
180+
}
166181
}

vortex-array/src/dtype/extension/vtable.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::scalar::ScalarValue;
1414

1515
/// The public API for defining new extension types.
1616
///
17-
/// This is the non-object-safe trait that plugin authors implement to define a new extension
18-
/// type. It specifies the type's identity, metadata, serialization, and validation.
17+
/// This is the non-object-safe trait that plugin authors implement to define a new extension type.
18+
/// It specifies the type's identity, metadata, serialization, and validation.
1919
pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
2020
/// Associated type containing the deserialized metadata for this extension type.
2121
type Metadata: 'static + Send + Sync + Clone + Debug + Display + Eq + Hash;
@@ -39,26 +39,27 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
3939
/// Validate that the given storage type is compatible with this extension type.
4040
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()>;
4141

42-
/// Can a value of `other` be implicitly widened into this type?
43-
/// e.g. GeographyType might accept Point, LineString, etc.
42+
/// Can a value of `other` be implicitly widened into this type? (e.g. GeographyType might
43+
/// accept Point, LineString, etc.)
4444
///
45-
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to` both
46-
/// exist so that either side of the coercion can provide the logic.
45+
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to`. We have both
46+
/// so that either side of the coercion can provide the logic.
4747
fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
4848
let _ = (ext_dtype, other);
4949
false
5050
}
5151

5252
/// Can this type be implicitly widened into `other`?
5353
///
54-
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to` both
55-
/// exist so that either side of the coercion can provide the logic.
54+
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to`. We have both
55+
/// so that either side of the coercion can provide the logic.
5656
fn can_coerce_to(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
5757
let _ = (ext_dtype, other);
5858
false
5959
}
6060

6161
/// Given two types in a Uniform context, what is their least supertype?
62+
///
6263
/// Return None if no supertype exists.
6364
fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
6465
let _ = (ext_dtype, other);
@@ -69,7 +70,8 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
6970

7071
/// Validate the given storage value is compatible with the extension type.
7172
///
72-
/// By default, this calls [`unpack_native()`](ExtVTable::unpack_native) and discards the result.
73+
/// By default, this calls [`unpack_native()`](ExtVTable::unpack_native) and discards the
74+
/// result.
7375
///
7476
/// # Errors
7577
///

vortex-tensor/public-api.lock

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub const vortex_tensor::encodings::turboquant::MIN_DIMENSION: u32
8080

8181
pub fn vortex_tensor::encodings::turboquant::tq_validate_vector_dtype(dtype: &vortex_array::dtype::DType) -> vortex_error::VortexResult<vortex_tensor::vector::VectorMatcherMetadata>
8282

83-
pub fn vortex_tensor::encodings::turboquant::turboquant_encode(ext: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::extension::vtable::Extension>, config: &vortex_tensor::encodings::turboquant::TurboQuantConfig, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
83+
pub fn vortex_tensor::encodings::turboquant::turboquant_encode(input: vortex_array::array::erased::ArrayRef, config: &vortex_tensor::encodings::turboquant::TurboQuantConfig, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
8484

8585
pub unsafe fn vortex_tensor::encodings::turboquant::turboquant_encode_unchecked(ext: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::extension::vtable::Extension>, config: &vortex_tensor::encodings::turboquant::TurboQuantConfig, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
8686

@@ -502,7 +502,7 @@ pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::child_name(&sel
502502

503503
pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::execute(&self, options: &Self::Options, args: &dyn vortex_array::scalar_fn::vtable::ExecutionArgs, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
504504

505-
pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::fmt_sql(&self, _options: &Self::Options, expr: &vortex_array::expr::expression::Expression, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
505+
pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::fmt_sql(&self, options: &Self::Options, expr: &vortex_array::expr::expression::Expression, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
506506

507507
pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::id(&self) -> vortex_array::scalar_fn::ScalarFnId
508508

@@ -570,10 +570,12 @@ pub struct vortex_tensor::vector::VectorMatcherMetadata
570570

571571
impl vortex_tensor::vector::VectorMatcherMetadata
572572

573-
pub fn vortex_tensor::vector::VectorMatcherMetadata::dimensions(&self) -> u32
573+
pub fn vortex_tensor::vector::VectorMatcherMetadata::dimensions(&self) -> usize
574574

575575
pub fn vortex_tensor::vector::VectorMatcherMetadata::element_ptype(&self) -> vortex_array::dtype::ptype::PType
576576

577+
pub fn vortex_tensor::vector::VectorMatcherMetadata::list_size(&self) -> u32
578+
577579
pub fn vortex_tensor::vector::VectorMatcherMetadata::try_new(element_ptype: vortex_array::dtype::ptype::PType, dimensions: u32) -> vortex_error::VortexResult<Self>
578580

579581
impl core::clone::Clone for vortex_tensor::vector::VectorMatcherMetadata
@@ -600,12 +602,8 @@ impl core::marker::StructuralPartialEq for vortex_tensor::vector::VectorMatcherM
600602

601603
pub mod vortex_tensor::vector_search
602604

603-
pub fn vortex_tensor::vector_search::build_constant_query_vector<T: vortex_array::dtype::ptype::NativePType + core::convert::Into<vortex_array::scalar::typed_view::primitive::pvalue::PValue>>(query: &[T], num_rows: usize) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
604-
605605
pub fn vortex_tensor::vector_search::build_similarity_search_tree<T: vortex_array::dtype::ptype::NativePType + core::convert::Into<vortex_array::scalar::typed_view::primitive::pvalue::PValue>>(data: vortex_array::array::erased::ArrayRef, query: &[T], threshold: T) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
606606

607-
pub fn vortex_tensor::vector_search::compress_turboquant(data: vortex_array::array::erased::ArrayRef, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
608-
609607
pub const vortex_tensor::SCALAR_FN_ARRAY_TENSOR_PLUGIN_ENV: &str
610608

611609
pub fn vortex_tensor::initialize(session: &vortex_session::VortexSession)

0 commit comments

Comments
 (0)