Mercurial > repos > public > sbplib_julia
changeset 1521:2fa325f08b66 feature/grids/componentview
Add docstring for `componentview`
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 22 Mar 2024 08:55:26 +0100 |
parents | 0cd6cf62af93 |
children | b29d2dc896a0 |
files | src/Grids/grid.jl |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/grid.jl Thu Mar 21 15:51:29 2024 +0100 +++ b/src/Grids/grid.jl Fri Mar 22 08:55:26 2024 +0100 @@ -48,6 +48,20 @@ component_type(T::Type) = eltype(eltype(T)) component_type(t) = component_type(typeof(t)) +""" + componentview(gf, component_index...) + +A view of `gf` with only the components specified by `component_index...`. + +# Examples +```julia-repl +julia> componentview([[1,2], [2,3], [3,4]],2) +3-element ArrayComponentView{Int64, Vector{Int64}, 1, Vector{Vector{Int64}}, Tuple{Int64}}: + 2 + 3 + 4 +``` +""" componentview(gf, component_index...) = ArrayComponentView(gf, component_index) struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} @@ -65,7 +79,7 @@ Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) -# TODO: Implement setindex!? +# TODO: Implement `setindex!`? # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. """