Skip to content

Commit f61157a

Browse files
committed
fix A/x and A*x differentiation
1 parent 28a9efb commit f61157a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/dual.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ function _map_dual_components!(fvalue!, fpartial!, y::AbstractArray{DT}, x::Abst
808808
# y allows res to be accessed as Array{T}
809809
yarr = reinterpret(reshape, T, y)
810810
@assert size(yarr) == (N + 1, size(y)...)
811-
ystride = size(y, 1)
811+
ystride = size(yarr, 1)
812812

813813
# calculate res values
814814
@inbounds for (j, v) in enumerate(x)
@@ -837,18 +837,21 @@ function _map_dual_components!(fvalue!, fpartial!, y::AbstractArray{DT}, x::Abst
837837
return y
838838
end
839839

840+
function Base.:\(m::Union{LowerTriangular{<:LinearAlgebra.BlasFloat},
841+
UpperTriangular{<:LinearAlgebra.BlasFloat}},
842+
x::StridedVector{<:Dual})
843+
T = valtype(eltype(x))
844+
res = copy(x)
845+
ldiv!(m, reinterpret(reshape, T, res)')
846+
return res
847+
end
848+
840849
for MT in (StridedMatrix{<:LinearAlgebra.BlasFloat},
841850
LowerTriangular{<:LinearAlgebra.BlasFloat},
842851
UpperTriangular{<:LinearAlgebra.BlasFloat})
843852

844-
@eval function Base.:\(m::$MT, x::StridedVector{<:Dual})
845-
T = valtype(eltype(x))
846-
ldiv!(m', reinterpret(reshape, T, res))
847-
return res
848-
end
849-
850853
@eval Base.:\(m::$MT, x::StridedMatrix{<:Dual}) =
851-
_map_dual_components!((x, _) -> ldiv!(m, x), (x, _, _) -> ldiv!(m, x), similar(x), x)
854+
_map_dual_components!((y, x) -> ldiv!(y, m, x), (y, x, _) -> ldiv!(y, m, x), similar(x), x)
852855

853856
@eval function Base.:*(m::$MT, x::StridedVector{<:Dual})
854857
T = valtype(eltype(x))

0 commit comments

Comments
 (0)