Skip to content

Commit 15e4f80

Browse files
Merge pull request #253 from JuliaDiffEq/myb/one
Add diff rule for `one`
2 parents 5220a41 + 4f523e6 commit 15e4f80

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "1.2.9"
4+
version = "1.2.10"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

src/differentials.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ end
113113

114114
derivative(::typeof(+), args::NTuple{N,Any}, ::Val) where {N} = 1
115115
derivative(::typeof(*), args::NTuple{N,Any}, ::Val{i}) where {N,i} = Operation(*, deleteat!(collect(args), i))
116+
derivative(::typeof(one), args::Tuple{<:Any}, ::Val) = 0
116117

117118
function count_order(x)
118119
@assert !(x isa Symbol) "The variable $x must have an order of differentiation that is greater or equal to 1!"

test/derivatives.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ isequal(ModelingToolkit.derivative(Operation(+, [x*y, y, z]), 1), 1)
7272
Expression[ModelingToolkit.Constant(1) ModelingToolkit.Constant(0)
7373
Differential(t)(x) ModelingToolkit.Constant(1)
7474
ModelingToolkit.Constant(0) ModelingToolkit.Constant(0)])
75+
76+
# issue 252
77+
@variables beta, alpha, delta
78+
@variables x1, x2, x3
79+
80+
# expression
81+
tmp = beta * (alpha * exp(x1) * x2 ^ (alpha - 1) + 1 - delta) / x3
82+
# derivative w.r.t. x1 and x2
83+
t1 = ModelingToolkit.gradient(tmp, [x1, x2])
84+
@test_nowarn ModelingToolkit.gradient(t1[1], [beta])

0 commit comments

Comments
 (0)