Skip to content

Commit ece238c

Browse files
committed
Move SparseArrays and Statistics to extensions
1 parent 2b85cfe commit ece238c

8 files changed

+57
-41
lines changed

Project.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2424
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2525

2626
[weakdeps]
27-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2827
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
28+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
29+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
30+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2931

3032
[extensions]
31-
ApproxFunBaseTestExt = "Test"
3233
ApproxFunBaseDualNumbersExt = "DualNumbers"
34+
ApproxFunBaseSparseArraysExt = "SparseArrays"
35+
ApproxFunBaseStatisticsExt = "Statistics"
36+
ApproxFunBaseTestExt = "Test"
3337

3438
[compat]
3539
AbstractFFTs = "0.5, 1"

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ using InfiniteArrays
1414
using IntervalSets
1515
using LinearAlgebra
1616
using LowRankMatrices
17-
using SparseArrays
1817
using SpecialFunctions
1918
using StaticArrays: SVector, @SArray, SArray
20-
import Statistics: mean
2119

2220
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, Point, ∂,
2321
SetdiffDomain, Interval, ChebyshevInterval, boundary,
@@ -63,10 +61,6 @@ import LinearAlgebra.LAPACK.chklapackerror
6361

6462
import LinearAlgebra.BLAS: @blasfunc, libblas, liblapack, BlasInt
6563

66-
import SparseArrays: blockdiag
67-
68-
# import Arpack: eigs
69-
7064
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
7165
# we can't do importall Base as we replace some Base definitions
7266
import SpecialFunctions: airy, besselh,
@@ -167,4 +161,9 @@ include("specialfunctions.jl")
167161
include("show.jl")
168162
include("testutils.jl")
169163

164+
if !isdefined(Base, :get_extension)
165+
include("../ext/ApproxFunBaseSparseArraysExt.jl")
166+
include("../ext/ApproxFunBaseStatisticsExt.jl")
167+
end
168+
170169
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
@@ -332,13 +332,6 @@ istril(A::Operator) = bandwidth(A, 2) <= 0
332332

333333
include("SubOperator.jl")
334334

335-
336-
#
337-
# sparse(B::Operator,n::Integer)=sparse(BandedMatrix(B,n))
338-
# sparse(B::Operator,n::AbstractRange,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
339-
# sparse(B::Operator,n::Colon,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
340-
# sparse(B::Operator,n::AbstractRange,m::Colon)=sparse(BandedMatrix(B,n,m))
341-
342335
## getindex
343336

344337

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)