Skip to content

Commit d761a08

Browse files
authored
A[1,:] lowers to layout_getindex (#45)
* A[1,:] and A[1,2:end] layout_getindex * AdjOrTrans indexing * Update runtests.jl
1 parent c6599ca commit d761a08

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.4.8"
4+
version = "0.4.9"
55

66
[deps]
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/ArrayLayouts.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ macro _layoutgetindex(Typ)
117117
@inline Base.getindex(A::$Typ, kr::Colon, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr)
118118
@inline Base.getindex(A::$Typ, kr::Colon, jr::Integer) = ArrayLayouts.layout_getindex(A, kr, jr)
119119
@inline Base.getindex(A::$Typ, kr::AbstractVector, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr)
120+
@inline Base.getindex(A::$Typ, kr::Integer, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr)
121+
@inline Base.getindex(A::$Typ, kr::Integer, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr)
120122
end)
121123
end
122124

@@ -155,6 +157,8 @@ end
155157

156158
getindex(A::LayoutVector, kr::AbstractVector) = layout_getindex(A, kr)
157159
getindex(A::LayoutVector, kr::Colon) = layout_getindex(A, kr)
160+
getindex(A::AdjOrTrans{<:Any,<:LayoutVector}, kr::Integer, jr::Colon) = layout_getindex(A, kr, jr)
161+
getindex(A::AdjOrTrans{<:Any,<:LayoutVector}, kr::Integer, jr::AbstractVector) = layout_getindex(A, kr, jr)
158162

159163
_copyto!(_, _, dest::AbstractArray{T,N}, src::AbstractArray{V,N}) where {T,V,N} =
160164
Base.invoke(copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src)

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
3939
@test a == a.A == Vector(a)
4040
@test a[1:3] == a.A[1:3]
4141
@test a[:] == a
42+
@test (a')[1,:] == (a')[1,1:3] == a
4243
@test stringmime("text/plain", a) == "3-element MyVector:\n 1.0\n 2.0\n 3.0"
4344
@test B*a B*a.A
4445
@test B'*a B'*a.A
@@ -56,7 +57,8 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
5657

5758
@testset "LayoutMatrix" begin
5859
A = MyMatrix(randn(5,5))
59-
for (kr,jr) in ((1:2,2:3), (:,:), (:,1:2), (2:3,:), ([1,2],3:4), (:,[1,2]), ([2,3],:))
60+
for (kr,jr) in ((1:2,2:3), (:,:), (:,1:2), (2:3,:), ([1,2],3:4), (:,[1,2]), ([2,3],:),
61+
(2,:), (:,2), (2,1:3), (1:3,2))
6062
@test A[kr,jr] == A.A[kr,jr]
6163
end
6264
b = randn(5)

0 commit comments

Comments
 (0)