comparison src/Grids/zero_dim_grid.jl @ 1260:8b9a77d2dc91 refactor/grids

Add tests and make them pass for ZeroDimGrid
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 23 Feb 2023 12:22:18 +0100
parents 198ccda331a6
children 5e28ae42caf2
comparison
equal deleted inserted replaced
1259:ee57bdb366e4 1260:8b9a77d2dc91
1 struct ZeroDimGrid{T,S} <: Grid{T,0} 1 """
2 p::S 2 ZeroDimGrid{T} <: Grid{T,0}
3 3 # TODO
4 function ZeroDimGrid(p) 4 """
5 T = eltype(p) 5 struct ZeroDimGrid{T} <: Grid{T,0}
6 S = typeof(p) 6 point::T
7 return new{T,S}(p)
8 end
9 end 7 end
10 8
11 Base.size(g::ZeroDimGrid) = () 9 # # Indexing interface
12 Base.getindex(g::ZeroDimGrid) = g.p 10 Base.getindex(g::ZeroDimGrid) = g.point
13 Base.eachindex(g::ZeroDimGrid) = CartesianIndices(()) 11 Base.eachindex(g::ZeroDimGrid) = CartesianIndices(())
14 12
15 # Indexing interface 13 # # Iteration interface
16 # TODO 14 Base.iterate(g::ZeroDimGrid) = (g.point, nothing)
17 # Iteration interface 15 Base.iterate(g::ZeroDimGrid, ::Any) = nothing
18 # TODO 16
17 Base.IteratorSize(::Type{ZeroDimGrid{T}}) where T = Base.HasShape{0}()
18 Base.eltype(::Type{ZeroDimGrid{T}}) where T = T
19 Base.length(g::ZeroDimGrid) = 1
20 Base.size(g::ZeroDimGrid) = ()