Description
Follow-up to #28504
Polars provides native row-wise dot product for fixed-size Array expressions:
import polars as pl
df = pl.DataFrame(
{
"lhs": [[1.0, 2.0], [3.0, 4.0]],
"rhs": [[10.0, 20.0], [30.0, 40.0]],
},
schema={
"lhs": pl.Array(pl.Float64, 2),
"rhs": pl.Array(pl.Float64, 2),
},
)
print(df.select(dot=pl.col("lhs").arr.dot("rhs")))
Output:
shape: (2, 1)
┌───────┐
│ dot │
│ --- │
│ f64 │
╞═══════╡
│ 50.0 │
│ 250.0 │
└───────┘
Equivalent operation is not exposed in Polars SQL:
df.sql("SELECT ARRAY_INNER_PRODUCT(lhs, rhs) AS dot FROM self")
Expected
Expose native fixed-size Array dot product as ARRAY_INNER_PRODUCT(lhs, rhs) with ARRAY_DOT_PRODUCT as alias. Both names follow existing SQL precedent in DuckDB here
For two fixed-size Array expressions, SQL function should lower directly to lhs.arr.dot(rhs) and inherit existing supertype coercion, broadcasting, null handling, output dtype, integer overflow, and execution-engine behavior.
It should not expand into (lhs * rhs).arr.sum(), which materializes an intermediate product Array.
Known-width SQL literals should also be supported:
SELECT ARRAY_INNER_PRODUCT(lhs, [10.0, 20.0]) AS dot FROM self
Polars SQL currently lowers [10.0, 20.0] to List(Float64). We need to infer inner dtype for conversion to fixed-size Array that would result one-row Array then use existing broadcasting.
Description
Follow-up to #28504
Polars provides native row-wise dot product for fixed-size Array expressions:
Output:
Equivalent operation is not exposed in Polars SQL:
Expected
Expose native fixed-size Array dot product as
ARRAY_INNER_PRODUCT(lhs, rhs)withARRAY_DOT_PRODUCTas alias. Both names follow existing SQL precedent in DuckDB hereFor two fixed-size Array expressions, SQL function should lower directly to
lhs.arr.dot(rhs)and inherit existing supertype coercion, broadcasting, null handling, output dtype, integer overflow, and execution-engine behavior.It should not expand into
(lhs * rhs).arr.sum(), which materializes an intermediate product Array.Known-width SQL literals should also be supported:
Polars SQL currently lowers [10.0, 20.0] to List(Float64). We need to infer inner dtype for conversion to fixed-size Array that would result one-row Array then use existing broadcasting.