changeset 1491:06dec7b68f82 feature/grids/componentview

REVIEW: Comment on dimensionality of input array to an ArrayComponentView, and on slicing ArrayComponetViews
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 30 Dec 2023 13:51:27 +0100
parents a7689021d4c2
children 0d630d4e1d21
files src/Grids/grid.jl
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/grid.jl	Sat Dec 30 13:33:17 2023 +0100
+++ b/src/Grids/grid.jl	Sat Dec 30 13:51:27 2023 +0100
@@ -42,6 +42,9 @@
 
 componentview(gf, component_index...) = ArrayComponentView(gf, component_index)
 
+# REVIEW: Should this only be defined for vector-valued component types of the same dimension?
+# Now one can for instance do:  v = [rand(2,2),rand(2,2), rand(2,1)] and cv = componentview(v,1,2)
+# resulting in #undef in the third component of cv.
 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D}
     v::AT
     component_index::IT
@@ -54,7 +57,7 @@
 
 Base.size(cv) = size(cv.v)
 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...]
-Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...]
+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?
 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT)
 
 # TODO: Implement the remaining optional methods from the array interface