Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only copy non-zero blocks #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BlockArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
broadcast, eltype, convert, similar,
tail, reindex,
RangeIndex, Int, Integer, Number,
+, -, *, /, \, min, max, isless, in, copy, copyto!, axes, @deprecate,
+, -, *, /, \, ==, min, max, isless, in, copy, copyto!, axes, @deprecate,
BroadcastStyle, checkbounds, throw_boundserror,
ones, zeros, intersect, Slice, resize!
using Base: ReshapedArray, dataids
Expand Down
8 changes: 7 additions & 1 deletion src/blocklinalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ function _copyto!(_, ::AbstractBlockLayout, dest::AbstractVector, src::AbstractV
return dest
end

@inbounds for K = blockaxes(src,1)
@inbounds for K = blockcolsupport(src)
copyto!(view(dest,K), view(src,K))
end
@inbounds for K = blockcolsupport(dest)
if K ∉ blockcolsupport(src)
zero!(view(dest,K))
end
end

dest
end

Expand Down
6 changes: 4 additions & 2 deletions src/pseudo_blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ convert(::Type{AbstractArray}, A::PseudoBlockArray) = A



PseudoBlockArray{T, N}(A::AbstractArray{T2, N}) where {T,T2,N} =
PseudoBlockArray(Array{T, N}(A), axes(A))
PseudoBlockArray{T, N}(A::AbstractArray{T2, N}) where {T,T2,N} = copyto!(PseudoBlockArray{T,N}(undef, axes(A)), A)
PseudoBlockArray{T1}(A::AbstractArray{T2, N}) where {T1,T2,N} = PseudoBlockArray{T1, N}(A)
PseudoBlockArray(A::AbstractArray{T, N}) where {T,N} = PseudoBlockArray{T, N}(A)
PseudoBlockVector(A::AbstractVector{T}) where T = PseudoBlockVector{T}(A)
PseudoBlockMatrix(A::AbstractMatrix{T}) where T = PseudoBlockMatrix{T}(A)

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

copy(A::PseudoBlockArray) = PseudoBlockArray(copy(A.blocks), A.axes)
==(A::PseudoBlockArray, B::PseudoBlockArray) = A.blocks == B.blocks

###########################
# AbstractArray Interface #
Expand Down