1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import array
cpdef bytes cstrencode(str pystr):
"""
Encode a string into bytes.
"""
try:
return pystr.encode("utf-8")
except UnicodeDecodeError:
return pystr.decode("utf-8").encode("utf-8")
cdef str cstrdecode(const char *instring):
if instring != NULL:
return instring
return None
IF CTE_PYTHON_IMPLEMENTATION == "CPython":
from cpython cimport array
cdef array.array _ARRAY_TEMPLATE = array.array("d", [])
cdef array.array empty_array(int npts):
return array.clone(_ARRAY_TEMPLATE, npts, zero=False)
ELSE:
# https://github.com/pyproj4/pyproj/issues/854
cdef empty_array(int npts):
return array.array("d", [float("NaN")] * npts)
|