From eea20bae5fbb8a21c84cffe53ea316a5dc9826d7 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 15 Oct 2024 09:30:47 +0200 Subject: [PATCH] performance improvement in state_indexing --- src/state_indexing.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/state_indexing.jl b/src/state_indexing.jl index a9a6b75..1945232 100644 --- a/src/state_indexing.jl +++ b/src/state_indexing.jl @@ -252,7 +252,11 @@ for (t1, t2) in [ return MultipleGetters(ContinuousTimeseries(), sym) end sym_arr = sym isa Tuple ? collect(sym) : sym - num_observed = count(x -> is_observed(sys, x), sym) + num_observed = 0 + for s in sym + num_observed += is_observed(sys, s) + num_observed > 1 && break # exit early, we only need to know whether 0, 1, or more + end if !is_time_dependent(sys) if num_observed == 0 || num_observed == 1 && sym isa Tuple return MultipleGetters(nothing, getu.((sys,), sym)) @@ -275,7 +279,6 @@ for (t1, t2) in [ ts_idxs = collect(ts_idxs) end - num_observed = count(x -> is_observed(sys, x), sym) if num_observed == 0 || num_observed == 1 && sym isa Tuple getters = getu.((sys,), sym) return MultipleGetters(ts_idxs, getters)