Skip to content

Commit d366157

Browse files
committed
only copy non-zero blocks
1 parent d0eac49 commit d366157

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/BlockArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
2626
broadcast, eltype, convert, similar,
2727
@_inline_meta, tail, @_propagate_inbounds_meta, reindex,
2828
RangeIndex, Int, Integer, Number,
29-
+, -, *, /, \, min, max, isless, in, copy, copyto!, axes, @deprecate,
29+
+, -, *, /, \, ==, min, max, isless, in, copy, copyto!, axes, @deprecate,
3030
BroadcastStyle, checkbounds, throw_boundserror,
3131
ones, zeros, intersect, Slice, resize!
3232
using Base: ReshapedArray, dataids

src/blocklinalg.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,15 @@ function _copyto!(_, ::AbstractBlockLayout, dest::AbstractVector, src::AbstractV
123123
return dest
124124
end
125125

126-
@inbounds for K = blockaxes(src,1)
126+
@inbounds for K = blockcolsupport(src)
127127
copyto!(view(dest,K), view(src,K))
128128
end
129+
@inbounds for K = blockcolsupport(dest)
130+
if K blockcolsupport(src)
131+
zero!(view(dest,K))
132+
end
133+
end
134+
129135
dest
130136
end
131137

src/pseudo_blockarray.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ convert(::Type{AbstractArray}, A::PseudoBlockArray) = A
129129

130130

131131

132-
PseudoBlockArray{T, N}(A::AbstractArray{T2, N}) where {T,T2,N} =
133-
PseudoBlockArray(Array{T, N}(A), axes(A))
132+
PseudoBlockArray{T, N}(A::AbstractArray{T2, N}) where {T,T2,N} = copyto!(PseudoBlockArray{T,N}(undef, axes(A)), A)
134133
PseudoBlockArray{T1}(A::AbstractArray{T2, N}) where {T1,T2,N} = PseudoBlockArray{T1, N}(A)
135134
PseudoBlockArray(A::AbstractArray{T, N}) where {T,N} = PseudoBlockArray{T, N}(A)
135+
PseudoBlockVector(A::AbstractVector{T}) where T = PseudoBlockVector{T}(A)
136+
PseudoBlockMatrix(A::AbstractMatrix{T}) where T = PseudoBlockMatrix{T}(A)
136137

137138
convert(::Type{PseudoBlockArray{T, N}}, A::AbstractArray{T2, N}) where {T,T2,N} =
138139
PseudoBlockArray(convert(Array{T, N}, A), axes(A))
@@ -145,6 +146,7 @@ AbstractArray{T}(A::PseudoBlockArray) where T = PseudoBlockArray(AbstractArray{T
145146
AbstractArray{T,N}(A::PseudoBlockArray) where {T,N} = PseudoBlockArray(AbstractArray{T,N}(A.blocks), A.axes)
146147

147148
copy(A::PseudoBlockArray) = PseudoBlockArray(copy(A.blocks), A.axes)
149+
==(A::PseudoBlockArray, B::PseudoBlockArray) = A.blocks == B.blocks
148150

149151
###########################
150152
# AbstractArray Interface #

0 commit comments

Comments
 (0)