Skip to content

Generalize substitute_sample_time so that other backends and extend it #2708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/systems/clock_inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
ClockInference(ts, eq_domain, var_domain, inferred)
end

struct NotInferedTimeDomain end

Check warning on line 24 in src/systems/clock_inference.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Infered" should be "Inferred".
function error_sample_time(eq)
error("$eq\ncontains `SampleTime` but it is not an infered discrete equation.")

Check warning on line 26 in src/systems/clock_inference.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"infered" should be "inferred".
end
function substitute_sample_time(ci::ClockInference)
@unpack ts, eq_domain = ci
function substitute_sample_time(ci::ClockInference, ts::TearingState)
@unpack eq_domain = ci

Check warning on line 29 in src/systems/clock_inference.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/clock_inference.jl#L28-L29

Added lines #L28 - L29 were not covered by tests
eqs = copy(equations(ts))
@assert length(eqs) == length(eq_domain)
for i in eachindex(eqs)
Expand All @@ -34,7 +34,7 @@
domain = eq_domain[i]
dt = sampletime(domain)
neweq = substitute_sample_time(eq, dt)
if neweq isa NotInferedTimeDomain

Check warning on line 37 in src/systems/clock_inference.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Infered" should be "Inferred".
error_sample_time(eq)
end
eqs[i] = neweq
Expand All @@ -52,13 +52,13 @@
op = operation(ex)
args = arguments(ex)
if op == SampleTime
dt === nothing && return NotInferedTimeDomain()

Check warning on line 55 in src/systems/clock_inference.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Infered" should be "Inferred".
return dt
else
new_args = similar(args)
for (i, arg) in enumerate(args)
ex_arg = substitute_sample_time(arg, dt)
if ex_arg isa NotInferedTimeDomain

Check warning on line 61 in src/systems/clock_inference.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Infered" should be "Inferred".
return ex_arg
end
new_args[i] = ex_arg
Expand Down Expand Up @@ -112,7 +112,7 @@
end
end

ci = substitute_sample_time(ci)
ci = substitute_sample_time(ci, ts)

Check warning on line 115 in src/systems/clock_inference.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/clock_inference.jl#L115

Added line #L115 was not covered by tests
return ci
end

Expand Down
Loading