Skip to content

Commit 7a13ed4

Browse files
authored
Fix copyto! when supports don't match (#216)
* Fix copyto! when supports don't match * Add tests
1 parent 32990fc commit 7a13ed4

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.16.18"
3+
version = "0.16.19"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/BlockArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import LinearAlgebra: lmul!, rmul!, AbstractTriangular, HermOrSym, AdjOrTrans,
4040
import ArrayLayouts: _fill_lmul!, MatMulVecAdd, MatMulMatAdd, MatLmulVec, MatLdivVec,
4141
materialize!, MemoryLayout, sublayout, transposelayout, conjlayout,
4242
triangularlayout, triangulardata, _inv, _copyto!, axes_print_matrix_row,
43-
colsupport, rowsupport, sub_materialize
43+
colsupport, rowsupport, sub_materialize, zero!
4444

4545
include("blockindices.jl")
4646
include("blockaxis.jl")

src/blockindices.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Block(n::NTuple{N, T}) where {N,T} = Block{N, T}(n)
4040
# iterate and broadcast like Number
4141
length(b::Block) = 1
4242
size(b::Block) = ()
43+
last(b::Block) = b
4344
iterate(x::Block) = (x, nothing)
4445
iterate(x::Block, ::Any) = nothing
4546
isempty(x::Block) = false

src/blocklinalg.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,18 @@ function _copyto!(_, ::AbstractBlockLayout, dest::AbstractMatrix, src::AbstractM
138138
return dest
139139
end
140140

141-
@inbounds for J = blockaxes(src,2),K = blockcolsupport(src,J)
142-
copyto!(view(dest,K,J), view(src,K,J))
141+
@inbounds for J = blockaxes(src,2)
142+
CS_s = blockcolsupport(src,J)
143+
CS_d = blockcolsupport(dest,J)
144+
for K = first(CS_d):first(CS_s)-Block(1)
145+
zero!(view(dest,K,J))
146+
end
147+
for K = CS_s
148+
copyto!(view(dest,K,J), view(src,K,J))
149+
end
150+
for K = last(CS_s)+Block(1):last(CS_d)
151+
zero!(view(dest,K,J))
152+
end
143153
end
144154
dest
145155
end

test/test_blockarrayinterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ end
125125
@test A[Block(1, 2)] == [0 0]
126126
@test_throws BlockBoundsError A[Block(1, 3)]
127127
@test A == [1 2 0 0; 0 0 1 2]
128+
@test BlockArray(A) == A
128129

129130
N = 3
130131
D = Diagonal(mortar(Fill.(-(0:N) - (0:N) .^ 2, 1:2:2N+1)))

0 commit comments

Comments
 (0)