Commit b6b4c32 1 parent f6e6554 commit b6b4c32 Copy full SHA for b6b4c32
File tree 4 files changed +56
-0
lines changed
4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ module IdentityCellNumbers
2
+
3
+ using Gridap
4
+
5
+ export IdentityCellNumber
6
+ import Gridap: reindex
7
+ import Base: size
8
+ import Base: getindex
9
+
10
+ struct IdentityCellNumber{T} <: IndexCellValue{T,1}
11
+ length:: Int
12
+ end
13
+
14
+ function IdentityCellNumber (:: Type{T} ,l:: Integer ) where T <: Integer
15
+ IdentityCellNumber {T} (l)
16
+ end
17
+
18
+ function getindex (c:: IdentityCellNumber{T} ,i:: Integer ) where T
19
+ @assert i > 0
20
+ @assert i <= c. length
21
+ j:: T = i
22
+ j
23
+ end
24
+
25
+ size (c:: IdentityCellNumber ) = (c. length,)
26
+
27
+ function reindex (values:: IndexCellValue , indices:: IdentityCellNumber )
28
+ @assert length (values) == length (indices)
29
+ values
30
+ end
31
+
32
+ end # module
Original file line number Diff line number Diff line change @@ -53,4 +53,7 @@ include("CompressedCellValues.jl")
53
53
include (" NonIterableCellMaps.jl" )
54
54
@reexport using Gridap. NonIterableCellMaps
55
55
56
+ include (" IdentityCellNumbers.jl" )
57
+ @reexport using Gridap. IdentityCellNumbers
58
+
56
59
Original file line number Diff line number Diff line change
1
+ module IdentityCellNumbersTests
2
+
3
+ using Test
4
+ using Gridap
5
+ using Gridap. CellValuesGallery
6
+
7
+ a = [2 ,3 ,4 ,6 ,1 ,8 ,3 ,5 ]
8
+ cn = CellValueFromArray (a)
9
+
10
+ l = length (a)
11
+ id = IdentityCellNumber (Int,l)
12
+ r = collect (1 : l)
13
+ test_index_cell_number (id,r)
14
+
15
+ cn2 = reindex (cn,id)
16
+
17
+ @test cn2 === cn
18
+
19
+ end # module
Original file line number Diff line number Diff line change @@ -42,5 +42,7 @@ include("MapsMocks.jl")
42
42
43
43
@testset " NonIterableCellMaps" begin include (" NonIterableCellMapsTests.jl" ) end
44
44
45
+ @testset " IdentityCellNumbers" begin include (" IdentityCellNumbersTests.jl" ) end
46
+
45
47
end # module
46
48
You can’t perform that action at this time.
0 commit comments