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
17 changes: 17 additions & 0 deletions vortex-array/src/expr/exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;
use std::sync::LazyLock;

use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_panic;
use vortex_utils::iter::ReduceBalancedIterExt;

Expand Down Expand Up @@ -434,6 +435,22 @@ where
iter.into_iter().reduce_balanced(and)
}

/// The conjunction of an expression's child validities — i.e. the validity of a scalar function
/// whose result is null exactly when any operand is null.
///
/// This is the `ScalarFnVTable::validity` for kernels that propagate nulls and never produce a
/// null from non-null inputs (comparisons, arithmetic, most geo and tensor ops). Returning it lets
/// the planner derive the output's null mask without executing the kernel. Yields `None` when the
/// expression has no children.
pub fn union_child_validities(expression: &Expression) -> VortexResult<Option<Expression>> {
let child_validities = expression
.children()
.iter()
.map(Expression::validity)
.collect::<VortexResult<Vec<_>>>()?;
Ok(and_collect(child_validities))
}

/// Create a new [`Binary`] using the [`Add`](Operator::Add) operator.
///
/// ## Example usage
Expand Down
7 changes: 2 additions & 5 deletions vortex-tensor/src/scalar_fns/cosine_similarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use vortex_array::arrays::scalar_fn::plugin::ScalarFnArrayVTable;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability;
use vortex_array::expr::Expression;
use vortex_array::expr::and;
use vortex_array::expr::union_child_validities;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar_fn::Arity;
use vortex_array::scalar_fn::ChildName;
Expand Down Expand Up @@ -180,10 +180,7 @@ impl ScalarFnVTable for CosineSimilarity {
expression: &Expression,
) -> VortexResult<Option<Expression>> {
// The result is null if either input tensor is null.
let lhs_validity = expression.child(0).validity()?;
let rhs_validity = expression.child(1).validity()?;

Ok(Some(and(lhs_validity, rhs_validity)))
union_child_validities(expression)
}

fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
Expand Down
7 changes: 2 additions & 5 deletions vortex-tensor/src/scalar_fns/inner_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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::expr::union_child_validities;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar_fn::Arity;
use vortex_array::scalar_fn::ChildName;
Expand Down Expand Up @@ -164,10 +164,7 @@ impl ScalarFnVTable for InnerProduct {
expression: &Expression,
) -> VortexResult<Option<Expression>> {
// The result is null if either input tensor is null.
let lhs_validity = expression.child(0).validity()?;
let rhs_validity = expression.child(1).validity()?;

Ok(Some(and(lhs_validity, rhs_validity)))
union_child_validities(expression)
}

fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
Expand Down
7 changes: 2 additions & 5 deletions vortex-tensor/src/scalar_fns/l2_denorm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use vortex_array::dtype::NativePType;
use vortex_array::dtype::Nullability;
use vortex_array::dtype::proto::dtype as pb;
use vortex_array::expr::Expression;
use vortex_array::expr::and;
use vortex_array::expr::union_child_validities;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar::Scalar;
use vortex_array::scalar::ScalarValue;
Expand Down Expand Up @@ -256,10 +256,7 @@ impl ScalarFnVTable for L2Denorm {
_options: &Self::Options,
expression: &Expression,
) -> VortexResult<Option<Expression>> {
let normalized_validity = expression.child(0).validity()?;
let norms_validity = expression.child(1).validity()?;

Ok(Some(and(normalized_validity, norms_validity)))
union_child_validities(expression)
}

fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion vortex-tensor/src/scalar_fns/l2_norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use vortex_array::dtype::NativePType;
use vortex_array::dtype::Nullability;
use vortex_array::dtype::proto::dtype as pb;
use vortex_array::expr::Expression;
use vortex_array::expr::union_child_validities;
use vortex_array::match_each_float_ptype;
use vortex_array::scalar::Scalar;
use vortex_array::scalar_fn::Arity;
Expand Down Expand Up @@ -184,7 +185,7 @@ impl ScalarFnVTable for L2Norm {
expression: &Expression,
) -> VortexResult<Option<Expression>> {
// The result is null if the input tensor is null.
Ok(Some(expression.child(0).validity()?))
union_child_validities(expression)
}

fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
Expand Down
Loading