Skip to content

Commit dbb53e3

Browse files
committed
v0.7-alpha compatibility
1 parent 5a7742c commit dbb53e3

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

src/BlockBandedMatrices.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Base: getindex, setindex!, checkbounds, @propagate_inbounds, convert,
2323
start, eltype, getindex, to_indices, to_index,
2424
reindex, _maybetail, tail, @_propagate_inbounds_meta
2525

26-
import Compat.LinearAlgebra: A_ldiv_B!, A_mul_B!, UniformScaling, isdiag
26+
import Compat.LinearAlgebra: UniformScaling, isdiag
2727
import Compat.LinearAlgebra.BLAS: BlasInt, BlasFloat, @blasfunc, libblas
2828
import Compat.LinearAlgebra.LAPACK: chktrans, chkdiag, liblapack, chklapackerror, checksquare, chkstride1,
2929
chkuplo
@@ -32,11 +32,14 @@ import Compat.LinearAlgebra.LAPACK: chktrans, chkdiag, liblapack, chklapackerror
3232
import Compat: axes, copyto!
3333

3434
if VERSION < v"0.7-"
35+
import Compat.LinearAlgebra: A_ldiv_B!, A_mul_B!
3536
const rmul! = scale!
3637
const lmul! = scale!
38+
const ldiv! = A_ldiv_B!
3739
const parentindices = parentindexes
3840
else
39-
import LinearAlgebra: rmul!, lmul!
41+
import LinearAlgebra: rmul!, lmul!, ldiv!, rdiv!
42+
findfirst(A, v) = something(Base.findfirst(isequal(v), A))
4043
end
4144

4245
export BandedBlockBandedMatrix, BlockBandedMatrix, blockbandwidth, blockbandwidths,

src/linalg.jl

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ function _mul!(Y::AbstractMatrix, A::AbstractMatrix, X::AbstractMatrix, α, β,
3030
Y
3131
end
3232

33-
A_mul_B!(y::AbstractVector, A::AbstractBlockBandedMatrix, b::AbstractVector) =
33+
mul!(y::AbstractVector, A::AbstractBlockBandedMatrix, b::AbstractVector) =
3434
mul!(fill!(y, zero(eltype(y))), A, b, one(eltype(A)), zero(eltype(y)))
3535

36-
A_mul_B!(y::AbstractMatrix, A::AbstractBlockBandedMatrix, b::AbstractMatrix) =
36+
mul!(y::AbstractMatrix, A::AbstractBlockBandedMatrix, b::AbstractMatrix) =
3737
mul!(fill!(y, zero(eltype(y))), A, b, one(eltype(A)), zero(eltype(y)))
3838

3939

@@ -54,6 +54,10 @@ end
5454

5555

5656
const BBBOrStridedVecOrMat{T} = Union{BlockBandedBlock{T}, StridedVecOrMat{T}}
57+
58+
*(V::BlockBandedBlock{T}, b::AbstractVector{T}) where T<:BlasFloat =
59+
mul!(Array{T}(undef, size(V,1)), V, b, one(T), zero(T))
60+
5761
if VERSION < v"0.7-"
5862
BLAS.gemv!(trans::Char, α::T, A::BlockBandedBlock{T}, X::AbstractVector{T}, β::T, Y::AbstractVector{T}) where T <: BlasFloat =
5963
gemv!(trans, α, A, X, β, Y)
@@ -144,7 +148,7 @@ function *(A::BlockBandedMatrix{T}, B::BlockBandedMatrix{V}) where {T<:Number,V<
144148
n,m = size(A,1), size(B,2)
145149

146150
l, u = A.l+B.l, A.u+B.u
147-
A_mul_B!(BlockBandedMatrix{promote_type(T,V)}(undef,
151+
mul!(BlockBandedMatrix{promote_type(T,V)}(undef,
148152
BlockBandedSizes(BlockSizes((Arows,Bcols)), l, u)),
149153
A, B)
150154
end
@@ -169,7 +173,7 @@ function *(A::BandedBlockBandedMatrix{T}, B::BandedBlockBandedMatrix{V}) where {
169173

170174
bs = BandedBlockBandedSizes(BlockSizes((Arows,Bcols)), A.l+B.l, A.u+B.u, A.λ+B.λ, A.μ+B.μ)
171175

172-
A_mul_B!(BandedBlockBandedMatrix{promote_type(T,V)}(undef, bs),
176+
mul!(BandedBlockBandedMatrix{promote_type(T,V)}(undef, bs),
173177
A, B)
174178
end
175179

@@ -227,8 +231,8 @@ end
227231
# BlockIndexRange subblocks
228232
####
229233

230-
A_mul_B!(c::AbstractVector{T}, V::BlockBandedBlock{T}, b::AbstractVector{T}) where T<:BlasFloat =
231-
mul!(c, V, b, one(T), zero(T))
234+
mul!(c::AbstractVector{T}, V::BlockBandedBlock{T}, b::AbstractVector{T}) where T<:BlasFloat =
235+
BandedMatrices.mul!(c, V, b, one(T), zero(T))
232236

233237
const BlockIndexRange1 = BlockIndexRange{1,Tuple{UnitRange{Int64}}}
234238
const BlockRangeBlockSubBlockBandedMatrix{T} = SubArray{T,2,BlockBandedMatrix{T},Tuple{BlockSlice{BlockRange1},BlockSlice{Block{1,Int}}}}
@@ -329,17 +333,17 @@ end
329333
# back substitution
330334
######
331335

332-
@inline A_ldiv_B!(U::UpperTriangular{T, BLOCK}, b::StridedVecOrMat{T}) where BLOCK <: Union{BlockBandedBlock{T}, BlockBandedSubBlock{T}} where T<:BlasFloat =
336+
@inline ldiv!(U::UpperTriangular{T, BLOCK}, b::StridedVecOrMat{T}) where BLOCK <: Union{BlockBandedBlock{T}, BlockBandedSubBlock{T}} where T<:BlasFloat =
333337
trtrs!('U', 'N', 'N', parent(U), b)
334338

335-
@inline A_ldiv_B!(U::UpperTriangular{T, BlockBandedBlock{T}}, b::StridedVecOrMat{T}) where {T<:BlasFloat} =
339+
@inline ldiv!(U::UpperTriangular{T, BlockBandedBlock{T}}, b::StridedVecOrMat{T}) where {T<:BlasFloat} =
336340
trtrs!('U', 'N', 'N', parent(U), b)
337341

338342

339343
@inline hasmatchingblocks(A) =
340344
block_sizes(A).cumul_sizes[1] == block_sizes(A).cumul_sizes[2]
341345

342-
function A_ldiv_B!(U::UpperTriangular{T, BM}, b::StridedVector) where BM <: Union{BlockBandedMatrix{T}, BlockBandedSubBlockBandedMatrix{T}} where T
346+
function ldiv!(U::UpperTriangular{T, BM}, b::StridedVector) where BM <: Union{BlockBandedMatrix{T}, BlockBandedSubBlockBandedMatrix{T}} where T
343347
A = parent(U)
344348

345349
@boundscheck size(A,1) == length(b) || throw(BoundsError(A))
@@ -363,7 +367,7 @@ function blockbanded_squareblocks_trtrs!(A::AbstractMatrix{T}, b::AbstractVector
363367
for K = N:-1:1
364368
V_22 = view(A, Block(K), Block(K))
365369
b_2 = view(b, parentindices(V_22)[1].indices)
366-
A_ldiv_B!(UpperTriangular(V_22), b_2)
370+
ldiv!(UpperTriangular(V_22), b_2)
367371

368372
V_12 = view(A, blockcolstart(A, K):Block(K-1), Block(K))
369373
b̃_1 = view(b, parentindices(V_12)[1].indices)
@@ -383,7 +387,7 @@ function hasmatchingblocks(V::SubArray{T,2,BlockBandedMatrix{T},Tuple{UnitRange{
383387
end
384388

385389
# Write U as [U_11 U_12; 0 U_22] and b = [b_1,b_2,b_3] to use efficient block versions
386-
function A_ldiv_B!(U::UpperTriangular{T,SV},
390+
function ldiv!(U::UpperTriangular{T,SV},
387391
b::AbstractVector{T}) where SV<:SubArray{T,2,BlockBandedMatrix{T},Tuple{UnitRange{Int},UnitRange{Int}}} where T
388392
V = parent(U)
389393
if hasmatchingblocks(V)
@@ -401,15 +405,15 @@ function blockbanded_squareblocks_intrange_trtrs!(V::AbstractMatrix{T}, b::Abstr
401405

402406
V_22 = view(A, Block(N)[1:N_n], Block(N)[1:N_n])
403407
b_2 = view(b, parentindices(V_22)[1].indices)
404-
A_ldiv_B!(UpperTriangular(V_22), b_2)
408+
ldiv!(UpperTriangular(V_22), b_2)
405409

406410
V_12 = view(A, blockcolstart(A, N):Block(N-1), Block(N)[1:N_n])
407411
b̃_1 = view(b, parentindices(V_12)[1].indices)
408412
mul!(b̃_1, V_12, b_2, -one(T), one(T))
409413

410414
V_11 = view(A, Block.(1:N-1), Block.(1:N-1))
411415
b_1 = view(b, parentindices(V_11)[1].indices)
412-
A_ldiv_B!(UpperTriangular(V_11), b_1)
416+
ldiv!(UpperTriangular(V_11), b_1)
413417
b
414418
end
415419

@@ -486,7 +490,7 @@ function blockbanded_rectblocks_trtrs!(A::AbstractMatrix{T}, b::AbstractVector{T
486490
for J = N:-1:1
487491
V_22 = view(A, KR_map[J], JR_map[J])
488492
b_2 = view(b, parentindices(V_22)[1].indices)
489-
A_ldiv_B!(UpperTriangular(V_22), b_2)
493+
ldiv!(UpperTriangular(V_22), b_2)
490494

491495
for K = max(1,J-u_new):J-1
492496
if KR_map[K].block JR_map[J].block - u # inside old blockbandwith
@@ -551,7 +555,7 @@ function blockbanded_rectblocks_intrange_trtrs!(V::AbstractMatrix{T}, b::Abstrac
551555
for J = N:-1:1
552556
V_22 = view(A, KR_map[J], JR_map[J])
553557
b_2 = view(b, parentindices(V_22)[1].indices)
554-
A_ldiv_B!(UpperTriangular(V_22), b_2)
558+
ldiv!(UpperTriangular(V_22), b_2)
555559

556560
for K = max(1,J-u_new):J-1
557561
if KR_map[K].block JR_map[J].block - u # inside old blockbandwith

test/test_linalg.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using BlockArrays, BlockBandedMatrices, Compat.Test
1+
using BlockArrays, BandedMatrices, BlockBandedMatrices, Compat.Test
22
import BandedMatrices: BandError
33
import BlockBandedMatrices: _BandedBlockBandedMatrix, MemoryLayout, mul!,
44
blockcolstop, blockrowstop, BlockSizes, block_sizes
55

6-
6+
if VERSION < v"0.7-"
7+
const ldiv! = A_ldiv_B!
8+
end
79

810

911
@testset "BlockBandedMatrix linear algebra" begin
@@ -25,7 +27,7 @@ using BlockArrays, BlockBandedMatrices, Compat.Test
2527
w = Matrix(U) \ v
2628
U \ v == w
2729
@test v == fill(1.0,4)
28-
@test A_ldiv_B!(U , v) === v
30+
@test ldiv!(U , v) === v
2931
@test v == w
3032

3133
v = fill(1.0,size(A,1))
@@ -35,7 +37,7 @@ using BlockArrays, BlockBandedMatrices, Compat.Test
3537
@test U \ v w
3638

3739
@test v == fill(1.0,size(A,1))
38-
@test A_ldiv_B!(U, v) === v
40+
@test ldiv!(U, v) === v
3941
@test v w
4042
end
4143

@@ -120,8 +122,6 @@ end
120122
A = BlockBandedMatrix{Float64}(undef, (rows,cols), (l,u))
121123
A.data .= randn(length(A.data))
122124

123-
124-
125125
V = view(A, Block.(1:3), Block.(1:3))
126126

127127
@test blockrowstop(V,1) == Block(2)
@@ -133,7 +133,7 @@ end
133133
r = UpperTriangular(Matrix(V)) \ b
134134
@test BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b)) r
135135

136-
@test all(A_ldiv_B!(UpperTriangular(V), copy(b)) .=== BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b)))
136+
@test all(ldiv!(UpperTriangular(V), copy(b)) .=== BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b)))
137137

138138
V = view(A, Block.(2:3), Block(3))
139139
@test unsafe_load(pointer(V)) == A[2,4]
@@ -178,8 +178,8 @@ end
178178
@test all(V*b .=== V_22*b .=== Matrix(V)*b .===
179179
BlockBandedMatrices.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1))))
180180

181-
@test all(UpperTriangular(V_22) \ b .=== A_ldiv_B!(UpperTriangular(V_22) , copy(b)) .=== A_ldiv_B!(UpperTriangular(V) , copy(b)) .===
182-
A_ldiv_B!(UpperTriangular(Matrix(V_22)) , copy(b)))
181+
@test all(UpperTriangular(V_22) \ b .=== ldiv!(UpperTriangular(V_22) , copy(b)) .=== ldiv!(UpperTriangular(V) , copy(b)) .===
182+
ldiv!(UpperTriangular(Matrix(V_22)) , copy(b)))
183183

184184

185185
V = view(A, Block.(rows), Block.(cols))

0 commit comments

Comments
 (0)