Ejemplo n.º 1
0
def _pad_array(array, boundary):
    """Adds padding to the array so the array size aligns to a next boundary."""
    size = array.buffer_info()[1]
    pad_bytes = boundary - (size % boundary)
    if pad_bytes == boundary:
        return
    for _ in xrange(pad_bytes):
        array.append(0)
Ejemplo n.º 2
0
def _pad_array(array, boundary):
  """Adds padding to the array so the array size aligns to a next boundary."""
  size = array.buffer_info()[1]
  pad_bytes = boundary - (size % boundary)
  if pad_bytes == boundary:
    return
  for _ in xrange(pad_bytes):
    array.append(0)
Ejemplo n.º 3
0
 def __init__(self, path):
     import array
     array = array.array('b')
     fd = os.open(path, os.O_RDONLY)
     sz = os.fstat(fd).st_size
     fp = os.fdopen(fd, 'rb')
     array.fromfile(fp, sz)
     os.close(fd)
     addr, count = array.buffer_info()
     self.lm = libngram.Ngram_init_from_bin(cast(addr, POINTER(c_byte)))
Ejemplo n.º 4
0
 def __init__(self, path):
     import array
     array = array.array('b')
     fd = os.open(path, os.O_RDONLY)
     sz = os.fstat(fd).st_size
     fp = os.fdopen(fd, 'rb')
     array.fromfile(fp, sz)
     os.close(fd)
     addr, count = array.buffer_info()
     self.lm = libngram.Ngram_init_from_bin(cast(addr, POINTER(c_byte)))