Skip to content

Commit 60b95f0

Browse files
authored
Fix bug in similar with adjoints/transpose (#180)
* Fix bug in indexing with adjoints/transpose * Fix adjortrans block indexing
1 parent 83d5d34 commit 60b95f0

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.16.3"
3+
version = "0.16.4"
44

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

src/blockarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ end
357357
BlockArray{T}(undef, axes)
358358
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{AbstractUnitRange{Int},BlockedUnitRange,Vararg{AbstractUnitRange{Int}}}) where T =
359359
BlockArray{T}(undef, axes)
360+
@inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{Int,BlockedUnitRange,Vararg{AbstractUnitRange{Int}}}) where T =
361+
similar(block_array, T, (Base.OneTo(axes[1]), tail(axes)...))
360362

361363
@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{BlockedUnitRange,Vararg{AbstractUnitRange{Int}}}) where T =
362364
BlockArray{T}(undef, axes)

src/views.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ end
146146

147147
Base.view(A::AdjOrTrans{<:Any,<:BlockArray}, K::Block{1}, J::Block{1}) = view(A, Block(Int(K), Int(J)))
148148

149+
@propagate_inbounds getindex(v::LinearAlgebra.AdjOrTransAbsVec, ::Colon, is::AbstractArray{<:Block{1}}) = LinearAlgebra.wrapperop(v)(v.parent[is])
150+
149151

150152
unsafe_convert(::Type{Ptr{T}}, V::SubArray{T,N,PseudoBlockArray{T,N,AT},<:Tuple{Vararg{BlockOrRangeIndex}}}) where {T,N,AT} =
151153
unsafe_convert(Ptr{T}, V.parent) + (Base.first_index(V)-1)*sizeof(T)

test/test_blockarrays.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,12 @@ end
547547
blockisequal(axes(permutedims(A)), axes(A))
548548
end
549549
end
550+
551+
@testset "adjoint getindex" begin
552+
a = BlockVector(1:5, [2,1,1,1])
553+
@test similar(a', Int, 1, axes(a,1)) isa BlockMatrix
554+
@test (a')[:,Block.(1:2)] == transpose(a)[:,Block.(1:2)] == [1 2 3]
555+
@test (a')[:,Block.(1:2)] isa Adjoint
556+
@test transpose(a)[:,Block.(1:2)] isa Transpose
557+
end
550558
end

0 commit comments

Comments
 (0)