Skip to content

Commit 6c623ab

Browse files
author
Alexey Stukalov
committed
filter_used_params()
not used currently
1 parent 48f64cb commit 6c623ab

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/additional_functions/params_array.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,30 @@ function params_range(arr::ParamsArray; allow_gaps::Bool = false)
265265

266266
return first_i:last_i
267267
end
268+
269+
"""
270+
filter_used_params([linearindex_test], arr::ParamsArray)
271+
272+
Filter the parameters that are referenced in the `arr`, and
273+
the linear indices of the corresponding parameters pass the
274+
optional `linearindex_test`.
275+
276+
Returns the indices of the used parameters.
277+
"""
278+
function filter_used_params(linearindex_test, arr::ParamsArray)
279+
inds = Vector{Int}()
280+
for i in 1:nparams(arr)
281+
par_range = SEM.param_occurences_range(arr, i)
282+
isempty(par_range) && continue # not relevant
283+
@inbounds for j in par_range
284+
lin_ind = arr.linear_indices[j]
285+
if isnothing(linearindex_test) || linearindex_test(lin_ind)
286+
push!(inds, i)
287+
break
288+
end
289+
end
290+
end
291+
return inds
292+
end
293+
294+
filter_used_params(arr::ParamsArray) = filter_used_params(nothing, arr)

0 commit comments

Comments
 (0)