comparison src/Grids/grid.jl @ 1508:6309ca375dcd feature/grids/componentview

Add responses to review comments
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 19 Feb 2024 15:57:10 +0100
parents de7b76b61ecd
children 8d64f8981bb0
comparison
equal deleted inserted replaced
1507:de7b76b61ecd 1508:6309ca375dcd
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? 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) 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. 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.
48 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} 51 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D}
49 v::AT 52 v::AT
50 component_index::IT 53 component_index::IT
51 54
52 function ArrayComponentView(v, component_index) 55 function ArrayComponentView(v, component_index)
56 end 59 end
57 60
58 Base.size(cv) = size(cv.v) 61 Base.size(cv) = size(cv.v)
59 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] 62 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...]
60 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? 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?
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.)
61 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) 68 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT)
62 69
63 # TODO: Implement the remaining optional methods from the array interface 70 # TODO: Implement the remaining optional methods from the array interface
64 # setindex!(A, v, i::Int) 71 # setindex!(A, v, i::Int)
65 # setindex!(A, v, I::Vararg{Int, N}) 72 # setindex!(A, v, I::Vararg{Int, N})