diff --git a/Project.toml b/Project.toml index db5c904..9ef689f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,21 +1,34 @@ name = "PTYQoL" uuid = "551ad714-b11a-4605-8871-12721def4e72" authors = ["Tianyi Pu <912396513@qq.com> and contributors"] -version = "0.1.2" +version = "0.1.3" [weakdeps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +CircularArrays = "7a955b69-7140-5f4e-a0ed-f168c5e2e749" +ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c" +IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" +QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c" +ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd" [extensions] PTYQoLLinearAlgebraExt = "LinearAlgebra" +PTYQoLCircularArraysExt = "CircularArrays" +PTYQoLContinuumArraysExt = "ContinuumArrays" +PTYQoLIntervalSetsExt = "IntervalSets" +PTYQoLQuasiArraysExt = "QuasiArrays" +PTYQoLClassicalOrthogonalPolynomialsExt = "ClassicalOrthogonalPolynomials" [compat] julia = "1" [extras] +ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd" [targets] -test = ["Test", "LinearAlgebra", "Documenter"] +test = ["Test", "LinearAlgebra", "Documenter", "DomainSets", "ContinuumArrays", "ClassicalOrthogonalPolynomials"] diff --git a/ext/PTYQoLCircularArraysExt.jl b/ext/PTYQoLCircularArraysExt.jl new file mode 100644 index 0000000..1a5edee --- /dev/null +++ b/ext/PTYQoLCircularArraysExt.jl @@ -0,0 +1,12 @@ +module PTYQoLCircularArraysExt + +import CircularArrays: CircularArray +""" + CircularMatrix{T,A} <: AbstractVector{T} + +Two-dimensional array backed by an `AbstractArray{T, 2}` of type `A` with fixed size and circular indexing. +Alias for [`CircularArray{T,2,A}`](@ref). +""" +const CircularMatrix{T} = CircularArray{T, 2} + +end diff --git a/ext/PTYQoLClassicalOrthogonalPolynomialsExt.jl b/ext/PTYQoLClassicalOrthogonalPolynomialsExt.jl new file mode 100644 index 0000000..434e20f --- /dev/null +++ b/ext/PTYQoLClassicalOrthogonalPolynomialsExt.jl @@ -0,0 +1,12 @@ +module PTYQoLClassicalOrthogonalPolynomialsExt + +import ClassicalOrthogonalPolynomials: AbstractJacobi, Jacobi, Chebyshev, Legendre, Ultraspherical + +AbstractJacobi{T}(a::Jacobi) where T = Jacobi{T}(a) +AbstractJacobi{T}(::Chebyshev{kind}) where T where kind = Chebyshev{kind,T}() +AbstractJacobi{T}(::Legendre) where T = Legendre{T}() +AbstractJacobi{T}(a::Ultraspherical) where T = Ultraspherical{T}(a) + +Jacobi{T}(a::Jacobi) where T = Jacobi(T(a.a), T(a.b)) + +end \ No newline at end of file diff --git a/ext/PTYQoLContinuumArraysExt.jl b/ext/PTYQoLContinuumArraysExt.jl new file mode 100644 index 0000000..36a3061 --- /dev/null +++ b/ext/PTYQoLContinuumArraysExt.jl @@ -0,0 +1,32 @@ +module PTYQoLContinuumArraysExt + +import Base: union, Fix2, isempty +import ContinuumArrays: AbstractInterval, BroadcastQuasiVector, Interval, Inclusion, endpoints, isleftclosed, isrightclosed + +function union(x::BroadcastQuasiVector{T, <:Fix2{typeof(^), <:Number}, <:Tuple{Inclusion{T, <:AbstractInterval}}}) where T + p = x.f.x + I = first(x.args).domain + a, b = endpoints(I) + if isempty(I) || b ≤ 0 + Inclusion(Interval{:open, :open}(zero(T), zero(T))) + elseif iszero(p) + Inclusion(Interval{:closed, :closed}(one(T), one(T))) + else + R = ifelse(isrightclosed(I), :closed, :open) + if a ≥ 0 + L = ifelse(isleftclosed(I), :closed, :open) + else + L = :closed + a = zero(T) + end + if p < 0 + Inclusion(Interval{R, L}(b^p, a^p)) + else + Inclusion(Interval{L, R}(a^p, b^p)) + end + end +end + +isempty(a::Inclusion) = isempty(a.domain) + +end \ No newline at end of file diff --git a/ext/PTYQoLIntervalSetsExt.jl b/ext/PTYQoLIntervalSetsExt.jl new file mode 100644 index 0000000..d7e729f --- /dev/null +++ b/ext/PTYQoLIntervalSetsExt.jl @@ -0,0 +1,8 @@ +module PTYQoLIntervalSetsExt + +import IntervalSets: Domain +import Base: union + +union(a::Domain) = a + +end \ No newline at end of file diff --git a/ext/PTYQoLQuasiArraysExt.jl b/ext/PTYQoLQuasiArraysExt.jl new file mode 100644 index 0000000..49a385c --- /dev/null +++ b/ext/PTYQoLQuasiArraysExt.jl @@ -0,0 +1,10 @@ +module PTYQoLQuasiArraysExt + +import Base: union, Fix2, Fix1, broadcasted, literal_pow +import QuasiArrays: BroadcastQuasiVector, LazyQuasiArrayStyle, AbstractQuasiVector + +broadcasted(::LazyQuasiArrayStyle{1}, ::typeof(^), x::AbstractQuasiVector, b::Number) = Fix2(^, b).(x) +broadcasted(::LazyQuasiArrayStyle{1}, ::typeof(^), a::Number, x::AbstractQuasiVector) = Fix1(^, a).(x) +broadcasted(::typeof(literal_pow), ::typeof(^), x::AbstractQuasiVector, ::Val{b}) where b = Fix2(^, b).(x) + +end \ No newline at end of file diff --git a/src/Utils.jl b/src/Utils.jl index cdfe249..0dc4c18 100644 --- a/src/Utils.jl +++ b/src/Utils.jl @@ -115,4 +115,8 @@ export ln The same as `log` but only accepts one argument. """ -ln(x::Number) = log(x) \ No newline at end of file +ln(x::Number) = log(x) + +export precision_convert +precision_convert(::Type{BigFloat}, x, precision) = BigFloat(x, precision = precision) +precision_convert(T, x, precision) = convert(T, x) \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 09a262d..a5608dd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -54,6 +54,33 @@ end @test ln(1) == 0 # just for coverage end +@testset "precision_convert" begin + setprecision(256) + x = precision_convert(BigFloat, BigFloat(1), 128) + @test precision(x) == 128 +end + +@testset "Extensions" begin + @testset "IntervalSets" begin + using DomainSets + @test union(ChebyshevInterval()) ≡ ChebyshevInterval() + end + @testset "QuasiArrays" begin + using ContinuumArrays + @test union(Inclusion(0..1).^2) == Inclusion(0..1) == union(Inclusion(-1..1).^1.0) == union(Inclusion(1..Inf).^(-0.5)) + @test isempty(union(Inclusion(-1..0).^1.5)) + @test union(Inclusion(0..1).^0) == Inclusion(1..1) + end + @testset "ClassicalOrthogonalPolynomials" begin + using ClassicalOrthogonalPolynomials + using ClassicalOrthogonalPolynomials: AbstractJacobi + @test AbstractJacobi{Float32}(Jacobi(1,1)) isa Jacobi{Float32} + @test AbstractJacobi{Float16}(ChebyshevU()) isa ChebyshevU{Float16} + @test AbstractJacobi{BigFloat}(Legendre()) isa Legendre{BigFloat} + @test AbstractJacobi{Float32}(Ultraspherical(2)) isa Ultraspherical{Float32} + end +end + DocMeta.setdocmeta!(PTYQoL, :DocTestSetup, :(using PTYQoL); recursive=true) @testset "Docs" begin doctest(PTYQoL)