Skip to content

Commit fa5bcc2

Browse files
committed
Fix more type stable issues
Signed-off-by: ErikQQY <[email protected]>
1 parent e79f6ce commit fa5bcc2

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

docs/src/Derivative/derivativeapi.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ FractionalCalculus.CaputoTrap
1616
FractionalCalculus.CaputoDiethelm
1717
FractionalCalculus.CaputoHighPrecision
1818
FractionalCalculus.CaputoHighOrder
19+
FractionalCalculus.CaputoL1
20+
FractionalCalculus.CaputoL2
1921
```
2022

2123
## Grunwald Letnikov sense fractional derivative

src/Derivative/ABC.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Fractional Stochastic Differential Equations
2121
struct AtanganaSeda <: AtanganaBaleanu end
2222

2323
function fracdiff(f::FunctionAndNumber,
24-
α::Float64,
24+
α::Real,
2525
point::Real,
26-
h::Float64,
26+
h::Real,
2727
::AtanganaSeda)
2828
n::Int = round(Int, point/h)
2929
result = zero(Float64)

src/Derivative/CaputoFabrizio.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Fractional Stochastic Differential Equations
2424
struct CaputoFabrizioAS <: CaputoFabrizio end
2525

2626
function fracdiff(f::FunctionAndNumber,
27-
α::Float64,
27+
α::Real,
2828
point::Real,
29-
h::Float64,
29+
h::Real,
3030
::CaputoFabrizioAS)
3131
M = 1-α+α/gamma(α)
3232
n::Int = round(Int, point/h)
33-
result = zero(Float64)
33+
result = zero(Real)
3434
for j in 0:n
3535
result += (f((j+1)*h)-f(j*h))/h*((1-α)/α*(exp(-α/(1-α)*(n-j)*h)-exp(-α/(1-α)*(n-j+1)*h)))
3636
end

src/Derivative/Riesz.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ struct RieszOrtigueira <: Riesz end
4040

4141

4242
function fracdiff(f::FunctionAndNumber,
43-
α::Float64,
43+
α::Real,
4444
end_point::Real,
45-
h::Float64,
45+
h::Real,
4646
::RieszSymmetric)
4747
N=floor(Int, end_point/h)
4848

src/Integral/Hadamard.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function JacobiGQ(α, β, N)
8888
return diag(x), w
8989
end
9090

91-
function Jac_Frac_Diff(x, a, b,N, α, output_type)
91+
function Jac_Frac_Diff(x, a, b, N, α, output_type)
9292
if size(x, 2) !== 1
9393
x=x'
9494
end

src/Integral/RL.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function checks(f, α, start_point, end_point)
248248
end
249249
end
250250

251-
function fracint(f::FunctionAndNumber, α, start_point, end_point::Real, h::Float64, ::RLDirect)
251+
function fracint(f::FunctionAndNumber, α, start_point, end_point::Real, h::Real, ::RLDirect)
252252
#checks(f, α, start_point, end_point)
253253
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
254254
end_point == 0 ? (return 0) : nothing
@@ -261,13 +261,13 @@ function fracint(f::FunctionAndNumber, α, start_point, end_point::Real, h::Floa
261261
return result
262262
end
263263

264-
function fracint(f::FunctionAndNumber, α::Float64, end_point, h::Float64, ::RLPiecewise)::Float64
264+
function fracint(f::FunctionAndNumber, α::Real, end_point, h::Real, ::RLPiecewise)::Real
265265
#checks(f, α, 0, end_point)
266266
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
267267
end_point == 0 ? (return 0) : nothing
268268
#Initialize
269269
n = round(Int, end_point/h)
270-
result = zero(Float64)
270+
result = zero(Real)
271271

272272
@fastmath @inbounds @simd for i 0:n
273273
result += W(i, n, α)*f(i*h)
@@ -287,19 +287,19 @@ function W(i, n, α)
287287
end
288288

289289

290-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLPiecewise)::Vector
290+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLPiecewise)::Vector
291291
result = map(x->fracint(f, α, x, h, RLPiecewise()), end_point)
292292
return result
293293
end
294294

295295

296-
function fracint(f::FunctionAndNumber, α::Float64, end_point, h::Float64, ::RLIntApprox)::Float64
296+
function fracint(f::FunctionAndNumber, α::Real, end_point, h::Real, ::RLIntApprox)::Real
297297
#checks(f, α, 0, end_point)
298298
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
299299
end_point == 0 ? (return 0) : nothing
300300
α = -α
301301
n = round(Int, end_point/h)
302-
result = zero(Float64)
302+
result = zero(Real)
303303

304304
@fastmath @inbounds @simd for i 0:n-1
305305
result += (f(end_point-i*h) + f(end_point-(i+1)*h))*((i+1)^(-α) - i^(-α))
@@ -309,21 +309,21 @@ function fracint(f::FunctionAndNumber, α::Float64, end_point, h::Float64, ::RLI
309309
return result1
310310
end
311311

312-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLIntApprox)::Vector
312+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLIntApprox)::Vector
313313
result = map(x->fracint(f, α, x, h, RLIntApprox()), end_point)
314314
return result
315315
end
316316

317317

318318

319319

320-
function fracint(f::FunctionAndNumber, α::Float64, end_point::Number, h::Float64, ::RLLinearInterp)::Float64
320+
function fracint(f::FunctionAndNumber, α::Real, end_point::Number, h::Real, ::RLLinearInterp)::Real
321321
typeof(f) <: Number ? (end_point == 0 ? (return 0) : (return 2*f*sqrt(end_point/pi))) : nothing
322322
end_point == 0 ? (return 0) : nothing
323323

324324
α = -α
325325
n = round(Int, end_point/h)
326-
result = zero(Float64)
326+
result = zero(Real)
327327

328328
@fastmath @inbounds @simd for i 0:n-1
329329
result += ((i+1)*f(end_point-i*h)-i*f(end_point-(i+1)*h))/(-α)*((i+1)^(-α) - i^(-α))+(f(end_point - (i+1)*h) - f(end_point-i*h))/(1-α)*((i+1)^(1-α) - i^(1-α))
@@ -333,14 +333,14 @@ function fracint(f::FunctionAndNumber, α::Float64, end_point::Number, h::Float6
333333
return result1
334334
end
335335

336-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLLinearInterp)::Vector
336+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLLinearInterp)::Vector
337337
result = map(x->fracint(f, α, x, h, RLLinearInterp()), end_point)
338338
return result
339339
end
340340

341341

342342

343-
function fracint(f, α::Number, end_point, h::Float64, ::RLIntMatrix)
343+
function fracint(f, α::Number, end_point, h::Real, ::RLIntMatrix)
344344
N = round(Int, end_point/h+1)
345345
tspan = collect(0:h:end_point)
346346
return J(N, α, h)*f.(tspan)
@@ -356,7 +356,7 @@ function omega(n, p)
356356
return omega
357357
end
358358

359-
function J(N, p, h::Float64)
359+
function J(N, p, h::Real)
360360
result = zeros(N, N)
361361
temp = omega(N, -p)
362362

@@ -371,7 +371,7 @@ end
371371
#=
372372
RLIntSimpson Algorithm
373373
=#
374-
function fracint(f, α, point, h::Float64, ::RLIntSimpson)
374+
function fracint(f, α, point, h::Real, ::RLIntSimpson)
375375
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
376376
point == 0 ? (return 0) : nothing
377377

@@ -403,20 +403,20 @@ function ĉₖₙ(k, n, α)
403403
return ((α+2)*((n+1-k)^(1+α)+(n-k)^(1+α))-2*((n+1-k)^(2+α)-(n-k)^(2+α)))
404404
end
405405

406-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLIntSimpson)::Vector
406+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLIntSimpson)::Vector
407407
result = map(x->fracint(f, α, x, h, RLIntSimpson()), end_point)
408408
return result
409409
end
410410

411411
#=
412412
RLIntTrapezoidal Algorithm
413413
=#
414-
function fracint(f::FunctionAndNumber, α, point, h::Float64, ::RLIntTrapezoidal)
414+
function fracint(f::FunctionAndNumber, α, point, h::Real, ::RLIntTrapezoidal)
415415
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
416416
point == 0 ? (return 0) : nothing
417417

418418
N = round(Int, point/h)
419-
result = zero(Float64)
419+
result = zero(Real)
420420

421421
@fastmath @inbounds @simd for i 0:N
422422
result += aₖₙ(i, N, α)*f(i*h)
@@ -436,12 +436,12 @@ function aₖₙ(k, n, α)
436436
end
437437

438438

439-
function fracint(f::Union{Number, Function}, α, point, h::Float64, ::RLIntRectangular)
439+
function fracint(f::Union{Number, Function}, α, point, h::Real, ::RLIntRectangular)
440440
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
441441
point == 0 ? (return 0) : nothing
442442

443443
N = round(Int, point/h)
444-
result = zero(Float64)
444+
result = zero(Real)
445445

446446
@fastmath @inbounds @simd for i 0:N-1
447447
result += bₖ(N-i-1, α)*f(i*h)
@@ -454,20 +454,20 @@ function bₖ(k, α)
454454
return (k+1)^α-k^α
455455
end
456456

457-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLIntRectangular)::Vector
457+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLIntRectangular)::Vector
458458
result = map(x->fracint(f, α, x, h, RLIntRectangular()), end_point)
459459
return result
460460
end
461461

462462
#=
463463
RLIntCubicSplineInterp Algorithm, when h is 0.01 behave best
464464
=#
465-
function fracint(f, α, point, h::Float64, ::RLIntCubicSplineInterp)
465+
function fracint(f, α, point, h::Real, ::RLIntCubicSplineInterp)
466466
typeof(f) <: Number ? (point == 0 ? (return 0) : (return 2*f*sqrt(point/pi))) : nothing
467467
point == 0 ? (return 0) : nothing
468468

469469
N = round(Int, point/h)
470-
result = zero(Float64)
470+
result = zero(Real)
471471

472472
@fastmath @inbounds @simd for j 0:N
473473
result += eⱼₙ(j, N, α)*f(j*h) + h*êⱼₙ(j, N, α)*first_order(f, j*h, h)
@@ -495,7 +495,7 @@ function êⱼₙ(j, n, α)
495495
end
496496
end
497497

498-
function fracint(f::Union{Number, Function}, α::Float64, end_point::AbstractArray, h::Float64, ::RLIntCubicSplineInterp)::Vector
498+
function fracint(f::Union{Number, Function}, α::Real, end_point::AbstractArray, h::Real, ::RLIntCubicSplineInterp)::Vector
499499
result = map(x->fracint(f, α, x, h, RLIntCubicSplineInterp()), end_point)
500500
return result
501501
end

0 commit comments

Comments
 (0)