Skip to content

Commit 17017a1

Browse files
authored
Fix imports of special functions (#268)
* Fix special functions from Calculus * Fix imports of special functions * Add test * Avoid overwriting gamma * Relax signatures for gamma/loggamma
1 parent 17cce1f commit 17017a1

File tree

5 files changed

+117
-59
lines changed

5 files changed

+117
-59
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.7.34"
3+
version = "0.7.35"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/ApproxFunBase.jl

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
module ApproxFunBase
22
using Base: AnyDict
3-
using Base, BlockArrays, BandedMatrices, BlockBandedMatrices, DomainSets, IntervalSets,
4-
SpecialFunctions, AbstractFFTs, FFTW, SpecialFunctions, DSP, DualNumbers,
5-
LinearAlgebra, SparseArrays, LowRankApprox, FillArrays, InfiniteArrays, InfiniteLinearAlgebra #, Arpack
6-
import StaticArrays, Calculus
7-
8-
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, FullSpace, Point, elements, DifferenceDomain,
9-
Interval, ChebyshevInterval, boundary, ∂, rightendpoint, leftendpoint,
10-
dimension, WrappedDomain, VcatDomain, component, components, ncomponents
11-
12-
3+
using Base, BlockArrays, BandedMatrices, BlockBandedMatrices, DomainSets,
4+
IntervalSets, SpecialFunctions, AbstractFFTs, FFTW,
5+
SpecialFunctions, DSP, DualNumbers, LinearAlgebra, SparseArrays,
6+
LowRankApprox, FillArrays, InfiniteArrays, InfiniteLinearAlgebra
7+
# Arpack
138

14-
import AbstractFFTs: Plan, fft, ifft
15-
import FFTW: plan_r2r!, fftwNumber, REDFT10, REDFT01, REDFT00, RODFT00, R2HC, HC2R,
16-
r2r!, r2r, plan_fft, plan_ifft, plan_ifft!, plan_fft!
17-
18-
19-
import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, iterate,
20-
>=, /, ^, \, , transpose, size, tail, broadcast, broadcast!, copyto!, copy, to_index, (:),
21-
similar, map, vcat, hcat, hvcat, show, summary, stride, sum, cumsum, sign, imag, conj, inv,
22-
complex, reverse, exp, sqrt, abs, abs2, sign, issubset, values, in, first, last, rand, intersect, setdiff,
23-
isless, union, angle, join, isnan, isapprox, isempty, sort, merge, promote_rule,
24-
minimum, maximum, extrema, argmax, argmin, findmax, findmin, isfinite,
25-
zeros, zero, one, promote_rule, repeat, length, resize!, isinf,
26-
getproperty, findfirst, unsafe_getindex, fld, cld, div,
27-
@_inline_meta, eachindex, firstindex, lastindex, keys, isreal, OneTo,
28-
Array, Vector, Matrix, view, ones, @propagate_inbounds, print_array,
29-
split, iszero, permutedims, rad2deg, deg2rad
9+
import StaticArrays, Calculus
3010

31-
import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle, broadcastable,
32-
DefaultArrayStyle, broadcasted
11+
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, Point, ∂,
12+
elements, DifferenceDomain, Interval, ChebyshevInterval, boundary,
13+
rightendpoint, leftendpoint, dimension, WrappedDomain, VcatDomain,
14+
component, components, ncomponents
15+
16+
using AbstractFFTs: Plan
17+
18+
import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
19+
!=, eltype, iterate, /, ^, \,
20+
transpose, size, tail, broadcast, broadcast!, copyto!, copy,
21+
to_index, (:), similar, map, vcat, hcat, hvcat, show, summary,
22+
stride, sum, cumsum, imag, conj, inv, complex, reverse, exp,
23+
sqrt, abs, abs2, sign, issubset, in, first, last, rand, intersect,
24+
setdiff, isless, union, angle, join, isnan, isapprox, isempty,
25+
sort, merge, minimum, maximum, extrema, argmax,
26+
argmin, findmax, findmin, isfinite,
27+
zeros, zero, one, promote_rule, repeat, length, resize!, isinf,
28+
getproperty, findfirst, unsafe_getindex, fld, div,
29+
eachindex, firstindex, lastindex, isreal,
30+
OneTo, Array, Vector, Matrix, view, ones, @propagate_inbounds,
31+
print_array, split, iszero, permutedims, rad2deg, deg2rad
32+
33+
import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
34+
broadcastable, DefaultArrayStyle, broadcasted
3335

3436
import Statistics: mean
3537

36-
import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, eigvals, cross,
37-
qr, qr!, rank, isdiag, istril, istriu, issymmetric, ishermitian,
38-
Tridiagonal, diagm, diagm_container, factorize, nullspace,
39-
Hermitian, Symmetric, adjoint, transpose, char_uplo
38+
import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, cross,
39+
qr, qr!, rank, isdiag, istril, istriu, issymmetric,
40+
Tridiagonal, diagm, diagm_container, factorize,
41+
nullspace, Hermitian, Symmetric, adjoint, transpose, char_uplo
4042

4143
import SparseArrays: blockdiag
4244

@@ -45,35 +47,38 @@ import SparseArrays: blockdiag
4547
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
4648
# we can't do importall Base as we replace some Base definitions
4749
import SpecialFunctions: sinpi, cospi, airy, besselh,
48-
asinh, acosh,atanh, erfcx, dawson, erf, erfi,
49-
sin, cos, sinh, cosh, airyai, airybi, airyaiprime, airybiprime,
50-
hankelh1, hankelh2, besselj, besselj0, bessely, besseli, besselk,
51-
besselkx, hankelh1x, hankelh2x, exp2, exp10, log2, log10,
52-
tan, tanh, csc, asin, acsc, sec, acos, asec,
53-
cot, atan, acot, sinh, csch, asinh, acsch,
54-
sech, acosh, asech, tanh, coth, atanh, acoth,
55-
expm1, log1p, lfact, sinc, cosc, erfinv, erfcinv, beta, lbeta,
56-
eta, zeta, gamma, lgamma, polygamma, invdigamma, digamma, trigamma,
57-
abs, sign, log, expm1, tan, abs2, sqrt, angle, max, min, cbrt, log,
58-
atan, acos, asin, erfc, inv
59-
60-
import StaticArrays: SVector
61-
62-
import BandedMatrices: bandrange, bandshift,
63-
inbands_getindex, inbands_setindex!, bandwidth, AbstractBandedMatrix,
64-
colstart, colstop, colrange, rowstart, rowstop, rowrange,
65-
bandwidths, _BandedMatrix, BandedMatrix
50+
sin, cos, cosh, exp2, exp10, log2, log10, csc, acsc, sec,
51+
asec, cot, acot, sinh, csch, asinh, acsch,
52+
sech, acosh, asech, tanh, coth, atanh, acoth,
53+
log1p, lfact, sinc, cosc, beta, lbeta,
54+
eta, zeta, polygamma, logabsgamma, loggamma,
55+
abs, sign, log, expm1, tan, abs2, sqrt, angle,
56+
max, min, cbrt, atan, acos, asin, inv,
57+
besselj, bessely, besseli, besselk, besselkx,
58+
hankelh1, hankelh2, hankelh1x, hankelh2x,
59+
# functions from Calculus.symbolic_derivatives_1arg
60+
erf, erfinv, erfc, erfcinv, erfi, gamma, lgamma,
61+
digamma, invdigamma, trigamma,
62+
airyai, airybi, airyaiprime, airybiprime,
63+
besselj0, besselj1, bessely0, bessely1,
64+
erfcx, dawson
65+
66+
import BandedMatrices: bandrange, inbands_setindex!, bandwidth,
67+
colstart, colstop, colrange, rowstart, rowstop, rowrange,
68+
bandwidths, _BandedMatrix, BandedMatrix
6669

6770
import BlockArrays: blocksize, block, blockaxes, blockindex
68-
import BlockBandedMatrices: blockbandwidth, blockbandwidths, blockcolstop, blockcolrange,
69-
blockcolstart, blockrowstop, blockrowstart, blockrowrange,
70-
subblockbandwidth, subblockbandwidths, _BlockBandedMatrix,
71-
_BandedBlockBandedMatrix, BandedBlockBandedMatrix, BlockBandedMatrix,
72-
isblockbanded, isbandedblockbanded, bb_numentries, BlockBandedSizes
71+
import BlockBandedMatrices: blockbandwidth, blockbandwidths, blockcolstop,
72+
blockcolrange, blockcolstart, blockrowstop, blockrowstart,
73+
subblockbandwidth, subblockbandwidths, _BlockBandedMatrix,
74+
_BandedBlockBandedMatrix, BandedBlockBandedMatrix,
75+
BlockBandedMatrix, isblockbanded, isbandedblockbanded,
76+
bb_numentries, BlockBandedSizes
7377

7478
import FillArrays: AbstractFill, getindex_value
7579
import LazyArrays: cache, CachedVector, cacheddata
76-
import InfiniteArrays: PosInfinity, InfRanges, AbstractInfUnitRange, OneToInf, InfiniteCardinal
80+
import InfiniteArrays: PosInfinity, InfRanges, AbstractInfUnitRange,
81+
OneToInf, InfiniteCardinal
7782

7883

7984
# convenience for 1-d block ranges
@@ -93,7 +98,8 @@ export pad!, pad, chop!, sample,
9398
complexroots, roots,
9499
reverseorientation
95100

96-
export .., Interval, ChebyshevInterval, leftendpoint, rightendpoint, endpoints, cache
101+
export .., Interval, ChebyshevInterval, leftendpoint, rightendpoint
102+
export endpoints, cache
97103

98104
import Base: oneto
99105

src/Fun.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ iterate(x::ScalarFun) = (x, nothing)
245245
iterate(x::ScalarFun, ::Any) = nothing
246246
isempty(x::ScalarFun) = false
247247

248-
iterate(A::ArrayFun, i=1) = (@_inline_meta; (i % UInt) - 1 < length(A) ? (@inbounds A[i], i + 1) : nothing)
248+
@inline function iterate(A::ArrayFun, i=1)
249+
(i % UInt) - 1 < length(A) ? (@inbounds A[i], i + 1) : nothing
250+
end
249251

250252
in(x::ScalarFun, y::ScalarFun) = x == y
251253

src/specialfunctions.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,31 @@ for (funsym, exp) in Calculus.symbolic_derivatives_1arg()
467467
end
468468
end
469469

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))
486+
end
487+
end
488+
end
489+
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+
470495
# Roots
471496

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

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ApproxFunBase, LinearAlgebra, Random, Test
22
using ApproxFunBase:
33
using Aqua
4+
using SpecialFunctions
45

56
@testset "Project quality" begin
67
Aqua.test_all(ApproxFunBase, ambiguities=false)
@@ -389,5 +390,29 @@ end
389390
end
390391
end
391392

393+
@testset "Special functions" begin
394+
pt = 0.5
395+
x = Fun(pt, ConstantSpace(1..2))
396+
for f in [erf, erfinv, erfc, erfcinv, erfi, gamma,
397+
digamma, invdigamma, trigamma, loggamma,
398+
airyai, airybi, airyaiprime, airybiprime,
399+
besselj0, besselj1, bessely0, bessely1,
400+
erfcx, dawson]
401+
402+
@test Number(f(x)) f(pt)
403+
if f [erfinv, erfcinv, invdigamma]
404+
@test Number(f(x*im)) f(pt*im)
405+
end
406+
end
407+
for f in [besselj, bessely, besseli, besselk, besselkx,
408+
hankelh1, hankelh2, hankelh1x, hankelh2x]
409+
@test Number(f(1, x)) f(1, pt)
410+
end
411+
@test Number(logabsgamma(x)[1]) logabsgamma(pt)[1]
412+
@test logabsgamma(x)[2] logabsgamma(pt)[2]
413+
@test Number(gamma(2, x)) gamma(2, pt)
414+
@test Number(gamma(2, x*im)) gamma(2, pt*im)
415+
end
416+
392417
@time include("ETDRK4Test.jl")
393418
include("show.jl")

0 commit comments

Comments
 (0)