Skip to content

Commit

Permalink
More flexible Formula.
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergu committed Nov 27, 2024
1 parent a8013ea commit 8180341
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Frameworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ end
end
@inline update!(expression::Function; parameters...) = expression
@inline Parameters(formula::Formula) = formula.parameters
@inline @generated function (formula::Formula)(; kwargs...)
@inline @generated function (formula::Formula)(args...; kwargs...)
exprs = [:(getfield(formula.parameters, $i)) for i = 1:fieldcount(fieldtype(formula, :parameters))]
return :(formula.expression($(exprs...); kwargs...))
return :(formula.expression($(exprs...), args...; kwargs...))
end

"""
Expand Down
6 changes: 3 additions & 3 deletions test/Frameworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ end
end

@testset "Formula" begin
A(t, μ, Δ; k=SVector(0, 0)) = [
A(t, μ, Δ, k=SVector(0, 0)) = [
2t*cos(k[1]) + 2t*cos(k[2]) + μ 2im*Δ*sin(k[1]) + 2Δ*sin(k[2]);
-2im*Δ*sin(k[1]) + 2Δ*sin(k[2]) -2t*cos(k[1]) - 2t*cos(k[2]) - μ
]::Matrix{ComplexF64}
f = Formula(A, (t=1.0, μ=0.0, Δ=0.1))
@test valtype(f) == valtype(typeof(f)) == Matrix{ComplexF64}
@test eltype(f) == eltype(typeof(f)) == dtype(f) == dtype(typeof(f)) == ComplexF64
@test Parameters(f) == (t=1.0, μ=0.0, Δ=0.1)
@test f(; k=[0.0, 0.0]) [4 0; 0 -4]
@test f([0.0, 0.0]) [4 0; 0 -4]

update!(f; μ=0.3)
@test f(; k=[pi/2, pi/2]) [0.3 0.2+0.2im; 0.2-0.2im -0.3]
@test f([pi/2, pi/2]) [0.3 0.2+0.2im; 0.2-0.2im -0.3]
end

@testset "CategorizedGenerator twist" begin
Expand Down

0 comments on commit 8180341

Please sign in to comment.