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

Added setindex! method for Reindexed. #309

Merged
merged 2 commits into from
Jul 3, 2020
Merged
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `CDLagrangianRefFE` struct, that provides a Lagrangian reference FE with different conformity per direction. Since PR [#299](https://github.com/gridap/Gridap.jl/pull/299).
- New `FESpace` method that takes a model and a `RefFE`. Since PR [#299](https://github.com/gridap/Gridap.jl/pull/299).
- Possibility to have 0 order in `DISC` directions of a `CDLagrangianRefFE`. Since PR [#308](https://github.com/gridap/Gridap.jl/pull/308).
- Added setindex! method for Reindexed. Since PR [#309](https://github.com/gridap/Gridap.jl/pull/309).

### Changed

Expand Down
7 changes: 7 additions & 0 deletions src/Arrays/Reindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ end
a.i_to_v[i]
end

@propagate_inbounds function Base.setindex!(a::Reindexed,v,j::Integer)
i = a.j_to_i[j]
a.i_to_v[i]=v
end



function testitem(a::Reindexed)
if length(a.j_to_i) == 0
testitem(a.i_to_v)
Expand Down
8 changes: 8 additions & 0 deletions test/ArraysTests/ReindexTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ using FillArrays
using Gridap.Arrays
using Gridap.Arrays: AppliedArray

a = [1,2,3]
b = reindex(a,[3,2,1])
for i=1:3
b[i]=i
end
@test b == [1,2,3]
@test a == [3,2,1]

a = [[1,2,4,5],[2,4,6,7],[4,3,5,1],[2,3]]
b = [3,1,2]

Expand Down