Skip to content

Commit

Permalink
Merge pull request #8 from putianyi889/version-0.2.1
Browse files Browse the repository at this point in the history
Version 0.2.1
  • Loading branch information
putianyi889 authored Feb 12, 2024
2 parents f466460 + 6aac112 commit fdc73c0
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9'
- '1.10'
os:
- ubuntu-latest
- macOS-latest
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PTYQoL"
uuid = "551ad714-b11a-4605-8871-12721def4e72"
authors = ["Tianyi Pu <[email protected]> and contributors"]
version = "0.2.0"
version = "0.2.1"

[weakdeps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -10,9 +10,9 @@ ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
AlgebraicNumbers = "e86d093a-a386-599e-b7c7-df0420c8bcba"

[extensions]
PTYQoLLinearAlgebraExt = "LinearAlgebra"
Expand All @@ -21,9 +21,9 @@ PTYQoLContinuumArraysExt = "ContinuumArrays"
PTYQoLIntervalSetsExt = "IntervalSets"
PTYQoLQuasiArraysExt = "QuasiArrays"
PTYQoLClassicalOrthogonalPolynomialsExt = "ClassicalOrthogonalPolynomials"
PTYQoLInfiniteArraysExt = "InfiniteArrays"
PTYQoLBandedMatricesExt = "BandedMatrices"
PTYQoLArrayLayoutsExt = "ArrayLayouts"
PTYQoLAlgebraicNumbersExt = "AlgebraicNumbers"

[compat]
julia = "1"
Expand All @@ -35,9 +35,9 @@ DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
AlgebraicNumbers = "e86d093a-a386-599e-b7c7-df0420c8bcba"

[targets]
test = ["Test", "Aqua", "LinearAlgebra", "Documenter", "DomainSets", "ContinuumArrays", "ClassicalOrthogonalPolynomials", "InfiniteArrays", "ArrayLayouts"]
test = ["Test", "Aqua", "LinearAlgebra", "Documenter", "DomainSets", "ContinuumArrays", "ClassicalOrthogonalPolynomials", "ArrayLayouts", "AlgebraicNumbers"]
25 changes: 25 additions & 0 deletions ext/PTYQoLAlgebraicNumbersExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module PTYQoLAlgebraicNumbersExt

import AlgebraicNumbers: sin_alg, cos_alg, AlgebraicNumber
import Base: sinpi, cospi, tanpi, sincospi, sind, cosd, sincosd, promote_rule, float

export tan_alg, sincos_alg

tan_alg(x) = sin_alg(x) // cos_alg(x)
sincos_alg(x) = (sin_alg(x), cos_alg(x))

for (fd, fpi, falg) in ((:sind, :sinpi, :sin_alg), (:cosd, :cospi, :cos_alg), (:tand, :tanpi, :tan_alg), (:sincosd, :sincospi, :sincos_alg))
@eval begin
$fpi(x::Rational) = $falg(x)
$fpi(x::AlgebraicNumber) = $falg(x)
$fd(x::Integer) = $falg(x//180)
$fd(x::Rational) = $falg(x//180)
end
end

promote_rule(::Type{<:AlgebraicNumber}, ::Type{T}) where T <: AbstractFloat = T
float(x::AlgebraicNumber) = x.apprx
(::Type{T})(x::AlgebraicNumber) where T<:Number = T(x.apprx)
AlgebraicNumber(x::AlgebraicNumber) = x

end # module
14 changes: 0 additions & 14 deletions ext/PTYQoLInfiniteArraysExt.jl

This file was deleted.

6 changes: 6 additions & 0 deletions src/PTYQoL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ end
show(io::IO, f::ComposedFunction{<:Fix1}) = print(io, f.outer.f, '(', f.outer.x, ',', f.inner, ')')
show(io::IO, f::ComposedFunction{<:Fix2}) = print(io, f.outer.f, '(', f.inner, ',', f.outer.x, ')')

# Against Julia Base
# import Base: sinpi, cospi, tanpi, sincospi
# sinpi(x::Integer) = zero(x)
# cospi(x::Integer) = ifelse(isodd(x), -one(x), one(x))
# tanpi(x::Integer) = zero(x)

end
53 changes: 49 additions & 4 deletions src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,59 @@ macro struct_map(TYP, ops...)
end)
end

import Base: Fix1, show, string
export ln
"""
ln(x) = log(x)
const ln = Fix1(log,ℯ)
The same as `log` but only accepts one argument.
Natural logarithm.
"""
ln(x::Number) = log(x)
const ln = Fix1(log,ℯ)
show(io::IO, ::MIME"text/plain", ::typeof(ln)) = print(io,"ln (alias function for $(Fix1){typeof(log), Irrational{:ℯ}})")
string(::typeof(ln)) = "ln"

export precision_convert
precision_convert(::Type{BigFloat}, x, precision) = BigFloat(x, precision = precision)
precision_convert(T, x, precision) = convert(T, x)
precision_convert(T, x, precision) = convert(T, x)

export isalias
"""
isalias(type)
Check if a type is alias.
# Examples
```jldoctest
julia> isalias(Vector)
true
julia> isalias(Array)
false
```
"""
@generated isalias(::Type{T}) where T = string(T) != string(Base.typename(T).name)

export fracpochhammer
"""
fracpochhammer(a, b, n)
Calculate the fraction of two Pochhammer symbols ``\\frac{(a)_n}{(b)_n}`` by multiplying the fractions. This approach reduces the risk of overflow/underflow when ``n`` is large.
# Examples
```jldoctest
julia> fracpochhammer(1, 2, 3) # (1 * 2 * 3) / (2 * 3 * 4)
0.25
```
fracpochhammer(a, b, stepa, stepb, n)
Similar to `fracpochhammer(a, b, n)`, except that the steps of the Pochhammer symbols are not necessarily ``1``.
# Examples
```jldoctest
julia> fracpochhammer(1, 2, 0.5, 1, 3) # (1 * 1.5 * 2) / (2 * 3 * 4)
0.125
```
"""
fracpochhammer(a,b,n) = prod(range(a,length=n)./range(b,length=n));
fracpochhammer(a,b,stepa,stepb,n) = prod(range(a,step=stepa,length=n)./range(b,step=stepb,length=n));
17 changes: 11 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ end
x = precision_convert(BigFloat, BigFloat(1), 128)
@test precision(x) == 128
end
@testset "fracpochhammer" begin
@test fracpochhammer(1, 2, 3) 0.25
@test fracpochhammer(1, 2, 0.5, 1, 3) 0.125
end
end

@testset "Extensions" begin
Expand All @@ -101,19 +105,20 @@ end
@test AbstractJacobi{BigFloat}(Legendre()) isa Legendre{BigFloat}
@test AbstractJacobi{Float32}(Ultraspherical(2)) isa Ultraspherical{Float32}
end
@testset "InfiniteArrays" begin
using InfiniteArrays
D = Diagonal(1:∞)
@test diag(D) == 1:
@test diag(D, 1) == Zeros(∞)
end
@testset "ArrayLayouts" begin
using ArrayLayouts
A = rand(3,5)
ind = CartesianIndex(2,3)
@test rowsupport(A, ind) == rowsupport(A,2)
@test colsupport(A, ind) == colsupport(A,3)
end
@testset "AlgebraicNumbers" begin
using AlgebraicNumbers
@test sincospi(1//3) == sincosd(60) == sincospi(1/3)
@test tanpi(1//3) == tanpi(1/3)
@test sincospi(1//3) isa NTuple{2,AlgebraicNumber}
@test tanpi(1//3) isa AlgebraicNumber
end
end

using Documenter
Expand Down

0 comments on commit fdc73c0

Please sign in to comment.