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

Fix strides from numpy #7796

Merged
merged 3 commits into from
Jan 6, 2020

Conversation

johnc1231
Copy link
Contributor

It's wrong to use the strides as given from numpy in the current implementation. When we do x.reshape(x.size).tolist(), we are flattening the ndarray into a single contiguous list that can be thought of as being stored in row major. So I always want to generate the strides that the row major version of the numpy array would have had. The if shape_element > 0 bit is because if you have an empty numpy array of a certain type, you still don't want it to have 0 stride.

danking
danking previously requested changes Jan 3, 2020
Copy link
Contributor

@danking danking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little things

hail/python/hail/expr/types.py Outdated Show resolved Hide resolved
running_shape_product = x.itemsize
for shape_element in reversed(x.shape):
strides.insert(0, running_shape_product)
running_shape_product = running_shape_product * (shape_element if shape_element > 0 else 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use *=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agh, clearly I've been spending too much time in the emitter

@@ -653,9 +653,16 @@ def _convert_from_json(self, x):

def _convert_to_json(self, x):
data = x.reshape(x.size).tolist()

strides = []
running_shape_product = x.itemsize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of like axis_one_step_byte_size? Like, if I want to increment this axis' index by one, I move this many bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and that's a better name

@danking danking merged commit c353899 into hail-is:master Jan 6, 2020
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.

None yet

2 participants