Skip to content

Commit

Permalink
More descriptive summary (#213)
Browse files Browse the repository at this point in the history
* More descriptive summary

* Update test_miscs.jl

* Update Project.toml

* fix Zeros bandwidths

* Update test_interface.jl

* v0.16

* use very large bandwidths

* Update Project.toml

* Drop Julia <v1.5 support
  • Loading branch information
dlfivefifty authored Jan 8, 2021
1 parent 31472a5 commit 1992b5c
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 66 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:
- 1.0
- 1.5
- nightly
matrix:
Expand Down
10 changes: 4 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "0.15.25"
version = "0.16.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
ArrayLayouts = "0.4.3"
Compat = "3.20"
FillArrays = "0.9.7, 0.10"
julia = "1"
ArrayLayouts = "0.4.3, 0.5"
FillArrays = "0.9.7, 0.10, 0.11"
julia = "1.5"

[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: 1
- julia_version: 1.5
- julia_version: nightly

Expand Down
15 changes: 2 additions & 13 deletions src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import ArrayLayouts: MemoryLayout, transposelayout, triangulardata,

import FillArrays: AbstractFill, getindex_value, _broadcasted_zeros, unique_value

using Compat # dot(x, A, y) for Julia < 1.3

export BandedMatrix,
bandrange,
Expand All @@ -59,18 +58,8 @@ export BandedMatrix,
Eye


if VERSION < v"1.2-"
import Base: has_offset_axes
require_one_based_indexing(A...) = !has_offset_axes(A...) || throw(ArgumentError("offset arrays are not supported but got an array with index other than 1"))
else
import Base: require_one_based_indexing
end

if VERSION < v"1.3-"
const _apply_ipiv_rows! = LinearAlgebra._apply_ipiv!
else
import LinearAlgebra: _apply_ipiv_rows!
end
import Base: require_one_based_indexing
import LinearAlgebra: _apply_ipiv_rows!

include("blas.jl")
include("lapack.jl")
Expand Down
41 changes: 22 additions & 19 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -739,29 +739,18 @@ end
bandwidths(S::SubArray{T,2,<:AbstractMatrix,I}) where {T,I<:Tuple{Vararg{AbstractUnitRange}}} =
min.(size(S) .- 1, bandwidths(parent(S)) .+ (-1,1) .* bandshift(S))

if VERSION < v"1.2-"
@inline function inbands_getindex(S::BandedSubBandedMatrix{T}, k::Integer, j::Integer) where {T}
@inbounds r = inbands_getindex(parent(S), reindex(S, parentindices(S), (k, j))...)
r
end
@inline function inbands_getindex(S::BandedSubBandedMatrix{T}, k::Integer, j::Integer) where {T}
@inbounds r = inbands_getindex(parent(S), reindex(parentindices(S), (k, j))...)
r
end

@inline function inbands_setindex!(S::BandedSubBandedMatrix{T}, v, k::Integer, j::Integer) where {T}
@inbounds r = inbands_setindex!(parent(S), v, reindex(S, parentindices(S), (k, j))...)
r
end
else
@inline function inbands_getindex(S::BandedSubBandedMatrix{T}, k::Integer, j::Integer) where {T}
@inbounds r = inbands_getindex(parent(S), reindex(parentindices(S), (k, j))...)
r
end

@inline function inbands_setindex!(S::BandedSubBandedMatrix{T}, v, k::Integer, j::Integer) where {T}
@inbounds r = inbands_setindex!(parent(S), v, reindex(parentindices(S), (k, j))...)
r
end
@inline function inbands_setindex!(S::BandedSubBandedMatrix{T}, v, k::Integer, j::Integer) where {T}
@inbounds r = inbands_setindex!(parent(S), v, reindex(parentindices(S), (k, j))...)
r
end



function convert(::Type{BandedMatrix}, S::BandedSubBandedMatrix)
A=parent(S)
kr,jr=parentindices(S)
Expand All @@ -780,3 +769,17 @@ function convert(::Type{BandedMatrix}, S::BandedSubBandedMatrix)
end
_BandedMatrix(data,length(kr),max(0, l-shft),max(0, u+shft))
end

_banded_summary(io, B::BandedMatrix{T}, inds) where T = print(io, Base.dims2string(length.(inds)), " BandedMatrix{$T} with bandwidths $(bandwidths(B))")
Base.array_summary(io::IO, B::DefaultBandedMatrix, inds::Tuple{Vararg{OneTo}}) = _banded_summary(io, B, inds)
function Base.array_summary(io::IO, B::BandedMatrix, inds::Tuple{Vararg{OneTo}})
_banded_summary(io, B, inds)
print(io, " with data ")
summary(io, B.data)
end
function Base.array_summary(io::IO, B::BandedMatrix, inds)
_banded_summary(io, B, inds)
print(io, " with data ")
summary(io, B.data)
print(io, " with indices ", Base.inds2string(inds))
end
3 changes: 0 additions & 3 deletions src/generic/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,6 @@ end

_bcsize(A) = size(A)

if VERSION < v"1.5"
_bcsize(bc::Broadcasted) = map(length,axes(bc))
end

_broadcast_bandwidths(bnds) = bnds
_broadcast_bandwidths(bnds, _) = bnds
Expand Down
2 changes: 1 addition & 1 deletion src/interfaceimpl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

# Here we implement the banded matrix interface for some key examples
isbanded(::Zeros) = true
bandwidths(::Zeros) = (0,0)
bandwidths(::Zeros) = (-40320,-40320) # 40320 == prod(1:8), used for special cases involving gcd
inbands_getindex(::Zeros{T}, k::Integer, j::Integer) where T = zero(T)

isbanded(::Eye) = true
Expand Down
4 changes: 1 addition & 3 deletions src/symbanded/ldlt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
@inline bandwidth(A::LDLt{T,Symmetric{T,M}}, k) where {T,M<:BandedMatrix{T}} = bandwidth(A.data, k)

factorize(S::Symmetric{<:Any,<:BandedMatrix}) = ldlt(S)
if VERSION  v"1.4-"
LinearAlgebra._factorize(S::Symmetric{<:Any,<:BandedMatrix}; check=false) = ldlt(S)
end
LinearAlgebra._factorize(S::Symmetric{<:Any,<:BandedMatrix}; check=false) = ldlt(S)

function ldlt!(F::Symmetric{T,M}) where {T,M<:BandedMatrix{T}}
A = F.data
Expand Down
22 changes: 10 additions & 12 deletions src/symbanded/symbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
parent(A).data[bandwidth(A) - abs(k-j) + 1, max(k,j)]

# this is a hack but is much faster than default
if VERSION  v"1.5"
function getindex(S::Symmetric{<:Any, <:BandedMatrix}, kr::AbstractUnitRange, jr::AbstractUnitRange)
A = parent(S)
m = max(maximum(kr), maximum(jr))
B = if S.uplo == 'U'
BandedMatrix(A[1:m,1:m],(0, bandwidth(A,2)))
else
BandedMatrix(A[1:m,1:m],(bandwidth(A,1),0))
end
ret = B + transpose(B)
rdiv!(view(ret, band(0)), 2)
ret[kr, jr]
function getindex(S::Symmetric{<:Any, <:BandedMatrix}, kr::AbstractUnitRange, jr::AbstractUnitRange)
A = parent(S)
m = max(maximum(kr), maximum(jr))
B = if S.uplo == 'U'
BandedMatrix(A[1:m,1:m],(0, bandwidth(A,2)))
else
BandedMatrix(A[1:m,1:m],(bandwidth(A,1),0))
end
ret = B + transpose(B)
rdiv!(view(ret, band(0)), 2)
ret[kr, jr]
end

symmetriclayout(::ML) where ML<:BandedColumns = SymmetricLayout{ML}()
Expand Down
9 changes: 9 additions & 0 deletions test/test_banded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,14 @@ Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef,
@test A - B == A .- B == Matrix(A) - Matrix(B)
@test B - A == B .- A == Matrix(B) - Matrix(A)
end

@testset "summary" begin
A = BandedMatrix{Float64}(undef, (5, 5), (1,2))
@test summary(A) == "5×5 BandedMatrix{Float64} with bandwidths (1, 2)"
A = _BandedMatrix(Fill(1,1,5), 4, 1, -1)
@test summary(A) == "4×5 BandedMatrix{$Int} with bandwidths (1, -1) with data 1×5 Fill{Int64}"
A = _BandedMatrix(Fill(1,1,5), Base.Slice(1:4), 1, -1)
@test summary(A) == "4×5 BandedMatrix{$Int} with bandwidths (1, -1) with data 1×5 Fill{Int64} with indices 1:4×Base.OneTo(5)"
end
end

8 changes: 3 additions & 5 deletions test/test_broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,9 @@ import BandedMatrices: BandedStyle, BandedRows
@test A .* b' == b' .* A == Matrix(A) .* b'
@test bandwidths(A .* b') == bandwidths(b' .* A) == bandwidths(A)

if VERSION  v"1.5"
@testset "nested broadcast" begin
@test bandwidths((b ./ 2) .* A) == (1,2)
@test (b ./ 2) .* A == (b ./ 2) .* Matrix(A)
end
@testset "nested broadcast" begin
@test bandwidths((b ./ 2) .* A) == (1,2)
@test (b ./ 2) .* A == (b ./ 2) .* Matrix(A)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LinearAlgebra.fill!(A::PseudoBandedMatrix, v) = fill!(A.data,v)
@testset "banded matrix interface" begin
@testset "Zeros" begin
@test isbanded(Zeros(5,6))
@test bandwidths(Zeros(5,6)) == (0,0)
@test bandwidths(Zeros(5,6)) == (-40320,-40320)
@test BandedMatrices.inbands_getindex(Zeros(5,6), 1,2) == 0
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_miscs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import BandedMatrices: _BandedMatrix, DefaultBandedMatrix
end

@time @testset "show" begin
@test occursin("10×10 BandedMatrix{Float64,$(Matrix{Float64}),"*string(Base.OneTo{Int})*"}",
@test occursin("10×10 BandedMatrix{Float64} with bandwidths (3, 3)",
sprint() do io
show(io, MIME"text/plain"(), brand(10, 10, 3, 3))
end)
Expand Down

0 comments on commit 1992b5c

Please sign in to comment.