Skip to content

Commit 8f842f8

Browse files
Merge pull request #834 from gridap/add-lastindex
added `lastindex` for MultiValue and tests
2 parents eb9f22e + 0773305 commit 8f842f8

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Added
10+
- `lastindex` for `MultiValue`s for consistent usage of `[end]` as per `length`. Since PR [#834](https://github.com/gridap/Gridap.jl/pull/834)
11+
- BDM (Brezzi-Douglas-Marini) ReferenceFEs in PR [#823](https://github.com/gridap/Gridap.jl/pull/823)
12+
713
## [0.17.14] - 2022-07-29
814

915
### Added

src/TensorValues/Indexing.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
eachindex(arg::MultiValue) = eachindex(1:prod(size(arg)))
33

4+
lastindex(arg::MultiValue) = length(arg)
5+
46
CartesianIndices(arg::MultiValue) = CartesianIndices(size(arg))
57

68
LinearIndices(arg::MultiValue) = LinearIndices(size(arg))
@@ -78,4 +80,3 @@ function _4d_sym_tensor_linear_index(D,i,j,k,l)
7880
index=(block_index-1)*block_length+element_index
7981
index
8082
end
81-

src/TensorValues/TensorValues.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import Base: zero, one
6565
import Base: +, -, *, /, \, ==, , isless
6666
import Base: conj
6767
import Base: sum, maximum, minimum
68-
import Base: getindex, iterate, eachindex
68+
import Base: getindex, iterate, eachindex, lastindex
6969
import Base: size, length, eltype
7070
import Base: reinterpret
7171
import Base: convert

test/TensorValuesTests/IndexingTests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ v = VectorValue{4}(a)
1313

1414
@test size(v) == (4,)
1515
@test length(v) == 4
16+
@test lastindex(v) == length(v)
1617

1718
for (k,i) in enumerate(eachindex(v))
1819
@test v[i] == a[k]
@@ -22,6 +23,7 @@ t = TensorValue{2}(a)
2223

2324
@test size(t) == (2,2)
2425
@test length(t) == 4
26+
@test lastindex(t) == length(t)
2527

2628
for (k,i) in enumerate(eachindex(t))
2729
@test t[i] == a[k]
@@ -40,6 +42,7 @@ t = TensorValue(convert(SMatrix{2,2,Int},s))
4042

4143
@test size(s) == (2,2)
4244
@test length(s) == 4
45+
@test lastindex(s) == length(s)
4346

4447
for (k,i) in enumerate(eachindex(t))
4548
@test s[i] == t[k]

0 commit comments

Comments
 (0)