Skip to content

Commit b887031

Browse files
committed
fix A/x and A*x differentiation
1 parent ea4b724 commit b887031

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
@@ -777,7 +777,7 @@ function _map_dual_components!(fvalue!, fpartial!, y::AbstractArray{DT}, x::Abst
777777
# y allows res to be accessed as Array{T}
778778
yarr = reinterpret(reshape, T, y)
779779
@assert size(yarr) == (N + 1, size(y)...)
780-
ystride = size(y, 1)
780+
ystride = size(yarr, 1)
781781

782782
# calculate res values
783783
@inbounds for (j, v) in enumerate(x)
@@ -806,18 +806,21 @@ function _map_dual_components!(fvalue!, fpartial!, y::AbstractArray{DT}, x::Abst
806806
return y
807807
end
808808

809+
function Base.:\(m::Union{LowerTriangular{<:LinearAlgebra.BlasFloat},
810+
UpperTriangular{<:LinearAlgebra.BlasFloat}},
811+
x::StridedVector{<:Dual})
812+
T = valtype(eltype(x))
813+
res = copy(x)
814+
ldiv!(m, reinterpret(reshape, T, res)')
815+
return res
816+
end
817+
809818
for MT in (StridedMatrix{<:LinearAlgebra.BlasFloat},
810819
LowerTriangular{<:LinearAlgebra.BlasFloat},
811820
UpperTriangular{<:LinearAlgebra.BlasFloat})
812821

813-
@eval function Base.:\(m::$MT, x::StridedVector{<:Dual})
814-
T = valtype(eltype(x))
815-
ldiv!(m', reinterpret(reshape, T, res))
816-
return res
817-
end
818-
819822
@eval Base.:\(m::$MT, x::StridedMatrix{<:Dual}) =
820-
_map_dual_components!((x, _) -> ldiv!(m, x), (x, _, _) -> ldiv!(m, x), similar(x), x)
823+
_map_dual_components!((y, x) -> ldiv!(y, m, x), (y, x, _) -> ldiv!(y, m, x), similar(x), x)
821824

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

0 commit comments

Comments
 (0)