-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
align is not working when using only strings #5293
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
Comments
I'm not even sure what alignment is supposed to mean for strings - What are you hoping to learn by checking the alignment flag? Do you have
|
I need to call c code with an array of character. It has been working for 2014-11-19 8:30 GMT-05:00 Nathaniel J. Smith notifications@github.com:
|
you are using a 32 bit platform and the array is 8 byte aligned? the issue is that in the new indexing code the string is copied by the itemsize so it needs itemsize alignment. Though currently it uses 16 bytes for all string types which could probably be reduced to the itemsize which would allow S4 to work but not S16 or S9. I think the new indexing is the only code that tries to copy based on the itemsize so possibly we could revert back to no alignment requirements for sizes not powers of 2 and itemsize alignment for sizes of power 2, that would still leave S16 as problematic as we need to check what is the maximum algnment the compiler needs to copy. GCC provides this information in a macro, other compilers likely not. |
or we decouple the aligned flag of an array from the actual required alignment. |
Yeah, that's why I'm looking for information on how people are actually @pduch: In general there shouldn't be any problem with calling C code with
|
Hi Jilian, Here is the full version... :) We are calling, from Python, an optimizer with a C api. It has been working We are using ctypes to call the C api. The parameter causing the problem is my_array = zeros(26, dtype='|S1') When I check the flags on this, ALIGNED is always False. It was True with Thanks, 2014-11-19 9:44 GMT-05:00 Julian Taylor notifications@github.com:
|
hm why should it be unaligned on win64, what is the alignment of the array? check with:
|
nevermind there is a bug in the alignment check it also needs uses the copy alignment for the strides which is of course false for stride 1, that needs to be fixed |
OK thanks a lot :) Cheers, 2014-11-19 12:21 GMT-05:00 Julian Taylor notifications@github.com:
|
If itemsize is a power of two use that as the required alignment up to the maximum provided by the platform. Power of two sizes may be accessed via larger moves than bytes. Non-power of two sizes are accessed bytewise and can thus always be considered aligned. Closes numpygh-5293
thanks guys 2015-04-21 22:25 GMT-04:00 Julian Taylor notifications@github.com:
|
import numpy as np
a = np.zeros(4, dtype=np.dtype('|S4', align=True))
print a.flags['ALIGNED'] # -- should be True
Works with 1.8 but not with 1.9
The text was updated successfully, but these errors were encountered: