-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dont pirate convert * add helper functions * docs * drop shiftedabstractarray and generalize
- Loading branch information
Pietro Vertechi
authored
Sep 5, 2018
1 parent
eb5b8ad
commit bfb6622
Showing
6 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
function Base.convert(::Type{<:Array}, ss::AbstractArray{<:ShiftedAbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N | ||
""" | ||
`to_array(ss::AbstractArray{<:AbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N` | ||
Collect a `AbstractArray` of `AbstractArrays` into a normal `Array` selecting indices `I` (can take negative values if inner `AbstractArrays` allow it). | ||
The output `Array` first few dimensions will be indexed by `I` (though starting from `1`) | ||
and the last one will correspond to the index of the inner `AbstractArray` within the `AbstractArray` of `AbstractArrays`. | ||
""" | ||
function to_array(ss::AbstractArray{<:AbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N | ||
v = VectorOfArray([view(s, I...) for s in ss]) | ||
Array(v) | ||
end | ||
|
||
function Base.convert(::Type{<:OffsetArray}, ss::AbstractArray{<:ShiftedAbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N | ||
m = convert(Array, ss, I...) | ||
""" | ||
`to_offsetarray(ss::AbstractArray{<:AbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N` | ||
Collect a `AbstractArray` of `ShiftedArrays` into an `OffsetArray` selecting indices `I` (can take negative values if inner `AbstractArrays` allow it). | ||
The output `OffsetArray` first few dimensions will be indexed by `I` | ||
and the last one will correspond to the index of the inner `AbstractArray` within the `AbstractArray` of `AbstractArrays`. | ||
""" | ||
function to_offsetarray(ss::AbstractArray{<:AbstractArray{<:Any, N}}, I::Vararg{<:AbstractArray, N}) where N | ||
m = to_array(ss, I...) | ||
OffsetArray(m, I..., last(Compat.axes(m))) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters