Skip to content

Commit 87c911b

Browse files
authored
Revert "Move SpecialFunctions to an extension (#564)" (#569)
This reverts commit cf27073.
1 parent 65c88d3 commit 87c911b

File tree

4 files changed

+89
-176
lines changed

4 files changed

+89
-176
lines changed

Project.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.9.10"
3+
version = "0.9.9"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -24,12 +24,6 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2424
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2525
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2626

27-
[weakdeps]
28-
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
29-
30-
[extensions]
31-
ApproxFunBaseSpecialFunctionsExt = "SpecialFunctions"
32-
3327
[compat]
3428
AbstractFFTs = "0.5, 1"
3529
Aqua = "0.6"
@@ -56,8 +50,7 @@ julia = "1.9"
5650
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
5751
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
5852
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
59-
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
6053
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6154

6255
[targets]
63-
test = ["Aqua", "Random", "Infinities", "Test", "SpecialFunctions"]
56+
test = ["Aqua", "Random", "Infinities", "Test"]

ext/ApproxFunBaseSpecialFunctionsExt.jl

Lines changed: 0 additions & 152 deletions
This file was deleted.

src/ApproxFunBase.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using IntervalSets
1616
using LinearAlgebra
1717
using LowRankMatrices
1818
using SparseArrays
19-
# using SpecialFunctions
19+
using SpecialFunctions
2020
using StaticArrays: SVector, @SArray, SArray
2121
import Statistics: mean
2222

@@ -60,6 +60,22 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, cross,
6060

6161
import SparseArrays: blockdiag
6262

63+
# import Arpack: eigs
64+
65+
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
66+
# we can't do importall Base as we replace some Base definitions
67+
import SpecialFunctions: airy, besselh,
68+
lfact, beta, lbeta,
69+
eta, zeta, polygamma, logabsgamma, loggamma,
70+
besselj, bessely, besseli, besselk, besselkx,
71+
hankelh1, hankelh2, hankelh1x, hankelh2x,
72+
# functions from Calculus.symbolic_derivatives_1arg
73+
erf, erfinv, erfc, erfcinv, erfi, gamma, lgamma,
74+
digamma, invdigamma, trigamma,
75+
airyai, airybi, airyaiprime, airybiprime,
76+
besselj0, besselj1, bessely0, bessely1,
77+
erfcx, dawson
78+
6379
import BandedMatrices: bandrange, inbands_setindex!, bandwidth,
6480
colstart, colstop, colrange, rowstart, rowstop, rowrange,
6581
bandwidths, _BandedMatrix, BandedMatrix, isbanded

src/specialfunctions.jl

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ end
164164
# ODE gives the first order ODE a special function op satisfies,
165165
# RHS is the right hand side
166166
# growth says what to use to choose a good point to impose an initial condition
167-
for (op, ODE, RHS, growth) in (
168-
(:(exp), "D-f'", "0", :(real)),
167+
for (op, ODE, RHS, growth) in ((:(exp), "D-f'", "0", :(real)),
169168
(:(asinh), "sqrt(f^2+1)*D", "f'", :(real)),
170169
(:(acosh), "sqrt(f^2-1)*D", "f'", :(real)),
171170
(:(atanh), "(1-f^2)*D", "f'", :(real)),
172-
)
171+
(:(erfcx), "D-2f*f'", "-2f'/sqrt(π)", :(real)),
172+
(:(dawson), "D+2f*f'", "f'", :(real)))
173173
L,R = Meta.parse(ODE), Meta.parse(RHS)
174174
@eval begin
175175
# depice before doing op
@@ -208,12 +208,16 @@ function specialfunctionnormalizationpoint2(op, growth, f, T = cfstype(f))
208208
xmin, xmax, opfxmin, opfxmax, opmax
209209
end
210210

211-
for (op,ODE,RHS,growth) in (
211+
for (op,ODE,RHS,growth) in ((:(erf),"f'*D^2+(2f*f'^2-f'')*D","0",:(imag)),
212+
(:(erfi),"f'*D^2-(2f*f'^2+f'')*D","0",:(real)),
212213
(:(sin),"f'*D^2-f''*D+f'^3","0",:(imag)),
213214
(:(cos),"f'*D^2-f''*D+f'^3","0",:(imag)),
214215
(:(sinh),"f'*D^2-f''*D-f'^3","0",:(real)),
215216
(:(cosh),"f'*D^2-f''*D-f'^3","0",:(real)),
216-
)
217+
(:(airyai),"f'*D^2-f''*D-f*f'^3","0",:(imag)),
218+
(:(airybi),"f'*D^2-f''*D-f*f'^3","0",:(imag)),
219+
(:(airyaiprime),"f'*D^2-f''*D-f*f'^3","airyai(f)*f'^3",:(imag)),
220+
(:(airybiprime),"f'*D^2-f''*D-f*f'^3","airybi(f)*f'^3",:(imag)))
217221
L,R = Meta.parse(ODE),Meta.parse(RHS)
218222
@eval begin
219223
function $op(fin::Fun)
@@ -230,6 +234,8 @@ for (op,ODE,RHS,growth) in (
230234
end
231235
end
232236

237+
erfc(f::Fun) = 1-erf(f)
238+
233239

234240
exp2(f::Fun) = exp(log(2)*f)
235241
exp10(f::Fun) = exp(log(10)*f)
@@ -271,8 +277,35 @@ end
271277
sinpi(f::Fun) = sin*f)
272278
cospi(f::Fun) = cos*f)
273279

280+
function airy(k::Number,f::Fun)
281+
if k == 0
282+
airyai(f)
283+
elseif k == 1
284+
airyaiprime(f)
285+
elseif k == 2
286+
airybi(f)
287+
elseif k == 3
288+
airybiprime(f)
289+
else
290+
error("invalid argument")
291+
end
292+
end
293+
294+
besselh(ν,k::Integer,f::Fun) = k == 1 ? hankelh1(ν,f) : k == 2 ? hankelh2(ν,f) : throw(Base.Math.AmosException(1))
295+
296+
for jy in (:j, :y)
297+
bjy = Symbol(:bessel, jy)
298+
for ν in (0,1)
299+
bjynu = Symbol(bjy, ν)
300+
@eval SpecialFunctions.$bjynu(f::Fun) = $bjy($ν,f)
301+
end
302+
end
303+
274304
## Miscellaneous
275-
for op in (:(expm1),:(log1p),:(sinc),:(cosc))
305+
for op in (:(expm1),:(log1p),:(lfact),:(sinc),:(cosc),
306+
:(erfinv),:(erfcinv),:(beta),:(lbeta),
307+
:(eta),:(zeta),:(gamma),:(lgamma),
308+
:(polygamma),:(invdigamma),:(digamma),:(trigamma))
276309
@eval begin
277310
$op(f::Fun) = Fun($op f,domain(f))
278311
end
@@ -424,18 +457,41 @@ for (funsym, exp) in Calculus.symbolic_derivatives_1arg()
424457
funsym == :sign && continue
425458
funsym == :exp && continue
426459
funsym == :sqrt && continue
427-
if isdefined(Base, funsym)
428-
@eval begin
429-
$(funsym)(z::Fun{<:ConstantSpace,<:Real}) =
430-
Fun($(funsym)(Number(z)),space(z))
431-
$(funsym)(z::Fun{<:ConstantSpace,<:Complex}) =
432-
Fun($(funsym)(Number(z)),space(z))
433-
$(funsym)(z::Fun{<:ConstantSpace}) =
434-
Fun($(funsym)(Number(z)),space(z))
460+
@eval begin
461+
$(funsym)(z::Fun{<:ConstantSpace,<:Real}) =
462+
Fun($(funsym)(Number(z)),space(z))
463+
$(funsym)(z::Fun{<:ConstantSpace,<:Complex}) =
464+
Fun($(funsym)(Number(z)),space(z))
465+
$(funsym)(z::Fun{<:ConstantSpace}) =
466+
Fun($(funsym)(Number(z)),space(z))
467+
end
468+
end
469+
470+
# Other special functions
471+
for f in [:logabsgamma]
472+
@eval function $f(z::Fun{<:ConstantSpace, <:Real})
473+
t = $f(Number(z))
474+
Fun(t[1], space(z)), t[2]
475+
end
476+
end
477+
function loggamma(z::Fun{<:ConstantSpace})
478+
t = loggamma(Number(z))
479+
Fun(t, space(z))
480+
end
481+
for f in [:gamma, :loggamma]
482+
@eval begin
483+
function $f(a, z::Fun{<:ConstantSpace})
484+
t = $f(a, Number(z))
485+
Fun(t, space(z))
435486
end
436487
end
437488
end
438489

490+
for f in [:besselj, :besselk, :besselkx, :bessely, :besseli,
491+
:hankelh1x, :hankelh2x, :hankelh1, :hankelh2]
492+
@eval $f(nu, x::Fun{<:ConstantSpace}) = Fun($f(nu, Number(x)), space(x))
493+
end
494+
439495
# Roots
440496

441497
for op in (:(argmax),:(argmin))

0 commit comments

Comments
 (0)