numpy  2.0.0
include/numpy/arrayscalars.h
Go to the documentation of this file.
00001 #ifndef _NPY_ARRAYSCALARS_H_
00002 #define _NPY_ARRAYSCALARS_H_
00003 
00004 #ifndef _MULTIARRAYMODULE
00005 typedef struct {
00006         PyObject_HEAD
00007         npy_bool obval;
00008 } PyBoolScalarObject;
00009 #endif
00010 
00011 
00012 typedef struct {
00013         PyObject_HEAD
00014         signed char obval;
00015 } PyByteScalarObject;
00016 
00017 
00018 typedef struct {
00019         PyObject_HEAD
00020         short obval;
00021 } PyShortScalarObject;
00022 
00023 
00024 typedef struct {
00025         PyObject_HEAD
00026         int obval;
00027 } PyIntScalarObject;
00028 
00029 
00030 typedef struct {
00031         PyObject_HEAD
00032         long obval;
00033 } PyLongScalarObject;
00034 
00035 
00036 typedef struct {
00037         PyObject_HEAD
00038         npy_longlong obval;
00039 } PyLongLongScalarObject;
00040 
00041 
00042 typedef struct {
00043         PyObject_HEAD
00044         unsigned char obval;
00045 } PyUByteScalarObject;
00046 
00047 
00048 typedef struct {
00049         PyObject_HEAD
00050         unsigned short obval;
00051 } PyUShortScalarObject;
00052 
00053 
00054 typedef struct {
00055         PyObject_HEAD
00056         unsigned int obval;
00057 } PyUIntScalarObject;
00058 
00059 
00060 typedef struct {
00061         PyObject_HEAD
00062         unsigned long obval;
00063 } PyULongScalarObject;
00064 
00065 
00066 typedef struct {
00067         PyObject_HEAD
00068         npy_ulonglong obval;
00069 } PyULongLongScalarObject;
00070 
00071 
00072 typedef struct {
00073         PyObject_HEAD
00074         npy_half obval;
00075 } PyHalfScalarObject;
00076 
00077 
00078 typedef struct {
00079         PyObject_HEAD
00080         float obval;
00081 } PyFloatScalarObject;
00082 
00083 
00084 typedef struct {
00085         PyObject_HEAD
00086         double obval;
00087 } PyDoubleScalarObject;
00088 
00089 
00090 typedef struct {
00091         PyObject_HEAD
00092         npy_longdouble obval;
00093 } PyLongDoubleScalarObject;
00094 
00095 
00096 typedef struct {
00097         PyObject_HEAD
00098         npy_cfloat obval;
00099 } PyCFloatScalarObject;
00100 
00101 
00102 typedef struct {
00103         PyObject_HEAD
00104         npy_cdouble obval;
00105 } PyCDoubleScalarObject;
00106 
00107 
00108 typedef struct {
00109         PyObject_HEAD
00110         npy_clongdouble obval;
00111 } PyCLongDoubleScalarObject;
00112 
00113 
00114 typedef struct {
00115         PyObject_HEAD
00116         PyObject * obval;
00117 } PyObjectScalarObject;
00118 
00119 typedef struct {
00120         PyObject_HEAD
00121         npy_datetime obval;
00122         PyArray_DatetimeMetaData obmeta;
00123 } PyDatetimeScalarObject;
00124 
00125 typedef struct {
00126         PyObject_HEAD
00127         npy_timedelta obval;
00128         PyArray_DatetimeMetaData obmeta;
00129 } PyTimedeltaScalarObject;
00130 
00131 
00132 typedef struct {
00133         PyObject_HEAD
00134         char obval;
00135 } PyScalarObject;
00136 
00137 #define PyStringScalarObject PyStringObject
00138 #define PyUnicodeScalarObject PyUnicodeObject
00139 
00140 typedef struct {
00141         PyObject_VAR_HEAD
00142         char *obval;
00143         PyArray_Descr *descr;
00144         int flags;
00145         PyObject *base;
00146 } PyVoidScalarObject;
00147 
00148 /* Macros
00149      Py<Cls><bitsize>ScalarObject
00150      Py<Cls><bitsize>ArrType_Type
00151    are defined in ndarrayobject.h
00152 */
00153 
00154 #define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))
00155 #define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))
00156 #define PyArrayScalar_FromLong(i) \
00157         ((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))
00158 #define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)                  \
00159         return Py_INCREF(PyArrayScalar_FromLong(i)), \
00160                 PyArrayScalar_FromLong(i)
00161 #define PyArrayScalar_RETURN_FALSE              \
00162         return Py_INCREF(PyArrayScalar_False),  \
00163                 PyArrayScalar_False
00164 #define PyArrayScalar_RETURN_TRUE               \
00165         return Py_INCREF(PyArrayScalar_True),   \
00166                 PyArrayScalar_True
00167 
00168 #define PyArrayScalar_New(cls) \
00169         Py##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)
00170 #define PyArrayScalar_VAL(obj, cls)             \
00171         ((Py##cls##ScalarObject *)obj)->obval
00172 #define PyArrayScalar_ASSIGN(obj, cls, val) \
00173         PyArrayScalar_VAL(obj, cls) = val
00174 
00175 #endif