Skip to content

Commit 79e3f39

Browse files
committed
More generic safe similar
1 parent c76e08f commit 79e3f39

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/NonlinearSolveBase/src/jacobian.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function construct_jacobian_cache(
4141
(linsolve === nothing || needs_concrete_A(linsolve)))
4242
needs_jac = linsolve_needs_jac || concrete_jac(alg)
4343

44-
@bb fu_cache = similar(fu)
44+
fu_cache = Utils.safe_similar(fu)
4545

4646
if !has_analytic_jac && needs_jac
4747
if autodiff === nothing
@@ -80,9 +80,9 @@ function construct_jacobian_cache(
8080
end
8181
else
8282
if eltype(f.jac_prototype) <: Bool
83-
similar(f.jac_prototype, promote_type(eltype(fu), eltype(u)))
83+
Utils.safe_similar(f.jac_prototype, promote_type(eltype(fu), eltype(u)))
8484
else
85-
similar(f.jac_prototype)
85+
Utils.safe_similar(f.jac_prototype)
8686
end
8787
end
8888
end

lib/NonlinearSolveBase/src/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ restructure(y, x) = ArrayInterface.restructure(y, x)
101101

102102
function safe_similar(x, args...; kwargs...)
103103
y = similar(x, args...; kwargs...)
104-
return init_bigfloat_array!!(y)
104+
return init_similar_array!!(y)
105105
end
106106

107-
init_bigfloat_array!!(x) = x
107+
init_similar_array!!(x) = x
108108

109-
function init_bigfloat_array!!(x::AbstractArray{<:BigFloat})
110-
ArrayInterface.can_setindex(x) && fill!(x, BigFloat(0))
109+
function init_similar_array!!(x::AbstractArray{<:T}) where {T}
110+
ArrayInterface.can_setindex(x) && fill!(x, T(0))
111111
return x
112112
end
113113

0 commit comments

Comments
 (0)