@@ -117,7 +117,7 @@ function init_nested(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, abstol = 1e-3
117117 stage = alg_stage (alg)
118118
119119 k_discrete = [__maybe_allocate_diffcache (
120- __similar (X, M, stage), chunksize, alg. jac_alg) for _ in 1 : Nig]
120+ safe_similar (X, M, stage), chunksize, alg. jac_alg) for _ in 1 : Nig]
121121
122122 bcresid_prototype, resid₁_size = __get_bcresid_prototype (prob. problem_type, prob, X)
123123
@@ -131,7 +131,7 @@ function init_nested(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, abstol = 1e-3
131131 nothing
132132 end
133133
134- defect = VectorOfArray ([__similar (X, ifelse (adaptive, M, 0 )) for _ in 1 : Nig])
134+ defect = VectorOfArray ([safe_similar (X, ifelse (adaptive, M, 0 )) for _ in 1 : Nig])
135135
136136 # Transform the functions to handle non-vector inputs
137137 bcresid_prototype = __vec (bcresid_prototype)
@@ -212,7 +212,7 @@ function init_expanded(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, abstol = 1e
212212 y = __alloc .(copy .(y₀. u)) # Runtime dispatch
213213
214214 k_discrete = [__maybe_allocate_diffcache (
215- __similar (X, M, stage), chunksize, alg. jac_alg) for _ in 1 : Nig] # Runtime dispatch
215+ safe_similar (X, M, stage), chunksize, alg. jac_alg) for _ in 1 : Nig] # Runtime dispatch
216216
217217 bcresid_prototype, resid₁_size = __get_bcresid_prototype (prob. problem_type, prob, X)
218218
@@ -436,7 +436,7 @@ function __construct_nlproblem(
436436
437437 resid_bc = cache. bcresid_prototype
438438 L = length (resid_bc)
439- resid_collocation = __similar (y, cache. M * (N - 1 ) * (stage + 1 ))
439+ resid_collocation = safe_similar (y, cache. M * (N - 1 ) * (stage + 1 ))
440440
441441 cache_bc = if iip
442442 DI. prepare_jacobian (loss_bc, resid_bc, bc_diffmode, y, Constant (cache. p))
@@ -517,7 +517,7 @@ function __construct_nlproblem(
517517 (; stage) = cache
518518 N = length (cache. mesh)
519519
520- resid_collocation = __similar (y, cache. M * (N - 1 ) * (stage + 1 ))
520+ resid_collocation = safe_similar (y, cache. M * (N - 1 ) * (stage + 1 ))
521521
522522 resid = vcat (
523523 @view (cache. bcresid_prototype[1 : prod (cache. resid_size[1 ])]), resid_collocation,
@@ -576,7 +576,7 @@ function __construct_nlproblem(
576576 N = length (cache. mesh)
577577 resid_bc = cache. bcresid_prototype
578578 L = length (resid_bc)
579- resid_collocation = __similar (y, cache. M * (N - 1 ))
579+ resid_collocation = safe_similar (y, cache. M * (N - 1 ))
580580
581581 cache_bc = if iip
582582 DI. prepare_jacobian (loss_bc, resid_bc, bc_diffmode, y, Constant (cache. p))
@@ -654,7 +654,7 @@ function __construct_nlproblem(
654654 N = length (cache. mesh)
655655
656656 resid = vcat (@view (cache. bcresid_prototype[1 : prod (cache. resid_size[1 ])]),
657- __similar (y, cache. M * (N - 1 )),
657+ safe_similar (y, cache. M * (N - 1 )),
658658 @view (cache. bcresid_prototype[(prod (cache. resid_size[1 ]) + 1 ): end ]))
659659
660660 diffmode = if jac_alg. diffmode isa AutoSparse
0 commit comments