Skip to content

Commit 79a44f7

Browse files
committed
Execute tensor products with RowFn
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 47c76eb commit 79a44f7

4 files changed

Lines changed: 247 additions & 231 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
//! Row-level arithmetic shared by tensor scalar functions.
55
//!
66
//! These kernels preserve the scalar functions' left-to-right floating-point arithmetic. Keeping
7-
//! the arithmetic here ensures that fused and single-result operations use the same result contract.
7+
//! the arithmetic here ensures that fused and single-result operations use the same result
8+
//! contract.
89
910
use num_traits::Float;
1011
use vortex_array::dtype::NativePType;
@@ -21,3 +22,14 @@ pub(crate) fn l2_norm_row<T: Float + NativePType>(row: &[T]) -> T {
2122

2223
sum_squared.sqrt()
2324
}
25+
26+
/// Computes `sum(lhs_i * rhs_i)` for one pair of rows.
27+
///
28+
/// Both rows must have the same length. Otherwise, trailing values are ignored and the result is
29+
/// incorrect. Callers preserve the left-to-right multiplication and accumulation order.
30+
pub(crate) fn inner_product_row<T: Float + NativePType>(lhs: &[T], rhs: &[T]) -> T {
31+
lhs.iter()
32+
.zip(rhs)
33+
.map(|(&lhs_value, &rhs_value)| lhs_value * rhs_value)
34+
.fold(T::zero(), |sum, product| sum + product)
35+
}

0 commit comments

Comments
 (0)