Skip to content

Commit 7602c1f

Browse files
Merge pull request #82 from SciML/requires
Remove Requires and split to subpackages
2 parents 45baf21 + 5ff2132 commit 7602c1f

File tree

13 files changed

+368
-280
lines changed

13 files changed

+368
-280
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1414
MonteCarloIntegration = "4886b29c-78c9-11e9-0a6e-41e1f4161f7b"
1515
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1616
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
17-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1817
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
1918
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2019
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
@@ -29,7 +28,6 @@ HCubature = "1.4"
2928
MonteCarloIntegration = "0.0.1, 0.0.2, 0.0.3"
3029
QuadGK = "2.1"
3130
Reexport = "0.2, 1.0"
32-
Requires = "0.5, 1.0"
3331
ReverseDiff = "1"
3432
Zygote = "0.4.22, 0.5, 0.6"
3533
ZygoteRules = "0.2"

lib/QuadratureCuba/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 Chris Rackauckas <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

lib/QuadratureCuba/Project.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name = "QuadratureCuba"
2+
uuid = "1e5cbd8a-c439-4026-92c2-98742b2c817b"
3+
authors = ["Chris Rackauckas <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
Cuba = "8a292aeb-7a57-582c-b821-06e4c11590b1"
8+
Quadrature = "67601950-bd08-11e9-3c89-fd23fb4432d2"
9+
10+
[compat]
11+
julia = "1.6"
12+
13+
[extras]
14+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
15+
16+
[targets]
17+
test = ["Test"]
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
module QuadratureCuba
2+
3+
using Quadrature, Cuba
4+
import Quadrature: transformation_if_inf, scale_x, scale_x!
5+
6+
abstract type AbstractCubaAlgorithm <: DiffEqBase.AbstractQuadratureAlgorithm end
7+
struct CubaVegas <: AbstractCubaAlgorithm end
8+
struct CubaSUAVE <: AbstractCubaAlgorithm end
9+
struct CubaDivonne <: AbstractCubaAlgorithm end
10+
struct CubaCuhre <: AbstractCubaAlgorithm end
11+
12+
function Quadrature.__solvebp_call(prob::QuadratureProblem, alg::AbstractCubaAlgorithm, sensealg,
13+
lb, ub, p, args...;
14+
reltol=1e-8, abstol=1e-8,
15+
maxiters=alg isa CubaSUAVE ? 1000000 : typemax(Int),
16+
kwargs...)
17+
prob = transformation_if_inf(prob) #intercept for infinite transformation
18+
p = p
19+
if lb isa Number && prob.batch == 0
20+
_x = Float64[lb]
21+
elseif lb isa Number
22+
_x = zeros(length(lb), prob.batch)
23+
elseif prob.batch == 0
24+
_x = zeros(length(lb))
25+
else
26+
_x = zeros(length(lb), prob.batch)
27+
end
28+
ub = ub
29+
lb = lb
30+
31+
if prob.batch == 0
32+
if isinplace(prob)
33+
f = function (x, dx)
34+
prob.f(dx, scale_x!(_x, ub, lb, x), p)
35+
dx .*= prod((y) -> y[1] - y[2], zip(ub, lb))
36+
end
37+
else
38+
f = function (x, dx)
39+
dx .= prob.f(scale_x!(_x, ub, lb, x), p) .* prod((y) -> y[1] - y[2], zip(ub, lb))
40+
end
41+
end
42+
else
43+
if lb isa Number
44+
if isinplace(prob)
45+
f = function (x, dx)
46+
#todo check scale_x!
47+
prob.f(dx', scale_x!(view(_x, 1:length(x)), ub, lb, x), p)
48+
dx .*= prod((y) -> y[1] - y[2], zip(ub, lb))
49+
end
50+
else
51+
if prob.f([lb ub], p) isa Vector
52+
f = function (x, dx)
53+
dx .= prob.f(scale_x(ub, lb, x), p)' .* prod((y) -> y[1] - y[2], zip(ub, lb))
54+
end
55+
else
56+
f = function (x, dx)
57+
dx .= prob.f(scale_x(ub, lb, x), p) .* prod((y) -> y[1] - y[2], zip(ub, lb))
58+
end
59+
end
60+
end
61+
else
62+
if isinplace(prob)
63+
f = function (x, dx)
64+
prob.f(dx, scale_x(ub, lb, x), p)
65+
dx .*= prod((y) -> y[1] - y[2], zip(ub, lb))
66+
end
67+
else
68+
if prob.f([lb ub], p) isa Vector
69+
f = function (x, dx)
70+
dx .= prob.f(scale_x(ub, lb, x), p)' .* prod((y) -> y[1] - y[2], zip(ub, lb))
71+
end
72+
else
73+
f = function (x, dx)
74+
dx .= prob.f(scale_x(ub, lb, x), p) .* prod((y) -> y[1] - y[2], zip(ub, lb))
75+
end
76+
end
77+
end
78+
end
79+
end
80+
81+
ndim = length(lb)
82+
83+
nvec = prob.batch == 0 ? 1 : prob.batch
84+
85+
if alg isa CubaVegas
86+
out = Cuba.vegas(f, ndim, prob.nout; rtol=reltol,
87+
atol=abstol, nvec=nvec,
88+
maxevals=maxiters, kwargs...)
89+
elseif alg isa CubaSUAVE
90+
out = Cuba.suave(f, ndim, prob.nout; rtol=reltol,
91+
atol=abstol, nvec=nvec,
92+
maxevals=maxiters, kwargs...)
93+
elseif alg isa CubaDivonne
94+
out = Cuba.divonne(f, ndim, prob.nout; rtol=reltol,
95+
atol=abstol, nvec=nvec,
96+
maxevals=maxiters, kwargs...)
97+
elseif alg isa CubaCuhre
98+
out = Cuba.cuhre(f, ndim, prob.nout; rtol=reltol,
99+
atol=abstol, nvec=nvec,
100+
maxevals=maxiters, kwargs...)
101+
end
102+
103+
if isinplace(prob) || prob.batch != 0
104+
val = out.integral
105+
else
106+
if prob.nout == 1 && prob.f(lb, p) isa Number
107+
val = out.integral[1]
108+
else
109+
val = out.integral
110+
end
111+
end
112+
113+
DiffEqBase.build_solution(prob, alg, val, out.error,
114+
chi=out.probability, retcode=:Success)
115+
end
116+
117+
export CubaVegas, CubaSUAVE, CubaDivonne, CubaCuhre
118+
119+
end

lib/QuadratureCuba/test/runtests.jl

Whitespace-only changes.

lib/QuadratureCubature/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 Chris Rackauckas <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name = "QuadratureCubature"
2+
uuid = "e0ec9b62-6d54-4d46-b3b0-ad6116370d23"
3+
authors = ["Chris Rackauckas <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
Cubature = "667455a9-e2ce-5579-9412-b964f529a492"
8+
Quadrature = "67601950-bd08-11e9-3c89-fd23fb4432d2"
9+
10+
[compat]
11+
julia = "1.6"
12+
13+
[extras]
14+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
15+
16+
[targets]
17+
test = ["Test"]
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
module QuadratureCubature
2+
3+
using Quadrature, Cubature
4+
5+
import Quadrature: transformation_if_inf, scale_x, scale_x!
6+
7+
abstract type AbstractCubatureJLAlgorithm <: DiffEqBase.AbstractQuadratureAlgorithm end
8+
struct CubatureJLh <: AbstractCubatureJLAlgorithm end
9+
struct CubatureJLp <: AbstractCubatureJLAlgorithm end
10+
11+
function Quadrature.__solvebp_call(prob::QuadratureProblem,
12+
alg::AbstractCubatureJLAlgorithm,
13+
sensealg, lb, ub, p, args...;
14+
reltol=1e-8, abstol=1e-8,
15+
maxiters=typemax(Int),
16+
kwargs...)
17+
prob = transformation_if_inf(prob) #intercept for infinite transformation
18+
nout = prob.nout
19+
if nout == 1
20+
if prob.batch == 0
21+
if isinplace(prob)
22+
dx = zeros(prob.nout)
23+
f = (x) -> (prob.f(dx, x, p); dx[1])
24+
else
25+
f = (x) -> prob.f(x, p)[1]
26+
end
27+
if lb isa Number
28+
if alg isa CubatureJLh
29+
_val, err = Cubature.hquadrature(f, lb, ub;
30+
reltol=reltol, abstol=abstol,
31+
maxevals=maxiters)
32+
else
33+
_val, err = Cubature.pquadrature(f, lb, ub;
34+
reltol=reltol, abstol=abstol,
35+
maxevals=maxiters)
36+
end
37+
val = prob.f(lb, p) isa Number ? _val : [_val]
38+
else
39+
if alg isa CubatureJLh
40+
_val, err = Cubature.hcubature(f, lb, ub;
41+
reltol=reltol, abstol=abstol,
42+
maxevals=maxiters)
43+
else
44+
_val, err = Cubature.pcubature(f, lb, ub;
45+
reltol=reltol, abstol=abstol,
46+
maxevals=maxiters)
47+
end
48+
49+
if isinplace(prob) || !isa(prob.f(lb, p), Number)
50+
val = [_val]
51+
else
52+
val = _val
53+
end
54+
end
55+
else
56+
if isinplace(prob)
57+
f = (x, dx) -> prob.f(dx', x, p)
58+
elseif lb isa Number
59+
if prob.f([lb ub], p) isa Vector
60+
f = (x, dx) -> (dx .= prob.f(x', p))
61+
else
62+
f = function (x, dx)
63+
dx[:] = prob.f(x', p)
64+
end
65+
end
66+
else
67+
if prob.f([lb ub], p) isa Vector
68+
f = (x, dx) -> (dx .= prob.f(x, p))
69+
else
70+
f = function (x, dx)
71+
dx .= prob.f(x, p)[:]
72+
end
73+
end
74+
end
75+
if lb isa Number
76+
if alg isa CubatureJLh
77+
_val, err = Cubature.hquadrature_v(f, lb, ub;
78+
reltol=reltol, abstol=abstol,
79+
maxevals=maxiters)
80+
else
81+
_val, err = Cubature.pquadrature_v(f, lb, ub;
82+
reltol=reltol, abstol=abstol,
83+
maxevals=maxiters)
84+
end
85+
else
86+
if alg isa CubatureJLh
87+
_val, err = Cubature.hcubature_v(f, lb, ub;
88+
reltol=reltol, abstol=abstol,
89+
maxevals=maxiters)
90+
else
91+
_val, err = Cubature.pcubature_v(f, lb, ub;
92+
reltol=reltol, abstol=abstol,
93+
maxevals=maxiters)
94+
end
95+
end
96+
val = _val isa Number ? [_val] : _val
97+
end
98+
else
99+
if prob.batch == 0
100+
if isinplace(prob)
101+
f = (x, dx) -> (prob.f(dx, x, p); dx)
102+
else
103+
f = (x, dx) -> (dx .= prob.f(x, p))
104+
end
105+
if lb isa Number
106+
if alg isa CubatureJLh
107+
val, err = Cubature.hquadrature(nout, f, lb, ub;
108+
reltol=reltol, abstol=abstol,
109+
maxevals=maxiters)
110+
else
111+
val, err = Cubature.pquadrature(nout, f, lb, ub;
112+
reltol=reltol, abstol=abstol,
113+
maxevals=maxiters)
114+
end
115+
else
116+
if alg isa CubatureJLh
117+
val, err = Cubature.hcubature(nout, f, lb, ub;
118+
reltol=reltol, abstol=abstol,
119+
maxevals=maxiters)
120+
else
121+
val, err = Cubature.pcubature(nout, f, lb, ub;
122+
reltol=reltol, abstol=abstol,
123+
maxevals=maxiters)
124+
end
125+
end
126+
else
127+
if isinplace(prob)
128+
f = (x, dx) -> prob.f(dx, x, p)
129+
else
130+
if lb isa Number
131+
f = (x, dx) -> (dx .= prob.f(x', p))
132+
else
133+
f = (x, dx) -> (dx .= prob.f(x, p))
134+
end
135+
end
136+
137+
if lb isa Number
138+
if alg isa CubatureJLh
139+
val, err = Cubature.hquadrature_v(nout, f, lb, ub;
140+
reltol=reltol, abstol=abstol,
141+
maxevals=maxiters)
142+
else
143+
val, err = Cubature.pquadrature_v(nout, f, lb, ub;
144+
reltol=reltol, abstol=abstol,
145+
maxevals=maxiters)
146+
end
147+
else
148+
if alg isa CubatureJLh
149+
val, err = Cubature.hcubature_v(nout, f, lb, ub;
150+
reltol=reltol, abstol=abstol,
151+
maxevals=maxiters)
152+
else
153+
val, err = Cubature.pcubature_v(nout, f, lb, ub;
154+
reltol=reltol, abstol=abstol,
155+
maxevals=maxiters)
156+
end
157+
end
158+
end
159+
end
160+
DiffEqBase.build_solution(prob, alg, val, err, retcode=:Success)
161+
end
162+
163+
export CubatureJLh, CubatureJLp
164+
165+
end

lib/QuadratureCubature/test/runtests.jl

Whitespace-only changes.

0 commit comments

Comments
 (0)