Skip to content

Commit 128938c

Browse files
Add promote_eltype primitive to ArrayInterfaceCore
The description is pretty self-explanatory. I found that this is a generally missing part of the interface which is required in order to compute types generated when doing type promotions on the element types of arrays.
1 parent 951f2a4 commit 128938c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ArrayInterfaceCore.lu_instance
3333
ArrayInterfaceCore.matrix_colors
3434
ArrayInterfaceCore.issingular
3535
ArrayInterfaceCore.parent_type
36+
ArrayInterfaceCore.promote_eltype
3637
ArrayInterfaceCore.restructure
3738
ArrayInterfaceCore.safevec
3839
ArrayInterfaceCore.zeromatrix

lib/ArrayInterfaceCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterfaceCore"
22
uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2"
3-
version = "0.1.18"
3+
version = "0.1.19"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ parent_type(@nospecialize T::Type{<:Union{Base.Slice,Base.IdentityUnitRange}}) =
131131
parent_type(::Type{Diagonal{T,V}}) where {T,V} = V
132132
parent_type(T::Type) = T
133133

134+
"""
135+
promote_eltype(::Type{<:AbstractArray{T,N}}, ::Type{T2})
136+
137+
Computes the type of the `AbstractArray` that results from the element
138+
type changing to `promote_type(T,T2)`.
139+
140+
Note that no generic fallback is given.
141+
"""
142+
function promote_eltype end
143+
promote_eltype(::Type{Array{T,N}}, ::Type{T2}) where {T,T2,N} = Array{promote_type(T,T2),N}
144+
134145
"""
135146
buffer(x)
136147

0 commit comments

Comments
 (0)