Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/integration_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Integration Rules
################################################################################

function _kwargs_to_string(kwargs)
return join([string(k) * " = " * string(v) for (k, v) in pairs(kwargs)], ", ")
end

abstract type IntegrationRule end

"""
Expand All @@ -18,6 +22,10 @@ struct GaussKronrod <: IntegrationRule
GaussKronrod(; kwargs...) = new(kwargs)
end

function Base.show(io::IO, rule::GaussKronrod)
print(io, "GaussKronrod(; ", _kwargs_to_string(rule.kwargs), ")")
end

"""
GaussLegendre(n)

Expand All @@ -39,6 +47,10 @@ struct GaussLegendre <: IntegrationRule
GaussLegendre(n::Int64) = new(n, FastGaussQuadrature.gausslegendre(n)...)
end

function Base.show(io::IO, rule::GaussLegendre)
print(io, "GaussLegendre(", rule.n, ")")
end

"""
HAdaptiveCubature(kwargs...)

Expand All @@ -50,3 +62,7 @@ struct HAdaptiveCubature <: IntegrationRule
kwargs::Base.Pairs
HAdaptiveCubature(; kwargs...) = new(kwargs)
end

function Base.show(io::IO, rule::HAdaptiveCubature)
print(io, "HAdaptiveCubature(; ", _kwargs_to_string(rule.kwargs), ")")
end
8 changes: 8 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import Enzyme
end

@testitem "Integration Rules" begin
@test sprint(show, GaussKronrod(; atol = 1e-12, rtol = 1e-10)) ==
"GaussKronrod(; atol = 1.0e-12, rtol = 1.0e-10)"

@test sprint(show, GaussLegendre(5)) == "GaussLegendre(5)"
@test sprint(show, HAdaptiveCubature()) == "HAdaptiveCubature(; )"
end

@testitem "Utilities" setup=[Utils] begin
# _KVector
v = Meshes.Vec(3, 4)
Expand Down
Loading