@@ -20,6 +20,7 @@ use vortex_array::expr::and;
2020use vortex_array:: match_each_float_ptype;
2121use vortex_array:: scalar_fn:: Arity ;
2222use vortex_array:: scalar_fn:: ChildName ;
23+ use vortex_array:: scalar_fn:: EmptyOptions ;
2324use vortex_array:: scalar_fn:: ExecutionArgs ;
2425use vortex_array:: scalar_fn:: ScalarFn ;
2526use vortex_array:: scalar_fn:: ScalarFnId ;
@@ -29,7 +30,6 @@ use vortex_buffer::Buffer;
2930use vortex_error:: VortexResult ;
3031use vortex_error:: vortex_ensure;
3132
32- use crate :: scalar_fns:: ApproxOptions ;
3333use crate :: scalar_fns:: inner_product:: InnerProduct ;
3434use crate :: scalar_fns:: l2_denorm:: L2Denorm ;
3535use crate :: scalar_fns:: l2_norm:: L2Norm ;
@@ -56,10 +56,9 @@ use crate::utils::validate_tensor_float_input;
5656pub struct CosineSimilarity ;
5757
5858impl 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
8276impl 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