Mercurial > repos > public > sbplib_julia
changeset 1257:198ccda331a6 refactor/grids
Remove range dim as a type paratmeter on Grid as it is already encoded in T if available
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Feb 2023 11:38:19 +0100 |
parents | 3fc78ad26d03 |
children | e67cddbb8adc |
files | src/Grids/equidistant_grid.jl src/Grids/grid.jl src/Grids/tensor_grid.jl src/Grids/zero_dim_grid.jl |
diffstat | 4 files changed, 9 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl Wed Feb 22 22:38:54 2023 +0100 +++ b/src/Grids/equidistant_grid.jl Thu Feb 23 11:38:19 2023 +0100 @@ -2,7 +2,7 @@ # TODO: """ #TODO: Document recomendations for type of range. (LinRange is faster?) -struct EquidistantGrid{T,R<:AbstractRange{T}} <: Grid{T,1,1} +struct EquidistantGrid{T,R<:AbstractRange{T}} <: Grid{T,1} points::R end
--- a/src/Grids/grid.jl Wed Feb 22 22:38:54 2023 +0100 +++ b/src/Grids/grid.jl Thu Feb 23 11:38:19 2023 +0100 @@ -1,5 +1,5 @@ """ - Grid{T,D,RD} <: AbstractArray{T,D} + Grid{T,D} The top level type for grids. @@ -8,12 +8,11 @@ """ #TBD: Should it be an AbstractArray? See notes in grid_refactor.md # TODO: Document that grids should implement the interfaces for iteration and indexing. -abstract type Grid{T,D,RD} end +abstract type Grid{T,D} end -Base.ndims(::Grid{T,D,RD}) where {T,D,RD} = D # nidms borde nog vara antalet index som används för att indexera nätet. Snarare än vilken dimension nätet har (tänk ostrukturerat) -nrangedims(::Grid{T,D,RD}) where {T,D,RD} = RD -Base.eltype(::Grid{T,D,RD}) where {T,D,RD} = T # vad ska eltype vara? Inte T väl... en vektor? SVector{T,D}? +Base.ndims(::Grid{T,D}) where {T,D} = D # nidms borde nog vara antalet index som används för att indexera nätet. Snarare än vilken dimension nätet har (tänk ostrukturerat) +Base.eltype(::Grid{T,D}) where {T,D} = T # vad ska eltype vara? Inte T väl... en vektor? SVector{T,D}? function refine(::Grid) end function coarsen(::Grid) end # Should this be here? What if it is not possible?
--- a/src/Grids/tensor_grid.jl Wed Feb 22 22:38:54 2023 +0100 +++ b/src/Grids/tensor_grid.jl Thu Feb 23 11:38:19 2023 +0100 @@ -1,12 +1,11 @@ -struct TensorGrid{T,D,RD,GT<:NTuple{N,Grid} where N} <: Grid{T,D,RD} +struct TensorGrid{T,D,GT<:NTuple{N,Grid} where N} <: Grid{T,D} grids::GT function TensorGrid(gs...) T = eltype(gs[1]) # All gs should have the same T D = sum(ndims,gs) - RD = sum(nrangedims, gs) - return new{T,D,RD,typeof(gs)}(gs) + return new{T,D,typeof(gs)}(gs) end end
--- a/src/Grids/zero_dim_grid.jl Wed Feb 22 22:38:54 2023 +0100 +++ b/src/Grids/zero_dim_grid.jl Thu Feb 23 11:38:19 2023 +0100 @@ -1,11 +1,10 @@ -struct ZeroDimGrid{T,S,RD} <: Grid{T,0,RD} +struct ZeroDimGrid{T,S} <: Grid{T,0} p::S function ZeroDimGrid(p) T = eltype(p) S = typeof(p) - RD = length(p) - return new{T,S,RD}(p) + return new{T,S}(p) end end