Skip to content

Fix strides from numpy#7796

Merged
danking merged 3 commits intohail-is:masterfrom
johnc1231:johnc-fix-strides-from-numpy
Jan 6, 2020
Merged

Fix strides from numpy#7796
danking merged 3 commits intohail-is:masterfrom
johnc1231:johnc-fix-strides-from-numpy

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

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

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.

2 participants