Skip to content

Commit 7dc29df

Browse files
authored
Support hcat with non-number indexing (#122)
* Support hcat with non-number indexing * add tests * Update QuasiArrays.jl * Update test_quasiconcat.jl * Update test_quasiconcat.jl
1 parent 8f3e26d commit 7dc29df

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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 <solver@mac.com>"]
4-
version = "0.13"
4+
version = "0.13.1"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/QuasiArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ const AbstractQuasiOrArray{T} = Union{AbstractArray{T},AbstractQuasiArray{T}}
7878

7979

8080
cardinality(d) = length(d)
81-
cardinality(d::UnionDomain) = +(cardinality.(d.domains)...)
81+
cardinality(d::UnionDomain) = sum(cardinality, d.domains)
82+
cardinality(d::VcatDomain) = prod(cardinality, d.domains)
8283

8384
size(A::AbstractQuasiArray) = map(cardinality, axes(A))
8485
axes(A::AbstractQuasiArray) = error("Override axes for $(typeof(A))")

src/quasiconcat.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ _vecormat_getindex(A::AbstractQuasiVector,k,ξ) = A[k]
1313
# TODO: generalize
1414
@inline LazyArrays._view_hcat(a::AbstractQuasiVector, kr::Number, jr) = a[kr]
1515

16-
function getindex(f::ApplyQuasiMatrix{T,typeof(hcat)}, k::Number, j::Number) where T
16+
function _getindex(::Type{IND}, f::ApplyQuasiMatrix{T,typeof(hcat)}, (k,j)::IND) where {T,IND}
1717
ξ = j
1818
for A in f.args
1919
n = size(A,2)
20-
ξ  n && return T(_vecormat_getindex(A,k,ξ))::T
20+
ξ n && return T(_vecormat_getindex(A,k,ξ))::T
2121
ξ -= n
2222
end
2323
throw(BoundsError(f, (k,j)))

test/test_quasiconcat.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using QuasiArrays, DomainSets, Test
2-
import QuasiArrays: ApplyQuasiMatrix, UnionVcat
2+
import QuasiArrays: ApplyQuasiMatrix, UnionVcat, cardinality
33

44
@testset "Concatenation" begin
55
@testset "Hcat" begin
@@ -9,7 +9,7 @@ import QuasiArrays: ApplyQuasiMatrix, UnionVcat
99
@test axes(B) == (axes(A,1), Base.OneTo(4))
1010
@test B[0.0,1] == B[0.0,3] == A[0.0,1]
1111
@test B == B
12-
@test B  A
12+
@test B A
1313
@test B [A A A]
1414
@test_throws BoundsError B[0.1,1]
1515
@test_throws BoundsError B[0.0,5]
@@ -36,8 +36,11 @@ import QuasiArrays: ApplyQuasiMatrix, UnionVcat
3636
b = QuasiVector([5,6,8], [1,3,4])
3737
c = UnionVcat(a,b)
3838
@test axes(c,1) == Inclusion(union(0:0.5:2, [1,3,4]))
39+
@test cardinality(axes(c,1)) == length(c) == 7
3940
@test c[0.5] a[0.5]
4041
@test c[3] c[3.0] 6.0
42+
@test c[1] == a[1] # first
43+
@test cardinality(UnionDomain(0:0.5:2, 3:5)) == 8
4144
@test_throws BoundsError c[2.5]
4245
end
4346
@testset "matrix" begin

test/test_quasikron.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import QuasiArrays: ArrayQuasiVector
1010
@test c[SVector(0.5,3)] == SVector(0.5,3)
1111
@test_throws BoundsError c[SVector(0.6,3)]
1212
@test_throws BoundsError c[SVector(0.5,2)]
13+
@testset "Hcat" begin
14+
H = [first.(c) last.(c)]
15+
@test H[SVector(0.5,3),1] == 0.5
16+
@test H[SVector(0.5,3),1:2] == H[SVector(0.5,3),:] == [0.5, 3]
17+
@test H[[SVector(0.5,3),SVector(1,4)],1] == [0.5,1]
18+
@test H[[SVector(0.5,3),SVector(1,4)],1:2] == H[[SVector(0.5,3),SVector(1,4)],:] == [0.5 3; 1 4]
19+
end
1320
end
1421

1522
@testset "QuasiKron" begin

0 commit comments

Comments
 (0)