From f63ee18b92ad58f0b84d91d4c664fcf6cce3c9cc Mon Sep 17 00:00:00 2001 From: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk> Date: Wed, 21 Feb 2024 15:18:24 +0000 Subject: [PATCH] allow qvec of zero to not become a vector --- src/variables.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/variables.jl b/src/variables.jl index 9a15631..1ce233b 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -255,7 +255,11 @@ for (target_name, all_vars) in all_variables_symbols throw(VariableNotAvailable(typeof(bb), Variables.$variable_func)) catch e if $use_get_func && e isa VariableNotAvailable && hasmethod($get_func, tuple(typeof(bb))) - apply_to = $(get_func)(bb) + apply_to = try + $(get_func)(bb) + catch + throw(VariableNotAvailable(typeof(bb), Variables.$variable_func)) + end if apply_to isa AbstractBlock return Variables.$variable_func(apply_to) elseif apply_to isa NamedTuple @@ -274,7 +278,9 @@ end function qvec(bb::AbstractBlock, args...; kwargs...) value = qval(bb, args...; kwargs...) - if value isa AbstractVector + if value isa Number && iszero(value) + return value + elseif value isa AbstractVector return value else return gradient_orientation(bb) .* value -- GitLab