Skip to content

Commit

Permalink
fix dispatch issues (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-wells authored Apr 9, 2021
1 parent c38ec1c commit 9ba72f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/NumericalIntegration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const HALF = 1//2
Compute numerical integral of y(x) from x=x[1] to x=x[end]. Return a scalar of the same type as the input. If no method is supplied, use Trapezdoial.
"""
function integrate(x,y...) end
function integrate end


"""
Expand Down Expand Up @@ -330,18 +330,7 @@ function cumul_integrate(x::AbstractVector, y::AbstractMatrix, M::IntegrationMet
end

#default behaviour
integrate(x::AbstractVector, y::AbstractVector) = integrate(x, y, Trapezoidal())

function integrate(x::AbstractVector, y::AbstractMatrix; kwargs...)
return integrate(x, y, Trapezoidal(); kwargs...)
end

integrate(X::NTuple, Y::AbstractArray) = integrate(X, Y, Trapezoidal())

cumul_integrate(x::AbstractVector, y::AbstractVector) = cumul_integrate(x, y, Trapezoidal())

function cumul_integrate(x::AbstractVector, y::AbstractMatrix; kwargs...)
return cumul_integrate(x, y, Trapezoidal(); kwargs...)
end
integrate(x, y; kwargs...) = integrate(x, y, Trapezoidal(); kwargs...)
cumul_integrate(x, y; kwargs...) = cumul_integrate(x, y, Trapezoidal(); kwargs...)

end # module
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ end
end

@test isapprox(integrate((X,Y,Z),A), hcubature(f,[0,-π,0],[2π,π,2])[1], atol=1e-4)

X = range(-π/2,stop=π/2,length=10)
Y = sin.(X)
ω = [x * y for x in X, y in Y]
res = integrate((X, Y), ω)
@test typeof(res) == Float64
end

@testset "SVector" begin
Expand Down

0 comments on commit 9ba72f8

Please # to comment.