API
Main NumFracDiff data structures
NumFracDiff.DiffMethod — Type
DiffMethodAbstract supertype for specifying numerical differentiation methods (e.g., Grünwald-Letnikov, Caputo, Riemann-Liouville).
NumFracDiff.NumDiffProblem — Type
NumDiffProblem{NumDiffFloat}
Definition of a numerical differentiation problem.
This structure stores the parameters that define the derivative
to be computed, independent of the input data. It can be reused
with multiple datasets without reallocation.
`NumDiffFloat` and `NumDiffInt` denote the numeric types used internally
by NumFracDiff.jl (typically `Float64` and `Int`).
# Fields
- `dt::NumDiffFloat`: Sampling interval (time step).
- `order::NumDiffFloat`: Derivative order. May be integer or fractional.
- `n::NumDiffInt`: Length of the data vector to be processed.
- `method::Symbol`: Numerical differentiation method. Currently supported methods include: `:caputo`, `:rl`, `:gl`.NumFracDiff.NumDiffWorkspace — Type
NumDiffWorkspace{NumDiffFloat}Workspace container for numerical differentiation routines.
This structure stores precomputed weights and preallocated buffers used during derivative evaluation. Reusing a workspace avoids memory allocations and improves performance when processing multiple signals.
NumDiffFloat denotes the numeric type used internally by NumFracDiff.jl.
Fields
weights::Vector{NumDiffFloat}: Precomputed convolution weights used by the differentiation algorithm.deriv::Vector{NumDiffFloat}: Preallocated vector where the computed derivative is stored.
NumFracDiff methods
NumFracDiff.init_workspace — Function
init_workspace(prob::NumDiffProblem) -> NumDiffWorkspace
Create a reusable workspace for numerical fractional differentiation.
Precomputes convolution weights based on the given problem `prob` and
allocates a buffer to store the derivative of a signal of length `prob.n`.
The returned workspace should be reused across calls to `compute!`
to **avoid repeated allocations** and improve performance, especially
in loops or optimization routines.
# Arguments
- `prob::NumDiffProblem` : Numerical differentiation problem definition.
# Returns
A `NumDiffWorkspace` containing:
- `weights` : Precomputed convolution weights.
- `deriv` : Preallocated vector for storing the derivative.NumFracDiff.generate_weights! — Function
generate_weights!(::RL, prob::NumDiffProblem, ws::NumDiffWorkspace)
Compute the convolution weights for the Riemann–Liouville (RL) fractional derivative
and store them **in-place** in `ws.weights`.
# Arguments
- `::RL` : dispatch type for RL methods Union{RL, RLThreads, RLShortMemCorr, RLShortMemCorrThreads}
- `prob::NumDiffProblem` : numerical differentiation problem definition
- `ws::NumDiffWorkspace` : workspace containing preallocated `weights` vector (length ≥ `prob.n`)generate_weights!(::GL, order::NumDiffFloat, L::Int, ws::NumDiffWorkspace)
Compute the convolution weights for the Grunwald-Letnikov fractional derivative
and store them **in-place** in the workspace `ws`.
# Arguments
- `::GL` : Dispatch type indicating the GL method.
- `prob::NumDiffProblem` : Numerical differentiation problem definition.
- `ws::NumDiffWorkspace` : Workspace containing preallocated `weights` field.
Must have at least `n` elements.NumFracDiff.optimal_L! — Function
optimal_L(data, prob; tol=1e-2)
Compute optimal memory length L (in samples) for the Short-Memory method.
# Arguments
- data : input signal
- prob : NumDiffProblem (must contain dt and order)
- tol : tolerated tail error
- safety : safety factor (>1 increases robustness)
Returns
-------
Integer memory length (number of time steps).NumFracDiff.compute! — Function
compute!(data::Vector{NumDiffFloat}, prob::NumDiffProblem,ws::NumDiffWorkspace)
Main compute function, dispatches into different versions of the code based on the method chosen in
the Problem struct.
The output derivative will be stored inside the workspace struct as deriv.
# Arguments
- `data::Vector{NumDiffFloat}` : Input vector .
- `prob::NumDiffProblem` : The problem struct containing `dt`, `order`, `n`, and `method`.
- `ws::NumDiffWorkspace` : Workspace containing weights and output derivative.