-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Description
Well, firstly thanks for providing OffsetArrays.
I want to make it simpler/cleaner to specify OffsetArrays backed by standard arrays. And also use analogous syntax to standard Arrays for creating and typing OffsetArrays.
An example might be best:
type MyType
x::OffsetStdVector{Int}
y::OffsetStdArray{Float64,2}
end
a = OffsetVector{Int}(0:5)
b = OffsetArray{Float64}(0:12, -1:1)
c = MyType(a, b)
a = zeros(Int, 0:5) # [3]
b = zeros(Float64, 0:12, -1:1) #[3]
c = MyType(a, b)
This can be achieved currently with something like:
using OffsetArrays
import OffsetArrays.OffsetVector
typealias OffsetStdVector{T} OffsetArray{T,1,Array{T,1}}
typealias OffsetStdArray{T,N} OffsetArray{T,N,Array{T,N}}
(::Type{OffsetVector{T}}){T}(inds::UnitRange{Int}) = OffsetArray{T}(inds)
(::Type{OffsetArray{T}}){T}(inds::UnitRange{Int}...) = OffsetArray{T}(inds)
Base.zeros{N}(T::Type, inds::Base.Indices{N}) = fill!(OffsetArray{T}(inds), zero(T))
Base.zeros(T::Type, inds::UnitRange{Int}...) = zeros(T, inds)
Ideally OffsetArray could be renamed to say OffsetGenArray, so that standard array-backed type could be just OffsetArray
In any case,
- Could
OffsetVectorbe exported? - Is there any problem with defining methods so that
OffsetArray{T}(inds)can construct (similar to recommended way to construct standard arrays)? - Why is
zerodeprecated? using syntax as above seems quite natural to me.
Metadata
Metadata
Assignees
Labels
No labels