-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add downstream tests for SymbolicIndexingInterface
- Loading branch information
1 parent
aa50d32
commit 2ded1ac
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using SymbolicIndexingInterface | ||
using Symbolics | ||
|
||
struct FakeIntegrator{P} | ||
p::P | ||
end | ||
|
||
SymbolicIndexingInterface.symbolic_container(fp::FakeIntegrator) = fp.sys | ||
SymbolicIndexingInterface.parameter_values(fp::FakeIntegrator) = fp.p | ||
|
||
@variables a[1:2] b | ||
sys = SymbolCache([:x, :y, :z], [a[1], a[2], b], [:t]) | ||
p = [1.0, 2.0, 3.0] | ||
fi = FakeIntegrator(copy(p)) | ||
for (i, sym) in [(1, a[1]), (2, a[2]), (3, b), ([1,2], a), ([1, 3], [a[1], b]), ((2, 3), (a[2], b))] | ||
get = getp(sys, sym) | ||
set! = setp(sys, sym) | ||
true_value = i isa Tuple ? getindex.((p,), i) : p[i] | ||
@test get(fi) == true_value | ||
set!(fi, 0.5 .* i) | ||
@test get(fi) == 0.5 .* i | ||
set!(fi, true_value) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Symbolics | ||
using SymbolicUtils | ||
using SymbolicIndexingInterface | ||
|
||
@test all(symbolic_type.([SymbolicUtils.BasicSymbolic, Symbolics.Num]) .== | ||
(ScalarSymbolic(),)) | ||
@test symbolic_type(Symbolics.Arr) == ArraySymbolic() | ||
@variables x | ||
@test symbolic_type(x) == ScalarSymbolic() | ||
@variables y[1:3] | ||
@test symbolic_type(y) == ArraySymbolic() | ||
@test all(symbolic_type.(collect(y)) .== (ScalarSymbolic(),)) |