Skip to content
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

Version 0.1.3 #4

Merged
merged 9 commits into from
Nov 22, 2023
Merged
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
17 changes: 15 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
name = "PTYQoL"
uuid = "551ad714-b11a-4605-8871-12721def4e72"
authors = ["Tianyi Pu <[email protected]> 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"]
12 changes: 12 additions & 0 deletions ext/PTYQoLCircularArraysExt.jl
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ext/PTYQoLClassicalOrthogonalPolynomialsExt.jl
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions ext/PTYQoLContinuumArraysExt.jl
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions ext/PTYQoLIntervalSetsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module PTYQoLIntervalSetsExt

import IntervalSets: Domain
import Base: union

union(a::Domain) = a

end
10 changes: 10 additions & 0 deletions ext/PTYQoLQuasiArraysExt.jl
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ export ln

The same as `log` but only accepts one argument.
"""
ln(x::Number) = log(x)
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)
27 changes: 27 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down