npconv.pyx 410 B

12345678910111213
  1. import cython
  2. import numpy as np
  3. from .buffer cimport ResponseBuffer
  4. @cython.boundscheck(False)
  5. @cython.wraparound(False)
  6. def read_numpy_array(ResponseBuffer buffer, np_type: str, unsigned long long num_rows):
  7. dtype = np.dtype(np_type)
  8. cdef sz = dtype.itemsize * num_rows
  9. cdef char * source = buffer.read_bytes_c(dtype.itemsize * num_rows)
  10. return np.frombuffer(source[:sz], dtype, num_rows)