[Numpy-discussion] "aligned" matrix / ctypes
Zachary Pincus
zachary.pincus at yale.edu
Fri Apr 25 15:03:46 EDT 2008
> There is one more important case, which is aligning just the beginning
> of the array.
Indeed -- thanks! The following should take care of that case (it's
all fluff around calling aligned_empty() with a dim_alignments tuple
of all 1's, and the array_alignment parameter as required):
def aligned_start_empty(shape, dtype, alignment, order='C'):
'''Return an array with the first element aligned to a byte that is
evenly-divisible by the specified alignment.'''
order = order.upper()
if order not in ('C', 'F'):
raise ValueError("Order must be 'C' or 'F'.")
dim_alignments = [1 for dim in shape]
if order == 'F':
shape = shape[::-1]
return aligned_empty(shape, dtype, dim_alignments, alignment).T
else:
return aligned_empty(shape, dtype, dim_alignments, alignment)
Zach
More information about the NumPy-Discussion
mailing list