Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
Comment thread
devmotion marked this conversation as resolved.
Outdated
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
Expand All @@ -9,6 +10,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
BFloat16s = "0.6"
Comment thread
devmotion marked this conversation as resolved.
Outdated
BenchmarkTools = "1.5"
ChainRulesCore = "1"
FiniteDifferences = "0.12.32"
Expand Down
11 changes: 11 additions & 0 deletions test/projection.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ChainRulesCore, Test
using LinearAlgebra, SparseArrays
using OffsetArrays, StaticArrays, BenchmarkTools
using BFloat16s
Comment thread
devmotion marked this conversation as resolved.
Outdated

# Like ForwardDiff.jl's Dual
struct Dual{T<:Real} <: Real
Expand Down Expand Up @@ -59,6 +60,16 @@ struct NoSuperType end
@test ProjectTo(Dual(1.0, 2.0))(Tangent{Dual}(; value=1.0)) isa Tangent
end

# BFloat16s.jl's own BFloat16, used where LLVM lacks bf16 support, is not covered
if isdefined(Core, :BFloat16) && BFloat16 === Core.BFloat16
@testset "BFloat16" begin
@test ProjectTo(BFloat16(1))(2.5f0) === BFloat16(2.5)
@test ProjectTo(BFloat16(1))(2.5) === BFloat16(2.5)
@test ProjectTo(BFloat16(1))(2) === BFloat16(2)
@test ProjectTo(BFloat16[1, 2])([1.5f0, 2.5f0]) isa Vector{BFloat16}
end
end
Comment thread
devmotion marked this conversation as resolved.
Outdated

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