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

transpose/permutedims with undefined values fails #5448

Closed
simonster opened this issue Jan 20, 2014 · 5 comments
Closed

transpose/permutedims with undefined values fails #5448

simonster opened this issue Jan 20, 2014 · 5 comments

Comments

@simonster
Copy link
Member

julia> Array(Any, 2).'
ERROR: access to undefined reference
 in transpose at array.jl:1237

julia> permutedims(Array(Any, 2, 1), (2, 1))
ERROR: access to undefined reference
 in permutedims! at multidimensional.jl:341
 in permutedims at bitarray.jl:1902

We could add isdefined checks, but that kind of sucks, since isdefined isn't inlined (#3440).

@StefanKarpinski
Copy link
Member

I don't really see that this is a bug. If you try to do anything that accesses the data of an uninitialized array, you get an error. Supporting operations like transpose on uninitialized arrays doesn't really make any sense.

@simonster
Copy link
Member Author

That's reasonable, although it makes me sad, since it means more code from Base needs to be copy/pasted to DataArrays with a few lines changed.

@kmsquire
Copy link
Member

Before giving up here, would it be better to explain the need to copy code into DataArrays fixing this behavior?

@simonster
Copy link
Member Author

DataArrays are encoded using data array of the specified type and an na mask, which is a BitArray. The easiest way to transpose a DataArray is simply to transpose both data and na. This works fine for DataArrays of bits types. For DataArrays of non-bits types, data can have undefined values in positions that correspond to NAs, so we need to reimplement transpose and permutedims so that they either check for undefineds or check that the corresponding element in na is false before trying to access copy a value to the transposed arrays.

@kmsquire
Copy link
Member

A Transpose type in Base (ala #2472 (comment), and more recently, JuliaLang/LinearAlgebra.jl#42), would alleviate this. I'm not sure how much support there is, but I would like to see something like this in base.

Alternatively, for non-bits types, we could require the user to provide a default value for types which don't have one. For the short term, this seems reasonable to me.

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

3 participants