8000 BUG: longdouble with elsize 12 is never uint alignable by mattip · Pull Request #12611 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: longdouble with elsize 12 is never uint alignable #12611

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

Merged
merged 5 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: non-uint-aligned arrays were counted as uint-aligned
  • Loading branch information
ahaldane committed Dec 26, 2018
commit cb690e5b3dac32e459a5657ea7b9083e91a27316
6 changes: 5 additions & 1 deletion numpy/core/src/common/array_assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ raw_array_is_aligned(int ndim, npy_intp *shape,

return npy_is_aligned((void *)align_check, alignment);
}
else {
else if (alignment == 1) {
return 1;
}
else {
/* always return false for alignment == 0, which means unaligned */
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why is alignment == 0 even a legal argument to this function?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe there is a better way to organize it... but the idea is that npy_uint_alignment, which normally returns the uint alignment, returns 0 if the type is not uint-alignable.

Then, it turned out to be convenient to allow the result of npy_uint_alignment to be passed directly to raw_array_is_aligned.

An alternative would be to check the return value of npy_uint_alignment explicitly everywhere it is used. But since it is pretty much always used as an arg to raw_array_is_aligned it seemed less complicated this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed the comment

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

}
}

NPY_NO_EXPORT int
Expand Down
3 changes: 2 additions & 1 deletion numpy/core/src/common/array_assign.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ broadcast_strides(int ndim, npy_intp *shape,
/*
* Checks whether a data pointer + set of strides refers to a raw
* array whose elements are all aligned to a given alignment.
* alignment should be a power of two.
* alignment should be a power of two, or may be the sentinel value 0 to mean
* unaligned, in which case false is always returned.
Copy link
Member

Choose a reason for hiding this comment

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

This comment confuses me - I read this as saying that is_aligned(..., alignment = 0) means is_unaligned(...)

Copy link
Member

Choose a reason for hiding this comment

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

If I am not misreading you, that is what the comment is meant to say. If you pass an alignment of 0, the function always returns "not aligned". Do you mean I should say "not aligned" instead of "unaligned"?

Copy link
Member

Choose a reason for hiding this comment

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

Right. the return value means "not aligned", but the meaning of the alignment argument is closer to "unalignable"

Copy link
Member Author

Choose a reason for hiding this comment

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

fixing

*/
NPY_NO_EXPORT int
raw_array_is_aligned(int ndim, npy_intp *shape,
Expand Down
3 changes: 0 additions & 3 deletions numpy/core/src/multiarray/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ npy_uint_alignment(int itemsize)
case 8:
alignment = _ALIGN(npy_uint64);
break;
case 12:
alignment = _ALIGN(npy_longdouble);
break;
case 16:
/*
* 16 byte types are copied using 2 uint64 assignments.
Expand Down
0