Skip to content

Commit f0d2a5e

Browse files
authored
Use union with ChebyshevInterval (#79)
* use union for ChebyshevInterval * v0.8.2 * add tests * fix tests, add converteltype * Fix array-valued isapprox * fix broadcasting with vectors * Update Project.toml
1 parent 87eb44b commit f0d2a5e

10 files changed

+40
-14
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuasiArrays"
22
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.8.1"
4+
version = "0.8.2"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -12,10 +12,10 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1212
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313

1414
[compat]
15-
ArrayLayouts = "0.7"
15+
ArrayLayouts = "0.7.6"
1616
DomainSets = "0.5"
17-
FillArrays = "0.11, 0.12"
18-
LazyArrays = "0.21.5, 0.22"
17+
FillArrays = "0.12"
18+
LazyArrays = "0.22.2"
1919
StaticArrays = "1"
2020
julia = "1.6"
2121

src/QuasiArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Base: Array, Matrix, Vector
2727
import Base: union, intersect, sort, sort!
2828
import Base: conj, real, imag
2929
# reducedim.jl imports
30-
import Base: prod, sum, cumsum, diff, add_sum, mul_prod, mapreduce, max, min, count, _count, any, _any, all, _all, _sum, _prod, _mapreduce, reduced_index, check_reducedims
30+
import Base: prod, sum, cumsum, diff, add_sum, mul_prod, mapreduce, max, min, count, _count, any, _any, all, _all, _sum, _prod, _mapreduce, reduced_index, check_reducedims, mapfoldl_impl
3131
import Base: BitInteger, IEEEFloat, uniontypes, _InitialValue, safe_tail, reducedim1, _simple_count
3232

3333
import Base: ones, zeros, one, zero, fill
@@ -107,7 +107,7 @@ include("dense.jl")
107107
include("quasikron.jl")
108108

109109
promote_leaf_eltypes(x::AbstractQuasiArray{T}) where {T<:Number} = T
110-
promote_leaf_eltypes(x::AbstractQuasiArray) = mapreduce(promote_leaf_eltypes, promote_type, x; init=Bool)
110+
promote_leaf_eltypes(x::AbstractQuasiArray) = eltype(eltype(x)) #mapreduce(promote_leaf_eltypes, promote_type, x; init=Bool)
111111

112112

113113
function isapprox(x::AbstractQuasiArray, y::AbstractQuasiArray;

src/indices.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ Base.issubset(S::Inclusion, d::Inclusion) = S.domain ⊆ d.domain
193193

194194
intersect(x::Inclusion...) = Inclusion{mapreduce(eltype,promote_type,x)}(intersect(map(domain,x)...))
195195
# use UnionDomain to support intervals
196-
union(x::Inclusion...) = Inclusion{mapreduce(eltype,promote_type,x)}(UnionDomain(map(domain,x)...))
196+
_union(a::ClosedInterval...) = UnionDomain(a...)
197+
_union(a...) = union(a...)
198+
union(x::Inclusion...) = Inclusion{mapreduce(eltype,promote_type,x)}(_union(map(domain,x)...))
197199

198200
checkindex(::Type{Bool}, inds::Inclusion{T}, i::T) where T = i inds
199201
checkindex(::Type{Bool}, inds::Inclusion, i) = i inds

src/inv.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ pinv(A::PInvQuasiMatrix) = first(A.args)
5353
## QuasiArray special case
5454
inv(A::QuasiMatrix) = QuasiArray(inv(A.parent), reverse(A.axes))
5555

56-
_factorize(_, A) = error("Overload for $(typeof(A))")
57-
factorize(A::AbstractQuasiArray) = _factorize(MemoryLayout(A), A)
56+
_factorize(lay, A, dims...; kws...) = error("Overload for $(typeof(A))")
57+
factorize(A::AbstractQuasiArray, dims...; kws...) = _factorize(MemoryLayout(A), A, dims...; kws...)

src/multidimensional.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ end
414414
to_indices(A::AbstractQuasiArray, I::Tuple{Any}) = (@_inline_meta; to_indices(A, axes(A), I))
415415
# But some index types require more context spanning multiple indices
416416
# QuasiCartesianIndexes are simple; they just splat out
417-
@inline to_indices(A::AbstractQuasiArray, inds, I::Tuple{QuasiCartesianIndex, Vararg{Any}}) =
418-
to_indices(A, inds, (I[1].I..., tail(I)...))
417+
@inline to_indices(A, inds, I::Tuple{QuasiCartesianIndex, Vararg{Any}}) = to_indices(A, inds, (I[1].I..., tail(I)...))
418+
@inline to_indices(A::AbstractQuasiArray, inds, I::Tuple{QuasiCartesianIndex, Vararg{Any}}) = to_indices(A, inds, (I[1].I..., tail(I)...))
419419
@inline to_indices(A::AbstractQuasiArray, I::Tuple{Vararg{Union{Integer, CartesianIndex}}}) = to_indices(A, axes(A), I)
420420
@inline to_indices(A::AbstractQuasiArray, I::Tuple{Vararg{Integer}}) = to_indices(A, axes(A), I)
421421
@inline to_indices(A::AbstractQuasiArray, I::Tuple{Vararg{Int}}) = to_indices(A, axes(A), I)
@@ -424,6 +424,10 @@ to_indices(A::AbstractQuasiArray, I::Tuple{Any}) = (@_inline_meta; to_indices(A,
424424
_, indstail = IteratorsMD.split(inds, Val(N))
425425
(to_index(A, I[1]), to_indices(A, indstail, tail(I))...)
426426
end
427+
@inline function to_indices(A, inds, I::Tuple{AbstractArray{QuasiCartesianIndex{N}}, Vararg{Any}}) where N
428+
_, indstail = IteratorsMD.split(inds, Val(N))
429+
(to_index(A, I[1]), to_indices(A, indstail, tail(I))...)
430+
end
427431
Base.to_indices(A::AbstractQuasiArray, I::Tuple{Vararg{Union{Integer, CartesianIndex, StaticArray{<:Tuple,Int}}}}) =
428432
to_indices(A, axes(A), I)
429433

src/quasibroadcast.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ BroadcastStyle(a::AbstractQuasiArrayStyle{N}, ::DefaultArrayStyle{0}) where N =
8181
BroadcastStyle(a::AbstractQuasiArrayStyle{N}, ::DefaultQuasiArrayStyle{N}) where N = a
8282
BroadcastStyle(a::AbstractQuasiArrayStyle{M}, ::DefaultQuasiArrayStyle{N}) where {M,N} =
8383
typeof(a)(Val(max(M, N)))
84+
BroadcastStyle(a::AbstractQuasiArrayStyle{M}, ::AbstractArrayStyle{N}) where {M,N} =
85+
typeof(a)(Val(max(M, N)))
8486

8587
Base.similar(bc::Broadcasted{DefaultQuasiArrayStyle{N}}, ::Type{ElType}) where {N,ElType} =
8688
similar(QuasiArray{ElType}, axes(bc))
@@ -191,3 +193,6 @@ _broadcasted_mul(A::Tuple{AbstractQuasiMatrix,Vararg{Any}}, B::AbstractQuasiMatr
191193
_broadcasted_mul(A::AbstractQuasiMatrix, b::Tuple{Number,Vararg{Any}}) = (sum(A; dims=2)*first(b)[1], _broadcasted_mul(A, tail(b))...)
192194
_broadcasted_mul(A::AbstractQuasiMatrix, b::Tuple{AbstractQuasiVector,Vararg{Any}}) = (size(first(b),1) == 1 ? (sum(A; dims=2)*first(b)[1]) : (A*first(b)), _broadcasted_mul(A, tail(b))...)
193195
_broadcasted_mul(A::AbstractQuasiMatrix, B::Tuple{AbstractQuasiMatrix,Vararg{Any}}) = (size(first(B),1) == 1 ? (sum(A; dims=2) * first(B)) : (A * first(B)), _broadcasted_mul(A, tail(B))...)
196+
197+
198+
LazyArrays.converteltype(::Type{T}, A::AbstractQuasiArray) where T = convert(AbstractQuasiArray{T}, A)

src/quasiconcat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getindex(f::ApplyQuasiMatrix{T,typeof(hcat)}, k::Number, j::Number) whe
2323
throw(BoundsError(f, (k,j)))
2424
end
2525

26-
\(A::AbstractQuasiArray, H::ApplyQuasiMatrix{<:Any,typeof(hcat)}) = hcat((Ref(A) .\ H.args)...)
26+
# \(A::AbstractQuasiArray, H::ApplyQuasiMatrix{<:Any,typeof(hcat)}) = hcat((Ref(A) .\ H.args)...)
2727

2828
function ==(A::ApplyQuasiMatrix{<:Any,typeof(hcat)}, B::ApplyQuasiMatrix{<:Any,typeof(hcat)})
2929
axes.(A.args,2) == axes.(B.args,2) && return all(A.args .== B.args)

test/test_continuous.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using QuasiArrays, IntervalSets, Test
1+
using QuasiArrays, IntervalSets, DomainSets, Test
22
import QuasiArrays: ApplyQuasiArray
33

44
@testset "Continuous" begin
@@ -32,6 +32,12 @@ import QuasiArrays: ApplyQuasiArray
3232
@test findfirst(isequal(2.3), Inclusion(0.0..1)) findlast(isequal(2.3), Inclusion(0..1)) nothing
3333
@test findall(isequal(0.1), Inclusion(0.0..1)) == [0.1]
3434
@test findall(isequal(2.3), Inclusion(0.0..1)) == Float64[]
35+
36+
@test 2.3 in union(x, Inclusion(2..3))
37+
y = Inclusion(ChebyshevInterval())
38+
@test union(y,y) y
39+
z = Inclusion(UnitInterval())
40+
@test union(z,z) z
3541
end
3642

3743
@testset "QuasiDiagonal" begin

test/test_quasibroadcast.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ import QuasiArrays: QuasiCartesianIndex, QuasiCartesianIndices, DefaultQuasiArra
172172
@test stringmime("text/plain", x ./ x) == "Inclusion(0.0:0.5:1.0) ./ Inclusion(0.0:0.5:1.0)"
173173
@test stringmime("text/plain", x .\ x) == "Inclusion(0.0:0.5:1.0) .\\ Inclusion(0.0:0.5:1.0)"
174174
end
175+
176+
@testset "x .* (1:10)'" begin
177+
x = Inclusion([0.1,0.2])
178+
B = x .* (1:10)'
179+
@test B[0.1,2] == 0.2
180+
@test B[0.1,1:3] == 0.1*(1:3)
181+
@test B[[0.1,0.2],2] == 2*[0.1,0.2]
182+
@test B[[0.1,0.2],2:3] == [0.1,0.2] * (2:3)'
183+
end
175184
end
176185

177186
@testset "SubQuasi Broadcast" begin

test/test_quasiconcat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import QuasiArrays: ApplyQuasiMatrix, UnionVcat
3535
a = QuasiVector(randn(5), 0:0.5:2)
3636
b = QuasiVector([5,6,8], [1,3,4])
3737
c = UnionVcat(a,b)
38-
@test axes(c,1) == Inclusion(UnionDomain(0:0.5:2, [1,3,4]))
38+
@test axes(c,1) == Inclusion(union(0:0.5:2, [1,3,4]))
3939
@test c[0.5] a[0.5]
4040
@test c[3] c[3.0] 6.0
4141
@test_throws BoundsError c[2.5]

0 commit comments

Comments
 (0)