MCPcopy Create free account
hub / github.com/numpy/numpy / _descriptor_from_pep3118_format

Function _descriptor_from_pep3118_format

numpy/core/src/multiarray/buffer.c:908–985  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

906_pep3118_letter_to_type(char letter, int native, int complex);
907
908NPY_NO_EXPORT PyArray_Descr*
909_descriptor_from_pep3118_format(char const *s)
910{
911 char *buf, *p;
912 int in_name = 0;
913 int obtained;
914 PyObject *descr;
915 PyObject *str;
916 PyObject *_numpy_internal;
917
918 if (s == NULL) {
919 return PyArray_DescrNewFromType(NPY_BYTE);
920 }
921
922 /* Fast path */
923 obtained = _descriptor_from_pep3118_format_fast(s, &descr);
924 if (obtained) {
925 return (PyArray_Descr*)descr;
926 }
927
928 /* Strip whitespace, except from field names */
929 buf = malloc(strlen(s) + 1);
930 if (buf == NULL) {
931 PyErr_NoMemory();
932 return NULL;
933 }
934 p = buf;
935 while (*s != '\0') {
936 if (*s == ':') {
937 in_name = !in_name;
938 *p = *s;
939 p++;
940 }
941 else if (in_name || !NumPyOS_ascii_isspace(*s)) {
942 *p = *s;
943 p++;
944 }
945 s++;
946 }
947 *p = '\0';
948
949 str = PyUnicode_FromStringAndSize(buf, strlen(buf));
950 if (str == NULL) {
951 free(buf);
952 return NULL;
953 }
954
955 /* Convert */
956 _numpy_internal = PyImport_ImportModule("numpy.core._internal");
957 if (_numpy_internal == NULL) {
958 Py_DECREF(str);
959 free(buf);
960 return NULL;
961 }
962 descr = PyObject_CallMethod(
963 _numpy_internal, "_dtype_from_pep3118", "O", str);
964 Py_DECREF(str);
965 Py_DECREF(_numpy_internal);

Callers 1

_dtype_from_buffer_3118Function · 0.85

Tested by

no test coverage detected