From 15ad6159b477191efab8571b42c3b46b06709eaa Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 17 Nov 2020 14:48:23 +0100 Subject: [PATCH] Remove implicit conversion warnings (#3324) --- ChangeLog | 3 ++- NEWS | 2 +- README.md | 2 +- doc/source/admin/release_history/2.0.rst | 6 ++++-- inst/cta/include/GCTAModelSpatialMultiplicative.hpp | 4 ++-- pyext/GFunctions.i | 2 +- pyext/GMatrix.i | 1 - pyext/GMatrixSparse.i | 1 - pyext/GMatrixSymmetric.i | 1 - pyext/GRmf.i | 3 +-- pyext/GTypemaps.i | 152 -------------------------------------------------------------------------------------------------------------------------------------------------------- pyext/gammalib/app.i | 3 ++- pyext/gammalib/base.i | 3 ++- pyext/gammalib/fits.i | 3 ++- pyext/gammalib/linalg.i | 4 +++- pyext/gammalib/model.i | 1 + pyext/gammalib/numerics.i | 3 ++- pyext/gammalib/obs.i | 1 + pyext/gammalib/opt.i | 3 ++- pyext/gammalib/sky.i | 3 ++- pyext/gammalib/support.i | 3 ++- pyext/gammalib/test.i | 3 ++- pyext/gammalib/vo.i | 3 ++- pyext/gammalib/xml.i | 3 ++- pyext/gammalib/xspec.i | 2 ++ pyext/typemap_GChatter.i | 37 +++++++++++++++++++++++++++++++++++++ pyext/typemap_GTuple.i | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 27 files changed, 210 insertions(+), 176 deletions(-) delete mode 100644 pyext/GTypemaps.i create mode 100644 pyext/typemap_GChatter.i create mode 100644 pyext/typemap_GTuple.i diff --git a/ChangeLog b/ChangeLog index e225cc2..9d17d9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2020-11-09 +2020-11-17 * Version 2.0.0 released ======================== @@ -12,6 +12,7 @@ Integrate analytical gradients for energy dispersion computation (#3333) Add GFunctions abstract base class (#3328) Add GIntegrals class (#3328) + Remove implicit conversion warnings (#3324) Implement vectorised response computation (#3203) Implement analytical gradients for the radial Gaussian model in a stacked analysis (#3203) diff --git a/NEWS b/NEWS index 39f87e1..4f2b338 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 2.0.0 -9 November 2020 +17 November 2020 1. Introduction diff --git a/README.md b/README.md index d95be79..10d5472 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ GammaLib information ==================== -* Version: 2.0.0.dev (9 November 2020) +* Version: 2.0.0.dev (17 November 2020) [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) diff --git a/doc/source/admin/release_history/2.0.rst b/doc/source/admin/release_history/2.0.rst index 4711ec5..1cf979e 100644 --- a/doc/source/admin/release_history/2.0.rst +++ b/doc/source/admin/release_history/2.0.rst @@ -1,7 +1,7 @@ .. _2.0: -GammaLib 2.0 release (9 November 2020) -====================================== +GammaLib 2.0 release (17 November 2020) +======================================= Overview -------- @@ -26,6 +26,8 @@ Improvements * [`3333 `_] - Integrate analytical gradients for energy dispersion computation +* [`3324 `_] - + Remove implicit conversion warnings * Implement ``GMatrixSparse::row()`` and ``GMatrixSparse::add_to_row()`` methods * [`3203 `_] - Implement vectorised response computation and analytical gradients for diff --git a/inst/cta/include/GCTAModelSpatialMultiplicative.hpp b/inst/cta/include/GCTAModelSpatialMultiplicative.hpp index de58edf..0247483 100644 --- a/inst/cta/include/GCTAModelSpatialMultiplicative.hpp +++ b/inst/cta/include/GCTAModelSpatialMultiplicative.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelSpatialMultiplicative.hpp - Multiplicative spatial model class * * ----------------------------------------------------------------------- * - * copyright (C) 2018 by Juergen Knoedlseder * + * copyright (C) 2018-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -132,7 +132,7 @@ std::string GCTAModelSpatialMultiplicative::type(void) const inline int GCTAModelSpatialMultiplicative::components(void) const { - return (m_spatial.size()); + return ((int)m_spatial.size()); } #endif /* GCTAMODELSPATIALMULTIPLICATIVE_HPP */ diff --git a/pyext/GFunctions.i b/pyext/GFunctions.i index 721066d..86dcf1e 100644 --- a/pyext/GFunctions.i +++ b/pyext/GFunctions.i @@ -40,7 +40,7 @@ public: // Constructors and destructors GFunctions(void); GFunctions(const GFunctions& functions); - virtual ~GFunction(void); + virtual ~GFunctions(void); // Methods virtual int size(void) const = 0; diff --git a/pyext/GMatrix.i b/pyext/GMatrix.i index 1e62d00..a2bda51 100755 --- a/pyext/GMatrix.i +++ b/pyext/GMatrix.i @@ -31,7 +31,6 @@ %} /* __ Includes ___________________________________________________________ */ -%include "GTypemaps.i" /***********************************************************************//** diff --git a/pyext/GMatrixSparse.i b/pyext/GMatrixSparse.i index 2cec1fe..4479d57 100644 --- a/pyext/GMatrixSparse.i +++ b/pyext/GMatrixSparse.i @@ -30,7 +30,6 @@ %} /* __ Includes ___________________________________________________________ */ -%include "GTypemaps.i" /***********************************************************************//** diff --git a/pyext/GMatrixSymmetric.i b/pyext/GMatrixSymmetric.i index fc14e34..e8cc8ce 100644 --- a/pyext/GMatrixSymmetric.i +++ b/pyext/GMatrixSymmetric.i @@ -30,7 +30,6 @@ %} /* __ Includes ___________________________________________________________ */ -%include "GTypemaps.i" /***********************************************************************//** diff --git a/pyext/GRmf.i b/pyext/GRmf.i index 03bd2fb..25ab75e 100644 --- a/pyext/GRmf.i +++ b/pyext/GRmf.i @@ -1,7 +1,7 @@ /*************************************************************************** * GRmf.i - XSPEC Redistribution Matrix File class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2018 by Juergen Knoedlseder * + * copyright (C) 2013-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -29,7 +29,6 @@ %} /* __ Includes ___________________________________________________________ */ -%include "GTypemaps.i" /* __ Constants __________________________________________________________ */ namespace gammalib { diff --git a/pyext/GTypemaps.i b/pyext/GTypemaps.i deleted file mode 100644 index cc1f6f2..0000000 --- a/pyext/GTypemaps.i +++ /dev/null @@ -1,152 +0,0 @@ -/*************************************************************************** - * GTypemaps.i - Typemaps for GammaLib Python interface * - * ----------------------------------------------------------------------- * - * copyright (C) 2012 by Juergen Knoedlseder * - * ----------------------------------------------------------------------- * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - ***************************************************************************/ -/** - * @file GTypemaps.i - * @brief Provides typemaps for GammaLib - * @author Juergen Knoedlseder - */ -%{ -/* Put headers and other declarations here that are needed for compilation */ -%} - - -/***********************************************************************//** - * @brief 2D tuple to index conversion - * - * The following typemap provides conversion between a 2-dimensional Python - * tuple and an integer array. This allows index access via tuples, such as - * in a[3,5] = 10.0 or c = a[2,9]. A typecheck typemap is provided to allow - * overloading. - ***************************************************************************/ -%typemap(in) int GTuple[2] (int temp[2]) { - if (!PySequence_Check($input)) { - PyErr_SetString(PyExc_ValueError,"Expected a sequence"); - return NULL; - } - if (PySequence_Length($input) != 2) { - PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected 2 elements"); - return NULL; - } - for (int i = 0; i < 2; ++i) { - PyObject *o = PySequence_GetItem($input,i); - if (PyInt_Check(o)) { - temp[i] = (int)PyInt_AsLong(o); - } - else { - PyErr_SetString(PyExc_ValueError,"Indices must be integers"); - return NULL; - } - } - $1 = temp; -} -%typemap(typecheck) int GTuple[2] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - - -/***********************************************************************//** - * @brief Tuple to index conversion using variable dimensions - * - * The following function provides conversion between a Python tuple and - * an integer array. This allows index access via tuples, such as in - * a[3,5,10] = 10.0 or c = a[2,9]. - ***************************************************************************/ -%{ -static int var_tuple_to_index(PyObject *input, int *ptr, int dim) { - if (PySequence_Check(input)) { - int size = PyObject_Length(input); - if (size > dim) { - PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); - return 0; - } - ptr[0] = size; - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyInt_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); - return 0; - } - ptr[i+1] = (int)PyInt_AsLong(o); - Py_DECREF(o); - } - return 1; - } - else { - ptr[0] = 1; - if (!PyInt_Check(input)) { - PyErr_SetString(PyExc_ValueError,"Expecting an integer"); - return 0; - } - ptr[1] = (int)PyInt_AsLong(input); - return 1; - } -} -%} -%typemap(in) int GTuple[ANY] (int temp[11]) { - if (!var_tuple_to_index($input,temp,10)) { - return NULL; - } - $1 = &temp[0]; -} -%typemap(typecheck) int GTuple[ANY] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - -/* __ Enumerations _______________________________________________________ */ -typedef enum { - SILENT = 0, - TERSE = 1, - NORMAL = 2, - EXPLICIT = 3, - VERBOSE = 4 -} GChatter; - diff --git a/pyext/gammalib/app.i b/pyext/gammalib/app.i index 3cb7efe..e220724 100644 --- a/pyext/gammalib/app.i +++ b/pyext/gammalib/app.i @@ -1,7 +1,7 @@ /*************************************************************************** * app.i - Application module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2018 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -45,6 +45,7 @@ namespace std { }; /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/base.i b/pyext/gammalib/base.i index 9ea8c9a..a2febf8 100644 --- a/pyext/gammalib/base.i +++ b/pyext/gammalib/base.i @@ -1,7 +1,7 @@ /*************************************************************************** * base.i - Base module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2016 by Juergen Knoedlseder * + * copyright (C) 2012-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i /* __ Base module ________________________________________________________ */ diff --git a/pyext/gammalib/fits.i b/pyext/gammalib/fits.i index a4203c2..04279d7 100644 --- a/pyext/gammalib/fits.i +++ b/pyext/gammalib/fits.i @@ -1,7 +1,7 @@ /*************************************************************************** * fits.i - FITS module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -45,6 +45,7 @@ namespace std { }; /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/linalg.i b/pyext/gammalib/linalg.i index 84f4b21..f6dc699 100644 --- a/pyext/gammalib/linalg.i +++ b/pyext/gammalib/linalg.i @@ -1,7 +1,7 @@ /*************************************************************************** * linalg.i - Linear algebra module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,7 +40,9 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/pyext/gammalib/model.i b/pyext/gammalib/model.i index 71408d3..3cfad72 100644 --- a/pyext/gammalib/model.i +++ b/pyext/gammalib/model.i @@ -43,6 +43,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/numerics.i b/pyext/gammalib/numerics.i index ee41a84..7c60938 100644 --- a/pyext/gammalib/numerics.i +++ b/pyext/gammalib/numerics.i @@ -44,7 +44,8 @@ %template(vectorc) std::vector >; /* __ Include GammaLib typemaps __________________________________________ */ -%include GTypemaps.i +%include typemap_GChatter.i +%include typemap_GTuple.i %include typemap_GFilename.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/gammalib/obs.i b/pyext/gammalib/obs.i index 439f3d6..18f7c51 100644 --- a/pyext/gammalib/obs.i +++ b/pyext/gammalib/obs.i @@ -60,6 +60,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/opt.i b/pyext/gammalib/opt.i index 0e0f438..f97a4f2 100644 --- a/pyext/gammalib/opt.i +++ b/pyext/gammalib/opt.i @@ -1,7 +1,7 @@ /*************************************************************************** * opt.i - Optimization module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2018 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/sky.i b/pyext/gammalib/sky.i index 068579e..2c4d38c 100644 --- a/pyext/gammalib/sky.i +++ b/pyext/gammalib/sky.i @@ -1,7 +1,7 @@ /*************************************************************************** * sky.i - Sky module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2018 by Jurgen Knodlseder * + * copyright (C) 2011-2020 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -47,6 +47,7 @@ namespace std { }; /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/support.i b/pyext/gammalib/support.i index da0822e..aa803d6 100644 --- a/pyext/gammalib/support.i +++ b/pyext/gammalib/support.i @@ -1,7 +1,7 @@ /*************************************************************************** * support.i - Support module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Jurgen Knodlseder * + * copyright (C) 2011-2020 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -44,6 +44,7 @@ %template(vectors) std::vector; /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/test.i b/pyext/gammalib/test.i index f11d89b..9ef4069 100644 --- a/pyext/gammalib/test.i +++ b/pyext/gammalib/test.i @@ -1,7 +1,7 @@ /*************************************************************************** * test.i - Test module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2017 by Jean-Baptiste Cayrou * + * copyright (C) 2012-2020 by Jean-Baptiste Cayrou * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/vo.i b/pyext/gammalib/vo.i index a4c519c..53d8b04 100644 --- a/pyext/gammalib/vo.i +++ b/pyext/gammalib/vo.i @@ -1,7 +1,7 @@ /*************************************************************************** * vo.i - Virtual Observatory module * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Juergen Knoedlseder * + * copyright (C) 2014-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/gammalib/xml.i b/pyext/gammalib/xml.i index f806c3d..cb73e15 100644 --- a/pyext/gammalib/xml.i +++ b/pyext/gammalib/xml.i @@ -1,7 +1,7 @@ /*************************************************************************** * xml.i - XML module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2018 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,7 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i %include typemap_slices.i diff --git a/pyext/gammalib/xspec.i b/pyext/gammalib/xspec.i index 0325798..250f600 100644 --- a/pyext/gammalib/xspec.i +++ b/pyext/gammalib/xspec.i @@ -44,7 +44,9 @@ namespace std { }; /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/pyext/typemap_GChatter.i b/pyext/typemap_GChatter.i new file mode 100644 index 0000000..3ad6471 --- /dev/null +++ b/pyext/typemap_GChatter.i @@ -0,0 +1,37 @@ +/*************************************************************************** + * typemap_GChatter.i - Chatter typemap * + * ----------------------------------------------------------------------- * + * copyright (C) 2020 by Juergen Knoedlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file typemap_GChatter.i + * @brief Provides GChatter typemap for GammaLib + * @author Juergen Knoedlseder + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +%} + +/* __ Enumerations _______________________________________________________ */ +typedef enum { + SILENT = 0, + TERSE = 1, + NORMAL = 2, + EXPLICIT = 3, + VERBOSE = 4 +} GChatter; diff --git a/pyext/typemap_GTuple.i b/pyext/typemap_GTuple.i new file mode 100644 index 0000000..cb3de2e --- /dev/null +++ b/pyext/typemap_GTuple.i @@ -0,0 +1,134 @@ +/*************************************************************************** + * typemap_GTuple.i - Tuple typemap * + * ----------------------------------------------------------------------- * + * copyright (C) 2020 by Juergen Knoedlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file typemap_GTuple.i + * @brief Provides GTuple typemap for GammaLib + * @author Juergen Knoedlseder + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +%} + + +/***********************************************************************//** + * @brief 2D tuple to index conversion + * + * The following typemap provides conversion between a 2-dimensional Python + * tuple and an integer array. This allows index access via tuples, such as + * in a[3,5] = 10.0 or c = a[2,9]. A typecheck typemap is provided to allow + * overloading. + ***************************************************************************/ +%typemap(in) int GTuple[2] (int temp[2]) { + if (!PySequence_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a sequence"); + return NULL; + } + if (PySequence_Length($input) != 2) { + PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected 2 elements"); + return NULL; + } + for (int i = 0; i < 2; ++i) { + PyObject *o = PySequence_GetItem($input,i); + if (PyInt_Check(o)) { + temp[i] = (int)PyInt_AsLong(o); + } + else { + PyErr_SetString(PyExc_ValueError,"Indices must be integers"); + return NULL; + } + } + $1 = temp; +} +%typemap(typecheck) int GTuple[2] { + $1 = 1; + if (PySequence_Check($input)) { + int size = PyObject_Length($input); + for (int i = 0; i < size; i++) { + PyObject *o = PySequence_GetItem($input,i); + if (!PyInt_Check(o)) { + $1 = 0; + break; + } + } + } + else { + if (!PyInt_Check($input)) { + $1 = 0; + } + } +} + + +/***********************************************************************//** + * @brief Tuple to index conversion using variable dimensions + * + * The following function provides conversion between a Python tuple and + * an integer array. This allows index access via tuples, such as in + * a[3,5,10] = 10.0 or c = a[2,9]. + ***************************************************************************/ +%typemap(in) int GTuple[ANY] (int temp[11]) { + if (PySequence_Check($input)) { + int size = PyObject_Length($input); + if (size > 10) { + PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); + return NULL; + } + temp[0] = size; + for (int i = 0; i < size; i++) { + PyObject *o = PySequence_GetItem($input,i); + if (!PyInt_Check(o)) { + Py_XDECREF(o); + PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); + return NULL; + } + temp[i+1] = (int)PyInt_AsLong(o); + Py_DECREF(o); + } + $1 = &temp[0]; + } + else { + temp[0] = 1; + if (!PyInt_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expecting an integer"); + return NULL; + } + temp[1] = (int)PyInt_AsLong($input); + $1 = &temp[0]; + } +} +%typemap(typecheck) int GTuple[ANY] { + $1 = 1; + if (PySequence_Check($input)) { + int size = PyObject_Length($input); + for (int i = 0; i < size; i++) { + PyObject *o = PySequence_GetItem($input,i); + if (!PyInt_Check(o)) { + $1 = 0; + break; + } + } + } + else { + if (!PyInt_Check($input)) { + $1 = 0; + } + } +} -- libgit2 0.21.4