Skip to content

Commit eb4021c

Browse files
committed
Rename incidence to infer_incidence
1 parent 81f24b8 commit eb4021c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

test/incidence.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ walk(ex, inner, outer) = outer(ex)
1717
postwalk(f, ex) = walk(ex, x -> postwalk(f, x), f)
1818

1919
"""
20-
@incidence u₁ + u₂ + t
21-
@incidence begin
20+
@infer_incidence u₁ + u₂ + t
21+
@infer_incidence begin
2222
x = u₁ + u₂
2323
x + u₃
2424
end
25-
@incidence u₁ + u₂ true # a second argument of `true` makes it return the IR, not the Incidence
26-
@incidence exp(u₂) + u₁ # will create u₂ as the second continuous variable
25+
@infer_incidence u₁ + u₂ true # a second argument of `true` makes it return the IR, not the Incidence
26+
@infer_incidence exp(u₂) + u₁ # will create u₂ as the second continuous variable
2727
2828
Return the `Incidence` object after inferring the structure of the provided code,
2929
substituting any variables starting by 'u'. Variables are created as `continuous()`
3030
in lexicographic order, so u₂ will appear before u₁. A special `t` variable may be
3131
used, which will be created as `sim_time()`.
3232
3333
Note that if variable indices are not contiguous starting from 1, incidence annotations
34-
will not correspond to the input symbols. `@incidence 1 + u₂` for example will be inferred
34+
will not correspond to the input symbols. `@infer_incidence 1 + u₂` for example will be inferred
3535
to `Incidence(1.0 + u₁)`.
3636
"""
37-
macro incidence(ex, return_ir = false)
37+
macro infer_incidence(ex, return_ir = false)
3838
variables = Symbol[]
3939
uses_time = false
4040
ex = postwalk(ex) do subex
@@ -131,62 +131,62 @@ dependencies(row) = sort(rowvals(row) .=> nonzeros(row), by = first)
131131
@test_throws "absence of state dependence for time" Incidence(Const(0.0), IncidenceValue[linear, linear_time_dependent])
132132
end
133133

134-
incidence = @incidence t
134+
incidence = @infer_incidence t
135135
@test incidence.typ === Const(0.0)
136136
@test dependencies(incidence.row) == [1 => 1]
137137
@test repr(incidence) == "Incidence(t)"
138138

139-
incidence = @incidence 5. +ᵢ u₁
139+
incidence = @infer_incidence 5. +ᵢ u₁
140140
@test incidence.typ === Const(5.0)
141141
@test dependencies(incidence.row) == [2 => 1]
142142
@test repr(incidence) == "Incidence(5.0 + u₁)"
143143

144-
incidence = @incidence 5.0 +ᵢ t +ᵢ u₁
144+
incidence = @infer_incidence 5.0 +ᵢ t +ᵢ u₁
145145
@test incidence.typ === Const(5.0)
146146
@test dependencies(incidence.row) == [1 => 1, 2 => 1]
147147
@test repr(incidence) == "Incidence(5.0 + t + u₁)"
148148

149-
incidence = @incidence t *ᵢ u₁
149+
incidence = @infer_incidence t *ᵢ u₁
150150
@test incidence.typ === Const(0.0)
151151
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => linear_time_dependent]
152152
@test repr(incidence) == "Incidence(f(∝t, ∝u₁))"
153153

154-
incidence = @incidence u₁
154+
incidence = @infer_incidence u₁
155155
@test incidence.typ === Const(0.0)
156156
@test dependencies(incidence.row) == [2 => 1]
157157
@test repr(incidence) == "Incidence(u₁)"
158158

159-
incidence = @incidence u₁ +ᵢ u₂
159+
incidence = @infer_incidence u₁ +ᵢ u₂
160160
@test incidence.typ === Const(0.0)
161161
@test dependencies(incidence.row) == [2 => 1, 3 => 1]
162162
@test repr(incidence) == "Incidence(u₁ + u₂)"
163163

164-
incidence = @incidence u₁ *ᵢ u₂
164+
incidence = @infer_incidence u₁ *ᵢ u₂
165165
@test incidence.typ === Const(0.0)
166166
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
167167
@test repr(incidence) == "Incidence(f(∝u₁, ∝u₂))"
168168

169-
incidence = @incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₂)
169+
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₂)
170170
@test incidence.typ === Const(6.0)
171171
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
172172
@test repr(incidence) == "Incidence(6.0 + f(∝u₁, ∝u₂))"
173173

174-
incidence = @incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂)
174+
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂)
175175
@test incidence.typ === Const(6.0)
176176
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent]
177177
@test repr(incidence) == "Incidence(6.0 + f(u₁, ∝u₂))"
178178

179-
incidence = @incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂) +ᵢ u₃
179+
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂) +ᵢ u₃
180180
@test incidence.typ === Const(6.0)
181181
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent, 4 => 1.0]
182182
@test repr(incidence) == "Incidence(6.0 + u₃ + f(u₁, ∝u₂))"
183183

184-
incidence = @incidence (u₁ +ᵢ u₂) *ᵢ t
184+
incidence = @infer_incidence (u₁ +ᵢ u₂) *ᵢ t
185185
@test incidence.typ === Const(0.0)
186186
@test dependencies(incidence.row) == [1 => linear_state_dependent, (2:3 .=> linear_time_dependent)...]
187187
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂))"
188188

189-
incidence = @incidence u₁ *ᵢ u₂ +ᵢ (u₁ +ᵢ t) *ᵢ u₃
189+
incidence = @infer_incidence u₁ *ᵢ u₂ +ᵢ (u₁ +ᵢ t) *ᵢ u₃
190190
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => linear_state_dependent, 3 => linear_state_dependent, 4 => linear_time_and_state_dependent]
191191
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂, ∝u₃))"
192192

@@ -195,53 +195,53 @@ dependencies(row) = sort(rowvals(row) .=> nonzeros(row), by = first)
195195
# NOTE: Most of additive terms (`.typ`) can't be precise given the current IPO representation.
196196
# We expect `Const(0.0)` in most cases, but widen to `Float64`.
197197

198-
incidence = @incidence 1.0t * 3.0
198+
incidence = @infer_incidence 1.0t * 3.0
199199
@test dependencies(incidence.row) == [1 => linear]
200200
@test repr(incidence) == "Incidence(a + cₜ * t)"
201201

202-
incidence = @incidence (1.0 + u₁ +ᵢ u₂) * 1.0
202+
incidence = @infer_incidence (1.0 + u₁ +ᵢ u₂) * 1.0
203203
@test incidence.typ === Float64
204204
@test dependencies(incidence.row) == (2:3 .=> linear_state_dependent)
205205
@test repr(incidence) == "Incidence(a + f(∝u₁, ∝u₂))"
206206

207-
incidence = @incidence (2.0 + u₁) * (3.0 + u₂)
207+
incidence = @infer_incidence (2.0 + u₁) * (3.0 + u₂)
208208
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
209209
@test repr(incidence) == "Incidence(a + f(∝u₁, ∝u₂))"
210210

211-
incidence = @incidence 5.0 + u₁
211+
incidence = @infer_incidence 5.0 + u₁
212212
@test incidence.typ === Const(5.0)
213213
@test dependencies(incidence.row) == [2 => 1]
214214
@test repr(incidence) == "Incidence(5.0 + u₁)"
215215

216-
incidence = @incidence u₁ * u₁
216+
incidence = @infer_incidence u₁ * u₁
217217
@test dependencies(incidence.row) == [2 => nonlinear]
218218
@test repr(incidence) == "Incidence(f(u₁))"
219219

220-
incidence = @incidence t * t
220+
incidence = @infer_incidence t * t
221221
@test dependencies(incidence.row) == [1 => nonlinear]
222222
@test repr(incidence) == "Incidence(f(t))"
223223

224224
mul3(a, b, c) = a *ᵢ (b *ᵢ c)
225-
incidence = @incidence mul3(t, u₁, u₂)
225+
incidence = @infer_incidence mul3(t, u₁, u₂)
226226
@test dependencies(incidence.row) == [1 => linear_state_dependent, (2:3 .=> linear_time_and_state_dependent)...]
227227
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂))"
228228

229-
incidence = @incidence mul3(t, u₁, u₁)
229+
incidence = @infer_incidence mul3(t, u₁, u₁)
230230
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => nonlinear]
231231
@test repr(incidence) == "Incidence(f(∝t, u₁))"
232232

233-
incidence = @incidence mul3(t, u₁, t)
233+
incidence = @infer_incidence mul3(t, u₁, t)
234234
# If we knew which state is used for state dependence,
235235
# state should be inferred as linear_time_dependent.
236236
@test dependencies(incidence.row) == [1 => nonlinear, 2 => linear_time_and_state_dependent]
237237
@test repr(incidence) == "Incidence(f(t, ∝u₁))"
238238

239-
incidence = @incidence mul3(u₂, u₁, u₂)
239+
incidence = @infer_incidence mul3(u₂, u₁, u₂)
240240
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => nonlinear]
241241
@test repr(incidence) == "Incidence(f(∝u₁, u₂))"
242242

243243
_muladd(a, b, c) = a +ᵢ b *ᵢ c
244-
incidence = @incidence _muladd(u₁, u₁, u₂)
244+
incidence = @infer_incidence _muladd(u₁, u₁, u₂)
245245
# We widen to `nonlinear` because we can't yet infer that `b := u₁` is
246246
# not multiplied by `a := u₁`. The solution would be to see that `a`
247247
# is linear but state-independent and therefore can't be a factor of `b`.
@@ -252,7 +252,7 @@ dependencies(row) = sort(rowvals(row) .=> nonzeros(row), by = first)
252252
# So `c := u₁` having a state-dependent coefficient might be multiplied by `a` a.k.a itself
253253
# which would make it nonlinear, so IPO can only infer `u₁` as nonlinear.
254254
_muladd2(a, b, c, d) = d *ᵢ a +ᵢ b *ᵢ c
255-
incidence = @incidence _muladd2(u₁, u₂, u₁, u₃)
255+
incidence = @infer_incidence _muladd2(u₁, u₂, u₁, u₃)
256256
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent, 4 => linear_state_dependent]
257257
@test repr(incidence) == "Incidence(f(u₁, ∝u₂, ∝u₃))"
258258
end;

0 commit comments

Comments
 (0)