Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some questions on useability #16

Closed
GregPlowman opened this issue Dec 9, 2016 · 2 comments · Fixed by #26
Closed

Some questions on useability #16

GregPlowman opened this issue Dec 9, 2016 · 2 comments · Fixed by #26

Comments

@GregPlowman
Copy link
Contributor

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.
@timholy
Copy link
Member

timholy commented Jan 5, 2017

Could OffsetVector be exported?

I don't see why not. Care to submit a PR?

Is there any problem with defining methods so that OffsetArray{T}(inds) can construct (similar to recommended way to construct standard arrays)?

Perhaps, see below.

Why is zero deprecated? using syntax as above seems quite natural to me.

See #12 (comment).

The fundamental problem is to distinguish a range that specifies indices from an AbstractArray that you'd like to wrap. Is OffsetArray(a, b) wrapping a, or does a describe the indices?

@timholy
Copy link
Member

timholy commented Mar 27, 2017

#26 will add some constructors that we were missing, and OffsetVector was added some time ago.

The only part of this we can't do is the zeros/ones bit. However, thanks to JuliaLang/julia#19635, by Julia 1.0 we should be able to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants