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

Missing convert(Vector, ::SubArray) #16519

Closed
cstjean opened this issue May 23, 2016 · 6 comments
Closed

Missing convert(Vector, ::SubArray) #16519

cstjean opened this issue May 23, 2016 · 6 comments
Labels
good first issue Indicates a good issue for first-time contributors to Julia types and dispatch Types, subtyping and method dispatch

Comments

@cstjean
Copy link
Contributor

cstjean commented May 23, 2016

On 0.4:

convert(Vector, slice(collect(1:10), 2:4))

is not defined, while convert(Array, slice(...)) is. I don't have 0.5 yet - please close if it's fixed there.

@nalimilan
Copy link
Member

Doesn't work on 0.5 either.

@kshyatt kshyatt added types and dispatch Types, subtyping and method dispatch good first issue Indicates a good issue for first-time contributors to Julia labels Aug 2, 2016
@Evizero
Copy link
Contributor

Evizero commented Aug 5, 2016

This may be a stupid question, but should convert work like that?

This code does work (v0.4):

convert(Vector{Int}, slice(collect(1:10), 2:4))
3-element Array{Int64,1}:
 2
 3
 4

So does

convert(Vector{Float64}, slice(collect(1:10), 2:4))
3-element Array{Float64,1}:
 2.0
 3.0
 4.0

Then again, if it works with convert(Array, ...) it would make sense to also work with Vector

EDIT: copied wrong code at first

@Sacha0
Copy link
Member

Sacha0 commented Aug 5, 2016

Then again, if it works with convert(Array, ...) it would make sense to also work with Vector

Having convert(Vector, view(collect(1:10), 1:2)) work would be consistent with the direction in #17066 / related threads. Adding

convert{T}(::Type{Vector}, A::AbstractVector{T}) = convert(Vector{T},  A)

just after this line should do the trick? And if so, might as well add

convert{T}(::Type{Matrix}, A::AbstractMatrix{T}) = convert(Matrix{T}, A)

in the process? Or perhaps a more generic solution exists? Best!

@Evizero
Copy link
Contributor

Evizero commented Aug 5, 2016

it can't go in abstractarray.jl because it will make compilation fail. array.jl seems like the best place. I am investigating

@Sacha0
Copy link
Member

Sacha0 commented Aug 5, 2016

it can't go in abstractarray.jl because it will make compilation fail. array.jl seems like the best place. I am investigating

Good call, array.jl sounds like the best place. Best!

@nalimilan
Copy link
Member

Fixed in master by #17848. Waiting for backport to 0.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

5 participants