MCPcopy Create free account
hub / github.com/pmneila/PyMCubes / PyArray_SafeGet

Function PyArray_SafeGet

mcubes/src/pyarraymodule.h:42–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41template<typename T>
42T PyArray_SafeGet(const PyArrayObject* aobj, const npy_intp* indaux)
43{
44 // HORROR.
45 npy_intp* ind = const_cast<npy_intp*>(indaux);
46 void* ptr = PyArray_GetPtr(const_cast<PyArrayObject*>(aobj), ind);
47 switch(PyArray_TYPE(aobj))
48 {
49 case NPY_BOOL:
50 return static_cast<T>(*reinterpret_cast<bool*>(ptr));
51 case NPY_BYTE:
52 return static_cast<T>(*reinterpret_cast<char*>(ptr));
53 case NPY_SHORT:
54 return static_cast<T>(*reinterpret_cast<short*>(ptr));
55 case NPY_INT:
56 return static_cast<T>(*reinterpret_cast<int*>(ptr));
57 case NPY_LONG:
58 return static_cast<T>(*reinterpret_cast<long*>(ptr));
59 case NPY_LONGLONG:
60 return static_cast<T>(*reinterpret_cast<long long*>(ptr));
61 case NPY_UBYTE:
62 return static_cast<T>(*reinterpret_cast<unsigned char*>(ptr));
63 case NPY_USHORT:
64 return static_cast<T>(*reinterpret_cast<unsigned short*>(ptr));
65 case NPY_UINT:
66 return static_cast<T>(*reinterpret_cast<unsigned int*>(ptr));
67 case NPY_ULONG:
68 return static_cast<T>(*reinterpret_cast<unsigned long*>(ptr));
69 case NPY_ULONGLONG:
70 return static_cast<T>(*reinterpret_cast<unsigned long long*>(ptr));
71 case NPY_FLOAT:
72 return static_cast<T>(*reinterpret_cast<float*>(ptr));
73 case NPY_DOUBLE:
74 return static_cast<T>(*reinterpret_cast<double*>(ptr));
75 case NPY_LONGDOUBLE:
76 return static_cast<T>(*reinterpret_cast<long double*>(ptr));
77 default:
78 throw std::runtime_error("data type not supported");
79 }
80}
81
82template<typename T>
83T PyArray_SafeSet(PyArrayObject* aobj, const npy_intp* indaux, const T& value)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected