Skip to content

Commit b879cea

Browse files
authored
== for sub array (#73)
* == for sub array * fix tests
1 parent af487b3 commit b879cea

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

Project.toml

Lines changed: 2 additions & 2 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.6"
4+
version = "0.7"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -13,7 +13,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313

1414
[compat]
1515
ArrayLayouts = "0.7"
16-
DomainSets = "0.4, 0.5"
16+
DomainSets = "0.5"
1717
FillArrays = "0.11, 0.12"
1818
LazyArrays = "0.21.5"
1919
StaticArrays = "1"

src/quasikron.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _kronaxes(::Tuple{}...) = ()
2525
_kronaxes(a::Tuple...) = (quasikron(map(first,a)...), _kronaxes(map(tail,a)...)...)
2626
axes(K::QuasiKron) = _kronaxes(map(axes,K.args)...)
2727

28-
function getindex(K::QuasiKron{<:Any,1}, i::Tuple)
29-
@boundscheck checkbounds(K, i)
30-
prod(getindex.(K.args,i))
28+
function _getindex(::Type{IND}, K::QuasiKron{<:Any,1}, i::IND) where IND
29+
@boundscheck checkbounds(K, i...)
30+
prod(getindex.(K.args,i...))
3131
end

src/subquasiarray.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,18 @@ function summary(io::IO, v::SubQuasiArray)
341341
print(io, " with eltype ", eltype(v))
342342
end
343343

344+
function (==)(A::SubQuasiArray, B::AbstractQuasiArray)
345+
parentindices(A) == axes(parent(A)) && return parent(A) == B
346+
Base.invoke(==, NTuple{2,AbstractQuasiArray}, A, B)
347+
end
348+
349+
function (==)(A::AbstractQuasiArray, B::SubQuasiArray)
350+
parentindices(B) == axes(parent(B)) && return A == parent(B)
351+
Base.invoke(==, NTuple{2,AbstractQuasiArray}, A, B)
352+
end
353+
354+
function (==)(A::SubQuasiArray, B::SubQuasiArray)
355+
parentindices(A) == axes(parent(A)) && return parent(A) == B
356+
parentindices(B) == axes(parent(B)) && return A == parent(B)
357+
Base.invoke(==, NTuple{2,AbstractQuasiArray}, A, B)
358+
end

test/test_quasikron.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
using QuasiArrays, DomainSets, Test
1+
using QuasiArrays, DomainSets, StaticArrays, Test
22

33
@testset "Kron" begin
44
@testset "InclusionKron" begin
55
a = Inclusion(0:0.5:2)
66
b = Inclusion([1,3,4])
77
c = quasikron(a,b)
8-
@test eltype(c) == Tuple{Float64,Int}
9-
@test c[(0.5,3)] == (0.5,3)
10-
@test_throws BoundsError c[(0.6,3)]
11-
@test_throws BoundsError c[(0.5,2)]
8+
@test eltype(c) == SVector{2,Float64}
9+
@test c[SVector(0.5,3)] == SVector(0.5,3)
10+
@test_throws BoundsError c[SVector(0.6,3)]
11+
@test_throws BoundsError c[SVector(0.5,2)]
1212
end
1313

1414
@testset "QuasiKron" begin
1515
a = QuasiVector(randn(5), 0:0.5:2)
1616
b = QuasiVector([5,6,8], [1,3,4])
1717
K = quasikron(a, b)
1818
@test axes(K) == (quasikron(axes(a,1),axes(b,1)),)
19-
@test K[(0.5,3)] == a[0.5]b[3]
20-
@test_throws BoundsError K[(0.6,3)]
21-
@test_throws BoundsError K[(0.5,2)]
19+
@test K[SVector(0.5,3)] == a[0.5]b[3]
20+
@test_throws BoundsError K[SVector(0.6,3)]
21+
@test_throws BoundsError K[SVector(0.5,2)]
2222
end
2323
end

test/test_quasisubarray.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,17 @@ using QuasiArrays, Base64, Test
302302
v = view(a, :)
303303
@test stringmime("text/plain", v) == "view(QuasiVector{Float64, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}, Inclusion(0.0:0.5:1.0)) with eltype Float64"
304304
end
305+
306+
@testset "==" begin
307+
A = QuasiArray(randn(3,3),(0:0.5:1,1:0.5:2))
308+
B = QuasiArray(randn(4,3),(0:0.5:1.5,1:0.5:2))
309+
@test A == view(A,:,:)
310+
@test view(A,:,:) == A
311+
@test view(A,:,:) == view(A,:,:)
312+
@test A view(A,Inclusion(0:0.5:0.5),:)
313+
@test view(A,Inclusion(0:0.5:0.5),:) A
314+
@test A  view(B,Inclusion(0:0.5:1),:)
315+
@test view(B,Inclusion(0:0.5:1),:)  A
316+
@test view(B,Inclusion(0:0.5:1),:)  view(A,Inclusion(0:0.5:0.5),:)
317+
end
305318
end

0 commit comments

Comments
 (0)