Skip to content

Commit eebba59

Browse files
committed
use a more idiomatic short name for unsigned int types
1 parent 56c5d31 commit eebba59

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

stringdtype/stringdtype/src/casts.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ static PyType_Slot b2s_slots[] = {{NPY_METH_resolve_descriptors,
499499

500500
static char *b2s_name = "cast_Bool_to_StringDType";
501501

502+
// casts between string and (u)int dtypes
503+
502504
static PyObject *
503505
string_to_pylong(char *in)
504506
{
@@ -691,23 +693,7 @@ uint_to_string(unsigned long long in, char *out)
691693
\
692694
PyArrayMethod_Spec *typename##ToStringCastSpec = get_cast_spec( \
693695
shortname##2s_name, NPY_UNSAFE_CASTING, NPY_METH_REQUIRES_PYAPI, \
694-
shortname##2s_dtypes, shortname##2s_slots); \
695-
\
696-
PyArray_DTypeMeta **s2u##shortname##_dtypes = \
697-
get_dtypes(this, &PyArray_U##typename##DType); \
698-
\
699-
PyArrayMethod_Spec *StringToU##typename##CastSpec = \
700-
get_cast_spec(s2u##shortname##_name, NPY_UNSAFE_CASTING, \
701-
NPY_METH_REQUIRES_PYAPI, s2u##shortname##_dtypes, \
702-
s2u##shortname##_slots); \
703-
\
704-
PyArray_DTypeMeta **u##shortname##2s_dtypes = \
705-
get_dtypes(&PyArray_U##typename##DType, this); \
706-
\
707-
PyArrayMethod_Spec *U##typename##ToStringCastSpec = \
708-
get_cast_spec(u##shortname##2s_name, NPY_UNSAFE_CASTING, \
709-
NPY_METH_REQUIRES_PYAPI, u##shortname##2s_dtypes, \
710-
u##shortname##2s_slots);
696+
shortname##2s_dtypes, shortname##2s_slots);
711697

712698
STRING_TO_INT(int8, int, i8, NPY_INT8, lli, npy_longlong)
713699
INT_TO_STRING(int8, int, i8, long long)
@@ -757,17 +743,17 @@ STRING_TO_INT(ulonglong, uint, ulonglong, NPY_ULONGLONG, llu, npy_ulonglong)
757743
INT_TO_STRING(ulonglong, uint, ulonglong, unsigned long long)
758744
#endif
759745

760-
STRING_TO_INT(uint8, uint, ui8, NPY_UINT8, llu, npy_ulonglong)
761-
INT_TO_STRING(uint8, uint, ui8, unsigned long long)
746+
STRING_TO_INT(uint8, uint, u8, NPY_UINT8, llu, npy_ulonglong)
747+
INT_TO_STRING(uint8, uint, u8, unsigned long long)
762748

763-
STRING_TO_INT(uint16, uint, ui16, NPY_UINT16, llu, npy_ulonglong)
764-
INT_TO_STRING(uint16, uint, ui16, unsigned long long)
749+
STRING_TO_INT(uint16, uint, u16, NPY_UINT16, llu, npy_ulonglong)
750+
INT_TO_STRING(uint16, uint, u16, unsigned long long)
765751

766-
STRING_TO_INT(uint32, uint, ui32, NPY_UINT32, llu, npy_ulonglong)
767-
INT_TO_STRING(uint32, uint, ui32, unsigned long long)
752+
STRING_TO_INT(uint32, uint, u32, NPY_UINT32, llu, npy_ulonglong)
753+
INT_TO_STRING(uint32, uint, u32, unsigned long long)
768754

769-
STRING_TO_INT(uint64, uint, ui64, NPY_UINT64, llu, npy_ulonglong)
770-
INT_TO_STRING(uint64, uint, ui64, unsigned long long)
755+
STRING_TO_INT(uint64, uint, u64, NPY_UINT64, llu, npy_ulonglong)
756+
INT_TO_STRING(uint64, uint, u64, unsigned long long)
771757

772758
PyArrayMethod_Spec *
773759
get_cast_spec(const char *name, NPY_CASTING casting,
@@ -880,17 +866,25 @@ get_casts(PyArray_DTypeMeta *this, PyArray_DTypeMeta *other)
880866
INT_DTYPES_AND_CAST_SPEC(i16, Int16)
881867
INT_DTYPES_AND_CAST_SPEC(i32, Int32)
882868
INT_DTYPES_AND_CAST_SPEC(i64, Int64)
869+
INT_DTYPES_AND_CAST_SPEC(u8, UInt8)
870+
INT_DTYPES_AND_CAST_SPEC(u16, UInt16)
871+
INT_DTYPES_AND_CAST_SPEC(u32, UInt32)
872+
INT_DTYPES_AND_CAST_SPEC(u64, UInt64)
883873
#if NPY_SIZEOF_BYTE == NPY_SIZEOF_SHORT
884874
INT_DTYPES_AND_CAST_SPEC(byte, Byte)
875+
INT_DTYPES_AND_CAST_SPEC(ubyte, UByte)
885876
#endif
886877
#if NPY_SIZEOF_SHORT == NPY_SIZEOF_INT
887878
INT_DTYPES_AND_CAST_SPEC(short, Short)
879+
INT_DTYPES_AND_CAST_SPEC(ushort, UShort)
888880
#endif
889881
#if NPY_SIZEOF_INT == NPY_SIZEOF_LONG
890882
INT_DTYPES_AND_CAST_SPEC(int, Int)
883+
INT_DTYPES_AND_CAST_SPEC(uint, UInt)
891884
#endif
892885
#if NPY_SIZEOF_LONGLONG == NPY_SIZEOF_LONG
893886
INT_DTYPES_AND_CAST_SPEC(longlong, LongLong)
887+
INT_DTYPES_AND_CAST_SPEC(ulonglong, ULongLong)
894888
#endif
895889

896890
PyArrayMethod_Spec **casts = NULL;

0 commit comments

Comments
 (0)