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

Isn't it better for OffsetArrays to have an additional method for OffsetArray argument? #44

Closed
suiato opened this issue Apr 23, 2018 · 2 comments

Comments

@suiato
Copy link

suiato commented Apr 23, 2018

Currently, when a = [1,2,3] and a_o = OffsetArray(a, -1), a_o1 = OffsetArray(a_o, 1) is of type OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,Array{Int64,1}}}. Likewise, a_o2 = OffsetArray(a_o1, -1) is of type OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,Array{Int64,1}}}}. (Julia version: 0.6.2.2)

This hampers operability of offset arrays. Wouldn't it be better if a_o1 has the same type as a_o?

using OffsetArrays
a = [1, 2, 3]
a_o = OffsetArray(a, -1)
a_o1 = OffsetArray(a_o, 1)
a_o2 = OffsetArray(a_o1, -1)
print(typeof(a), "\n", typeof(a_o), "\n", typeof(a_o1), "\n", typeof(a_o2), "\n")

prints

Array{Int64,1}
OffsetArrays.OffsetArray{Int64,1,Array{Int64,1}}
OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,Array{Int64,1}}}
OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,OffsetArrays.OffsetArray{Int64,1,Array{Int64,1}}}}

@suiato
Copy link
Author

suiato commented May 12, 2018

For a vector, the following function can be added:
OffsetArray(a::OffsetArray{T,1,Array{T,1}}, os) where T = OffsetArray(a.parent, a.offsets .+ os)

@timholy
Copy link
Member

timholy commented Nov 13, 2018

Yes, this would be a nice optimization. A pull request would be welcome!

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

No branches or pull requests

2 participants