From 78de952d9fc2e33e9837f9765b8362ecd8a1c1de Mon Sep 17 00:00:00 2001 From: SciML Bot Date: Thu, 31 Jul 2025 16:27:11 -0400 Subject: [PATCH] Apply JuliaFormatter to fix code formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Applied JuliaFormatter with SciML style guide - Formatted 9 files 🤖 Generated by OrgMaintenanceScripts.jl --- ext/IntegralsCubatureExt.jl | 48 +++++++++++++++++++++----------- ext/IntegralsMCIntegrationExt.jl | 3 +- src/Integrals.jl | 29 ++++++++++++------- src/sampled.jl | 8 ++++-- src/simpsons.jl | 8 ++++-- src/trapezoidal.jl | 8 ++++-- test/derivative_tests.jl | 25 ++++------------- test/inf_integral_tests.jl | 7 ++++- test/interface_tests.jl | 20 +++++++++---- 9 files changed, 94 insertions(+), 62 deletions(-) diff --git a/ext/IntegralsCubatureExt.jl b/ext/IntegralsCubatureExt.jl index 57327cca..4e3c8bea 100644 --- a/ext/IntegralsCubatureExt.jl +++ b/ext/IntegralsCubatureExt.jl @@ -35,21 +35,25 @@ function Integrals.__solvebp_call(prob::IntegralProblem, end if mid isa Number if alg isa CubatureJLh - val, err = Cubature.hquadrature_v(_f, lb, ub; + val, + err = Cubature.hquadrature_v(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) else - val, err = Cubature.pquadrature_v(_f, lb, ub; + val, + err = Cubature.pquadrature_v(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) end else if alg isa CubatureJLh - val, err = Cubature.hcubature_v(_f, lb, ub; + val, + err = Cubature.hcubature_v(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) else - val, err = Cubature.pcubature_v(_f, lb, ub; + val, + err = Cubature.pcubature_v(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) end @@ -73,21 +77,25 @@ function Integrals.__solvebp_call(prob::IntegralProblem, end if mid isa Number if alg isa CubatureJLh - val_, err = Cubature.hquadrature_v(fdim, _f, lb, ub; + val_, + err = Cubature.hquadrature_v(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) else - val_, err = Cubature.pquadrature_v(fdim, _f, lb, ub; + val_, + err = Cubature.pquadrature_v(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) end else if alg isa CubatureJLh - val_, err = Cubature.hcubature_v(fdim, _f, lb, ub; + val_, + err = Cubature.hcubature_v(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) else - val_, err = Cubature.pcubature_v(fdim, _f, lb, ub; + val_, + err = Cubature.pcubature_v(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) end @@ -102,21 +110,25 @@ function Integrals.__solvebp_call(prob::IntegralProblem, _f = u -> f(u, p) if lb isa Number if alg isa CubatureJLh - val, err = Cubature.hquadrature(_f, lb, ub; + val, + err = Cubature.hquadrature(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) else - val, err = Cubature.pquadrature(_f, lb, ub; + val, + err = Cubature.pquadrature(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) end else if alg isa CubatureJLh - val, err = Cubature.hcubature(_f, lb, ub; + val, + err = Cubature.hcubature(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) else - val, err = Cubature.pcubature(_f, lb, ub; + val, + err = Cubature.pcubature(_f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters) end @@ -133,21 +145,25 @@ function Integrals.__solvebp_call(prob::IntegralProblem, end if mid isa Number if alg isa CubatureJLh - val_, err = Cubature.hquadrature(fdim, _f, lb, ub; + val_, + err = Cubature.hquadrature(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) else - val_, err = Cubature.pquadrature(fdim, _f, lb, ub; + val_, + err = Cubature.pquadrature(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) end else if alg isa CubatureJLh - val_, err = Cubature.hcubature(fdim, _f, lb, ub; + val_, + err = Cubature.hcubature(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) else - val_, err = Cubature.pcubature(fdim, _f, lb, ub; + val_, + err = Cubature.pcubature(fdim, _f, lb, ub; reltol = reltol, abstol = abstol, maxevals = maxiters, error_norm = alg.error_norm) end diff --git a/ext/IntegralsMCIntegrationExt.jl b/ext/IntegralsMCIntegrationExt.jl index 06beb675..c7be38e3 100644 --- a/ext/IntegralsMCIntegrationExt.jl +++ b/ext/IntegralsMCIntegrationExt.jl @@ -42,7 +42,8 @@ function Integrals.__solvebp_call(prob::IntegralProblem, alg::VEGASMC, sensealg, res = integrate(_f; var, dof, inplace = isinplace(prob), type = eltype(prototype), solver = :vegasmc, niter = maxiters, verbose = -2, print = -2, alg.kws...) # the package itself is not type-stable - out::typeof(prototype), err::typeof(prototype), chi2 = if prototype isa Number + out::typeof(prototype), err::typeof(prototype), + chi2 = if prototype isa Number map(only, (res.mean, res.stdev, res.chi2)) else map(a -> reshape(a, size(prototype)), (res.mean, res.stdev, res.chi2)) diff --git a/src/Integrals.jl b/src/Integrals.jl index d49e065a..15f33d55 100644 --- a/src/Integrals.jl +++ b/src/Integrals.jl @@ -28,7 +28,8 @@ abstract type QuadSensitivityAlg end Wrapper for custom vector-Jacobian product functions in automatic differentiation. # Fields -- `vjp::V`: The vector-Jacobian product function + + - `vjp::V`: The vector-Jacobian product function """ struct ReCallVJP{V} vjp::V @@ -53,7 +54,8 @@ struct ZygoteVJP <: IntegralVJP end Uses ReverseDiff.jl for vector-Jacobian products in automatic differentiation of integrals. # Fields -- `compile::Bool`: Whether to compile the tape for better performance + + - `compile::Bool`: Whether to compile the tape for better performance """ struct ReverseDiffVJP <: IntegralVJP compile::Bool @@ -81,7 +83,8 @@ const KWARGERROR_MESSAGE = """ Exception thrown when unrecognized keyword arguments are passed to `solve`. # Fields -- `kwargs`: The keyword arguments that were passed + + - `kwargs`: The keyword arguments that were passed """ struct CommonKwargError <: Exception kwargs::Any @@ -185,7 +188,8 @@ function __solvebp_call(cache::IntegralCache, alg::QuadGKJL, sensealg, domain, p return end end - val, err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, + val, + err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, rtol = reltol, atol = abstol, order = alg.order, norm = alg.norm) else prototype = f(typeof(mid)[], p) @@ -198,19 +202,22 @@ function __solvebp_call(cache::IntegralCache, alg::QuadGKJL, sensealg, domain, p return end end - val, err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, + val, + err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, rtol = reltol, atol = abstol, order = alg.order, norm = alg.norm) end else if isinplace(f) result = f.integrand_prototype * mid # result may have different units than prototype _f = (y, u) -> f(y, u, p) - val, err = quadgk!(_f, result, lb, ub, segbuf = cache.cacheval, + val, + err = quadgk!(_f, result, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, rtol = reltol, atol = abstol, order = alg.order, norm = alg.norm) else _f = u -> f(u, p) - val, err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, + val, + err = quadgk(_f, lb, ub, segbuf = cache.cacheval, maxevals = maxiters, rtol = reltol, atol = abstol, order = alg.order, norm = alg.norm) end end @@ -244,7 +251,8 @@ function __solvebp_call(cache::IntegralCache, alg::HCubatureJL, sensealg, domain end end - val, err = if lb isa Number + val, + err = if lb isa Number hquadrature(_f, lb, ub; rtol = reltol, atol = abstol, buffer = cache.cacheval, maxevals = maxiters, norm = alg.norm, initdiv = alg.initdiv) @@ -307,8 +315,9 @@ function __solvebp_call(prob::IntegralProblem, alg::VEGAS, sensealg, domain, p; out = vegas(_f, lb, ub, rtol = reltol, atol = abstol, maxiter = maxiters, nbins = alg.nbins, debug = alg.debug, ncalls = ncalls, batch = prob.f isa BatchIntegralFunction) - val, err, chi = out isa Tuple ? out : - (out.integral_estimate, out.standard_deviation, out.chi_squared_average) + val, err, + chi = out isa Tuple ? out : + (out.integral_estimate, out.standard_deviation, out.chi_squared_average) SciMLBase.build_solution(prob, alg, val, err, chi = chi, retcode = ReturnCode.Success) end diff --git a/src/sampled.jl b/src/sampled.jl index 324b8da8..017a2739 100644 --- a/src/sampled.jl +++ b/src/sampled.jl @@ -11,8 +11,9 @@ abstract type AbstractWeights end Abstract type for quadrature weights with uniform (equally-spaced) sampling points. Implementations must have: -- field `n` for the number of points -- field `h` for the step size between points + + - field `n` for the number of points + - field `h` for the step size between points """ abstract type UniformWeights <: AbstractWeights end @inline Base.iterate(w::UniformWeights) = (0 == w.n) ? nothing : (w[1], 1) @@ -27,7 +28,8 @@ Base.size(w::UniformWeights) = (length(w),) Abstract type for quadrature weights with non-uniform (arbitrarily-spaced) sampling points. Implementations must have: -- field `x` containing the sampling points + + - field `x` containing the sampling points """ abstract type NonuniformWeights <: AbstractWeights end @inline Base.iterate(w::NonuniformWeights) = (0 == length(w.x)) ? nothing : diff --git a/src/simpsons.jl b/src/simpsons.jl index 0a7aa4a4..47bd65ac 100644 --- a/src/simpsons.jl +++ b/src/simpsons.jl @@ -4,8 +4,9 @@ Quadrature weights for Simpson's composite 1/3-3/8 rule with uniformly spaced points. # Fields -- `n::Int`: Number of points -- `h::T`: Step size between points + + - `n::Int`: Number of points + - `h::T`: Step size between points """ struct SimpsonUniformWeights{T} <: UniformWeights n::Int @@ -29,7 +30,8 @@ end Quadrature weights for Simpson's composite 1/3 rule with non-uniformly spaced points. # Fields -- `x::X`: Array of sampling points + + - `x::X`: Array of sampling points """ struct SimpsonNonuniformWeights{X <: AbstractArray} <: NonuniformWeights x::X diff --git a/src/trapezoidal.jl b/src/trapezoidal.jl index eeb31168..7cf697d3 100644 --- a/src/trapezoidal.jl +++ b/src/trapezoidal.jl @@ -4,8 +4,9 @@ Quadrature weights for the trapezoidal rule with uniformly spaced points. # Fields -- `n::Int`: Number of points -- `h::T`: Step size between points + + - `n::Int`: Number of points + - `h::T`: Step size between points """ struct TrapezoidalUniformWeights{T} <: UniformWeights n::Int @@ -22,7 +23,8 @@ end Quadrature weights for the trapezoidal rule with non-uniformly spaced points. # Fields -- `x::X`: Array of sampling points + + - `x::X`: Array of sampling points """ struct TrapezoidalNonuniformWeights{X <: AbstractArray} <: NonuniformWeights x::X diff --git a/test/derivative_tests.jl b/test/derivative_tests.jl index 50c620ec..7a21dea5 100644 --- a/test/derivative_tests.jl +++ b/test/derivative_tests.jl @@ -10,12 +10,14 @@ reltol = 1e-3 abstol = 1e-3 alg_req = Dict( - QuadratureRule(gausslegendre, n = 50) => ( + QuadratureRule(gausslegendre, + n = 50) => ( nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, allows_iip = false), GaussLegendre(n = 50) => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, allows_iip = false), - GaussLegendre(n = 50, subintervals = 3) => ( + GaussLegendre(n = 50, + subintervals = 3) => ( nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, allows_iip = false), QuadGKJL() => (nout = Inf, allows_batch = true, min_dim = 1, max_dim = 1, @@ -104,7 +106,8 @@ do_tests = function (; f, scalarize, lb, ub, p, alg, abstol, reltol) end testf(lb, ub, p) - dlb1, dub1, dp1 = Zygote.gradient( + dlb1, dub1, + dp1 = Zygote.gradient( testf, lb, ub, p isa Number && f isa BatchIntegralFunction ? Scalar(p) : p) f_lb = lb -> testf(lb, ub, p) @@ -144,7 +147,6 @@ end ### One Dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution) - req.nout > 1 || continue req.min_dim <= 1 || continue @@ -155,7 +157,6 @@ end ## One-dimensional nout for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), nout in 1:max_nout_test - req.nout > 1 || continue req.min_dim <= 1 || continue @@ -167,7 +168,6 @@ end ### N-dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test - req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -179,7 +179,6 @@ end for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test, nout in 1:max_nout_test - req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -191,7 +190,6 @@ end ### One Dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution) - req.allows_iip || continue req.nout > 1 || continue req.min_dim <= 1 || continue @@ -204,7 +202,6 @@ end ## One-dimensional nout for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), nout in 1:max_nout_test - req.allows_iip || continue req.nout > 1 || continue req.min_dim <= 1 || continue @@ -218,7 +215,6 @@ end ### N-dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test - req.allows_iip || continue req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -233,7 +229,6 @@ end for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test, nout in 1:max_nout_test - req.allows_iip || continue req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -247,7 +242,6 @@ end ### Batch, One Dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution) - req.allows_batch || continue req.nout > 1 || continue req.min_dim <= 1 || continue @@ -260,7 +254,6 @@ end ## Batch, One-dimensional nout for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), nout in 1:max_nout_test - req.allows_batch || continue req.nout > 1 || continue req.min_dim <= 1 || continue @@ -274,7 +267,6 @@ end ### Batch, N-dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test - req.allows_batch || continue req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -289,7 +281,6 @@ end for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test, nout in 1:max_nout_test - req.allows_batch || continue req.nout > 1 || continue req.min_dim <= dim <= req.max_dim || continue @@ -303,7 +294,6 @@ end ### Batch, one-dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution) - req.allows_batch || continue req.allows_iip || continue req.nout > 1 || continue @@ -317,7 +307,6 @@ end ## Batch, one-dimensional nout for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), nout in 1:max_nout_test - req.allows_batch || continue req.allows_iip || continue req.nout > 1 || continue @@ -332,7 +321,6 @@ end ### Batch, N-dimensional for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test - req.allows_batch || continue req.allows_iip || continue req.nout > 1 || continue @@ -348,7 +336,6 @@ end for (alg, req) in pairs(alg_req), (j, f) in enumerate(integrands), (i, scalarize) in enumerate(scalarize_solution), dim in 1:max_dim_test, nout in 1:max_nout_test - req.allows_batch || continue req.allows_iip || continue req.nout > 1 || continue diff --git a/test/inf_integral_tests.jl b/test/inf_integral_tests.jl index ee410832..607581ba 100644 --- a/test/inf_integral_tests.jl +++ b/test/inf_integral_tests.jl @@ -5,7 +5,8 @@ abstol = 1e-3 # not all quadratures are compatible with infinities if they evaluate the endpoints alg_req = Dict( - QuadratureRule(gausslegendre, n = 50) => ( + QuadratureRule(gausslegendre, + n = 50) => ( nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, allows_iip = false, allows_inf = true), QuadGKJL() => (nout = Inf, allows_batch = true, min_dim = 1, max_dim = 1, @@ -157,6 +158,7 @@ end # IntegralFunction{false} for (alg, req) in pairs(alg_req), (j, (; f, domain, solution)) in enumerate(problems) + req.allows_inf || continue req.nout >= length(solution) || continue req.min_dim <= length(first(domain)) <= req.max_dim || continue @@ -167,6 +169,7 @@ end # IntegralFunction{true} for (alg, req) in pairs(alg_req), (j, (; f, domain, solution)) in enumerate(problems) + req.allows_inf || continue req.nout >= length(solution) || continue req.allows_iip || continue @@ -179,6 +182,7 @@ end # BatchIntegralFunction{false} for (alg, req) in pairs(alg_req), (j, (; f, domain, solution)) in enumerate(problems) + req.allows_inf || continue req.nout >= length(solution) || continue req.allows_batch || continue @@ -191,6 +195,7 @@ end # BatchIntegralFunction{true} for (alg, req) in pairs(alg_req), (j, (; f, domain, solution)) in enumerate(problems) + req.allows_inf || continue req.nout >= length(solution) || continue req.allows_batch || continue diff --git a/test/interface_tests.jl b/test/interface_tests.jl index 93f815b5..937fd70c 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -10,7 +10,8 @@ abstol = 1e-5 alg_req = Dict( QuadGKJL() => (nout = Inf, allows_batch = true, min_dim = 1, max_dim = 1, allows_iip = true), - QuadratureRule(gausslegendre, n = 50) => ( + QuadratureRule(gausslegendre, + n = 50) => ( nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, allows_iip = false), GaussLegendre() => (nout = Inf, min_dim = 1, max_dim = 1, allows_batch = false, @@ -177,7 +178,8 @@ end for i in 1:length(integrands) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), (lb, ub)) + prob = IntegralProblem(BatchIntegralFunction(batch_f(integrands[i])), ( + lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch continue end @@ -200,7 +202,9 @@ end for i in 1:length(iip_integrands) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(BatchIntegralFunction(batch_iip_f(integrands[i]), zeros(0), max_batch = 1000), (lb, ub)) + prob = IntegralProblem( + BatchIntegralFunction(batch_iip_f(integrands[i]), zeros(0), max_batch = 1000), + (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || !req.allows_iip continue @@ -305,7 +309,8 @@ end (dim, nout) = (1, 2) for (alg, req) in pairs(alg_req) for i in 1:length(integrands_v) - prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub)) + prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), ( + lb, ub)) if req.min_dim > 1 || !req.allows_batch || req.nout < nout continue end @@ -323,7 +328,8 @@ end for i in 1:length(integrands_v) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), (lb, ub)) + prob = IntegralProblem(BatchIntegralFunction(batch_f_v(integrands_v[i], nout)), ( + lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || req.nout < nout continue @@ -343,7 +349,9 @@ end for i in 1:length(iip_integrands_v) for dim in 1:max_dim_test (lb, ub) = (ones(dim), 3ones(dim)) - prob = IntegralProblem(BatchIntegralFunction(batch_iip_f_v(integrands_v[i], nout), zeros(nout, 0)), (lb, ub)) + prob = IntegralProblem( + BatchIntegralFunction(batch_iip_f_v(integrands_v[i], nout), zeros(nout, 0)), + (lb, ub)) if dim > req.max_dim || dim < req.min_dim || !req.allows_batch || !req.allows_iip || req.nout < nout continue