Mercurial > repos > public > sbplib_julia
comparison src/Grids/grid.jl @ 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 | 4df668d00d03 d641798539c2 |
comparison
equal
deleted
inserted
replaced
| 1518:0cd6cf62af93 | 1521:2fa325f08b66 |
|---|---|
| 46 ``` | 46 ``` |
| 47 """ | 47 """ |
| 48 component_type(T::Type) = eltype(eltype(T)) | 48 component_type(T::Type) = eltype(eltype(T)) |
| 49 component_type(t) = component_type(typeof(t)) | 49 component_type(t) = component_type(typeof(t)) |
| 50 | 50 |
| 51 """ | |
| 52 componentview(gf, component_index...) | |
| 53 | |
| 54 A view of `gf` with only the components specified by `component_index...`. | |
| 55 | |
| 56 # Examples | |
| 57 ```julia-repl | |
| 58 julia> componentview([[1,2], [2,3], [3,4]],2) | |
| 59 3-element ArrayComponentView{Int64, Vector{Int64}, 1, Vector{Vector{Int64}}, Tuple{Int64}}: | |
| 60 2 | |
| 61 3 | |
| 62 4 | |
| 63 ``` | |
| 64 """ | |
| 51 componentview(gf, component_index...) = ArrayComponentView(gf, component_index) | 65 componentview(gf, component_index...) = ArrayComponentView(gf, component_index) |
| 52 | 66 |
| 53 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} | 67 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} |
| 54 v::AT | 68 v::AT |
| 55 component_index::IT | 69 component_index::IT |
| 63 Base.size(cv) = size(cv.v) | 77 Base.size(cv) = size(cv.v) |
| 64 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] | 78 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] |
| 65 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] | 79 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] |
| 66 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) | 80 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) |
| 67 | 81 |
| 68 # TODO: Implement setindex!? | 82 # TODO: Implement `setindex!`? |
| 69 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. | 83 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. |
| 70 | 84 |
| 71 """ | 85 """ |
| 72 refine(g::Grid, r) | 86 refine(g::Grid, r) |
| 73 | 87 |
