Skip to content

Some questions on useability #16

@GregPlowman

Description

@GregPlowman

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,

  1. Could OffsetVector be exported?
  2. Is there any problem with defining methods so that OffsetArray{T}(inds) can construct (similar to recommended way to construct standard arrays)?
  3. Why is zero deprecated? using syntax as above seems quite natural to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions