Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit bae8815

Browse files
don't restructure on number
1 parent 4386e22 commit bae8815

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/broyden.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::Broyden, args...;
5858
xₙ₋₁ = x
5959
fₙ₋₁ = fₙ
6060
for _ in 1:maxiters
61-
xₙ = xₙ₋₁ - ArrayInterface.restructure(xₙ₋₁, J⁻¹ * _vec(fₙ₋₁))
61+
xₙ = xₙ₋₁ - _restructure(xₙ₋₁, J⁻¹ * _vec(fₙ₋₁))
6262
fₙ = f(xₙ)
6363
Δxₙ = xₙ - xₙ₋₁
6464
Δfₙ = fₙ - fₙ₋₁
65-
J⁻¹Δfₙ = ArrayInterface.restructure(Δfₙ, J⁻¹ * _vec(Δfₙ))
66-
J⁻¹ += ArrayInterface.restructure(J⁻¹, ((_vec(Δxₙ) .- _vec(J⁻¹Δfₙ)) ./ (_vec(Δxₙ)' * _vec(J⁻¹Δfₙ))) * (_vec(Δxₙ)' * J⁻¹))
65+
J⁻¹Δfₙ = _restructure(Δfₙ, J⁻¹ * _vec(Δfₙ))
66+
J⁻¹ += _restructure(J⁻¹, ((_vec(Δxₙ) .- _vec(J⁻¹Δfₙ)) ./ (_vec(Δxₙ)' * _vec(J⁻¹Δfₙ))) * (_vec(Δxₙ)' * J⁻¹))
6767

6868
if termination_condition(fₙ, xₙ, xₙ₋₁, atol, rtol)
6969
return SciMLBase.build_solution(prob, alg, xₙ, fₙ; retcode = ReturnCode.Success)

src/klement.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function SciMLBase.__solve(prob::NonlinearProblem,
7575
F = lu(J, check = false)
7676
end
7777

78-
tmp = ArrayInterface.restructure(fₙ₋₁, F \ _vec(fₙ₋₁))
78+
tmp = _restructure(fₙ₋₁, F \ _vec(fₙ₋₁))
7979
xₙ = xₙ₋₁ - tmp
8080
fₙ = f(xₙ)
8181

@@ -92,9 +92,9 @@ function SciMLBase.__solve(prob::NonlinearProblem,
9292
Δfₙ = fₙ - fₙ₋₁
9393

9494
# Prevent division by 0
95-
denominator = ArrayInterface.restructure(Δxₙ, max.(J' .^ 2 * _vec(Δxₙ) .^ 2, 1e-9))
95+
denominator = _restructure(Δxₙ, max.(J' .^ 2 * _vec(Δxₙ) .^ 2, 1e-9))
9696

97-
k = (Δfₙ - ArrayInterface.restructure(Δxₙ, J * _vec(Δxₙ))) ./ denominator
97+
k = (Δfₙ - _restructure(Δxₙ, J * _vec(Δxₙ))) ./ denominator
9898
J += (_vec(k) * _vec(Δxₙ)' .* J) * J
9999

100100
xₙ₋₁ = xₙ

src/raphson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function SciMLBase.__solve(prob::NonlinearProblem,
100100
end
101101
iszero(fx) &&
102102
return SciMLBase.build_solution(prob, alg, x, fx; retcode = ReturnCode.Success)
103-
Δx = ArrayInterface.restructure(fx, dfx \ _vec(fx))
103+
Δx = _restructure(fx, dfx \ _vec(fx))
104104
x -= Δx
105105
if isapprox(x, xo, atol = atol, rtol = rtol)
106106
return SciMLBase.build_solution(prob, alg, x, fx; retcode = ReturnCode.Success)

src/utils.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,7 @@ end
8585

8686
@inline _vec(v) = vec(v)
8787
@inline _vec(v::Number) = v
88-
@inline _vec(v::AbstractVector) = v
88+
@inline _vec(v::AbstractVector) = v
89+
90+
@inline _restructure(y::Number, x::Number) = x
91+
@inline _restructure(y, x) = ArrayInterface.restructure(y,x)

0 commit comments

Comments
 (0)