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

Function _descriptor_from_pep3118_format_fast

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

Source from the content-addressed store, hash-verified

991 */
992
993static int
994_descriptor_from_pep3118_format_fast(char const *s, PyObject **result)
995{
996 PyArray_Descr *descr;
997
998 int is_standard_size = 0;
999 char byte_order = '=';
1000 int is_complex = 0;
1001
1002 int type_num = NPY_BYTE;
1003 int item_seen = 0;
1004
1005 for (; *s != '\0'; ++s) {
1006 is_complex = 0;
1007 switch (*s) {
1008 case '@':
1009 case '^':
1010 /* ^ means no alignment; doesn't matter for a single element */
1011 byte_order = '=';
1012 is_standard_size = 0;
1013 break;
1014 case '<':
1015 byte_order = '<';
1016 is_standard_size = 1;
1017 break;
1018 case '>':
1019 case '!':
1020 byte_order = '>';
1021 is_standard_size = 1;
1022 break;
1023 case '=':
1024 byte_order = '=';
1025 is_standard_size = 1;
1026 break;
1027 case 'Z':
1028 is_complex = 1;
1029 ++s;
1030 default:
1031 if (item_seen) {
1032 /* Not a single-element data type */
1033 return 0;
1034 }
1035 type_num = _pep3118_letter_to_type(*s, !is_standard_size,
1036 is_complex);
1037 if (type_num < 0) {
1038 /* Something unknown */
1039 return 0;
1040 }
1041 item_seen = 1;
1042 break;
1043 }
1044 }
1045
1046 if (!item_seen) {
1047 return 0;
1048 }
1049
1050 descr = PyArray_DescrFromType(type_num);

Callers 1

Calls 2

_pep3118_letter_to_typeFunction · 0.85

Tested by

no test coverage detected