[Numpy-discussion] "aligned" matrix / ctypes

Zachary Pincus zachary.pincus@yale....
Fri Apr 25 14:03:46 CDT 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
     return aligned_empty(shape, dtype, dim_alignments, alignment)


More information about the Numpy-discussion mailing list