Skip to content

Commit

Permalink
Dl/resize (#8)
Browse files Browse the repository at this point in the history
* resize

* Add resize

* Remove FactorizationStyle

* Update Project.toml

* Update Project.toml

* v0.2.4
  • Loading branch information
dlfivefifty authored Apr 8, 2020
1 parent 7fe9ecf commit 02687f6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ os:
- windows
julia:
- 1.2
- 1.3
- 1.4
- nightly
matrix:
Expand Down
14 changes: 7 additions & 7 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.3"
version = "0.2.4"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -15,13 +15,13 @@ MatrixFactorizations = "a3b82374-2e81-5b9e-98ce-41277c0e4c87"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
ArrayLayouts = "0.1, 0.2"
BandedMatrices = "0.14, 0.15"
BlockArrays = "0.11"
BlockBandedMatrices = "0.7"
ArrayLayouts = "0.2.4"
BandedMatrices = "0.15.2"
BlockArrays = "0.12"
BlockBandedMatrices = "0.8"
FillArrays = "0.8"
LazyArrays = "0.15, 0.16"
MatrixFactorizations = "0.2.1, 0.3"
LazyArrays = "0.16.3"
MatrixFactorizations = "0.3.1"
julia = "1.2"

[extras]
Expand Down
21 changes: 16 additions & 5 deletions src/LazyBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import LazyArrays: LazyArrayStyle, combine_mul_styles, mulapplystyle, PaddedLayo
broadcastlayout, applylayout, arguments, _arguments, call,
LazyArrayApplyStyle, ApplyArrayBroadcastStyle, ApplyStyle,
LazyLayout, ApplyLayout, BroadcastLayout, FlattenMulStyle, CachedVector,
_mul_args_rows, _mul_args_cols, paddeddata, factorizestyle, sub_materialize,
_mul_args_rows, _mul_args_cols, paddeddata, sub_materialize,
MulMatrix, Mul, CachedMatrix, CachedArray, cachedlayout, resizedata!, applybroadcaststyle,
LazyMatrix, LazyVector, LazyArray
import BandedMatrices: bandedcolumns, bandwidths, isbanded, AbstractBandedLayout,
prodbandwidths, BandedStyle, BandedColumns, BandedRows,
AbstractBandedMatrix, BandedSubBandedMatrix, BandedStyle, _bnds,
banded_rowsupport, banded_colsupport, _BandedMatrix, bandeddata,
banded_qr_lmul!, banded_qr_rmul!, banded_qr
banded_qr_lmul!, banded_qr_rmul!
import BlockBandedMatrices: AbstractBlockBandedLayout, BlockSlice, Block1, AbstractBlockBandedLayout,
isblockbanded, isbandedblockbanded, blockbandwidths,
bandedblockbandedbroadcaststyle, bandedblockbandedcolumns,
Expand Down Expand Up @@ -220,6 +220,7 @@ end


call(b::BroadcastBandedLayout, a) = call(BroadcastLayout(b), a)
call(b::BroadcastBandedLayout, a::SubArray) = call(BroadcastLayout(b), a)

sublayout(M::MulBandedLayout, ::Type{<:Tuple{Vararg{AbstractUnitRange}}}) = M
sublayout(M::BroadcastBandedLayout, ::Type{<:Tuple{Vararg{AbstractUnitRange}}}) = M
Expand Down Expand Up @@ -288,8 +289,18 @@ function bandeddata(B::SubArray{<:Any,2,<:CachedMatrix})
bandeddata(view(A.data,kr,jr))
end

function resizedata!(B::CachedMatrix{T,BandedMatrix{T,Matrix{T},OneTo{Int}}}, n::Integer, m::Integer) where T<:Number
@boundscheck checkbounds(Bool, B, n, m) || throw(ArgumentError("Cannot resize beyound size of operator"))
function resize(A::BandedMatrix, n::Integer, m::Integer)
l,u = bandwidths(A)
_BandedMatrix(reshape(resize!(vec(bandeddata(A)), (l+u+1)*m), l+u+1, m), n, l,u)
end
function resize(A::BandedSubBandedMatrix, n::Integer, m::Integer)
l,u = bandwidths(A)
_BandedMatrix(reshape(resize!(vec(copy(bandeddata(A))), (l+u+1)*m), l+u+1, m), n, l,u)
end

function resizedata!(::BandedColumns{DenseColumnMajor}, _, B::AbstractMatrix{T}, n::Integer, m::Integer) where T<:Number
(n 0 || m 0) && return B
@boundscheck checkbounds(Bool, B, n, m) || throw(ArgumentError("Cannot resize to ($n,$m) which is beyond size $(size(B))"))

# increase size of array if necessary
olddata = B.data
Expand All @@ -301,7 +312,7 @@ function resizedata!(B::CachedMatrix{T,BandedMatrix{T,Matrix{T},OneTo{Int}}}, n:
λ,ω = bandwidths(B.data)
if n size(B.data,1) || m size(B.data,2)
M = 2*max(m,n+u)
B.data = _BandedMatrix(reshape(resize!(vec(olddata.data), (λ+ω+1)*M), λ+ω+1, M), M+λ, λ,ω)
B.data = resize(olddata, M+λ, M)
end
if ν > 0 # upper-right
kr = max(1+1-ω):ν
Expand Down
7 changes: 0 additions & 7 deletions src/bandedql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
# MatrixFactorizations.QRPackedQ
###

struct BandedFactorizationStyle <: ApplyStyle end

factorizestyle(::AbstractBandedLayout) = BandedFactorizationStyle()

copy(A::Applied{BandedFactorizationStyle,typeof(qr)}) = banded_qr(A.args...)
copy(A::Applied{BandedFactorizationStyle,typeof(factorize)}) = banded_qr(A.args...)

banded_lmul!(A::QRPackedQ, B::AbstractVecOrMat) = banded_qr_lmul!(A, B)
banded_lmul!(adjA::Adjoint{<:Any,<:QRPackedQ}, B::AbstractVecOrMat) = banded_qr_lmul!(adjA, B)
banded_rmul!(A::AbstractMatrix, Q::QRPackedQ) = banded_qr_rmul!(A, Q)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@ Base.size(F::FiniteDifference) = (F.n,F.n)
@test A*A == BandedMatrix(A)*A == A*BandedMatrix(A)
@test A[1:5,1:5] isa BandedMatrix
end

@testset "resize" begin
A = brand(4,5,1,1)
@test LazyBandedMatrices.resize(A,6,5)[1:4,1:5] == A
@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
end

@testset "QR" begin
Expand Down

2 comments on commit 02687f6

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

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.4 -m "<description of version>" 02687f60354a24dd56428b5846e8fe809a2982d4
git push origin v0.2.4

Please sign in to comment.