Mercurial > repos > public > sbplib_julia
annotate src/Grids/zero_dim_grid.jl @ 1262:5e28ae42caf2 refactor/grids
Clean up IteratorSize and eltype for EquidistantGrid, Grid, and ZeroDimGrid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Feb 2023 22:29:36 +0100 |
parents | 8b9a77d2dc91 |
children | dbddd0f61bde |
rev | line source |
---|---|
1260
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
1 """ |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
2 ZeroDimGrid{T} <: Grid{T,0} |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
3 # TODO |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
4 """ |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
5 struct ZeroDimGrid{T} <: Grid{T,0} |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
6 point::T |
1234
8806f4cd6fee
Move ZeroDimGrid to its own file
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
7 end |
8806f4cd6fee
Move ZeroDimGrid to its own file
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
8 |
1262
5e28ae42caf2
Clean up IteratorSize and eltype for EquidistantGrid, Grid, and ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1260
diff
changeset
|
9 # Indexing interface |
1260
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
10 Base.getindex(g::ZeroDimGrid) = g.point |
1234
8806f4cd6fee
Move ZeroDimGrid to its own file
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
11 Base.eachindex(g::ZeroDimGrid) = CartesianIndices(()) |
1256
3fc78ad26d03
Add notes and todos about interface implementations for grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1234
diff
changeset
|
12 |
1262
5e28ae42caf2
Clean up IteratorSize and eltype for EquidistantGrid, Grid, and ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1260
diff
changeset
|
13 # Iteration interface |
1260
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
14 Base.iterate(g::ZeroDimGrid) = (g.point, nothing) |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
15 Base.iterate(g::ZeroDimGrid, ::Any) = nothing |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
16 |
1262
5e28ae42caf2
Clean up IteratorSize and eltype for EquidistantGrid, Grid, and ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1260
diff
changeset
|
17 Base.IteratorSize(::Type{<:ZeroDimGrid}) = Base.HasShape{0}() |
1260
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
18 Base.length(g::ZeroDimGrid) = 1 |
8b9a77d2dc91
Add tests and make them pass for ZeroDimGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
1257
diff
changeset
|
19 Base.size(g::ZeroDimGrid) = () |