Skip to content

Commit 63d52bb

Browse files
committed
Move SparseArrays and Statistics to extensions
1 parent 8e897ae commit 63d52bb

8 files changed

+63
-42
lines changed

Project.toml

+11-2
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.8.43"
3+
version = "0.8.44"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -26,6 +26,14 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2626
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2727
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2828

29+
[weakdeps]
30+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
31+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
32+
33+
[extensions]
34+
ApproxFunBaseSparseArraysExt = "SparseArrays"
35+
ApproxFunBaseStatisticsExt = "Statistics"
36+
2937
[compat]
3038
AbstractFFTs = "0.5, 1"
3139
Aqua = "0.6"
@@ -63,6 +71,7 @@ Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
6371
OddEvenIntegers = "8d37c425-f37a-4ca2-9b9d-a61bc06559d2"
6472
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6573
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
74+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
6675

6776
[targets]
68-
test = ["Aqua", "Random", "FastTransforms", "FastGaussQuadrature", "HalfIntegers", "Infinities", "OddEvenIntegers", "Static"]
77+
test = ["Aqua", "Random", "FastTransforms", "FastGaussQuadrature", "HalfIntegers", "Infinities", "OddEvenIntegers", "Static", "Statistics"]

ext/ApproxFunBaseSparseArraysExt.jl

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module ApproxFunBaseSparseArraysExt
2+
3+
using SparseArrays
4+
import SparseArrays: blockdiag
5+
using ApproxFunBase
6+
using ApproxFunBase: promote_eltypeof
7+
8+
##TODO: unify with other blockdiag
9+
function blockdiag(d1::AbstractVector{T}, d2::AbstractVector{T}) where T<:Operator
10+
if isempty(d1) && isempty(d2)
11+
error("Empty blockdiag")
12+
end
13+
if isempty(d1)
14+
TT=promote_eltypeof(d2)
15+
elseif isempty(d2)
16+
TT=promote_eltypeof(d1)
17+
else
18+
TT=promote_type(promote_eltypeof(d1),
19+
promote_eltypeof(d2))
20+
end
21+
22+
D=zeros(Operator{TT},length(d1)+length(d2),2)
23+
D[1:length(d1),1]=d1
24+
D[length(d1)+1:end,2]=d2
25+
D
26+
end
27+
28+
function blockdiag(a::Operator, b::Operator)
29+
blockdiag(Operator{promote_type(eltype(a),eltype(b))}[a],
30+
Operator{promote_type(eltype(a),eltype(b))}[b])
31+
end
32+
33+
blockdiag(A::PlusOperator) = mapreduce(blockdiag, +, A.ops)
34+
blockdiag(A::TimesOperator) = mapreduce(blockdiag, .*, A.ops)
35+
36+
end

ext/ApproxFunBaseStatisticsExt.jl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module ApproxFunBaseStatisticsExt
2+
3+
import Statistics: mean
4+
using ApproxFunBase
5+
using ApproxFunBase: IntervalOrSegment
6+
7+
mean(d::IntervalOrSegment) = ApproxFunBase.mean(d)
8+
9+
end

src/ApproxFunBase.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ApproxFunBase
22
using BlockArrays, BandedMatrices, BlockBandedMatrices, DomainSets,
33
IntervalSets, SpecialFunctions, AbstractFFTs, FFTW,
4-
SpecialFunctions, DSP, DualNumbers, LinearAlgebra, SparseArrays,
4+
SpecialFunctions, DSP, DualNumbers, LinearAlgebra,
55
LowRankApprox, FillArrays, InfiniteArrays, InfiniteLinearAlgebra
66

77
import Calculus
@@ -39,8 +39,6 @@ import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
3939
import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
4040
broadcastable, DefaultArrayStyle, broadcasted
4141

42-
import Statistics: mean
43-
4442
import Combinatorics: multiexponents
4543

4644
import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, cross,
@@ -49,10 +47,6 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, cross,
4947
nullspace, Hermitian, Symmetric, adjoint, transpose, char_uplo,
5048
axpy!, eigvals
5149

52-
import SparseArrays: blockdiag
53-
54-
# import Arpack: eigs
55-
5650
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
5751
# we can't do importall Base as we replace some Base definitions
5852
import SpecialFunctions: airy, besselh,
@@ -155,4 +149,9 @@ include("testing.jl")
155149
include("specialfunctions.jl")
156150
include("show.jl")
157151

152+
if !isdefined(Base, :get_extension)
153+
include("../ext/ApproxFunBaseSparseArraysExt.jl")
154+
include("../ext/ApproxFunBaseStatisticsExt.jl")
155+
end
156+
158157
end #module

src/Domains/Segment.jl

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ issubset(a::Segment,b::Segment) = leftendpoint(a)∈b && rightendpoint(a)∈b
6868
arclength(d::AbstractInterval) = width(d)
6969
arclength(d::Segment) = norm(complexlength(d))
7070
complexlength(d::IntervalOrSegment) = rightendpoint(d)-leftendpoint(d)
71+
# ApproxFunBase.mean != Statistics.mean, as the latter is defined in the Statistics extension
7172
mean(d::IntervalOrSegment) = (rightendpoint(d)+leftendpoint(d))/2
7273
angle(d::IntervalOrSegment) = angle(complexlength(d))
7374
sign(d::IntervalOrSegment) = sign(complexlength(d))

src/Operators/Operator.jl

-7
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,6 @@ istril(A::Operator) = bandwidth(A, 2) <= 0
329329

330330
include("SubOperator.jl")
331331

332-
333-
#
334-
# sparse(B::Operator,n::Integer)=sparse(BandedMatrix(B,n))
335-
# sparse(B::Operator,n::AbstractRange,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
336-
# sparse(B::Operator,n::Colon,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
337-
# sparse(B::Operator,n::AbstractRange,m::Colon)=sparse(BandedMatrix(B,n,m))
338-
339332
## getindex
340333

341334

src/Operators/systems.jl

-23
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,6 @@ function diagm_container(size, kv::Pair{<:Integer,<:AbstractVector{<:Operator}}.
3333
zeros(Operator{T}, n, n)
3434
end
3535

36-
##TODO: unify with other blockdiag
37-
function blockdiag(d1::AbstractVector{T},d2::AbstractVector{T}) where T<:Operator
38-
if isempty(d1)&&isempty(d2)
39-
error("Empty blockdiag")
40-
end
41-
if isempty(d1)
42-
TT=promote_eltypeof(d2)
43-
elseif isempty(d2)
44-
TT=promote_eltypeof(d1)
45-
else
46-
TT=promote_type(promote_eltypeof(d1),
47-
promote_eltypeof(d2))
48-
end
49-
50-
D=zeros(Operator{TT},length(d1)+length(d2),2)
51-
D[1:length(d1),1]=d1
52-
D[length(d1)+1:end,2]=d2
53-
D
54-
end
55-
56-
blockdiag(a::Operator,b::Operator) = blockdiag(Operator{promote_type(eltype(a),eltype(b))}[a],
57-
Operator{promote_type(eltype(a),eltype(b))}[b])
58-
5936
## broadcase
6037

6138
broadcast(::typeof(*),A::AbstractArray{N},D::Operator) where {N<:Number} =

src/Spaces/ProductSpaceOperators.jl

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ end
5555
continuity(d::UnionDomain,k) = continuity(Space(d),k)
5656
continuity(d) = continuity(d,0)
5757

58-
blockdiag(A::PlusOperator) = mapreduce(blockdiag, +, A.ops)
59-
blockdiag(A::TimesOperator) = mapreduce(blockdiag, .*, A.ops)
60-
6158
# TODO: general wrappers
6259

6360
Evaluation(S::SumSpace,x,order) =

0 commit comments

Comments
 (0)