Skip to content

Commit da2f733

Browse files
committed
remove approx options entirely
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent f960787 commit da2f733

4 files changed

Lines changed: 46 additions & 110 deletions

File tree

‎vortex-tensor/public-api.lock‎

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,23 @@ pub struct vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity
240240

241241
impl vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity
242242

243-
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::new(options: &vortex_tensor::scalar_fns::ApproxOptions) -> vortex_array::scalar_fn::typed::ScalarFn<vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity>
243+
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::new() -> vortex_array::scalar_fn::typed::ScalarFn<vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity>
244244

245-
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::try_new_array(options: &vortex_tensor::scalar_fns::ApproxOptions, lhs: vortex_array::array::erased::ArrayRef, rhs: vortex_array::array::erased::ArrayRef, len: usize) -> vortex_error::VortexResult<vortex_array::arrays::scalar_fn::vtable::ScalarFnArray>
245+
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::try_new_array(lhs: vortex_array::array::erased::ArrayRef, rhs: vortex_array::array::erased::ArrayRef, len: usize) -> vortex_error::VortexResult<vortex_array::arrays::scalar_fn::vtable::ScalarFnArray>
246246

247247
impl core::clone::Clone for vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity
248248

249249
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::clone(&self) -> vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity
250250

251251
impl vortex_array::scalar_fn::vtable::ScalarFnVTable for vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity
252252

253-
pub type vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::Options = vortex_tensor::scalar_fns::ApproxOptions
253+
pub type vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::Options = vortex_array::scalar_fn::vtable::EmptyOptions
254254

255255
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::arity(&self, _options: &Self::Options) -> vortex_array::scalar_fn::vtable::Arity
256256

257257
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::child_name(&self, _options: &Self::Options, child_idx: usize) -> vortex_array::scalar_fn::vtable::ChildName
258258

259-
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::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>
259+
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::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>
260260

261261
pub fn vortex_tensor::scalar_fns::cosine_similarity::CosineSimilarity::fmt_sql(&self, _options: &Self::Options, expr: &vortex_array::expr::expression::Expression, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
262262

@@ -276,23 +276,23 @@ pub struct vortex_tensor::scalar_fns::inner_product::InnerProduct
276276

277277
impl vortex_tensor::scalar_fns::inner_product::InnerProduct
278278

279-
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::new(options: &vortex_tensor::scalar_fns::ApproxOptions) -> vortex_array::scalar_fn::typed::ScalarFn<vortex_tensor::scalar_fns::inner_product::InnerProduct>
279+
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::new() -> vortex_array::scalar_fn::typed::ScalarFn<vortex_tensor::scalar_fns::inner_product::InnerProduct>
280280

281-
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::try_new_array(options: &vortex_tensor::scalar_fns::ApproxOptions, lhs: vortex_array::array::erased::ArrayRef, rhs: vortex_array::array::erased::ArrayRef, len: usize) -> vortex_error::VortexResult<vortex_array::arrays::scalar_fn::vtable::ScalarFnArray>
281+
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::try_new_array(lhs: vortex_array::array::erased::ArrayRef, rhs: vortex_array::array::erased::ArrayRef, len: usize) -> vortex_error::VortexResult<vortex_array::arrays::scalar_fn::vtable::ScalarFnArray>
282282

283283
impl core::clone::Clone for vortex_tensor::scalar_fns::inner_product::InnerProduct
284284

285285
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::clone(&self) -> vortex_tensor::scalar_fns::inner_product::InnerProduct
286286

287287
impl vortex_array::scalar_fn::vtable::ScalarFnVTable for vortex_tensor::scalar_fns::inner_product::InnerProduct
288288

289-
pub type vortex_tensor::scalar_fns::inner_product::InnerProduct::Options = vortex_tensor::scalar_fns::ApproxOptions
289+
pub type vortex_tensor::scalar_fns::inner_product::InnerProduct::Options = vortex_array::scalar_fn::vtable::EmptyOptions
290290

291291
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::arity(&self, _options: &Self::Options) -> vortex_array::scalar_fn::vtable::Arity
292292

293293
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::child_name(&self, _options: &Self::Options, child_idx: usize) -> vortex_array::scalar_fn::vtable::ChildName
294294

295-
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::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>
295+
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::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>
296296

297297
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::fmt_sql(&self, _options: &Self::Options, expr: &vortex_array::expr::expression::Expression, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
298298

@@ -466,46 +466,6 @@ pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::return_dtype(&s
466466

467467
pub fn vortex_tensor::scalar_fns::sorf_transform::SorfTransform::validity(&self, _options: &Self::Options, expression: &vortex_array::expr::expression::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::expression::Expression>>
468468

469-
pub enum vortex_tensor::scalar_fns::ApproxOptions
470-
471-
pub vortex_tensor::scalar_fns::ApproxOptions::Approximate
472-
473-
pub vortex_tensor::scalar_fns::ApproxOptions::Exact
474-
475-
impl vortex_tensor::scalar_fns::ApproxOptions
476-
477-
pub fn vortex_tensor::scalar_fns::ApproxOptions::is_approx(&self) -> bool
478-
479-
pub fn vortex_tensor::scalar_fns::ApproxOptions::is_exact(&self) -> bool
480-
481-
impl core::clone::Clone for vortex_tensor::scalar_fns::ApproxOptions
482-
483-
pub fn vortex_tensor::scalar_fns::ApproxOptions::clone(&self) -> vortex_tensor::scalar_fns::ApproxOptions
484-
485-
impl core::cmp::Eq for vortex_tensor::scalar_fns::ApproxOptions
486-
487-
impl core::cmp::PartialEq for vortex_tensor::scalar_fns::ApproxOptions
488-
489-
pub fn vortex_tensor::scalar_fns::ApproxOptions::eq(&self, other: &vortex_tensor::scalar_fns::ApproxOptions) -> bool
490-
491-
impl core::default::Default for vortex_tensor::scalar_fns::ApproxOptions
492-
493-
pub fn vortex_tensor::scalar_fns::ApproxOptions::default() -> vortex_tensor::scalar_fns::ApproxOptions
494-
495-
impl core::fmt::Debug for vortex_tensor::scalar_fns::ApproxOptions
496-
497-
pub fn vortex_tensor::scalar_fns::ApproxOptions::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
498-
499-
impl core::fmt::Display for vortex_tensor::scalar_fns::ApproxOptions
500-
501-
pub fn vortex_tensor::scalar_fns::ApproxOptions::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
502-
503-
impl core::hash::Hash for vortex_tensor::scalar_fns::ApproxOptions
504-
505-
pub fn vortex_tensor::scalar_fns::ApproxOptions::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
506-
507-
impl core::marker::StructuralPartialEq for vortex_tensor::scalar_fns::ApproxOptions
508-
509469
pub mod vortex_tensor::vector
510470

511471
pub struct vortex_tensor::vector::AnyVector

‎vortex-tensor/src/encodings/turboquant/tests/compute.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use vortex_array::arrays::fixed_size_list::FixedSizeListArrayExt;
1111
use vortex_error::VortexResult;
1212

1313
use super::*;
14-
use crate::scalar_fns::ApproxOptions;
1514
use crate::scalar_fns::cosine_similarity::CosineSimilarity;
1615
use crate::scalar_fns::l2_norm::L2Norm;
1716

@@ -29,7 +28,7 @@ fn execute_cosine_similarity(
2928
len: usize,
3029
ctx: &mut vortex_array::ExecutionCtx,
3130
) -> VortexResult<PrimitiveArray> {
32-
CosineSimilarity::try_new_array(&ApproxOptions::Exact, lhs, rhs, len)?
31+
CosineSimilarity::try_new_array(lhs, rhs, len)?
3332
.into_array()
3433
.execute(ctx)
3534
}

‎vortex-tensor/src/scalar_fns/cosine_similarity.rs‎

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_array::expr::and;
2020
use vortex_array::match_each_float_ptype;
2121
use vortex_array::scalar_fn::Arity;
2222
use vortex_array::scalar_fn::ChildName;
23+
use vortex_array::scalar_fn::EmptyOptions;
2324
use vortex_array::scalar_fn::ExecutionArgs;
2425
use vortex_array::scalar_fn::ScalarFn;
2526
use vortex_array::scalar_fn::ScalarFnId;
@@ -29,7 +30,6 @@ use vortex_buffer::Buffer;
2930
use vortex_error::VortexResult;
3031
use vortex_error::vortex_ensure;
3132

32-
use crate::scalar_fns::ApproxOptions;
3333
use crate::scalar_fns::inner_product::InnerProduct;
3434
use crate::scalar_fns::l2_denorm::L2Denorm;
3535
use crate::scalar_fns::l2_norm::L2Norm;
@@ -56,10 +56,9 @@ use crate::utils::validate_tensor_float_input;
5656
pub struct CosineSimilarity;
5757

5858
impl CosineSimilarity {
59-
/// Creates a new [`ScalarFn`] wrapping the cosine similarity operation with the given
60-
/// [`ApproxOptions`] controlling approximation behavior.
61-
pub fn new(options: &ApproxOptions) -> ScalarFn<CosineSimilarity> {
62-
ScalarFn::new(CosineSimilarity, options.clone())
59+
/// Creates a new [`ScalarFn`] wrapping the cosine similarity operation.
60+
pub fn new() -> ScalarFn<CosineSimilarity> {
61+
ScalarFn::new(CosineSimilarity, EmptyOptions)
6362
}
6463

6564
/// Constructs a [`ScalarFnArray`] that lazily computes the cosine similarity between `lhs` and
@@ -69,18 +68,13 @@ impl CosineSimilarity {
6968
///
7069
/// Returns an error if the [`ScalarFnArray`] cannot be constructed (e.g. due to dtype
7170
/// mismatches).
72-
pub fn try_new_array(
73-
options: &ApproxOptions,
74-
lhs: ArrayRef,
75-
rhs: ArrayRef,
76-
len: usize,
77-
) -> VortexResult<ScalarFnArray> {
78-
ScalarFnArray::try_new(CosineSimilarity::new(options).erased(), vec![lhs, rhs], len)
71+
pub fn try_new_array(lhs: ArrayRef, rhs: ArrayRef, len: usize) -> VortexResult<ScalarFnArray> {
72+
ScalarFnArray::try_new(CosineSimilarity::new().erased(), vec![lhs, rhs], len)
7973
}
8074
}
8175

8276
impl ScalarFnVTable for CosineSimilarity {
83-
type Options = ApproxOptions;
77+
type Options = EmptyOptions;
8478

8579
fn id(&self) -> ScalarFnId {
8680
ScalarFnId::from("vortex.tensor.cosine_similarity")
@@ -131,7 +125,7 @@ impl ScalarFnVTable for CosineSimilarity {
131125

132126
fn execute(
133127
&self,
134-
options: &Self::Options,
128+
_options: &Self::Options,
135129
args: &dyn ExecutionArgs,
136130
ctx: &mut ExecutionCtx,
137131
) -> VortexResult<ArrayRef> {
@@ -145,12 +139,12 @@ impl ScalarFnVTable for CosineSimilarity {
145139
let rhs_is_denorm = rhs_ref.is::<ExactScalarFn<L2Denorm>>();
146140

147141
if lhs_is_denorm && rhs_is_denorm {
148-
return self.execute_both_denorm(options, &lhs_ref, &rhs_ref, len, ctx);
142+
return self.execute_both_denorm(&lhs_ref, &rhs_ref, len, ctx);
149143
} else if lhs_is_denorm || rhs_is_denorm {
150144
if rhs_is_denorm {
151145
(lhs_ref, rhs_ref) = (rhs_ref, lhs_ref);
152146
}
153-
return self.execute_one_denorm(options, &lhs_ref, &rhs_ref, len, ctx);
147+
return self.execute_one_denorm(&lhs_ref, &rhs_ref, len, ctx);
154148
}
155149
}
156150

@@ -160,7 +154,7 @@ impl ScalarFnVTable for CosineSimilarity {
160154
// Compute inner product and norms as columnar operations, and propagate the options.
161155
let norm_lhs_arr = L2Norm::try_new_array(lhs_ref.clone(), len)?;
162156
let norm_rhs_arr = L2Norm::try_new_array(rhs_ref.clone(), len)?;
163-
let dot_arr = InnerProduct::try_new_array(options, lhs_ref, rhs_ref, len)?;
157+
let dot_arr = InnerProduct::try_new_array(lhs_ref, rhs_ref, len)?;
164158

165159
// Execute to get the inner product and norms of the arrays. We only fully decompress
166160
// because we need to perform special logic (guard against 0) during division.
@@ -217,7 +211,6 @@ impl CosineSimilarity {
217211
/// `cosine_similarity = dot(n_l, n_r)`.
218212
fn execute_both_denorm(
219213
&self,
220-
options: &ApproxOptions,
221214
lhs_ref: &ArrayRef,
222215
rhs_ref: &ArrayRef,
223216
len: usize,
@@ -230,8 +223,7 @@ impl CosineSimilarity {
230223

231224
// `L2Denorm` makes the normalized children authoritative, so their dot product is the
232225
// cosine similarity even for lossy storage wrappers.
233-
let dot =
234-
InnerProduct::try_new_array(options, normalized_l, normalized_r, len)?.into_array();
226+
let dot = InnerProduct::try_new_array(normalized_l, normalized_r, len)?.into_array();
235227

236228
if !matches!(validity, Validity::NonNullable) {
237229
// Masking always changes the nullability to nullable.
@@ -247,7 +239,6 @@ impl CosineSimilarity {
247239
/// The caller must pass the denorm array as `denorm_ref` and the plain array as `plain_ref`.
248240
fn execute_one_denorm(
249241
&self,
250-
options: &ApproxOptions,
251242
denorm_ref: &ArrayRef,
252243
plain_ref: &ArrayRef,
253244
len: usize,
@@ -257,7 +248,7 @@ impl CosineSimilarity {
257248

258249
let (normalized, _) = extract_l2_denorm_children(denorm_ref);
259250

260-
let dot_arr = InnerProduct::try_new_array(options, normalized, plain_ref.clone(), len)?;
251+
let dot_arr = InnerProduct::try_new_array(normalized, plain_ref.clone(), len)?;
261252
let norm_arr = L2Norm::try_new_array(plain_ref.clone(), len)?;
262253
let dot: PrimitiveArray = dot_arr.into_array().execute(ctx)?;
263254
let plain_norm: PrimitiveArray = norm_arr.into_array().execute(ctx)?;
@@ -294,13 +285,11 @@ mod tests {
294285
use vortex_array::arrays::MaskedArray;
295286
use vortex_array::arrays::PrimitiveArray;
296287
use vortex_array::arrays::ScalarFnArray;
297-
use vortex_array::scalar_fn::ScalarFn;
298288
use vortex_array::session::ArraySession;
299289
use vortex_array::validity::Validity;
300290
use vortex_error::VortexResult;
301291
use vortex_session::VortexSession;
302292

303-
use crate::scalar_fns::ApproxOptions;
304293
use crate::scalar_fns::cosine_similarity::CosineSimilarity;
305294
use crate::scalar_fns::l2_denorm::L2Denorm;
306295
use crate::utils::test_helpers::assert_close;
@@ -314,7 +303,7 @@ mod tests {
314303

315304
/// Evaluates cosine similarity between two tensor arrays and returns the result as `Vec<f64>`.
316305
fn eval_cosine_similarity(lhs: ArrayRef, rhs: ArrayRef, len: usize) -> VortexResult<Vec<f64>> {
317-
let scalar_fn = ScalarFn::new(CosineSimilarity, ApproxOptions::Exact).erased();
306+
let scalar_fn = CosineSimilarity::new().erased();
318307
let result = ScalarFnArray::try_new(scalar_fn, vec![lhs, rhs], len)?;
319308
let mut ctx = SESSION.create_execution_ctx();
320309
let prim: PrimitiveArray = result.into_array().execute(&mut ctx)?;
@@ -485,7 +474,7 @@ mod tests {
485474
let rhs = tensor_array(&[2], &[3.0, 4.0, 0.0, 1.0])?;
486475
let rhs = MaskedArray::try_new(rhs, Validity::from_iter([true, false]))?.into_array();
487476

488-
let scalar_fn = ScalarFn::new(CosineSimilarity, ApproxOptions::Exact).erased();
477+
let scalar_fn = CosineSimilarity::new().erased();
489478
let result = ScalarFnArray::try_new(scalar_fn, vec![lhs, rhs], 2)?;
490479
let mut ctx = SESSION.create_execution_ctx();
491480
let prim: PrimitiveArray = result.into_array().execute(&mut ctx)?;
@@ -577,7 +566,7 @@ mod tests {
577566
let mut ctx = SESSION.create_execution_ctx();
578567
let rhs = L2Denorm::try_new_array(normalized_r, norms_r, 2, &mut ctx)?.into_array();
579568

580-
let scalar_fn = ScalarFn::new(CosineSimilarity, ApproxOptions::Exact).erased();
569+
let scalar_fn = CosineSimilarity::new().erased();
581570
let result = ScalarFnArray::try_new(scalar_fn, vec![lhs, rhs], 2)?;
582571
let prim: PrimitiveArray = result.into_array().execute(&mut ctx)?;
583572

0 commit comments

Comments
 (0)