Skip to content

Commit

Permalink
Support ArrayLayouts 0.2 (#162)
Browse files Browse the repository at this point in the history
* Support ArrayLayouts 0.2

* Update test_indexing.jl
  • Loading branch information
dlfivefifty authored Mar 26, 2020
1 parent da0c126 commit 2faf902
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 31 deletions.
4 changes: 2 additions & 2 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.14.3"
version = "0.15"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -10,7 +10,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
ArrayLayouts = "0.1"
ArrayLayouts = "0.2"
FillArrays = "0.8"
julia = "1"

Expand Down
2 changes: 1 addition & 1 deletion src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import ArrayLayouts: MemoryLayout, transposelayout, triangulardata,
triangularlayout, MatLdivVec, hermitianlayout, hermitiandata,
materialize!, BlasMatMulMatAdd, BlasMatMulVecAdd, BlasMatLmulVec, BlasMatLdivVec,
colsupport, rowsupport, symmetricuplo, MatMulMatAdd, MatMulVecAdd,
sublayout, sub_materialize, @lazyldiv, @lazylmul, @lazymul, _fill_lmul!,
sublayout, sub_materialize, _fill_lmul!,
reflector!, reflectorApply!

import FillArrays: AbstractFill, getindex_value
Expand Down
2 changes: 0 additions & 2 deletions src/banded/BandedLU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ end
# return BandedLU{T,typeof(A)}(A, ipiv, convert(BlasInt, info))
# end

@lazyldiv BandedMatrix


_apply_ipiv_rows!(A::BandedLU, B::AbstractVecOrMat) = _ipiv_rows!(A, 1 : length(A.ipiv), B)
_apply_inverse_ipiv_rows!(A::BandedLU, B::AbstractVecOrMat) = _ipiv_rows!(A, length(A.ipiv) : -1 : 1, B)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/AbstractBandedMatrix.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AbstractBandedMatrix must implement

abstract type AbstractBandedMatrix{T} <: AbstractSparseMatrix{T,Int} end
abstract type AbstractBandedMatrix{T} <: LayoutMatrix{T} end


"""
Expand Down
16 changes: 4 additions & 12 deletions src/generic/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@ inbands_setindex!(x::Transpose, v, i::Integer, j::Integer) =

###
# Lazy getindex
# this uses a lazy-materialize idiom to construct a matrix based
# this uses a layout-materialize idiom to construct a matrix based
# on the memory layout
###

sub_materialize(::AbstractBandedLayout, V) = BandedMatrix(V)

@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::AbstractVector, jr::AbstractVector) = lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::Colon, jr::AbstractVector) = lazy_getindex(A, kr, jr)
@inline getindex(A::AbstractBandedMatrix, kr::AbstractVector, jr::Colon) = 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) = layout_getindex(A, b)
@inline getindex(A::AbstractMatrix, kr::BandRangeType, j::Integer) = layout_getindex(A, kr, j)
@inline getindex(A::AbstractMatrix, k::Integer, jr::BandRangeType) = layout_getindex(A, k, jr)
3 changes: 0 additions & 3 deletions src/generic/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,3 @@ function materialize!(M::MatMulMatAdd{<:AbstractBandedLayout,<:DiagonalLayout{<:
M.C .= (M.α * getindex_value(M.B.diag)) .* M.A .+ M.β .* M.C
M.C
end


@lazymul AbstractBandedMatrix
10 changes: 0 additions & 10 deletions src/tribanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ Base.replace_in_print_matrix(A::Union{LowerTriangular{<:Any,<:AbstractBandedMatr
-bandwidth(A,1) j-i  bandwidth(A,2) ? s : Base.replace_with_centered_mark(s)

# Mul
@lazylmul UpperTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazylmul UnitUpperTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazylmul LowerTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazylmul UnitLowerTriangular{T, <:AbstractBandedMatrix{T}} where T


@inline function materialize!(M::BlasMatLmulVec{<:TriangularLayout{'U',UNIT,<:BandedColumnMajor},
<:AbstractStridedLayout}) where UNIT
Expand Down Expand Up @@ -69,11 +64,6 @@ end
end

# Ldiv
@lazyldiv UpperTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazyldiv UnitUpperTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazyldiv LowerTriangular{T, <:AbstractBandedMatrix{T}} where T
@lazyldiv UnitLowerTriangular{T, <:AbstractBandedMatrix{T}} where T

for UNIT in ('N', 'U')
@eval begin
@inline function materialize!(M::BlasMatLdivVec{<:TriangularLayout{'U',$UNIT,<:BandedColumnMajor},
Expand Down
82 changes: 82 additions & 0 deletions test/test_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,88 @@ import BandedMatrices: rowstart, rowstop, colstart, colstop,
@test_throws DimensionMismatch a[BandRange, 1] = [1, 2]
end

@testset "scalar integer - - BandRange/Colon" begin
a = BandedMatrix(Ones(5, 5), (1, 1))
# 1.0 1.0 0.0 0.0 0.0
# 1.0 1.0 1.0 0.0 0.0
# 0.0 1.0 1.0 1.0 0.0
# 0.0 0.0 1.0 1.0 1.0
# 0.0 0.0 0.0 1.0 1.0

# in band
a[1, BandRange] .= 2
a[2, BandRange] .= 3
a[3, BandRange] .= 4
a[4, BandRange] .= 5
a[5, BandRange] .= 6
@test a == [2 2 0 0 0;
3 3 3 0 0;
0 4 4 4 0;
0 0 5 5 5;
0 0 0 6 6]

@test a[1, BandRange] == [2, 2]
@test a[2, BandRange] == [3, 3, 3]
@test a[3, BandRange] == [4, 4, 4]
@test a[4, BandRange] == [5, 5, 5]
@test a[5, BandRange] == [6, 6]

@test_throws BoundsError a[0, :] .= 1
@test_throws BandError a[1, :] .= 1
@test_throws BoundsError a[0, BandRange] .= 1
@test_throws BoundsError a[6, BandRange] .= 1

a = BandedMatrix(Ones(5, 3), (2, -1))
@test isempty(a[1,BandRange])
a[2,BandRange] = [1]
a[3,BandRange] = [2, 2]
a[4,BandRange] = [3, 3]
a[5,BandRange] = [4]

@test a == [0 0 0;
1 0 0;
2 2 0;
0 3 3;
0 0 4]
end

@testset "vector - integer - BandRange/Colon" begin
a = BandedMatrix(Ones{Int}(7, 5), (1, 2))
# 5x7 BandedMatrices.BandedMatrix{Float64}:
# 1.0 1.0 0 0 0 0 0 0
# 1.0 1.0 1.0 0 0 0 0 0
# 1.0 1.0 1.0 1.0 0 0 0 0
# 0 1.0 1.0 1.0 1.0 0 0 0
# 0 0 1.0 1.0 1.0 1.0 0 0

# in band
a[1, BandRange] = [1, 2, 3]
a[2, BandRange] = [4, 5, 6, 7]
a[3, BandRange] = [8, 9, 10, 11]
a[4, BandRange] = [12, 13, 14]
a[5, BandRange] = [15, 16]
a[6, BandRange] = [17]

@test a == [ 1 4 0 0 0 0 0;
2 5 8 0 0 0 0;
3 6 9 12 0 0 0;
0 7 10 13 15 0 0;
0 0 11 14 16 17 0]'

@test a[1, BandRange] == [1, 2, 3]
@test a[2, BandRange] == [4, 5, 6, 7]
@test a[3, BandRange] == [8, 9, 10, 11]
@test a[4, BandRange] == [12, 13, 14]
@test a[5, BandRange] == [15, 16]
@test a[6, BandRange] == [17]

@test_throws BoundsError a[0, :] = [1, 2, 3]
@test_throws DimensionMismatch a[1, :] = [1, 2, 3]
@test_throws BoundsError a[0, BandRange] = [1, 2, 3]
@test_throws BoundsError a[8, BandRange] = [1, 2, 3]
@test_throws DimensionMismatch a[1, BandRange] = [1, 2]
end


# scalar - range - integer
let
Expand Down

2 comments on commit 2faf902

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

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.15.0 -m "<description of version>" 2faf902f17718c205e46f1268afcb908dac88d67
git push origin v0.15.0

Please sign in to comment.