Mercurial > repos > public > sbplib_julia
comparison src/Grids/grid.jl @ 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 | 62f9d0387a2a |
children | de7b76b61ecd |
comparison
equal
deleted
inserted
replaced
1490:a7689021d4c2 | 1491:06dec7b68f82 |
---|---|
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. | |
45 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} | 48 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} |
46 v::AT | 49 v::AT |
47 component_index::IT | 50 component_index::IT |
48 | 51 |
49 function ArrayComponentView(v, component_index) | 52 function ArrayComponentView(v, component_index) |
52 end | 55 end |
53 end | 56 end |
54 | 57 |
55 Base.size(cv) = size(cv.v) | 58 Base.size(cv) = size(cv.v) |
56 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] | 59 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] |
57 Base.getindex(cv::ArrayComponentView, I::Vararg{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? |
58 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) | 61 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) |
59 | 62 |
60 # TODO: Implement the remaining optional methods from the array interface | 63 # TODO: Implement the remaining optional methods from the array interface |
61 # setindex!(A, v, i::Int) | 64 # setindex!(A, v, i::Int) |
62 # setindex!(A, v, I::Vararg{Int, N}) | 65 # setindex!(A, v, I::Vararg{Int, N}) |