Skip to content

Commit

Permalink
Bugfix: Block indexing allocates copies
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Apr 12, 2024
1 parent 73b87b2 commit e2ecabf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0] 2024-03-22
## [0.4.0] 2024-04-12

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/Algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ end

function local_views(a::BlockPMatrix,new_rows::BlockPRange,new_cols::BlockPRange)
vals = map(CartesianIndices(blocksize(a))) do I
local_views(a[Block(I)],new_rows[Block(I[1])],new_cols[Block(I[2])])
local_views(blocks(a)[I],blocks(new_rows)[I],blocks(new_cols)[I])
end |> to_parray_of_arrays
return map(mortar,vals)
end
Expand Down
11 changes: 7 additions & 4 deletions src/BlockPartitionedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,19 @@ function Base.broadcasted(f, a::Union{BlockPArray,BlockPBroadcasted}, b::Number)
return BlockPBroadcasted(blocks_out,blockaxes(a))
end

function Base.broadcasted(f,
a::Union{BlockPArray,BlockPBroadcasted},
b::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}})
function Base.broadcasted(
f,
a::Union{BlockPArray,BlockPBroadcasted},
b::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}}
)
Base.broadcasted(f,a,Base.materialize(b))
end

function Base.broadcasted(
f,
a::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}},
b::Union{BlockPArray,BlockPBroadcasted})
b::Union{BlockPArray,BlockPBroadcasted}
)
Base.broadcasted(f,Base.materialize(a),b)
end

Expand Down
5 changes: 3 additions & 2 deletions src/MultiField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ function FESpaces.get_free_dof_ids(fs::DistributedMultiFieldFESpace)
end

function MultiField.restrict_to_field(
f::DistributedMultiFieldFESpace,free_values::AbstractVector,field::Integer)
values = map(f.part_fe_space,partition(free_values)) do u,x
f::DistributedMultiFieldFESpace,free_values::AbstractVector,field::Integer
)
values = map(local_views(f),partition(free_values)) do u,x
restrict_to_field(u,x,field)
end
gids = f.field_fe_space[field].gids
Expand Down

0 comments on commit e2ecabf

Please sign in to comment.