def cast_items(exporter, fmt, itemsize, shape=None):
 bytelen = exporter.nbytes
 if shape:
  if ((prod(shape) * itemsize) != bytelen):
   return (None, shape)
 elif (shape == []):
  if ((exporter.ndim == 0) or (itemsize != bytelen)):
   return (None, shape)
 else:
  (n, r) = divmod(bytelen, itemsize)
  shape = [n]
  if (r != 0):
   return (None, shape)
 mem = exporter.tobytes()
 byteitems = [mem[i:(i + itemsize)] for i in range(0, len(mem), itemsize)]
 items = []
 for v in byteitems:
  item = struct.unpack(fmt, v)[0]
  if (item != item):
   return ('nan', shape)
  items.append(item)
 return ((items, shape) if (shape != []) else (items[0], shape))

def cast_items ( exporter , fmt , itemsize , shape = None ) : bytelen = exporter . nbytes if shape : if ( ( prod ( shape ) * itemsize ) != bytelen ) : return ( None , shape ) elif ( shape == [ ] ) : if ( ( exporter . ndim == 0 ) or ( itemsize != bytelen ) ) : return ( None , shape ) else : ( n , r ) = divmod ( bytelen , itemsize ) shape = [ n ] if ( r != 0 ) : return ( None , shape ) mem = exporter . tobytes ( ) byteitems = [ mem [ i : ( i + itemsize ) ] for i in range ( 0 , len ( mem ) , itemsize ) ] items = [ ] for v in byteitems : item = struct . unpack ( fmt , v ) [ 0 ] if ( item != item ) : return ( 'nan' , shape ) items . append ( item ) return ( ( items , shape ) if ( shape != [ ] ) else ( items [ 0 ] , shape ) )
interpret the raw memory of exporter as a list of items with size itemsize .