Skip to content

Commit 5a7742c

Browse files
committed
Start update for Julia v0.7-alpha
1 parent a15e611 commit 5a7742c

9 files changed

+132
-114
lines changed

src/AbstractBlockBandedMatrix.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ abstract type AbstractBlockBandedLayout <: MemoryLayout end
66

77

88

9-
doc"""
9+
"""
1010
blockbandwidths(A)
1111
1212
Returns a tuple containing the upper and lower blockbandwidth of `A`.
1313
"""
1414
blockbandwidths(A::AbstractMatrix) = blockbandwidth(A,1),blockbandwidth(A,2)
1515

16-
doc"""
16+
"""
1717
blockbandwidth(A,i)
1818
1919
Returns the lower blockbandwidth (`i==1`) or the upper blockbandwidth (`i==2`).
2020
"""
2121
blockbandwidth(A::AbstractMatrix, k::Integer) = k==1 ? nblocks(A,1)-1 : nblocks(A,2)-1
2222

23-
doc"""
23+
"""
2424
bandrange(A)
2525
2626
Returns the range `-blockbandwidth(A,1):blockbandwidth(A,2)`.
@@ -48,7 +48,7 @@ end
4848
@inline blockrowlength(A::AbstractVecOrMat, i) = max(Int(blockrowstop(A, i)) - Int(blockrowstart(A, i)) + 1, 0)
4949

5050

51-
doc"""
51+
"""
5252
isblockbanded(A)
5353
5454
returns true if a matrix implements the block banded interface.

src/BandedBlockBandedMatrix.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ end
3535
convert(::Type{BlockBandedSizes}, B::BandedBlockBandedSizes) =
3636
BlockBandedSizes(B.block_sizes, B.l, B.u)
3737

38+
BlockBandedSizes(B::BandedBlockBandedSizes) = convert(BlockBandedSizes, B)
39+
3840
function check_data_sizes(data::AbstractBlockMatrix, B::BandedBlockBandedSizes)
3941
bs = data.block_sizes
4042
c_rows, c_cols = bs.cumul_sizes
@@ -105,7 +107,7 @@ BandedBlockBandedMatrix{T}(::UndefInitializer, dims::NTuple{2, AbstractVector{In
105107

106108
function convert(::Type{BandedBlockBandedMatrix{T}}, B::BandedMatrix) where T
107109
if isdiag(B)
108-
_BandedBlockBandedMatrix(copy(B.data), (ones(Int,size(B,1)),ones(Int,size(B,2))), (0,0), (0,0))
110+
_BandedBlockBandedMatrix(copy(B.data), (fill(1,size(B,1)),fill(1,size(B,2))), (0,0), (0,0))
109111
else
110112
_BandedBlockBandedMatrix(copy(B.data), [size(B,1)], [size(B,2)], (0,0), (B.l,B.u))
111113
end
@@ -131,14 +133,14 @@ function BandedBlockBandedMatrix{T}(E::Eye, dims::NTuple{2,AbstractVector{Int}},
131133
throw(DimensionMismatch())
132134
end
133135
ret = BandedBlockBandedMatrix(Zeros{T}(E), dims, lu, λμ)
134-
ret[diagind(ret)] = one(T)
136+
ret[diagind(ret)] .= one(T)
135137
ret
136138
end
137139

138140
function BandedBlockBandedMatrix{T}(A::UniformScaling, dims::NTuple{2, AbstractVector{Int}},
139141
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where T
140142
ret = BandedBlockBandedMatrix(Zeros{T}(sum.(dims)), dims, lu, λμ)
141-
ret[diagind(ret)] = convert(T, A.λ)
143+
ret[diagind(ret)] .= convert(T, A.λ)
142144
ret
143145
end
144146

@@ -277,14 +279,14 @@ function Base.fill!(A::BandedBlockBandedMatrix, x)
277279
A
278280
end
279281

280-
function Base.scale!(A::BandedBlockBandedMatrix, x::Number)
281-
scale!(A.data, x)
282+
function rmul!(A::BandedBlockBandedMatrix, x::Number)
283+
rmul!(A.data, x)
282284
A
283285
end
284286

285287

286-
function Base.scale!(x::Number, A::BandedBlockBandedMatrix)
287-
scale!(x, A.data)
288+
function lmul!(x::Number, A::BandedBlockBandedMatrix)
289+
lmul!(x, A.data)
288290
A
289291
end
290292

@@ -334,14 +336,14 @@ end
334336
# end
335337
# end
336338
#
337-
# @generated function Base.copy!(block_array::BlockArray{T, N, R}, arr::R) where {T,N,R <: AbstractArray}
339+
# @generated function Base.copyto!(block_array::BlockArray{T, N, R}, arr::R) where {T,N,R <: AbstractArray}
338340
# return quote
339341
# block_sizes = block_array.block_sizes
340342
#
341343
# @nloops $N i i->(1:nblocks(block_sizes, i)) begin
342344
# block_index = @ntuple $N i
343345
# indices = globalrange(block_sizes, block_index)
344-
# copy!(getblock(block_array, block_index...), arr[indices...])
346+
# copyto!(getblock(block_array, block_index...), arr[indices...])
345347
# end
346348
#
347349
# return block_array
@@ -386,7 +388,7 @@ const BandedBlockBandedBlock{T} = SubArray{T,2,BandedBlockBandedMatrix{T},Tuple{
386388

387389
function inblockbands(V::BandedBlockBandedBlock)
388390
A = parent(V)
389-
K_sl, J_sl = parentindexes(V)
391+
K_sl, J_sl = parentindices(V)
390392
K, J = K_sl.block, J_sl.block
391393
-A.l  Int(J-K) A.u
392394
end
@@ -400,14 +402,14 @@ end
400402

401403

402404
# gives the columns of parent(V).data that encode the block
403-
blocks(V::BandedBlockBandedBlock)::Tuple{Int,Int} = Int(first(parentindexes(V)).block),
404-
Int(last(parentindexes(V)).block)
405+
blocks(V::BandedBlockBandedBlock)::Tuple{Int,Int} = Int(first(parentindices(V)).block),
406+
Int(last(parentindices(V)).block)
405407

406408

407409
function dataview(V::BandedBlockBandedBlock)
408410
A = parent(V)
409411
u = A.u
410-
K_sl, J_sl = parentindexes(V)
412+
K_sl, J_sl = parentindices(V)
411413
K, J = K_sl.block, J_sl.block
412414
view(A.data, u + K - J + 1, J)
413415
end
@@ -457,6 +459,9 @@ end
457459

458460
convert(::Type{BandedMatrix}, V::BandedBlockBandedBlock) = convert(BandedMatrix{eltype(V)}, V)
459461

462+
BandedMatrix{T}(V::BandedBlockBandedBlock) where T = convert(BandedMatrix{T}, V)
463+
BandedMatrix(V::BandedBlockBandedBlock) = convert(BandedMatrix, V)
464+
460465

461466

462467

src/BlockBandedMatrices.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ __precompile__()
22

33
module BlockBandedMatrices
44
using BlockArrays, BandedMatrices, FillArrays, Compat
5+
using Compat.LinearAlgebra
56

67
import BlockArrays: BlockSizes, nblocks, blocksize, blockcheckbounds, global2blockindex,
78
Block, BlockSlice, getblock, unblock, setblock!, globalrange,
@@ -17,17 +18,26 @@ import BandedMatrices: isbanded, leadingdimension, bandwidth, banded_getindex,
1718
_BandedMatrix, colstart, colstop, rowstart, rowstop
1819

1920
import Base: getindex, setindex!, checkbounds, @propagate_inbounds, convert,
20-
isdiag, +, *, -, /, \, strides, zeros, eye, size,
21-
unsafe_convert, copy!, fill!, length, done, first, last, next,
22-
start, iteratorsize, eltype, getindex, to_indices, to_index,
21+
+, *, -, /, \, strides, zeros, size,
22+
unsafe_convert, fill!, length, done, first, last, next,
23+
start, eltype, getindex, to_indices, to_index,
2324
reindex, _maybetail, tail, @_propagate_inbounds_meta
2425

25-
import Base.LinAlg: A_ldiv_B!, A_mul_B!
26-
import Base.BLAS: BlasInt, BlasFloat, @blasfunc, libblas
27-
import Base.LAPACK: chktrans, chkdiag, liblapack, chklapackerror, checksquare, chkstride1,
26+
import Compat.LinearAlgebra: A_ldiv_B!, A_mul_B!, UniformScaling, isdiag
27+
import Compat.LinearAlgebra.BLAS: BlasInt, BlasFloat, @blasfunc, libblas
28+
import Compat.LinearAlgebra.LAPACK: chktrans, chkdiag, liblapack, chklapackerror, checksquare, chkstride1,
2829
chkuplo
2930

30-
import Compat: axes
31+
32+
import Compat: axes, copyto!
33+
34+
if VERSION < v"0.7-"
35+
const rmul! = scale!
36+
const lmul! = scale!
37+
const parentindices = parentindexes
38+
else
39+
import LinearAlgebra: rmul!, lmul!
40+
end
3141

3242
export BandedBlockBandedMatrix, BlockBandedMatrix, blockbandwidth, blockbandwidths,
3343
subblockbandwidth, subblockbandwidths, Ones, Zeros, Fill, Block

src/BlockBandedMatrix.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727

2828
function bb_blockstrides(b_size, l, u)
2929
N, M = nblocks(b_size)
30-
b_strides = Vector{Int}(M)
30+
b_strides = Vector{Int}(undef, M)
3131
for J=1:M
3232
KR = max(1,J-u):min(J+l,N)
3333
if !isempty(KR)
@@ -136,13 +136,13 @@ function BlockBandedMatrix{T}(E::Eye, block_sizes::BlockBandedSizes) where T
136136
throw(DimensionMismatch("Size of input $(size(E)) must be consistent with $(sum.(dims))"))
137137
end
138138
ret = BlockBandedMatrix(Zeros{T}(size(E)), block_sizes)
139-
ret[diagind(ret)] = one(T)
139+
ret[diagind(ret)] .= one(T)
140140
ret
141141
end
142142

143143
function BlockBandedMatrix{T}(A::UniformScaling, block_sizes::BlockBandedSizes) where T
144144
ret = BlockBandedMatrix(Zeros{T}(size(block_sizes)), block_sizes)
145-
ret[diagind(ret)] = convert(T, A.λ)
145+
ret[diagind(ret)] .= convert(T, A.λ)
146146
ret
147147
end
148148

@@ -165,6 +165,8 @@ function convert(::Type{BlockBandedMatrix}, A::AbstractMatrix)
165165
end
166166

167167

168+
BlockBandedMatrix(A::AbstractMatrix) = convert(BlockBandedMatrix, A)
169+
168170
################################
169171
# BlockBandedMatrix Interface #
170172
################################
@@ -272,14 +274,14 @@ end
272274
# end
273275
# end
274276
#
275-
# @generated function Base.copy!(block_array::BlockArray{T, N, R}, arr::R) where {T,N,R <: AbstractArray}
277+
# @generated function Base.copyto!(block_array::BlockArray{T, N, R}, arr::R) where {T,N,R <: AbstractArray}
276278
# return quote
277279
# block_sizes = block_array.block_sizes
278280
#
279281
# @nloops $N i i->(1:nblocks(block_sizes, i)) begin
280282
# block_index = @ntuple $N i
281283
# indices = globalrange(block_sizes, block_index)
282-
# copy!(getblock(block_array, block_index...), arr[indices...])
284+
# copyto!(getblock(block_array, block_index...), arr[indices...])
283285
# end
284286
#
285287
# return block_array
@@ -306,8 +308,8 @@ const BlockBandedBlock{T} = SubArray{T,2,BlockBandedMatrix{T},Tuple{BlockSlice1,
306308

307309

308310
# gives the columns of parent(V).data that encode the block
309-
blocks(V::BlockBandedBlock)::Tuple{Int,Int} = first(first(parentindexes(V)).block.n),
310-
first(last(parentindexes(V)).block.n)
311+
blocks(V::BlockBandedBlock)::Tuple{Int,Int} = first(first(parentindices(V)).block.n),
312+
first(last(parentindices(V)).block.n)
311313

312314
######################################
313315
# Matrix interface for Blocks #

0 commit comments

Comments
 (0)