Skip to content

Commit

Permalink
Fix matrix slices of Hcat (#277)
Browse files Browse the repository at this point in the history
* Fix matrix slices of Hcat

* Update lazyconcat.jl
  • Loading branch information
dlfivefifty authored Nov 14, 2023
1 parent 0db4aec commit 7a96032
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LazyArrays"
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
version = "1.8.1"
version = "1.8.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
6 changes: 3 additions & 3 deletions src/lazyconcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,10 @@ end
# subarrays
###

sublayout(::ApplyLayout{typeof(vcat)}, _) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, _) = ApplyLayout{typeof(hcat)}()
sublayout(::ApplyLayout{typeof(vcat)}, ::Type{<:Tuple{Vararg{Union{AbstractVector{Int},Int}}}}) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Vararg{Union{AbstractVector{Int},Int}}}}) = ApplyLayout{typeof(hcat)}()
# a row-slice of an Hcat is equivalent to a Vcat
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Number,AbstractVector}}) = ApplyLayout{typeof(vcat)}()
sublayout(::ApplyLayout{typeof(hcat)}, ::Type{<:Tuple{Int,AbstractVector{Int}}}) = ApplyLayout{typeof(vcat)}()

_vcat_lastinds(sz) = _vcat_cumsum(sz...)
_vcat_firstinds(sz) = (1, (1 .+ Base.front(_vcat_lastinds(sz)))...)
Expand Down
10 changes: 9 additions & 1 deletion test/concattests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using LazyArrays, FillArrays, LinearAlgebra, ArrayLayouts, Test, Base64
using StaticArrays
import LazyArrays: MemoryLayout, DenseColumnMajor, materialize!, call, paddeddata,
MulAdd, Applied, ApplyLayout, DefaultApplyStyle, sub_materialize, resizedata!,
CachedVector, ApplyLayout, arguments, BroadcastVector
CachedVector, ApplyLayout, arguments, BroadcastVector, LazyLayout


@testset "concat" begin
Expand Down Expand Up @@ -611,4 +611,12 @@ import LazyArrays: MemoryLayout, DenseColumnMajor, materialize!, call, paddeddat
@test v isa AbstractVector{Any}
@test stringmime("text/plain", v) == "vcat()"
end

@testset "matrix indexing" begin
a = Vcat(2, Ones(5))
h = Hcat([2,3], Ones(2,5))
@test MemoryLayout(view(a, [1 2; 1 2])) isa LazyLayout
@test MemoryLayout(view(h, [1 2; 1 2], 1)) isa LazyLayout
@test h[[1 2; 1 2],:] == Matrix(h)[[1 2; 1 2],:]
end
end

2 comments on commit 7a96032

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/95312

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.8.2 -m "<description of version>" 7a9603201d30ec87f6dd5ce3b9a4715b1410599b
git push origin v1.8.2

Please sign in to comment.