Skip to content

Commit 8254f9e

Browse files
committed
Try to make it non-breaking as much as possible
1 parent 1dff8c3 commit 8254f9e

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1616
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
1717
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1818
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
19-
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2019
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
2120
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2221
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -50,7 +49,6 @@ LinearAlgebra = "1.6"
5049
PackageExtensionCompat = "1"
5150
Random = "1.6"
5251
Reexport = "1"
53-
SciMLBase = "2"
5452
SciMLOperators = "0.3.7"
5553
Setfield = "1"
5654
SparseArrays = "1.6"

src/SparseDiffTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import ArrayInterface: matrix_colors
1818
import StaticArrays
1919
import StaticArrays: StaticArray
2020
# Others
21-
using SciMLBase, SciMLOperators, LinearAlgebra, Random
21+
using SciMLOperators, LinearAlgebra, Random
2222
import DataStructures: DisjointSets, find_root!, union!
2323
import SciMLOperators: update_coefficients, update_coefficients!
2424
import Setfield: @set!

src/differentiation/common.jl

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,50 @@ function JacFunctionWrapper(f::F, fu_, u, p, t) where {F}
4242
# The warning instead of error ensures a non-breaking change for users relying on an
4343
# undefined / undocumented feature
4444
fu = fu_ === nothing ? copy(u) : copy(fu_)
45+
46+
# Check this first else we were breaking things
47+
# In the next breaking release, we will fix the ordering of the checks
48+
iip = static_hasmethod(f, typeof((fu, u)))
49+
oop = static_hasmethod(f, typeof((u,)))
50+
if iip || oop
51+
if p !== nothing || t !== nothing
52+
Base.depwarn("""`p` and/or `t` provided and are not `nothing`. But we
53+
potentially detected `f(du, u)` or `f(u)`. This can be caused by:
54+
55+
1. `f(du, u)` or `f(u)` is defined, in-which case `p` and/or `t` should not be
56+
supplied.
57+
2. `f(args...)` is defined, in which case `hasmethod` can be spurious.
58+
59+
Currently, we perform the check for `f(du, u)` and `f(u)` first, but in future
60+
breaking releases, this check will be performed last, which means that if `t`
61+
is provided `f(du, u, p, t)`/`f(u, p, t)` will be given precedence, similarly
62+
if `p` is provided `f(du, u, p)`/`f(u, p)` will be given precedence.""",
63+
:JacFunctionWrapper)
64+
end
65+
return JacFunctionWrapper{iip, oop, 3, F, typeof(fu), typeof(p), typeof(t)}(f,
66+
fu, p, t)
67+
end
68+
4569
if t !== nothing
4670
iip = static_hasmethod(f, typeof((fu, u, p, t)))
4771
oop = static_hasmethod(f, typeof((u, p, t)))
4872
if !iip && !oop
49-
@warn """`p` and `t` provided but `f(u, p, t)` or `f(fu, u, p, t)` not defined
50-
for `f`! Will fallback to `f(u)` or `f(fu, u)`.""" maxlog=1
51-
else
52-
return JacFunctionWrapper{iip, oop, 1, F, typeof(fu), typeof(p), typeof(t)}(f,
53-
fu, p, t)
73+
throw(ArgumentError("""`p` and `t` provided but `f(u, p, t)` or `f(fu, u, p, t)`
74+
not defined for `f`!"""))
5475
end
55-
elseif p !== nothing && !(p isa SciMLBase.NullParameters)
76+
return JacFunctionWrapper{iip, oop, 1, F, typeof(fu), typeof(p), typeof(t)}(f,
77+
fu, p, t)
78+
elseif p !== nothing
5679
iip = static_hasmethod(f, typeof((fu, u, p)))
5780
oop = static_hasmethod(f, typeof((u, p)))
5881
if !iip && !oop
59-
@warn """`p` provided but `f(u, p)` or `f(fu, u, p)` not defined for `f`! Will
60-
fallback to `f(u)` or `f(fu, u)`.""" maxlog=1
61-
else
62-
return JacFunctionWrapper{iip, oop, 2, F, typeof(fu), typeof(p), typeof(t)}(f,
63-
fu, p, t)
82+
throw(ArgumentError("""`p` is provided but `f(u, p)` or `f(fu, u, p)`
83+
not defined for `f`!"""))
6484
end
85+
return JacFunctionWrapper{iip, oop, 2, F, typeof(fu), typeof(p), typeof(t)}(f,
86+
fu, p, t)
6587
end
66-
iip = static_hasmethod(f, typeof((fu, u)))
67-
oop = static_hasmethod(f, typeof((u,)))
68-
!iip && !oop && throw(ArgumentError("`f(u)` or `f(fu, u)` not defined for `f`"))
69-
return JacFunctionWrapper{iip, oop, 3, F, typeof(fu), typeof(p), typeof(t)}(f,
70-
fu, p, t)
88+
89+
throw(ArgumentError("""Couldn't determine the function signature of `f` to construct a
90+
JacobianWrapper!"""))
7191
end

0 commit comments

Comments
 (0)