Skip to content

Commit

Permalink
Dl/lazybandedtimespadded (#9)
Browse files Browse the repository at this point in the history
* banded * padded should be padded

* Update runtests.jl

* more lazy cases

* increase coverage
  • Loading branch information
dlfivefifty authored Apr 16, 2020
1 parent 6f2487b commit 6476f47
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
deps/deps.jl
Manifest.toml
.DS_Store
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LazyBandedMatrices"
uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f"
authors = ["Sheehan Olver <solver@mac.com>"]
version = "0.2.5"
version = "0.2.6"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -20,7 +20,7 @@ BandedMatrices = "0.15.2"
BlockArrays = "0.12"
BlockBandedMatrices = "0.8"
FillArrays = "0.8"
LazyArrays = "0.16.3"
LazyArrays = "0.16.5"
MatrixFactorizations = "0.3.1"
julia = "1.2"

Expand Down
6 changes: 5 additions & 1 deletion src/LazyBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LazyArrays: LazyArrayStyle, combine_mul_styles, mulapplystyle, PaddedLayo
LazyLayout, ApplyLayout, BroadcastLayout, FlattenMulStyle, CachedVector,
_mul_args_rows, _mul_args_cols, paddeddata, sub_materialize,
MulMatrix, Mul, CachedMatrix, CachedArray, cachedlayout, resizedata!, applybroadcaststyle,
LazyMatrix, LazyVector, LazyArray
LazyMatrix, LazyVector, LazyArray, MulAddStyle
import BandedMatrices: bandedcolumns, bandwidths, isbanded, AbstractBandedLayout,
prodbandwidths, BandedStyle, BandedColumns, BandedRows,
AbstractBandedMatrix, BandedSubBandedMatrix, BandedStyle, _bnds,
Expand Down Expand Up @@ -183,8 +183,12 @@ combine_mul_styles(::MulBandedLayout, ::MulBandedLayout) = LazyArrayApplyStyle()
combine_mul_styles(::MulBandedLayout, ::BroadcastBandedLayout) = LazyArrayApplyStyle()
combine_mul_styles(::BroadcastBandedLayout, ::MulBandedLayout) = LazyArrayApplyStyle()

mulapplystyle(::LazyBandedLayout, ::LazyBandedLayout) = LazyArrayApplyStyle()
mulapplystyle(::LazyBandedLayout, ::AbstractBandedLayout) = LazyArrayApplyStyle()
mulapplystyle(::AbstractBandedLayout, ::LazyBandedLayout) = LazyArrayApplyStyle()
mulapplystyle(::LazyBandedLayout, ::MulBandedLayout) = FlattenMulStyle()
mulapplystyle(::MulBandedLayout, ::LazyBandedLayout) = FlattenMulStyle()
mulapplystyle(::AbstractBandedLayout, ::PaddedLayout) = MulAddStyle()


@inline colsupport(::BroadcastBandedLayout, A, j) = banded_colsupport(A, j)
Expand Down
38 changes: 35 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LazyBandedMatrices, BlockBandedMatrices, BandedMatrices, LazyArrays,
ArrayLayouts, MatrixFactorizations, LinearAlgebra, Random, Test
import LazyArrays: Applied, resizedata!, FillLayout, MulAddStyle, arguments, colsupport, rowsupport
import LazyBandedMatrices: MulBandedLayout, VcatBandedMatrix, BroadcastBandedLayout, ApplyBandedLayout, BlockKron
import BandedMatrices: BandedStyle, _BandedMatrix, AbstractBandedMatrix
import LazyArrays: Applied, resizedata!, FillLayout, MulAddStyle, arguments, colsupport, rowsupport, LazyLayout, ApplyStyle
import LazyBandedMatrices: MulBandedLayout, VcatBandedMatrix, BroadcastBandedLayout, ApplyBandedLayout, BlockKron, LazyBandedLayout
import BandedMatrices: BandedStyle, _BandedMatrix, AbstractBandedMatrix, BandedRows, BandedColumns

Random.seed!(0)

Expand Down Expand Up @@ -39,6 +39,17 @@ BandedMatrices.inbands_getindex(A::PseudoBandedMatrix, j::Int, k::Int) = A.data[
BandedMatrices.inbands_setindex!(A::PseudoBandedMatrix, v, j::Int, k::Int) = setindex!(A.data, v, j, k)
LinearAlgebra.fill!(A::PseudoBandedMatrix, v) = fill!(A.data,v)

struct MyLazyArray{T,N} <: AbstractArray{T,N}
data::Array{T,N}
end


Base.size(A::MyLazyArray) = size(A.data)
Base.getindex(A::MyLazyArray, j::Int...) = A.data[j...]
LazyArrays.MemoryLayout(::Type{<:MyLazyArray}) = LazyLayout()
LinearAlgebra.factorize(A::MyLazyArray) = factorize(A.data)


@testset "Mul" begin
A = PseudoBandedMatrix(rand(5, 4), 1, 2)
B = PseudoBandedMatrix(rand(4, 4), 2, 3)
Expand Down Expand Up @@ -508,6 +519,27 @@ Base.size(F::FiniteDifference) = (F.n,F.n)
@test LazyBandedMatrices.resize(view(A,2:3,2:5),5,5) isa BandedMatrix
@test LazyBandedMatrices.resize(view(A,2:3,2:5),5,5)[1:2,1:4] == A[2:3,2:5]
end

@testset "Lazy banded * Padded" begin
A = _BandedMatrix(Vcat(BroadcastArray(exp, 1:5)', Ones(1,5)), 5, 1, 0)
@test MemoryLayout(A) isa BandedColumns{LazyLayout}
x = Vcat([1,2], Zeros(3))
@test A*x isa Vcat
end

@testset "Lazy banded" begin
A = _BandedMatrix(Ones{Int}(1,10),10,0,0)'
B = _BandedMatrix((-2:-2:-20)', 10,-1,1)
C = Diagonal( BroadcastVector(/, 2, (1:2:20)))
@test MemoryLayout(A) isa BandedRows{FillLayout}
@test MemoryLayout(B) isa BandedColumns{UnknownLayout}
@test MemoryLayout(C) isa DiagonalLayout{LazyLayout}
BC = BroadcastArray(*, B, permutedims(MyLazyArray(Array(C.diag))))
@test MemoryLayout(BC) isa LazyBandedLayout
@test A*BC isa MulMatrix
@test BC*B isa MulMatrix
@test BC*BC isa MulMatrix
end
end

@testset "QR" begin
Expand Down

2 comments on commit 6476f47

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

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.2.6 -m "<description of version>" 6476f47a58d867c1c93dcfc7249c44714c48dfc0
git push origin v0.2.6

Please sign in to comment.