mirror of
https://github.com/hanzo-ds/connect.git
synced 2026-10-30 20:31:24 +00:00
* reenable and fix driverc drift * target ctypes directly * linting * update changelog * pivot cython optimization * update changelog
17 lines
540 B
Cython
17 lines
540 B
Cython
import cython
|
|
|
|
import numpy as np
|
|
|
|
from .buffer cimport ResponseBuffer
|
|
|
|
@cython.boundscheck(False)
|
|
@cython.wraparound(False)
|
|
def read_numpy_array(buffer, np_type: str, unsigned long long num_rows):
|
|
dtype = np.dtype(np_type)
|
|
cdef sz = dtype.itemsize * num_rows
|
|
cdef char * source
|
|
if isinstance(buffer, ResponseBuffer):
|
|
source = (<ResponseBuffer>buffer).read_bytes_c(dtype.itemsize * num_rows)
|
|
return np.frombuffer(source[:sz], dtype, num_rows)
|
|
return np.frombuffer(buffer.read_bytes(sz), dtype, num_rows)
|