Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.26.3"
version = "1.26.4"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
3 changes: 3 additions & 0 deletions src/projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ ProjectTo(x::Complex{<:Integer}) = ProjectTo(float(x))
for T in (Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64)
@eval ProjectTo(::$T) = ProjectTo{$T}()
end
@static if isdefined(Core, :BFloat16)
ProjectTo(::Core.BFloat16) = ProjectTo{Core.BFloat16}()
end

# In these cases we can just `convert` as we know we are dealing with plain and simple types
(::ProjectTo{T})(dx::AbstractFloat) where {T<:AbstractFloat} = convert(T, dx)
Expand Down
8 changes: 8 additions & 0 deletions test/projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ struct NoSuperType end
@test ProjectTo(Dual(1.0, 2.0))(Tangent{Dual}(; value=1.0)) isa Tangent
end

if isdefined(Core, :BFloat16)
@testset "BFloat16" begin
# Base defines no conversions to Core.BFloat16, so build one from its bits
x = reinterpret(Core.BFloat16, 0x3f80)
@test ProjectTo(x) === ProjectTo{Core.BFloat16}()
end
end

@testset "Base: arrays of numbers" begin
pvec3 = ProjectTo([1, 2, 3])
@test pvec3(1.0:3.0) === 1.0:3.0
Expand Down
Loading