Skip to content

Commit

Permalink
Change metadata allocation to allocate within the macro
Browse files Browse the repository at this point in the history
  • Loading branch information
LalitChauhan56 committed Jul 20, 2023
1 parent 375b4ba commit 27353ca
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/compound.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ macro compound(species_expr, arr_expr...)
coeffs_expr = Expr(:vect, coeffs...)
species_expr = Expr(:vect, species...)

# Ensure the expression is evaluated in the correct scope by escaping it
escaped_setcomponentcoefficients_expr = esc(setcomponentcoefficients_expr)

# Construct the expression to set the components metadata
setcomponents_expr = :($(species_name) = ModelingToolkit.setmetadata($(species_name),
Catalyst.CompoundComponents,
Expand All @@ -66,7 +63,7 @@ macro compound(species_expr, arr_expr...)

# Return a block that contains the escaped expressions
return Expr(:block, escaped_species_expr, escaped_setmetadata_expr,
escaped_setcomponents_expr, escaped_setcoefficients_expr, escaped_setcomponentcoefficients_expr)
escaped_setcomponents_expr, escaped_setcoefficients_expr)
end

# Check if a species is a compound
Expand All @@ -85,11 +82,6 @@ function components(s)
MT.getmetadata(s, CompoundComponents)

Check warning on line 82 in src/compound.jl

View check run for this annotation

Codecov / codecov/patch

src/compound.jl#L80-L82

Added lines #L80 - L82 were not covered by tests
end

component_coefficients(s::Num) = component_coefficients(MT.value(s))
function component_coefficients(s)
MT.getmetadata(s, CompoundComponentCoefficients)
end

component_coefficients(s::Num) = component_coefficients(MT.value(s))
function component_coefficients(s)
return [c => co for (c, co) in zip(components(s), coefficients(s))]

Check warning on line 87 in src/compound.jl

View check run for this annotation

Codecov / codecov/patch

src/compound.jl#L85-L87

Added lines #L85 - L87 were not covered by tests
Expand Down

0 comments on commit 27353ca

Please sign in to comment.