Skip to content

Commit

Permalink
Vector views of matrix should be lazy (#61)
Browse files Browse the repository at this point in the history
* lazy broadcast for vector views of matrices

* v0.9.5

* Update Project.toml

* Update runtests.jl

* Update runtests.jl
  • Loading branch information
dlfivefifty authored Feb 10, 2021
1 parent 0f573aa commit 5968738
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.9.4"
version = "0.9.5"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -14,7 +14,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
ArrayLayouts = "0.5"
DSP = "0.6"
FillArrays = "0.11"
LazyArrays = "0.20.2"
LazyArrays = "0.20.5"
julia = "1.5"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Statistics: mean, median

import FillArrays: AbstractFill, getindex_value, fill_reshape, RectDiagonal
import LazyArrays: LazyArrayStyle, AbstractBandedLayout, MemoryLayout, LazyLayout, UnknownLayout,
ZerosLayout, AbstractArrayApplyStyle, CachedArray, CachedVector, ApplyLayout,
ZerosLayout, AbstractArrayApplyStyle, CachedArray, CachedVector, ApplyLayout, LazyMatrix,
reshapedlayout, sub_materialize, LayoutMatrix, LayoutVector, _padded_sub_materialize, PaddedLayout

import DSP: conv
Expand Down
13 changes: 10 additions & 3 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,16 @@ BroadcastStyle(::Type{<:Base.Slice{<:InfRanges}}) = LazyArrayStyle{1}()
const InfIndexRanges{T<:Integer} = Union{InfStepRange{T},AbstractInfUnitRange{T},Slice{OneToInf{T}}}

BroadcastStyle(::Type{<:SubArray{<:Any,1,<:Any,Tuple{<:InfIndexRanges}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:InfIndexRanges,<:InfIndexRanges}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:InfIndexRanges,<:Any}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:Any,<:InfIndexRanges}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,1,<:Any,<:Tuple{<:InfIndexRanges,<:Any}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,1,<:Any,<:Tuple{<:Any,<:InfIndexRanges}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,1,<:LazyMatrix,<:Tuple{<:InfIndexRanges,<:Any}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,1,<:LazyMatrix,<:Tuple{<:Any,<:InfIndexRanges}}})= LazyArrayStyle{1}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:InfIndexRanges,<:InfIndexRanges}}})= LazyArrayStyle{2}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:InfIndexRanges,<:Any}}})= LazyArrayStyle{2}()
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:Any,<:Tuple{<:Any,<:InfIndexRanges}}})= LazyArrayStyle{2}()




broadcasted(::BroadcastStyle, f, r::Adjoint{<:Any,<:InfRanges}) = broadcast(f,parent(r))'
broadcasted(::BroadcastStyle, f, r::Transpose{<:Any,<:InfRanges}) = transpose(broadcast(f,parent(r)))
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,23 @@ end
@test v isa BroadcastArray
@test b[3:10] .+ 1 == v[1:8]
end

@testset "views of matrices" begin
D = Diagonal(1:∞)
V = Vcat(Ones(2,∞), D)
@test view(D,:,5) .+ 1 isa BroadcastVector
@test view(D,5,:) .+ 1 isa BroadcastVector
@test view(V,:,5) .+ 1 isa BroadcastVector
@test view(V,5,:) .+ 1 isa BroadcastVector

@test view(D,2:∞,2:∞) .+ 1 isa BroadcastMatrix
@test view(V,2:∞,2:∞) .+ 1 isa BroadcastMatrix

@test view(D,2:∞,[1,2,3]) .+ 1 isa BroadcastMatrix
@test view(D,[1,2,3],2:∞) .+ 1 isa BroadcastMatrix
@test view(V,2:∞,[1,2,3]) .+ 1 isa BroadcastMatrix
@test view(V,[1,2,3],2:∞) .+ 1 isa BroadcastMatrix
end
end

@testset "Cumsum and diff" begin
Expand Down

2 comments on commit 5968738

@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/29815

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 v0.9.5 -m "<description of version>" 59687386e92e900a79007ab29b86ba9d73e036dc
git push origin v0.9.5

Please sign in to comment.