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

[RFC] Before trying to lower() an AbstractArray, replace undef values with a defined value of the same type - fixes #3 #6

Closed
wants to merge 2 commits into from

Conversation

DilumAluthge
Copy link
Member

This is a really hacky way to solve #3. The basic idea is this: before trying to lower() an AbstractArray, we go through the array and replace all the #undef values with a value of the appropriate type. (Specifically, we replace the #undef values with the first defined value in the array.)

For example, if we have an array that looks like this:

5-element Array{String,1}:
 #undef
    "b"
 #undef
    "d"
    "e"

Then, before we try to lower() it, we change the #undef values so the array looks like this:

5-element Array{String,1}:
    "b"
    "b"
    "b"
    "d"
    "e"

It seems like those values are ignored, so it doesn't matter what we set them to, as long as we set them to values of the appropriate type.

@DilumAluthge DilumAluthge changed the title Da/ignore undefs in arrays Before trying to lower() an AbstractArray, replace #undef values with a defined value of the same type - fixes #3 May 26, 2018
@DilumAluthge
Copy link
Member Author

Requesting review @MikeInnes

@DilumAluthge DilumAluthge changed the title Before trying to lower() an AbstractArray, replace #undef values with a defined value of the same type - fixes #3 [RFC] Before trying to lower() an AbstractArray, replace #undef values with a defined value of the same type - fixes #3 May 26, 2018
@DilumAluthge DilumAluthge changed the title [RFC] Before trying to lower() an AbstractArray, replace #undef values with a defined value of the same type - fixes #3 [RFC] Before trying to lower() an AbstractArray, replace undef values with a defined value of the same type - fixes #3 May 26, 2018
@MikeInnes
Copy link
Collaborator

This doesn't seem ideal, because presumably those values will then re-appear when you try to load the file?

I think it'd be better to insert some kind of sentinel when writing the array, and use that when reading back in.

@DilumAluthge
Copy link
Member Author

DilumAluthge commented May 31, 2018 via email

@MikeInnes
Copy link
Collaborator

I mean at a lower level, i.e. when we write an array out as bytes in the file. e.g. we could say that a zero byte means undefined, and then the reader won't fill the array where it sees a zero. (Just an example, I'm not sure that would work).

@DilumAluthge
Copy link
Member Author

DilumAluthge commented May 31, 2018 via email

@DilumAluthge
Copy link
Member Author

DilumAluthge commented May 31, 2018 via email

@DilumAluthge
Copy link
Member Author

Actually, it turns out that "undefined" has been deprecated in the BSON spec.

@DilumAluthge
Copy link
Member Author

More importantly: I don't think that would work. The reference to undefined happens when we call lower(x::Array), which is well before we start writing bytes to file. So we have to fix the undefineds before or during the call to lower(x::Array).

@DilumAluthge DilumAluthge deleted the da/ignore_undefs_in_arrays branch May 31, 2018 22:09
@DilumAluthge
Copy link
Member Author

I'm closing this - I think I've found a way to avoid generating these arrays with #undef values in the first place. I'll make a PR soon.

@MikeInnes
Copy link
Collaborator

Right, so lower could insert undefined (or some other sentinel value, it doesn't have to be that specifically).

@MikeInnes
Copy link
Collaborator

Actually, that probably isn't quite right if you want to preserve types. But still, lower can just let undefined's through rather than throwing, and the final write can insert the sentinel.

@DilumAluthge
Copy link
Member Author

DilumAluthge commented Jun 25, 2018 via email

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 this pull request may close these issues.

2 participants