Honor source extension coercions - #9418
Conversation
Merging this PR will improve performance by 13.25%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | words_gather_scalar[65536] |
9.4 µs | 8.3 µs | +13.25% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ct/extension-coerce-to (ec1dddb) with develop (b363fb7)
Footnotes
-
89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
f8db2db to
f7d3820
Compare
| let target_storage = array | ||
| .storage_array() | ||
| .cast(target_ext_dtype.storage_dtype().clone())?; |
There was a problem hiding this comment.
@gatesn I think this is fine? only because we said above that it can be coerced
f7d3820 to
a30d702
Compare
| if let DType::Extension(source_ext) = source { | ||
| return source_ext.can_coerce_to(self); |
There was a problem hiding this comment.
this is the only logical change
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
a30d702 to
ec1dddb
Compare
Rationale for this change
DType::can_coerce_frompreviously asked only the target extension whether it accepted a source. This leftExtVTable::can_coerce_tounused and prevented source-owned refinement types from declaring lossless widening conversions.What changes are included in this PR?
Extension coercion now checks
target.can_coerce_from(source)first, thensource.can_coerce_to(target). The coercion APIs and existing extension implementations now usesourceandtargetinstead of ambiguous names such asotherandext_dtype. DirectExtensionArraycasts only rewrap storage when the source opts in because target-side coercions can require transforming values.What APIs are changed? Are there any user-facing changes?
Extension authors can implement
ExtVTable::can_coerce_to(source, target)for storage-compatible widening conversions. Existing extensions retain their target-side behavior.