Mercurial > repos > public > sbplib_julia
comparison src/Grids/grid.jl @ 1517:7ee7df7d9b61 feature/grids/componentview
Remove review comments
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 21 Mar 2024 07:43:48 +0100 |
| parents | 8d64f8981bb0 |
| children | 0cd6cf62af93 |
comparison
equal
deleted
inserted
replaced
| 1516:8d64f8981bb0 | 1517:7ee7df7d9b61 |
|---|---|
| 40 component_type(T::Type) = eltype(eltype(T)) | 40 component_type(T::Type) = eltype(eltype(T)) |
| 41 component_type(t) = component_type(typeof(t)) | 41 component_type(t) = component_type(typeof(t)) |
| 42 | 42 |
| 43 componentview(gf, component_index...) = ArrayComponentView(gf, component_index) | 43 componentview(gf, component_index...) = ArrayComponentView(gf, component_index) |
| 44 | 44 |
| 45 # REVIEW: Should this only be defined for vector-valued component types of the same dimension? | |
| 46 # Now one can for instance do: v = [rand(2,2),rand(2,2), rand(2,1)] and cv = componentview(v,1,2) | |
| 47 # resulting in #undef in the third component of cv. | |
| 48 # RESPONSE: I don't think it's possible to stop the user from | |
| 49 # doing stupid things. My inclination is to just keep it simple and let the | |
| 50 # user read the error messages they get. | |
| 51 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} | 45 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} |
| 52 v::AT | 46 v::AT |
| 53 component_index::IT | 47 component_index::IT |
| 54 | 48 |
| 55 function ArrayComponentView(v, component_index) | 49 function ArrayComponentView(v, component_index) |
| 58 end | 52 end |
| 59 end | 53 end |
| 60 | 54 |
| 61 Base.size(cv) = size(cv.v) | 55 Base.size(cv) = size(cv.v) |
| 62 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] | 56 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] |
| 63 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] #REVIEW: Will this allocate if I... slices v? if so, we should probably use a view on v? | 57 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] |
| 64 # RESPONSE: I imagine the values of `cv` will be small static vectors most of | |
| 65 # the time for which this won't be a problem. I say we cross that bridge when | |
| 66 # there is an obvoius need. (Just slapping a @view on there seems to be | |
| 67 # changing the return tyoe to a 0-dimensional array. That's where i gave up.) | |
| 68 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) | 58 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) |
| 69 | 59 |
| 70 # TODO: Implement setindex!? | 60 # TODO: Implement setindex!? |
| 71 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. | 61 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. |
| 72 | 62 |
