Skip to content

Commit 43dbff0

Browse files
committed
formatting
1 parent dd692d2 commit 43dbff0

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/dual.jl

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ struct Dual{T,V<:Real,N} <: Real
77
partials::Partials{N,V}
88
end
99

10-
1110
##############
1211
# Exceptions #
1312
##############
13+
1414
struct DualMismatchError{A,B} <: Exception
1515
a::A
1616
b::B
@@ -48,28 +48,14 @@ end
4848

4949
@inline Dual(args...) = Dual{Void}(args...)
5050

51-
###################
52-
# Promotion #
53-
###################
54-
55-
Base.@pure function Base.promote_rule(::Type{Dual{T1,V1,N1}},
56-
::Type{Dual{T2,V2,N2}}) where {T1,V1<:Real,N1,T2,V2<:Real,N2}
57-
# V1 and V2 might themselves be Dual types
58-
if T2 T1
59-
Dual{T1,promote_type(V1,Dual{T2,V2,N2}),N1}
60-
else
61-
Dual{T2,promote_type(V2,Dual{T1,V1,N1}),N2}
62-
end
63-
end
64-
6551
##############################
6652
# Utility/Accessor Functions #
6753
##############################
6854

6955
@inline value(x::Real) = x
7056
@inline value(d::Dual) = d.value
7157

72-
@inline value(::Type{T}, x::Real) where T = x
58+
@inline value(::Type{T}, x::Real) where T = x
7359
@inline value(::Type{T}, d::Dual{T}) where T = value(d)
7460
function value(::Type{T}, d::Dual{S}) where {T,S}
7561
# TODO: in the case of nested Duals, it may be possible to "transpose" the Dual objects
@@ -83,14 +69,9 @@ end
8369
@inline partials(d::Dual, i, j) = partials(d, i).partials[j]
8470
@inline partials(d::Dual, i, j, k...) = partials(partials(d, i, j), k...)
8571

86-
@inline partials(::Type{T}, x::Real, i...) where T =
87-
partials(x, i...)
88-
@inline partials(::Type{T}, d::Dual{T}, i...) where T =
89-
partials(d, i...)
90-
partials(::Type{T}, d::Dual{S}, i...) where {T,S} =
91-
throw(DualMismatchError(T,S))
92-
93-
72+
@inline partials(::Type{T}, x::Real, i...) where T = partials(x, i...)
73+
@inline partials(::Type{T}, d::Dual{T}, i...) where T = partials(d, i...)
74+
partials(::Type{T}, d::Dual{S}, i...) where {T,S} = throw(DualMismatchError(T,S))
9475

9576
@inline npartials(::Dual{T,V,N}) where {T,V,N} = N
9677
@inline npartials(::Type{Dual{T,V,N}}) where {T,V,N} = N
@@ -307,6 +288,16 @@ end
307288
# Promotion/Conversion #
308289
########################
309290

291+
Base.@pure function Base.promote_rule(::Type{Dual{T1,V1,N1}},
292+
::Type{Dual{T2,V2,N2}}) where {T1,V1<:Real,N1,T2,V2<:Real,N2}
293+
# V1 and V2 might themselves be Dual types
294+
if T2 T1
295+
Dual{T1,promote_type(V1,Dual{T2,V2,N2}),N1}
296+
else
297+
Dual{T2,promote_type(V2,Dual{T1,V1,N1}),N2}
298+
end
299+
end
300+
310301
function Base.promote_rule(::Type{Dual{T,A,N}},
311302
::Type{Dual{T,B,N}}) where {T,A<:Real,B<:Real,N}
312303
return Dual{T,promote_type(A, B),N}
@@ -337,7 +328,6 @@ Base.AbstractFloat(d::Dual{T,V,N}) where {T,V,N} = Dual{T,promote_type(V, Float1
337328

338329
@inline Base.conj(d::Dual) = d
339330

340-
341331
@inline Base.transpose(d::Dual) = d
342332

343333
@inline Base.ctranspose(d::Dual) = d

0 commit comments

Comments
 (0)