Skip to content

Commit 9574967

Browse files
Remove additional Variable methods in favor of Base.copy
1 parent c044ea1 commit 9574967

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/differentials.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ function Derivative end
1212
function (D::Differential)(x::Variable)
1313
D.x === x && return Constant(1)
1414
has_dependent(x, D.x) || return Constant(0)
15-
return Variable(x,D)
15+
16+
x′ = copy(x)
17+
x′.diff = D
18+
return x′
1619
end
1720
Base.:(==)(D1::Differential, D2::Differential) = D1.order == D2.order && D1.x == D2.x
1821

19-
Variable(x::Variable, D::Differential) = Variable(x.name, x.subtype, D, x.dependents)
20-
2122
function expand_derivatives(O::Operation)
2223
@. O.args = expand_derivatives(O.args)
2324

src/variables.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ end
77

88
Variable(name; subtype::Symbol=:Variable, dependents::Vector{Variable} = Variable[]) =
99
Variable(name, subtype, nothing, dependents)
10-
Variable(name,args...;kwargs...) = Variable(name,args...;subtype=:Variable,kwargs...)
11-
12-
Variable(name,x::Variable) = Variable(name,x.value_type,
13-
x.subtype,D,x.dependents,x.description,x.flow,x.domain,
14-
x.size,x.context)
10+
Variable(name, args...; kwargs...) = Variable(name, args...; subtype=:Variable, kwargs...)
1511

1612
Parameter(name,args...;kwargs...) = Variable(name,args...;subtype=:Parameter,kwargs...)
1713
IndependentVariable(name,args...;kwargs...) = Variable(name,args...;subtype=:IndependentVariable,kwargs...)
@@ -45,6 +41,9 @@ export Variable,Parameter,Constant,DependentVariable,IndependentVariable,JumpVar
4541
@Var, @DVar, @IVar, @Param, @Const
4642

4743

44+
Base.copy(x::Variable) = Variable(x.name, x.subtype, x.diff, x.dependents)
45+
46+
4847
struct Constant <: Expression
4948
value::Number
5049
end

0 commit comments

Comments
 (0)