Skip to content

Commit

Permalink
Update for LazyArrays v0.10 (#124)
Browse files Browse the repository at this point in the history
* using works with new LazyArrays

* Updata MemoryLayouts

* more tests pass

* Tests pass!

* v0.10

* Drop Julia v0.7

* Don't test on 0.7

* Update MulAdd shorthand
  • Loading branch information
dlfivefifty authored Aug 16, 2019
1 parent be286f3 commit ce6ff41
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 313 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- 1.1
- 1.2
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "0.9.4"
version = "0.10"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand All @@ -11,10 +11,10 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
FillArrays = "0.6"
LazyArrays = "0.9.1"
MatrixFactorizations = "0.0.4, 0.1"
julia = "0.7, 1"
FillArrays = "0.6.4"
LazyArrays = "0.10"
MatrixFactorizations = "0.1"
julia = "1"

[extras]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1
- julia_version: 1.1
- julia_version: 1.2
Expand Down
16 changes: 10 additions & 6 deletions src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, DefaultArrayStyle, Br

import LazyArrays: MemoryLayout, @lazymul, @lazylmul, @lazyldiv,
AbstractStridedLayout, AbstractColumnMajor, AbstractRowMajor,
_copyto!, MatMulVec, MatMulMat, transposelayout, triangulardata,
transposelayout, triangulardata,
ConjLayout, conjlayout, SymmetricLayout, symmetriclayout, symmetricdata,
triangularlayout, MatMulVec, MatLdivVec, TriangularLayout,
AbstractBandedLayout, DiagonalLayout, LayoutApplyStyle,
ArrayMulArrayStyle, HermitianLayout, hermitianlayout, hermitiandata,
MulAdd, materialize!, BlasMatMulMat, BlasMatMulVec, VcatLayout, ZerosLayout,
triangularlayout, MatLdivVec, TriangularLayout,
AbstractBandedLayout, DiagonalLayout,
HermitianLayout, hermitianlayout, hermitiandata,
MulAdd, materialize!, BlasMatMulMatAdd, BlasMatMulVecAdd, BlasMatLmulVec, BlasMatLdivVec,
VcatLayout, ZerosLayout,
AbstractColumnMajor, MulLayout, colsupport, rowsupport,
DenseColumnMajor, DenseRowMajor, ArrayLdivArray
DenseColumnMajor, DenseRowMajor, ApplyArrayBroadcastStyle,
mulapplystyle, AbstractMulAddStyle, symmetricuplo, MatMulMatAdd, MatMulVecAdd,
_fill_lmul!, applybroadcaststyle, subarraylayout, sub_materialize, lazy_getindex

import FillArrays: AbstractFill

export BandedMatrix,
Expand Down
11 changes: 6 additions & 5 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

_BandedMatrix(data::AbstractMatrix, m::Integer, l, u) = _BandedMatrix(data, Base.OneTo(m), l, u)

MemoryLayout(A::BandedMatrix) = BandedColumns(MemoryLayout(A.data))
MemoryLayout(A::Type{BandedMatrix{T,Cont,Axes}}) where {T,Cont,Axes} = BandedColumns{typeof(MemoryLayout(Cont))}()


## Constructors
Expand Down Expand Up @@ -616,7 +616,7 @@ function _bidiagonalize!(A::AbstractMatrix{T}, M::BandedColumnMajor) where T
Bidiagonal(d, e, :U)
end

bidiagonalize!(A::AbstractMatrix) = _bidiagonalize!(A, MemoryLayout(A))
bidiagonalize!(A::AbstractMatrix) = _bidiagonalize!(A, MemoryLayout(typeof(A)))
bidiagonalize(A::AbstractMatrix) = bidiagonalize!(copy(A))

svdvals!(A::BandedMatrix) = svdvals!(bidiagonalize!(A))
Expand Down Expand Up @@ -678,11 +678,12 @@ bandshift(S) = bandshift(parentindices(S)[1],parentindices(S)[2])


# BandedMatrix with unit range indexes is also banded
const BandedSubBandedMatrix{T, C, R} =
SubArray{T,2,BandedMatrix{T, C, R},I} where I<:Tuple{Vararg{AbstractUnitRange}}
const BandedSubBandedMatrix{T, C, R, I1<:AbstractUnitRange, I2<:AbstractUnitRange, t} =
SubArray{T,2,BandedMatrix{T, C, R},Tuple{I1,I2},t}

isbanded(::BandedSubBandedMatrix) = true
MemoryLayout(V::BandedSubBandedMatrix) = BandedColumns(MemoryLayout(bandeddata(V)))
MemoryLayout(::Type{BandedSubBandedMatrix{T,C,R,I1,I2,t}}) where {T,C,R,I1,I2,t} =
BandedColumns{typeof(MemoryLayout(SubArray{T,2,C,Tuple{Slice{OneTo{Int}},I2},t}))}()
BroadcastStyle(::Type{<:BandedSubBandedMatrix}) = BandedStyle()

function _shift(bm::BandedSubBandedMatrix)
Expand Down
2 changes: 0 additions & 2 deletions src/banded/gbmm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ end
# c+sz*(j-1)*stc)
# end

_fill_lmul!(β, A::AbstractArray{T}) where T = β == zero(T) ? fill!(A, β) : lmul!(β, A)

function _num_zeroband_u(A)
Al, Au = bandwidths(A)
for b = 0:Al+Au
Expand Down
13 changes: 6 additions & 7 deletions src/banded/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

# Direct and transposed algorithms

function _copyto!(_, dest::AbstractVecOrMat, L::ArrayLdivArray{<:BandedColumnMajor})
A, B = L.args
function materialize!(L::Ldiv{<:BandedColumnMajor})
A, B = L.A, L.B
checksquare(A)
dest B || copyto!(dest, B)
ldiv!(factorize(A), dest)
end

function _copyto!(_, dest::AbstractVecOrMat, L::ArrayLdivArray{<:BandedRowMajor})
A, B = L.args
function copyto!(dest::AbstractVecOrMat, L::Ldiv{<:BandedRowMajor})
A, B = L.A, L.B
copyto!(dest, Mul(transpose(factorize(transpose(A))), B))
end

function _copyto!(_, dest::AbstractVecOrMat, L::ArrayLdivArray{<:ConjLayout{<:BandedRowMajor}})
A, B = L.args
function copyto!(dest::AbstractVecOrMat, L::Ldiv{<:ConjLayout{<:BandedRowMajor}})
A, B = L.A, L.B
copyto!(dest, Mul(factorize(A')', B))
end

Expand Down
32 changes: 14 additions & 18 deletions src/generic/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
####


struct BandedColumns{ML} <: AbstractBandedLayout
layout::ML
end
struct BandedRows{ML} <: AbstractBandedLayout
layout::ML
end
struct BandedColumns{ML} <: AbstractBandedLayout end
struct BandedRows{ML} <: AbstractBandedLayout end

const BandedColumnMajor = BandedColumns{<:AbstractColumnMajor}
const BandedRowMajor = BandedRows{<:AbstractColumnMajor}
BandedColumnMajor() = BandedColumns(DenseColumnMajor())
BandedRowMajor() = Bandeds(DenseRowMajor())
BandedColumnMajor() = BandedColumns{DenseColumnMajor}()
BandedRowMajor() = BandedRows{DenseRowMajor}()

transposelayout(M::BandedColumns) = BandedRows(M.layout)
transposelayout(M::BandedRows) = BandedColumns(M.layout)
conjlayout(::Type{<:Complex}, M::AbstractBandedLayout) = ConjLayout(M)
transposelayout(M::BandedColumns{ML}) where ML = BandedRows{ML}()
transposelayout(M::BandedRows{ML}) where ML = BandedColumns{ML}()
conjlayout(::Type{<:Complex}, ::M) where M<:AbstractBandedLayout = ConjLayout{M}()

# Here we override broadcasting for banded matrices.
# The design is to to exploit the broadcast machinery so that
Expand Down Expand Up @@ -359,23 +355,23 @@ end

function copyto!(dest::AbstractArray, bc::Broadcasted{BandedStyle, <:Any, <:Any, <:Tuple{<:AbstractMatrix}})
(A,) = bc.args
_banded_broadcast!(dest, bc.f, A, MemoryLayout(dest), MemoryLayout(A))
_banded_broadcast!(dest, bc.f, A, MemoryLayout(typeof(dest)), MemoryLayout(typeof(A)))
end

function copyto!(dest::AbstractArray, bc::Broadcasted{BandedStyle, <:Any, <:Any, <:Tuple{<:AbstractMatrix,<:Number}})
(A,x) = bc.args
_banded_broadcast!(dest, bc.f, (A, x), MemoryLayout(dest), MemoryLayout(A))
_banded_broadcast!(dest, bc.f, (A, x), MemoryLayout(typeof(dest)), MemoryLayout(typeof(A)))
end


function copyto!(dest::AbstractArray, bc::Broadcasted{BandedStyle, <:Any, <:Any, <:Tuple{<:Number,<:AbstractMatrix}})
(x,A) = bc.args
_banded_broadcast!(dest, bc.f, (x,A), MemoryLayout(dest), MemoryLayout(A))
_banded_broadcast!(dest, bc.f, (x,A), MemoryLayout(typeof(dest)), MemoryLayout(typeof(A)))
end


function copyto!(dest::AbstractArray, bc::Broadcasted{BandedStyle, <:Any, <:Any, <:Tuple{<:AbstractMatrix,<:AbstractMatrix}})
_banded_broadcast!(dest, bc.f, bc.args, MemoryLayout(dest), MemoryLayout.(bc.args))
_banded_broadcast!(dest, bc.f, bc.args, MemoryLayout(typeof(dest)), MemoryLayout.(typeof.(bc.args)))
end

_bandwidths(::Number) = (-720,-720)
Expand Down Expand Up @@ -428,8 +424,8 @@ function _banded_rmul!(A::AbstractMatrix, α::Number, ::BandedColumns)
A
end

banded_lmul!(α, A::AbstractMatrix) = _banded_lmul!(α, A, MemoryLayout(A))
banded_rmul!(A::AbstractMatrix, α) = _banded_rmul!(A, α, MemoryLayout(A))
banded_lmul!(α, A::AbstractMatrix) = _banded_lmul!(α, A, MemoryLayout(typeof(A)))
banded_rmul!(A::AbstractMatrix, α) = _banded_rmul!(A, α, MemoryLayout(typeof(A)))

lmul!::Number, A::AbstractBandedMatrix) = banded_lmul!(α, A)
rmul!(A::AbstractBandedMatrix, α::Number) = banded_rmul!(A, α)
Expand All @@ -440,7 +436,7 @@ rmul!(A::AbstractBandedMatrix, α::Number) = banded_rmul!(A, α)
##

# these are the routines of the banded interface of other AbstractMatrices
banded_axpy!(a::Number, X::AbstractMatrix, Y::AbstractMatrix) = _banded_axpy!(a, X, Y, MemoryLayout(X), MemoryLayout(Y))
banded_axpy!(a::Number, X::AbstractMatrix, Y::AbstractMatrix) = _banded_axpy!(a, X, Y, MemoryLayout(typeof(X)), MemoryLayout(typeof(Y)))
_banded_axpy!(a::Number, X::AbstractMatrix, Y::AbstractMatrix, ::BandedColumns, ::BandedColumns) =
banded_generic_axpy!(a, X, Y)
_banded_axpy!(a::Number, X::AbstractMatrix, Y::AbstractMatrix, notbandedX, notbandedY) =
Expand Down
19 changes: 8 additions & 11 deletions src/generic/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ inbands_setindex!(x::Transpose, v, i::Integer, j::Integer) =
# on the memory layout
###

@inline _sub_materialize(_, V) = Array(V)
@inline _sub_materialize(::AbstractBandedLayout, V) = BandedMatrix(V)
@inline _materialize(V::SubArray) = _sub_materialize(MemoryLayout(V), V)
sub_materialize(::AbstractBandedLayout, V) = BandedMatrix(V)

@inline _lazy_getindex(A, I...) = _materialize(view(A, I...))
@inline getindex(A::AbstractBandedMatrix, kr::Colon, jr::Colon) = _lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::Colon, jr::AbstractUnitRange) = _lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::AbstractUnitRange, jr::Colon) = _lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::AbstractUnitRange, jr::AbstractUnitRange) = _lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::Colon, jr::Colon) = lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::Colon, jr::AbstractUnitRange) = lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::AbstractUnitRange, jr::Colon) = lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::AbstractUnitRange, jr::AbstractUnitRange) = lazy_getindex(A, kr, jr)

@inline getindex(A::AbstractMatrix, b::Band) = _lazy_getindex(A, b)
@inline getindex(A::AbstractMatrix, kr::BandRangeType, j::Integer) = _lazy_getindex(A, kr, j)
@inline getindex(A::AbstractMatrix, k::Integer, jr::BandRangeType) = _lazy_getindex(A, k, jr)
@inline getindex(A::AbstractMatrix, b::Band) = lazy_getindex(A, b)
@inline getindex(A::AbstractMatrix, kr::BandRangeType, j::Integer) = lazy_getindex(A, kr, j)
@inline getindex(A::AbstractMatrix, k::Integer, jr::BandRangeType) = lazy_getindex(A, k, jr)
Loading

2 comments on commit ce6ff41

@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 register()

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

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" ce6ff41fb82fad0ca55c99dde6bb7b1979188e6e
git push origin v0.10.0

Please sign in to comment.