Commit ab3b340
Add promote_eltype for CuArray / ROCArray / MtlArray
`ArrayInterface.promote_eltype` only had a method for plain `Array{T, N}`
(with an explicit "no generic fallback is given" note in the docstring).
Downstream packages that pass GPU array types through
`promote_eltype` therefore hit a `MethodError` — for example,
SciML/NonlinearSolve.jl#910 tripped this on
`test/cuda_tests.jl:33 "GeneralizedFirstOrderAlgorithm"` when deriving
a Dual-eltype wrapper-signature array type for `CuArray{Float32}`:
MethodError: no method matching promote_eltype(
::Type{CuArray{Float32, 1, CUDA.DeviceMemory}},
::Type{ForwardDiff.Dual{Tag{NonlinearSolveBase.NonlinearSolveTag, Float32}, Float32, 1}})
Adds the obvious eltype-swapping method in each GPU extension,
preserving the non-eltype type parameters (`M` for `CuArray` memory
kind, `B` for `ROCArray` buffer type, `S` for `MtlArray` storage mode):
ArrayInterface.promote_eltype(
::Type{<:CuArray{T, N, M}}, ::Type{T2}
) where {T, N, M, T2} = CuArray{promote_type(T, T2), N, M}
ArrayInterface.promote_eltype(
::Type{<:ROCArray{T, N, B}}, ::Type{T2}
) where {T, N, B, T2} = ROCArray{promote_type(T, T2), N, B}
ArrayInterface.promote_eltype(
::Type{<:MtlArray{T, N, S}}, ::Type{T2}
) where {T, N, S, T2} = MtlArray{promote_type(T, T2), N, S}
Bumps patch version 7.23.0 → 7.24.0 so downstream packages can
compat-bound the new method.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 192a325 commit ab3b340
File tree
4 files changed
+19
-1
lines changed- ext
4 files changed
+19
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
0 commit comments