Skip to content

Move SparseArrays and Statistics to extensions #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

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

[extensions]
ApproxFunBaseTestExt = "Test"
ApproxFunBaseDualNumbersExt = "DualNumbers"
ApproxFunBaseSparseArraysExt = "SparseArrays"
ApproxFunBaseStatisticsExt = "Statistics"
ApproxFunBaseTestExt = "Test"

[compat]
AbstractFFTs = "0.5, 1"
Expand Down
36 changes: 36 additions & 0 deletions ext/ApproxFunBaseSparseArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module ApproxFunBaseSparseArraysExt

using SparseArrays
import SparseArrays: blockdiag
using ApproxFunBase
using ApproxFunBase: promote_eltypeof

##TODO: unify with other blockdiag
function blockdiag(d1::AbstractVector{T}, d2::AbstractVector{T}) where T<:Operator
if isempty(d1) && isempty(d2)
error("Empty blockdiag")
end
if isempty(d1)
TT=promote_eltypeof(d2)
elseif isempty(d2)
TT=promote_eltypeof(d1)
else
TT=promote_type(promote_eltypeof(d1),
promote_eltypeof(d2))
end

D=zeros(Operator{TT},length(d1)+length(d2),2)
D[1:length(d1),1]=d1
D[length(d1)+1:end,2]=d2
D
end

function blockdiag(a::Operator, b::Operator)
blockdiag(Operator{promote_type(eltype(a),eltype(b))}[a],
Operator{promote_type(eltype(a),eltype(b))}[b])
end

blockdiag(A::PlusOperator) = mapreduce(blockdiag, +, A.ops)
blockdiag(A::TimesOperator) = mapreduce(blockdiag, .*, A.ops)

end
9 changes: 9 additions & 0 deletions ext/ApproxFunBaseStatisticsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ApproxFunBaseStatisticsExt

import Statistics: mean
using ApproxFunBase
using ApproxFunBase: IntervalOrSegment

mean(d::IntervalOrSegment) = ApproxFunBase.mean(d)

end
11 changes: 5 additions & 6 deletions src/ApproxFunBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ using InfiniteArrays
using IntervalSets
using LinearAlgebra
using LowRankMatrices
using SparseArrays
using SpecialFunctions
using StaticArrays: SVector, @SArray, SArray
import Statistics: mean

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

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

import SparseArrays: blockdiag

# import Arpack: eigs

# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
# we can't do importall Base as we replace some Base definitions
import SpecialFunctions: airy, besselh,
Expand Down Expand Up @@ -167,4 +161,9 @@ include("specialfunctions.jl")
include("show.jl")
include("testutils.jl")

if !isdefined(Base, :get_extension)
include("../ext/ApproxFunBaseSparseArraysExt.jl")
include("../ext/ApproxFunBaseStatisticsExt.jl")
end

end #module
1 change: 1 addition & 0 deletions src/Domains/Segment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ issubset(a::Segment,b::Segment) = leftendpoint(a)∈b && rightendpoint(a)∈b
arclength(d::AbstractInterval) = width(d)
arclength(d::Segment) = norm(complexlength(d))
complexlength(d::IntervalOrSegment) = rightendpoint(d)-leftendpoint(d)
# ApproxFunBase.mean != Statistics.mean, as the latter is defined in the Statistics extension
mean(d::IntervalOrSegment) = (rightendpoint(d)+leftendpoint(d))/2
angle(d::IntervalOrSegment) = angle(complexlength(d))
sign(d::IntervalOrSegment) = sign(complexlength(d))
Expand Down
7 changes: 0 additions & 7 deletions src/Operators/Operator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,6 @@ istril(A::Operator) = bandwidth(A, 2) <= 0

include("SubOperator.jl")


#
# sparse(B::Operator,n::Integer)=sparse(BandedMatrix(B,n))
# sparse(B::Operator,n::AbstractRange,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
# sparse(B::Operator,n::Colon,m::AbstractRange)=sparse(BandedMatrix(B,n,m))
# sparse(B::Operator,n::AbstractRange,m::Colon)=sparse(BandedMatrix(B,n,m))

## getindex


Expand Down
23 changes: 0 additions & 23 deletions src/Operators/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,6 @@ function diagm_container(size, kv::Pair{<:Integer,<:AbstractVector{<:Operator}}.
zeros(Operator{T}, n, n)
end

##TODO: unify with other blockdiag
function blockdiag(d1::AbstractVector{T},d2::AbstractVector{T}) where T<:Operator
if isempty(d1)&&isempty(d2)
error("Empty blockdiag")
end
if isempty(d1)
TT=promote_eltypeof(d2)
elseif isempty(d2)
TT=promote_eltypeof(d1)
else
TT=promote_type(promote_eltypeof(d1),
promote_eltypeof(d2))
end

D=zeros(Operator{TT},length(d1)+length(d2),2)
D[1:length(d1),1]=d1
D[length(d1)+1:end,2]=d2
D
end

blockdiag(a::Operator,b::Operator) = blockdiag(Operator{promote_type(eltype(a),eltype(b))}[a],
Operator{promote_type(eltype(a),eltype(b))}[b])

## broadcase

broadcast(::typeof(*),A::AbstractArray{N},D::Operator) where {N<:Number} =
Expand Down
3 changes: 0 additions & 3 deletions src/Spaces/ProductSpaceOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ end
continuity(d::UnionDomain,k) = continuity(Space(d),k)
continuity(d) = continuity(d,0)

blockdiag(A::PlusOperator) = mapreduce(blockdiag, +, A.ops)
blockdiag(A::TimesOperator) = mapreduce(blockdiag, .*, A.ops)

# TODO: general wrappers

Evaluation(S::SumSpace,x,order) =
Expand Down
Loading