Commit e8c48bb9 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

WIP: more type golfing

parent 6a61931c
Pipeline #48332 failed with stages
in 5 minutes and 58 seconds
......@@ -93,7 +93,7 @@ function flux_variability_analysis(
end,
],
),
args = [-reactions reactions],
args = [(x,) for x in [-reactions reactions]],
analysis = (_, opt_model, ridx) -> _max_variability_flux(opt_model, ridx, ret),
workers = workers,
)
......
"""
_with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, modsname, fn)
_screen_args(argtuple, kwargtuple, modsname)
Internal helper to check the presence and shape of modification and argument
arrays in [`screen`](@ref) and pals.
"""
function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, modsname, fn)
function _screen_args(argtuple, kwargtuple, modsname)
mods = get(kwargtuple, modsname, nothing)
args = get(kwargtuple, :args, nothing)
......@@ -16,9 +16,9 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods
DomainError(args, "at least one of `$modsname` and `args` must be defined"),
)
end
fn(argtuple...; kwargtuple..., NamedTuple([modsname => ([[] for _ in args])]))
return NamedTuple{(modsname,)}(Ref([[] for _ in args]))
elseif isnothing(args)
fn(argtuple...; kwargtuple..., args = [() for _ in mods])
return (args = [() for _ in mods],)
else
if size(mods) != size(args)
throw(
......@@ -28,18 +28,18 @@ function _with_screen_args_checked(argtuple::Tuple, kwargtuple::NamedTuple, mods
),
)
end
fn(argtuple...; kwargtuple...)
return ()
end
end
"""
screen(
model::MetabolicModel;
variants::Array{Vector{Function}, N},
variants::Array{Vector}, N},
analysis::Function,
args::Array{Vector{Tuple}, N},
workers = [myid()],
)::Array where N
)::Array where {N}
Take an array of model-modifying function vectors in `variants`, and execute
the function `analysis` on all variants of the `model` specified by `variants`.
......@@ -108,26 +108,26 @@ screen(m,
```
"""
screen(args...; kwargs...) =
_with_screen_args_checked(args, kwargs, :variants, _screen_impl)
_screen_impl(args...; kwargs..., _screen_args(args, kwargs, :variants)...)
"""
_screen_impl(
model::MetabolicModel;
variants::Array{Vector{Function}, N},
variants::Array{Vector, N},
analysis::Function,
args::Array{Vector{Tuple}, N},
args::Array{Tuple, N},
workers = [myid()],
)::Array where N
)::Array where {N}
The actual implementation of [`screen`](@ref).
"""
function _screen_impl(
model::MetabolicModel;
variants::Array{Vector{Function},N},
analysis::Function,
args::Array{Vector{Tuple},N},
variants::Array{V,N},
analysis,
args::Array{A,N},
workers = [myid()],
)::Array where {N}
)::Array where {V <: AbstractVector,A,N}
map(fetch, save_at.(workers, :cobrexa_screen_variants_model, Ref(model)))
map(fetch, save_at.(workers, :cobrexa_screen_variants_analysis_fn, Ref(analysis)))
......@@ -215,8 +215,8 @@ end
screen_optmodel_modifications(
model::MetabolicModel,
optimizer;
common_modifications::Vector{Function} = [],
modifications::Array{Vector{Function},N},
common_modifications::Vector = [],
modifications::Array{Vector,N},
args::Array{Vector{Tuple},N},
analysis::Function,
workers = [myid()],
......@@ -247,20 +247,19 @@ that may be modified and acted upon. As an example, you can use modification
Note: This function is a thin argument-handling wrapper around
[`_screen_optmodel_modifications_impl`](@ref).
"""
screen_optmodel_modifications(args...; kwargs...) = _with_screen_args_checked(
args,
kwargs,
:modifications,
_screen_optmodel_modifications_impl,
screen_optmodel_modifications(args...; kwargs...) = _screen_optmodel_modifications_impl(
args...;
kwargs...,
_screen_args(args, kwargs, :modifications)...,
)
"""
_screen_optmodel_modifications_impl(
model::MetabolicModel,
optimizer;
common_modifications::Vector{Function} = [],
modifications::Array{Vector{Function},N},
args::Array{Vector{Tuple},N},
common_modifications::Vector = [],
modifications::Array{Vector,N},
args::Array{Tuple,N},
analysis::Function,
workers = [myid()],
) where N
......@@ -270,14 +269,12 @@ The actual implementation of [`screen_optmodel_modifications`](@ref).
function _screen_optmodel_modifications_impl(
model::MetabolicModel,
optimizer;
common_modifications::Vector{Function} = [],
modifications::Array{Vector{Function},N},
args::Array{Vector{Tuple},N},
common_modifications::V = [],
modifications::Array{V,N},
args::Array{A,N},
analysis::Function,
workers = [myid()],
) where {N}
(modifications, args) = _check_screen_mods_args(modifications, args, :modifications)
)::Array where {V <: AbstractVector,A,N}
map(
fetch,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment