Skip to content

Commit 736ad75

Browse files
committed
Move SparseArrays and Statistics to extensions
1 parent 49429cd commit 736ad75

8 files changed

+59
-39
lines changed

Project.toml

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2424
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2525
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2626

27+
[weakdeps]
28+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
29+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
30+
31+
[extensions]
32+
ApproxFunBaseSparseArraysExt = "SparseArrays"
33+
ApproxFunBaseStatisticsExt = "Statistics"
34+
2735
[compat]
2836
AbstractFFTs = "0.5, 1"
2937
Aqua = "0.8"

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
@@ -15,10 +15,8 @@ using InfiniteArrays
1515
using IntervalSets
1616
using LinearAlgebra
1717
using LowRankMatrices
18-
using SparseArrays
1918
using SpecialFunctions
2019
using StaticArrays: SVector, @SArray, SArray
21-
import Statistics: mean
2220

2321
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, Point, ∂,
2422
SetdiffDomain, Interval, ChebyshevInterval, boundary,
@@ -58,10 +56,6 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, cross,
5856
nullspace, Hermitian, Symmetric, adjoint, transpose, char_uplo,
5957
axpy!, eigvals
6058

61-
import SparseArrays: blockdiag
62-
63-
# import Arpack: eigs
64-
6559
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
6660
# we can't do importall Base as we replace some Base definitions
6761
import SpecialFunctions: airy, besselh,
@@ -160,4 +154,9 @@ include("hacks.jl")
160154
include("specialfunctions.jl")
161155
include("show.jl")
162156

157+
if !isdefined(Base, :get_extension)
158+
include("../ext/ApproxFunBaseSparseArraysExt.jl")
159+
include("../ext/ApproxFunBaseStatisticsExt.jl")
160+
end
161+
163162
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)