Skip to content

Commit 7ad092c

Browse files
authored
Merge pull request #18 from putianyi889/version-0.2.6
Version 0.2.6
2 parents d4e5476 + a05e6e9 commit 7ad092c

10 files changed

Lines changed: 117 additions & 53 deletions

Project.toml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,48 @@ authors = ["Tianyi Pu <912396513@qq.com> and contributors"]
44
version = "0.2.5"
55

66
[weakdeps]
7-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7+
AlgebraicNumbers = "e86d093a-a386-599e-b7c7-df0420c8bcba"
8+
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
9+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
810
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
911
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
1012
CircularArrays = "7a955b69-7140-5f4e-a0ed-f168c5e2e749"
13+
ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
1114
ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
1215
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
1316
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
1417
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
1518
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
19+
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
20+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1621
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
17-
ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
18-
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
19-
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
20-
AlgebraicNumbers = "e86d093a-a386-599e-b7c7-df0420c8bcba"
2122

2223
[extensions]
23-
PTYQoLLinearAlgebraExt = "LinearAlgebra"
24+
PTYQoLAlgebraicNumbersExt = "AlgebraicNumbers"
25+
PTYQoLArrayLayoutsExt = "ArrayLayouts"
26+
PTYQoLBandedMatricesExt = "BandedMatrices"
2427
PTYQoLBlockArraysExt = "BlockArrays"
2528
PTYQoLBlockBandedMatricesExt = "BlockBandedMatrices"
2629
PTYQoLCircularArraysExt = "CircularArrays"
30+
PTYQoLClassicalOrthogonalPolynomialsExt = "ClassicalOrthogonalPolynomials"
2731
PTYQoLContinuumArraysExt = "ContinuumArrays"
2832
PTYQoLDomainSetsExt = "DomainSets"
2933
PTYQoLInfiniteArraysExt = "InfiniteArrays"
3034
PTYQoLInfinitiesExt = "Infinities"
3135
PTYQoLIntervalSetsExt = "IntervalSets"
36+
PTYQoLIrrationalConstantsExt = "IrrationalConstants"
37+
PTYQoLLinearAlgebraExt = "LinearAlgebra"
3238
PTYQoLQuasiArraysExt = "QuasiArrays"
33-
PTYQoLClassicalOrthogonalPolynomialsExt = "ClassicalOrthogonalPolynomials"
34-
PTYQoLBandedMatricesExt = "BandedMatrices"
35-
PTYQoLArrayLayoutsExt = "ArrayLayouts"
36-
PTYQoLAlgebraicNumbersExt = "AlgebraicNumbers"
3739

3840
[compat]
3941
julia = "1"
4042

4143
[extras]
44+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
45+
BeepBeep = "97dd0070-d6c0-43ac-b134-ca84cdbd343e"
4246
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4347
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
4448
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
45-
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
46-
BeepBeep = "97dd0070-d6c0-43ac-b134-ca84cdbd343e"
4749

4850
[targets]
49-
test = ["Test", "Aqua", "LinearAlgebra", "Documenter", "DomainSets", "ContinuumArrays", "ClassicalOrthogonalPolynomials", "ArrayLayouts", "AlgebraicNumbers", "Infinities", "BlockBandedMatrices", "BandedMatrices", "CircularArrays", "IntervalSets", "QuasiArrays", "InfiniteArrays", "BlockArrays", "BeepBeep"]
51+
test = ["Test", "Aqua", "LinearAlgebra", "Documenter", "DomainSets", "ContinuumArrays", "ClassicalOrthogonalPolynomials", "ArrayLayouts", "AlgebraicNumbers", "Infinities", "BlockBandedMatrices", "BandedMatrices", "CircularArrays", "IntervalSets", "IrrationalConstants", "QuasiArrays", "InfiniteArrays", "BlockArrays", "BeepBeep"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ Full of type piracies. However they are not supposed to break anything. They onl
88

99
**Remark** Technically this package does break things. Due to the extension, some method errors are eliminated, so if you rely on those errors, don't use this package.
1010

11+
This package should be only guaranteed to support the latest stable version of Julia.
12+
1113
Rule of new version:
1214
- `(It's been at least 24 hrs since the last version) && ((an external PR is merged) || (an issue is resolved) || (the number of line changes reach 100)`

ext/PTYQoLAlgebraicNumbersExt.jl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
module PTYQoLAlgebraicNumbersExt
22

33
import AlgebraicNumbers: sin_alg, cos_alg, AlgebraicNumber
4-
import Base: sinpi, cospi, tanpi, sincospi, sind, cosd, sincosd, promote_rule, float
5-
6-
export tan_alg, sincos_alg
7-
8-
tan_alg(x) = sin_alg(x) // cos_alg(x)
9-
sincos_alg(x) = (sin_alg(x), cos_alg(x))
10-
11-
for (fd, fpi, falg) in ((:sind, :sinpi, :sin_alg), (:cosd, :cospi, :cos_alg), (:tand, :tanpi, :tan_alg), (:sincosd, :sincospi, :sincos_alg))
12-
@eval begin
13-
$fpi(x::Rational) = $falg(x)
14-
$fpi(x::AlgebraicNumber) = $falg(x)
15-
$fd(x::Integer) = $falg(x//180)
16-
$fd(x::Rational) = $falg(x//180)
17-
end
18-
end
4+
import Base: promote_rule, float
195

6+
# https://github.com/anj1/AlgebraicNumbers.jl/pull/35
207
promote_rule(::Type{<:AlgebraicNumber}, ::Type{T}) where T <: AbstractFloat = T
218
float(x::AlgebraicNumber) = x.apprx
229
(::Type{T})(x::AlgebraicNumber) where T<:AbstractFloat = T(x.apprx)
10+
2311
AlgebraicNumber(x::AlgebraicNumber) = x
2412

2513
end # module

ext/PTYQoLBandedMatricesExt.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module PTYQoLBandedMatricesExt
22

3-
import BandedMatrices: inbands_getindex, inbands_setindex!, AbstractBandedMatrix, bandwidths, MemoryLayout, BandedLayout
4-
import Base: getindex, setindex!, @propagate_inbounds
3+
import BandedMatrices: inbands_getindex, inbands_setindex!, AbstractBandedMatrix, bandwidths, MemoryLayout, BandedLayout, BandedMatrix
4+
import Base: getindex, setindex!, @propagate_inbounds, convert
55

66
# too tedious to test
77

@@ -29,4 +29,6 @@ end
2929
end
3030
end
3131

32+
convert(::Type{AbstractArray{T}}, M::BandedMatrix{T}) where T = M
33+
3234
end

ext/PTYQoLBlockArraysExt.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
module PTYQoLBlockArraysExt
22

3+
import BlockArrays: findblockindex, BlockIndex
4+
import Base.IteratorsMD: flatten
5+
6+
function findblockindex(A::AbstractArray{T,N}, I::Tuple{Vararg{Integer,N}}) where {T,N}
7+
blockinds = findblockindex.(axes(A), I)
8+
BlockIndex(flatten(map(x->x.I, blockinds)), flatten(map(x->x.α, blockinds)))
9+
end
10+
311
# ambiguities
412
import BlockArrays: BlockArray, to_axes, colsupport, rowsupport, PseudoBlockArray, _pseudo_reshape
513
import Base: OneTo, similar, reshape
@@ -10,6 +18,8 @@ import Base: OneTo, similar, reshape
1018
rowsupport(A::PseudoBlockArray, i::CartesianIndex{2}) = rowsupport(A, first(i))
1119
colsupport(A::PseudoBlockArray, i::CartesianIndex{2}) = colsupport(A, last(i))
1220

13-
reshape(block_array::PseudoBlockArray, axes::Tuple{}) where N = _pseudo_reshape(block_array, axes)
21+
reshape(block_array::PseudoBlockArray, axes::Tuple{}) = _pseudo_reshape(block_array, axes)
22+
reshape(block_array::BlockArray, dims::Tuple{Vararg{Int}}) = reshape(PseudoBlockArray(block_array), dims)
23+
reshape(block_array::BlockArray, dims::Tuple{}) = reshape(PseudoBlockArray(block_array), dims)
1424

1525
end # module

ext/PTYQoLDomainSetsExt.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
module PTYQoLDomainSetsExt
22

33
# ambiguities
4-
import DomainSets: AnyDomain, setdiffdomain, domain, AffineMap, isaffine, matrix, vector, isequaldomain, uniondomain, _intersect, DomainStyle
5-
import Base: setdiff, ==, convert, union, intersect
4+
import DomainSets: AnyDomain, setdiffdomain, domain, AffineMap, isaffine, matrix, vector, isequaldomain, uniondomain, DomainStyle
5+
import Base: setdiff, ==, convert, union
66

77
setdiff(d1::AbstractSet, d2::AnyDomain) = setdiffdomain(d1, domain(d2))
88

9-
intersect(d1::AbstractSet, d2::AnyDomain, domains...) = _intersect(d1, domain(d2), DomainStyle(d1), domains...)
10-
119
union(d1::BitSet, d2::AnyDomain, domains...) = uniondomain(d1, domain(d2), domains...)
1210

1311
==(d1::AnyDomain, d2::WeakRef) = isequaldomain(domain(d1), d2)
1412
==(::AnyDomain, ::Missing) = missing
1513
==(::Missing, ::AnyDomain) = missing
1614

17-
convert(::Type{AffineMap}, m::AffineMap) = m
18-
convert(::Type{AffineMap{T}}, m::AffineMap{T}) where T = m
19-
2015
end # module

ext/PTYQoLInfinitiesExt.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import Infinities: InfiniteCardinal, ∞, Infinity, ComplexInfinity, RealInfinit
66

77
RealInfinity(x::Complex) = RealInfinity(Bool(x))
88
RealInfinity(x::TwicePrecision) = RealInfinity(Bool(x))
9+
RealInfinity(x::AbstractChar) = RealInfinity(Bool(x))
910
ComplexInfinity(x::Complex) = ComplexInfinity(Real(x))
10-
ComplexInfinity{T}(x::AbstractChar) where T<:Real = ComplexInfinity(Real(x))
11+
ComplexInfinity{T}(x::TwicePrecision) where T<:Real = ComplexInfinity(T(x))
12+
ComplexInfinity{T}(x::AbstractChar) where T<:Real = ComplexInfinity(T(x))
1113

1214
Bool(x::RealInfinity) = _convert(Bool, x)
15+
Bool(x::Infinity) = _convert(Bool, x)
1316

1417
+(::InfiniteCardinal, x::Rational) =+ x
1518
+(x::Rational, ::InfiniteCardinal) = x +
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module PTYQoLIrrationalConstantsExt
2+
3+
using IrrationalConstants
4+
import Base: +, -, *, /, inv, sqrt, exp, log
5+
6+
# x+x=2x, 2x-x=x, x/2x=1/2, 2x/x=2
7+
for (x, halfx) in ((halfπ,quartπ), (π,halfπ), (twoπ,π), (fourπ,twoπ), (inv2π,inv4π), (invπ,inv2π), (twoinvπ,invπ), (fourinvπ,twoinvπ), (sqrt2,invsqrt2), (sqrt2π,sqrthalfπ), (sqrt4π,sqrtπ))
8+
@eval +(::$(typeof(halfx)), ::$(typeof(halfx))) = $x
9+
@eval -(::$(typeof(x)), ::$(typeof(halfx))) = $halfx
10+
@eval /(::$(typeof(halfx)), ::$(typeof(x))) = 1/2
11+
@eval /(::$(typeof(x)), ::$(typeof(halfx))) = 2
12+
end
13+
14+
# x*inv(x)=1
15+
for (x,invx) in ((quartπ,fourinvπ), (halfπ,twoinvπ), (π,invπ), (twoπ,inv2π), (fourπ,inv4π), (sqrt2,invsqrt2), (sqrtπ,invsqrtπ), (sqrt2π,invsqrt2π))
16+
@eval inv(::$(typeof(x))) = $invx
17+
@eval inv(::$(typeof(invx))) = $x
18+
@eval *(::$(typeof(x)), ::$(typeof(invx))) = 1
19+
@eval *(::$(typeof(invx)), ::$(typeof(x))) = 1
20+
end
21+
22+
# sqrt(x)*sqrt(x)=x, x/sqrt(x)=sqrt(x)
23+
for (x,sqrtx) in ((π,sqrtπ), (twoπ,sqrt2π), (fourπ,sqrt4π), (halfπ,sqrthalfπ), (invπ,invsqrtπ), (inv2π,invsqrt2π))
24+
@eval sqrt(::$(typeof(x))) = $sqrtx
25+
@eval *(::$(typeof(sqrtx)), ::$(typeof(sqrtx))) = $x
26+
@eval /(::$(typeof(x)), ::$(typeof(sqrtx))) = $sqrtx
27+
@eval /(::$(typeof(sqrtx)), ::$(typeof(x))) = inv($sqrtx)
28+
end
29+
30+
# exp(log(x))=x
31+
for (x,logx) in ((π,logπ), (twoπ,log2π), (fourπ,log4π))
32+
@eval log(::$(typeof(x))) = $logx
33+
@eval exp(::$(typeof(logx))) = $x
34+
end
35+
36+
end # module

ext/PTYQoLQuasiArraysExt.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@ broadcasted(::typeof(literal_pow), ::typeof(^), x::AbstractQuasiVector, ::Val{b}
1212
# ambiguities
1313
import QuasiArrays: AbstractQuasiArray, AbstractQuasiMatrix, rowsupport, colsupport, MulQuasiArray
1414
import QuasiArrays.QuasiIteratorsMD: QuasiCartesianIndex
15+
import Base.IteratorsMD: split
1516
import Base: convert, to_indices, _to_subscript_indices, __to_subscript_indices, @_inline_meta, to_index
1617

1718
convert(::Type{T}, index::QuasiCartesianIndex{1}) where {T<:VecElement} = convert(T, index[1])
1819
convert(::Type{T}, index::QuasiCartesianIndex{1}) where {T>:Missing} = convert(T, index[1])
1920
convert(::Type{T}, index::QuasiCartesianIndex{1}) where {T>:Nothing} = convert(T, index[1])
2021
convert(::Type{T}, index::QuasiCartesianIndex{1}) where {T>:Union{Missing, Nothing}} = convert(T, index[1])
22+
convert(::Type{Ref{T}}, x::QuasiCartesianIndex{1}) where {T} = RefValue{T}(x)::RefValue{T}
2123

2224
@inline to_indices(A::AbstractQuasiArray, I::Tuple{}) = to_indices(A, axes(A), I)
2325

24-
# this change happens at https://github.com/JuliaLang/julia/pull/45869
25-
@static if VERSION <= v"1.10.1"
26-
to_indices(A::AbstractQuasiArray, ::Tuple{}, I::Union{Tuple{BitArray{N}}, Tuple{Array{Bool, N}}}) where N = (@_inline_meta; (to_index(A, I[1]), to_indices(A, (), tail(I))...))
27-
else
28-
to_indices(A::AbstractQuasiArray, ::Tuple{}, I::Tuple{AbstractArray{Bool, N}, Vararg}) where N = (@_inline_meta; (to_index(A, I[1]), to_indices(A, (), tail(I))...))
29-
end
26+
to_indices(A::AbstractQuasiArray, ::Tuple{}, I::Union{Tuple{BitArray{N}}, Tuple{Array{Bool, N}}}) where N = (@_inline_meta; (to_index(A, I[1]), to_indices(A, (), tail(I))...))
3027

3128
_to_subscript_indices(A::AbstractQuasiMatrix, J::Tuple, Jrem::Tuple) = J
3229
_to_subscript_indices(A::AbstractQuasiMatrix, J::Tuple, Jrem::Tuple{}) = __to_subscript_indices(A, axes(A), J, Jrem)
30+
function _to_subscript_indices(A::AbstractQuasiArray{T,N}, I::Tuple, J::Tuple) where {T,N}
31+
@_inline_meta
32+
J, Jrem = split((I,J), Val(N))
33+
_to_subscript_indices(A, J, Jrem)
34+
end
35+
_to_subscript_indices(::AbstractQuasiArray{T,0}, ::Tuple, ::Tuple{}) where T = ()
36+
_to_subscript_indices(::AbstractQuasiArray{T,0}, ::Tuple, ::Tuple) where T = ()
3337

3438
rowsupport(B::MulQuasiArray, i::CartesianIndex{2}) = rowsupport(B, first(i))
3539
colsupport(B::MulQuasiArray, i::CartesianIndex{2}) = colsupport(B, last(i))
3640

37-
38-
3941
end

test/runtests.jl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ end
8787
end
8888

8989
@testset "Extensions" begin
90+
@testset "BlockArrays" begin
91+
using BlockArrays
92+
@test findblockindex(mortar(reshape([randn(2,2), randn(1,2), randn(2,3), randn(1,3)],2,2)),(2,3)) == BlockIndex((1,2),(2,1))
93+
end
9094
@testset "IntervalSets" begin
9195
using DomainSets
9296
@test union(ChebyshevInterval()) ChebyshevInterval()
@@ -114,13 +118,33 @@ end
114118
end
115119
@testset "AlgebraicNumbers" begin
116120
using AlgebraicNumbers
117-
@test sincospi(1//3) == sincosd(60) == (sqrt(AlgebraicNumber(3))/2, 0.5)
118-
@test tanpi(1//3) == sqrt(AlgebraicNumber(3))
119-
@test sincospi(1//3) isa NTuple{2,AlgebraicNumber}
120-
@test tanpi(1//3) isa AlgebraicNumber
121121
end
122-
@testset "Infinities" begin
123-
using Infinities
122+
@testset "IrrationalConstants" begin
123+
using IrrationalConstants
124+
@testset "half" begin
125+
for (x, halfx) in ((halfπ,quartπ), (π,halfπ), (twoπ,π), (fourπ,twoπ), (inv2π,inv4π), (invπ,inv2π), (twoinvπ,invπ), (fourinvπ,twoinvπ), (sqrt2,invsqrt2), (sqrt2π,sqrthalfπ), (sqrt4π,sqrtπ))
126+
@test halfx + halfx === x
127+
@test x - halfx === halfx
128+
@test halfx / x === 0.5
129+
@test x / halfx === 2
130+
end
131+
end
132+
@testset "inv" begin
133+
for (x,invx) in ((quartπ,fourinvπ), (halfπ,twoinvπ), (π,invπ), (twoπ,inv2π), (fourπ,inv4π), (sqrt2,invsqrt2), (sqrtπ,invsqrtπ), (sqrt2π,invsqrt2π))
134+
@test inv(x) === invx
135+
@test inv(invx) === x
136+
@test x*invx === 1
137+
@test invx*x === 1
138+
end
139+
end
140+
@testset "sqrt" begin
141+
for (x,sqrtx) in ((π,sqrtπ), (twoπ,sqrt2π), (fourπ,sqrt4π), (halfπ,sqrthalfπ), (invπ,invsqrtπ), (inv2π,invsqrt2π))
142+
@test sqrt(x) === sqrtx
143+
@test sqrtx*sqrtx === x
144+
@test x/sqrtx === sqrtx
145+
@test sqrtx/x === inv(sqrtx)
146+
end
147+
end
124148
end
125149
end
126150

0 commit comments

Comments
 (0)