/*-*- C -*-*/ /* // @HEADER // *********************************************************************** // // PyTrilinos: Python Interfaces to Trilinos Packages // Copyright (2014) Sandia Corporation // // Under the terms of Contract DE-AC04-94AL85000 with Sandia // Corporation, the U.S. Government retains certain rights in this // software. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. Neither the name of the Corporation nor the names of the // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Questions? Contact William F. Spotz (wfspotz@sandia.gov) // // *********************************************************************** // @HEADER */ /**********************************************************************/ /* For numpy versions prior to 1.0, the names of certain data types * are different than in later versions. This fragment provides macro * substitutions that allow us to support old and new versions of * numpy. */ %fragment("NumPy_Backward_Compatibility", "header") { /* Support older NumPy data type names */ /* %#if NDARRAY_VERSION < 0x01000000 */ /* %#define NPY_BOOL PyArray_BOOL */ /* %#define NPY_BYTE PyArray_BYTE */ /* %#define NPY_UBYTE PyArray_UBYTE */ /* %#define NPY_SHORT PyArray_SHORT */ /* %#define NPY_USHORT PyArray_USHORT */ /* %#define NPY_INT PyArray_INT */ /* %#define NPY_UINT PyArray_UINT */ /* %#define NPY_LONG PyArray_LONG */ /* %#define NPY_ULONG PyArray_ULONG */ /* %#define NPY_LONGLONG PyArray_LONGLONG */ /* %#define NPY_ULONGLONG PyArray_ULONGLONG */ /* %#define NPY_FLOAT PyArray_FLOAT */ /* %#define NPY_DOUBLE PyArray_DOUBLE */ /* %#define NPY_LONGDOUBLE PyArray_LONGDOUBLE */ /* %#define NPY_CFLOAT PyArray_CFLOAT */ /* %#define NPY_CDOUBLE PyArray_CDOUBLE */ /* %#define NPY_CLONGDOUBLE PyArray_CLONGDOUBLE */ /* %#define NPY_OBJECT PyArray_OBJECT */ /* %#define NPY_STRING PyArray_STRING */ /* %#define NPY_UNICODE PyArray_UNICODE */ /* %#define NPY_VOID PyArray_VOID */ /* %#define NPY_NTYPES PyArray_NTYPES */ /* %#define NPY_NOTYPE PyArray_NOTYPE */ /* %#define NPY_CHAR PyArray_CHAR */ /* %#define NPY_USERDEF PyArray_USERDEF */ /* %#define npy_intp intp */ /* %#define NPY_MAX_BYTE MAX_BYTE */ /* %#define NPY_MIN_BYTE MIN_BYTE */ /* %#define NPY_MAX_UBYTE MAX_UBYTE */ /* %#define NPY_MAX_SHORT MAX_SHORT */ /* %#define NPY_MIN_SHORT MIN_SHORT */ /* %#define NPY_MAX_USHORT MAX_USHORT */ /* %#define NPY_MAX_INT MAX_INT */ /* %#define NPY_MIN_INT MIN_INT */ /* %#define NPY_MAX_UINT MAX_UINT */ /* %#define NPY_MAX_LONG MAX_LONG */ /* %#define NPY_MIN_LONG MIN_LONG */ /* %#define NPY_MAX_ULONG MAX_ULONG */ /* %#define NPY_MAX_LONGLONG MAX_LONGLONG */ /* %#define NPY_MIN_LONGLONG MIN_LONGLONG */ /* %#define NPY_MAX_ULONGLONG MAX_ULONGLONG */ /* %#define NPY_MAX_INTP MAX_INTP */ /* %#define NPY_MIN_INTP MIN_INTP */ /* %#define NPY_FARRAY FARRAY */ /* %#define NPY_F_CONTIGUOUS F_CONTIGUOUS */ /* %#endif */ %#if NPY_API_VERSION < 0x00000007 %#define NPY_ARRAY_DEFAULT NPY_DEFAULT %#define NPY_ARRAY_FARRAY NPY_FARRAY %#define NPY_FORTRANORDER NPY_FORTRAN %#endif } /**********************************************************************/ /* Override the SWIG_AsVal_frag(long) fragment so that it also checks * for numpy scalar array types. The code through the %#endif is * essentially cut-and-paste from pyprimtype.swg */ %fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_CanCastAsInteger", fragment="NumPy_Backward_Compatibility") { SWIGINTERN int SWIG_AsVal_dec(long)(PyObject * obj, long * val) { static PyArray_Descr * longDescr = PyArray_DescrNewFromType(NPY_LONG); %#if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { if (val) *val = PyInt_AsLong(obj); return SWIG_OK; } else %#endif if (PyLong_Check(obj)) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } %#ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; long v = PyInt_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d)); if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { if (val) *val = (long)(d); return res; } } } %#endif if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError; if (val) PyArray_CastScalarToCtype(obj, (void*)val, longDescr); return SWIG_OK; } } /* Override the SWIG_AsVal_frag(unsigned long) fragment so that it * also checks for numpy scalar array types. The code through the * %#endif is essentially cut-and-paste from pyprimtype.swg */ %fragment(SWIG_AsVal_frag(unsigned long),"header", fragment="SWIG_CanCastAsInteger", fragment="NumPy_Backward_Compatibility") { SWIGINTERN int SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) { static PyArray_Descr * ulongDescr = PyArray_DescrNewFromType(NPY_ULONG); %#if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { long v = PyInt_AsLong(obj); if (v >= 0) { if (val) *val = v; return SWIG_OK; } else { return SWIG_OverflowError; } } else %#endif if (PyLong_Check(obj)) { unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); return SWIG_OverflowError; } } %#ifdef SWIG_PYTHON_CAST_MODE { int dispatch = 0; unsigned long v = PyLong_AsUnsignedLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_AddCast(SWIG_OK); } else { PyErr_Clear(); } if (!dispatch) { double d; int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d)); if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) { if (val) *val = (unsigned long)(d); return res; } } } %#endif if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError; if (val) PyArray_CastScalarToCtype(obj, (void*)val, ulongDescr); return SWIG_OK; } }