Skip to content

Commit 2cb2740

Browse files
m-wellsdextorious
authored andcommitted
Bug fix in ndim integration and added project file (#19)
* update and bug fix * added Project.toml * functional barrier improvement
1 parent 311d46e commit 2cb2740

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
Manifest.toml

Project.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name = "NumericalIntegration"
2+
uuid = "5f557876-c23b-11e9-3c4d-2f49abec428a"
3+
authors = ["dextorious"]
4+
version = "0.2.1"
5+
6+
[deps]
7+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
9+
10+
[compat]
11+
julia = "0.7, 1"
12+
13+
[extras]
14+
HCubature = "19dc6840-f33b-545b-b366-655c7e3ffd49"
15+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
16+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
17+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
19+
[targets]
20+
test = ["Test", "InteractiveUtils", "StaticArrays", "HCubature"]

src/NumericalIntegration.jl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,24 @@ function integrate(x::AbstractVector, y::AbstractVector, m::RombergEven)
176176
@inbounds return rombaux[maxsteps, prevrow]
177177
end
178178

179+
180+
181+
function integrate(X::Tuple{AbstractVector}, Y::AbstractVector{T}, M::IntegrationMethod) :: T where {T}
182+
return integrate(X[1], Y, M)
183+
end
179184
"""
180185
integrate(X::NTuple{N,AbstractVector}, Y::AbstractArray{T,N}, method, cache=nothing)
181186
182187
Given an n-dimensional grid of values, compute the total integral along each dim
183188
"""
184-
function integrate(X::NTuple{N,AbstractVector}, Y::AbstractArray{T,N}, M::IntegrationMethod,
185-
cache::Union{AbstractVector{T}, Nothing}=nothing) :: T where {T,N}
186-
dims = size(Y)
187-
n = dims[end]
188-
if N == 1
189-
return integrate(X[1], Y, M)
190-
else
191-
if cache == nothing
192-
cache = Vector{T}(undef, n)
193-
end
194-
x = X[1:N-1]
195-
@inbounds for i in 1:n
196-
cache[i] = integrate(x, selectdim(Y,N,i), M)
197-
end
198-
return integrate(X[end], cache, M)
189+
function integrate(X::NTuple{N,AbstractVector}, Y::AbstractArray{T,N}, M::IntegrationMethod) :: T where {T,N}
190+
n = last(size(Y))
191+
cache = Vector{T}(undef, n)
192+
x = X[1:N-1]
193+
@inbounds for i in 1:n
194+
cache[i] = integrate(x, selectdim(Y,N,i), M)
199195
end
196+
return integrate(X[end], cache, M)
200197
end
201198

202199

0 commit comments

Comments
 (0)