Skip to content

Commit

Permalink
Merge pull request #115 from ErikQQY/qqy/drop_unpack
Browse files Browse the repository at this point in the history
Drop UnPack
  • Loading branch information
ErikQQY authored Sep 18, 2024
2 parents eccc025 + a24d03c commit 904a322
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 109 deletions.
6 changes: 1 addition & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FractionalDiffEq"
uuid = "c7492dd8-6170-483b-af64-cefb6c377d9a"
authors = ["Qingyu Qu <erikqqy123@gmail.com>"]
version = "0.3.5"
version = "0.3.6"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
Expand All @@ -19,8 +19,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
SpecialMatrices = "928aab9d-ef52-54ac-8ca1-acd7ca42c160"
ToeplitzMatrices = "c751599d-da0a-543b-9d20-d0a503d91d24"
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"

[compat]
ConcreteStructs = "0.2.2"
Expand All @@ -37,8 +35,6 @@ SparseArrays = "1.10"
SpecialFunctions = "2.3.1"
SpecialMatrices = "3.0.0"
ToeplitzMatrices = "0.8.3"
TruncatedStacktraces = "1.4.0"
UnPack = "1.0.2"
julia = "1.10"

[extras]
Expand Down
5 changes: 1 addition & 4 deletions src/FractionalDiffEq.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
module FractionalDiffEq

using LinearAlgebra, Reexport, SciMLBase, SpecialFunctions, SparseArrays, ToeplitzMatrices,
FFTW, RecipesBase, ForwardDiff, Polynomials, TruncatedStacktraces,
HypergeometricFunctions, DiffEqBase, ConcreteStructs
FFTW, RecipesBase, ForwardDiff, Polynomials, HypergeometricFunctions, DiffEqBase, ConcreteStructs

import SciMLBase: __solve
import DiffEqBase: solve
import InvertedIndices: Not
import SpecialMatrices: Vandermonde
import FFTW: fft, ifft
import UnPack: @unpack
import Polynomials: Polynomial
import TruncatedStacktraces: @truncate_stacktrace

@reexport using DiffEqBase, SciMLBase

Expand Down
6 changes: 3 additions & 3 deletions src/delay/abm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct DelayABM <: FDDEAlgorithm end
#FIXME: Fix DelayABM method for FDDESystem : https://www.researchgate.net/publication/245538900_A_Predictor-Corrector_Scheme_For_Solving_Nonlinear_Delay_Differential_Equations_Of_Fractional_Order
#TODO: Need more works
function SciMLBase.__init(prob::FDDEProblem, alg::DelayABM; dt = 0.0, kwargs...)
@unpack f, order, u0, h, tspan, p, constant_lags = prob
(; f, order, u0, h, tspan, p, constant_lags) = prob
τ = constant_lags[1]
T = eltype(u0)
l = length(u0)
Expand Down Expand Up @@ -89,7 +89,7 @@ function SciMLBase.__init(prob::FDDEProblem, alg::DelayABM; dt = 0.0, kwargs...)
end

function SciMLBase.solve!(cache::ABMCache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, constant_algs, p, x, x0, x1, N, Ndelay, dt, kwargs = cache
(; prob, alg, mesh, u0, order, p, x, x0, x1, N, Ndelay, dt) = cache
l = length(u0)
if iip
@fastmath @inbounds @simd for n in 1:N
Expand Down Expand Up @@ -150,7 +150,7 @@ DelayABM method for system of fractional delay differential equations.
=#

function solve(FDDESys::FDDESystem, dt, ::DelayABM)
@unpack f, ϕ, α, τ, T = FDDESys
(; f, ϕ, α, τ, T) = FDDESys
len = length(ϕ)
N::Int = round(Int, T / dt)
Ndelay = round(Int, τ / dt)
Expand Down
2 changes: 1 addition & 1 deletion src/delay/matrix_form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://github.com/mandresik/system-of-linear-fractional-differential-delayed-eq
struct MatrixForm <: FDDEAlgorithm end

function solve(prob::FDDEMatrixProblem, h, ::MatrixForm)
@unpack α, τ, A, B, f, x0, tspan = prob
(; α, τ, A, B, f, x0, tspan) = prob
t0 = tspan[1]
T = tspan[2]
limit = 100
Expand Down
12 changes: 6 additions & 6 deletions src/delay/pece.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end

function SciMLBase.__init(prob::FDDEProblem, alg::DelayPECE; dt = 0.0, kwargs...)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
@unpack f, h, order, u0, constant_lags, p, tspan = prob
(; f, h, order, u0, constant_lags, p, tspan) = prob
τ = constant_lags[1]
iip = SciMLBase.isinplace(prob)
t0 = tspan[1]
Expand Down Expand Up @@ -84,7 +84,7 @@ end
end

function SciMLBase.solve!(cache::DelayPECECache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, p, dt = cache
(; prob, alg, mesh, u0, order, p, dt) = cache
maxn = length(mesh)
l = length(u0)
initial = _generate_similar_array(u0, 1, prob.h(p, 0))
Expand Down Expand Up @@ -157,7 +157,7 @@ function generalized_binomials(j, n, order, dt)
end

function v(cache::DelayPECECache{iip, T}, n) where {iip, T}
@unpack prob, mesh, dt, constant_lags, p = cache
(; prob, mesh, dt, constant_lags, p) = cache
τ = constant_lags
if typeof(τ) <: Function
m = floor.(Int, τ.(mesh) / dt)
Expand Down Expand Up @@ -191,7 +191,7 @@ function v(cache::DelayPECECache{iip, T}, n) where {iip, T}
end

function solve_fdde_with_multiple_lags(FDDE::FDDEProblem, dt)
@unpack f, h, order, constant_lags, p, tspan = FDDE
(; f, h, order, constant_lags, p, tspan) = FDDE
τ = constant_lags[1]
mesh = collect(0:dt:tspan[2])
maxn = length(mesh)
Expand Down Expand Up @@ -274,7 +274,7 @@ end
#########################For variable order FDDE###########################

function solve_fdde_with_single_lag_and_variable_order(FDDE::FDDEProblem, dt)
@unpack f, order, h, constant_lags, p, tspan = FDDE
(; f, order, h, constant_lags, p, tspan) = FDDE
iip = SciMLBase.isinplace(FDDE)
order = order[1]
τ = constant_lags[1]
Expand Down Expand Up @@ -339,7 +339,7 @@ function solve_fdde_with_single_lag_and_variable_order(FDDE::FDDEProblem, dt)
end

function solve_fdde_with_multiple_lags_and_variable_order(FDDE::FDDEProblem, dt)
@unpack f, h, order, constant_lags, p, tspan = FDDE
(; f, h, order, constant_lags, p, tspan) = FDDE
τ = constant_lags[1]
mesh = collect(0:dt:tspan[2])
maxn = length(mesh)
Expand Down
4 changes: 2 additions & 2 deletions src/delay/product_integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Base.eltype(::DelayPIEXCache{iip, T}) where {iip, T} = T

function SciMLBase.__init(prob::FDDEProblem, alg::DelayPIEX; dt = 0.0, kwargs...)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
@unpack f, order, u0, h, tspan, p, constant_lags = prob
(; f, order, u0, h, tspan, p, constant_lags) = prob
τ = constant_lags[1]
iip = SciMLBase.isinplace(prob)
T = eltype(u0)
Expand All @@ -47,7 +47,7 @@ function SciMLBase.__init(prob::FDDEProblem, alg::DelayPIEX; dt = 0.0, kwargs...
end

function SciMLBase.solve!(cache::DelayPIEXCache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, constant_lags, p, N, y0, y, g, b, dt, kwargs = cache
(; prob, alg, mesh, u0, order, constant_lags, p, N, y0, y, g, b, dt, kwargs) = cache
h_al = dt^order[1]
τ = constant_lags
l = length(u0)
Expand Down
2 changes: 1 addition & 1 deletion src/discrete/GL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

function solve(prob::FractionalDiscreteSystem, N, ::GL)
@unpack fun, α, u0, p = prob
(; fun, α, u0, p) = prob
result = zeros(Float64, length(u0), N)# Initialization
result[:, 1] = u0

Expand Down
2 changes: 1 addition & 1 deletion src/discrete/PECE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Use the PECE algorithm to solve fractional difference equations
=#

function solve(FDProb::FractionalDiscreteProblem, h, ::PECE)
@unpack fun, α, u0, tspan = FDProb
(; fun, α, u0, tspan) = FDProb
if tspan isa Tuple
T = tspan[end]
elseif tspan isa Real
Expand Down
2 changes: 1 addition & 1 deletion src/dode/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct DOMatrixDiscrete <: DODEAlgorithm end
isFunction(x) = isa(x, Function) ? true : false

function solve(prob::DODEProblem, h, ::DOMatrixDiscrete)
@unpack parameters, orders, interval, rightfun, u0, tspan = prob
(; parameters, orders, interval, rightfun, u0, tspan) = prob
N = length(tspan)
# find the index of the distributed order
DOid = findall(isFunction, orders)
Expand Down
6 changes: 3 additions & 3 deletions src/ffode/atangana_seda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function solve(prob::Union{FFMODEProblem, FFMODESystem}, h::Float64, ::AtanganaS
end
end
function solve_singletermffode(prob::Union{FFMODEProblem, FFMODESystem}, h)
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
α = order[1] # Fractional order
β = order[2] # Fractal dimension
t0 = tspan[1]
Expand Down Expand Up @@ -63,7 +63,7 @@ function solve_singletermffode(prob::Union{FFMODEProblem, FFMODESystem}, h)
end

function solve_ffodesystem(prob::FFMODESystem, h)
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
α = order[1]
β = order[2]
t0 = tspan[1]
Expand Down Expand Up @@ -120,7 +120,7 @@ function solve_ffodesystem(prob::FFMODESystem, h)
end

function solve_cf_variable_ffodesystem(prob::FFMODESystem, h)
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
α = order[1]
β = order[2]
t0 = tspan[1]
Expand Down
4 changes: 2 additions & 2 deletions src/fode/atangana_seda.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function solve(prob::FODEProblem, alg::AtanganaSedaAB; dt = 0.0)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
order = order[1]
t0 = tspan[1]
tfinal = tspan[2]
Expand Down Expand Up @@ -78,7 +78,7 @@ struct AtanganaSedaCF <: FODEAlgorithm end
#FIXME: Tests
function solve(prob::FODEProblem, ::AtanganaSedaCF; dt = 0.0)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
t0 = tspan[1]
tfinal = tspan[2]
t = collect(Float64, t0:dt:tfinal)
Expand Down
15 changes: 8 additions & 7 deletions src/fode/bdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function SciMLBase.__init(prob::FODEProblem, alg::BDF; dt = 0.0, reltol = 1e-6,
abstol = 1e-6, maxiters = 1000, kwargs...)
prob = _is_need_convert!(prob)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
t0 = tspan[1]
tfinal = tspan[2]
T = eltype(u0)
Expand Down Expand Up @@ -89,7 +89,7 @@ function SciMLBase.__init(prob::FODEProblem, alg::BDF; dt = 0.0, reltol = 1e-6,
end

function SciMLBase.solve!(cache::BDFCache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, halpha, y, fy, zn, Jfdefun, p, problem_size, m_alpha, m_alpha_factorial, r, N, Nr, Q, NNr, omega, w, s, dt, reltol, abstol, maxiters, kwargs = cache
(; prob, alg, mesh, y, r, N, Q, s, dt) = cache
tfinal = mesh[end]

BDF_first_approximations(cache)
Expand Down Expand Up @@ -120,7 +120,7 @@ end

function BDF_disegna_blocchi(
cache::BDFCache{iip, T}, L::P, ff, nx0::P, ny0::P) where {P <: Integer, iip, T}
@unpack mesh, y, fy, zn, abstol, maxiters, r, Nr, N, Jfdefun, s, w, omega, halpha, u0 = cache
(; r, Nr, N) = cache

nxi::Int = copy(nx0)
nxf::Int = copy(nx0 + L * r - 1)
Expand Down Expand Up @@ -171,7 +171,7 @@ function BDF_disegna_blocchi(
end

function BDF_quadrato(cache::BDFCache, nxi::P, nxf::P, nyi::P, nyf::P) where {P <: Integer}
@unpack problem_size, omega = cache
(; problem_size, omega) = cache

coef_beg = nxi - nyf
coef_end = nxf - nyi + 1
Expand All @@ -186,7 +186,7 @@ end

function BDF_triangolo(
cache::BDFCache{iip, T}, nxi::P, nxf::P, j0) where {P <: Integer, iip, T}
@unpack prob, mesh, problem_size, zn, Jfdefun, N, abstol, maxiters, s, w, omega, halpha, u0, m_alpha, m_alpha_factorial, p = cache
(; prob, mesh, problem_size, zn, Jfdefun, N, abstol, maxiters, s, w, omega, halpha, p) = cache
for n in nxi:min(N, nxf)
n1 = n + 1
St = ABM_starting_term(cache, mesh[n1])
Expand Down Expand Up @@ -235,7 +235,8 @@ function BDF_triangolo(
end

function BDF_first_approximations(cache::BDFCache{iip, T}) where {iip, T}
@unpack prob, mesh, abstol, problem_size, maxiters, s, halpha, omega, w, Jfdefun, u0, m_alpha, m_alpha_factorial, p = cache
(; prob, mesh, abstol, problem_size, maxiters, s, halpha, omega, w, Jfdefun, p) = cache

Im = zeros(problem_size, problem_size) + I
Ims = zeros(problem_size * s, problem_size * s) + I
Y0 = zeros(T, s * problem_size, 1)
Expand Down Expand Up @@ -365,7 +366,7 @@ end
Jf_vectorfield(t, y, Jfdefun) = Jfdefun(t, y)

function ABM_starting_term(cache::BDFCache{iip, T}, t) where {iip, T}
@unpack u0, m_alpha, mesh, m_alpha_factorial, high_order_prob = cache
(; u0, m_alpha, mesh, m_alpha_factorial, high_order_prob) = cache
t0 = mesh[1]
u0 = high_order_prob ? reshape(u0, 1, length(u0)) : u0
ys = zeros(size(u0, 1), 1)
Expand Down
12 changes: 6 additions & 6 deletions src/fode/explicit_pi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Base.eltype(::PIEXCache{iip, T}) where {iip, T} = T
function SciMLBase.__init(prob::FODEProblem, alg::PIEX; dt = 0.0, abstol = 1e-6, kwargs...)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
prob = _is_need_convert!(prob)
@unpack f, order, u0, tspan, p = prob
(; f, order, u0, tspan, p) = prob
t0 = tspan[1]
tfinal = tspan[2]
T = eltype(u0)
Expand Down Expand Up @@ -140,7 +140,7 @@ function SciMLBase.__init(prob::FODEProblem, alg::PIEX; dt = 0.0, abstol = 1e-6,
mu, abstol, index_fft, bn_fft, high_order_prob, kwargs)
end
function SciMLBase.solve!(cache::PIEXCache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, y, fy, r, N, Nr, Qr, NNr, bn, halpha1, mu, abstol, index_fft, bn_fft, kwargs = cache
(; prob, alg, mesh, u0, y, r, N, Qr) = cache
tfinal = mesh[end]
PIEX_triangolo(cache, 1, r - 1)

Expand Down Expand Up @@ -174,7 +174,7 @@ end

function PIEX_disegna_blocchi(
cache::PIEXCache{iip, T}, L::P, ff, nx0::P, ny0::P) where {P <: Integer, iip, T}
@unpack mesh, N, r, Nr = cache
(; N, r, Nr) = cache

nxi::Int = nx0
nxf::Int = nx0 + L * r - 1
Expand Down Expand Up @@ -228,7 +228,7 @@ end

function PIEX_quadrato(cache::PIEXCache{iip, T}, nxi::P, nxf::P,
nyi::P, nyf::P) where {P <: Integer, iip, T}
@unpack prob, mesh, r, N, Nr, Qr, NNr, problem_size, bn, halpha1, mu, abstol, index_fft, bn_fft = cache
(; prob, r, N, problem_size, index_fft, bn_fft) = cache
coef_end = nxf - nyi + 1
alpha_length = length(prob.order)
i_fft::Int = log2(coef_end / r)
Expand All @@ -255,7 +255,7 @@ end

function PIEX_triangolo(
cache::PIEXCache{iip, T}, nxi::P, nxf::P) where {P <: Integer, iip, T}
@unpack prob, mesh, u0, order, m_alpha, m_alpha_factorial, p, problem_size, zn, N, bn, halpha1, mu, abstol, index_fft, bn_fft, high_order_prob = cache
(; prob, mesh, order, p, problem_size, N, bn, halpha1) = cache

alpha_length = length(order)
for n in nxi:min(N, nxf)
Expand Down Expand Up @@ -283,7 +283,7 @@ function PIEX_triangolo(
end

function PIEX_system_starting_term(cache::PIEXCache{iip, T}, t) where {iip, T}
@unpack mesh, u0, m_alpha, m_alpha_factorial, high_order_prob = cache
(; mesh, u0, m_alpha, m_alpha_factorial, high_order_prob) = cache
t0 = mesh[1]
u0 = high_order_prob ? reshape(u0, 1, length(u0)) : u0
ys = zeros(size(u0, 1), 1)
Expand Down
4 changes: 2 additions & 2 deletions src/fode/grunwald_letnikov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Base.eltype(::GLCache{iip, T}) where {iip, T} = T
function SciMLBase.__init(prob::FODEProblem, alg::GL; dt = 0.0, kwargs...)
dt 0 ? throw(ArgumentError("dt must be positive")) : nothing
# GL method is only for commensurate order FODE
@unpack f, order, u0, tspan, p = prob
(; order, u0, tspan, p) = prob
t0 = tspan[1]
tfinal = tspan[2]
order = order[1]
Expand All @@ -33,7 +33,7 @@ function SciMLBase.__init(prob::FODEProblem, alg::GL; dt = 0.0, kwargs...)
end

function SciMLBase.solve!(cache::GLCache{iip, T}) where {iip, T}
@unpack prob, alg, mesh, u0, order, horder, y, p, kwargs = cache
(; prob, alg, mesh, u0, order, horder, y, p) = cache
prob = _is_need_convert!(prob)
n = length(mesh)
l = length(u0)
Expand Down
Loading

1 comment on commit 904a322

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Benchmark suite Current: 904a322 Previous: eccc025 Ratio
FLMM/Trapezoid 19422373 ns 19841908 ns 0.98
FLMM/NewtonGregory 18519249 ns 18515591.5 ns 1.00
FLMM/BDF 18570106 ns 18477555 ns 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.