From: <sv...@ww...> - 2005-08-28 22:46:10
|
Author: mkrose Date: 2005-08-28 15:46:03 -0700 (Sun, 28 Aug 2005) New Revision: 1619 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py trunk/CSP/CSPSim/Include/Config.h trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/LUT.i trunk/CSP/SimData/Include/SimData/Random.h trunk/CSP/SimData/Include/SimData/Random.i trunk/CSP/tools/build.py Log: Small tweaks to the SimData API (Random.h), typemaps, and build scripts to workaround problems with swig 1.3.23 and newer. Tested with swig 1.3.22-25 under Linux. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1619 Modified: trunk/CSP/CSPSim/Bin/CSPSim.py =================================================================== --- trunk/CSP/CSPSim/Bin/CSPSim.py 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/CSPSim/Bin/CSPSim.py 2005-08-28 22:46:03 UTC (rev 1619) @@ -352,7 +352,7 @@ loadCSP() print "Loading configuration from '%s'." % config - if not cCSP.openConfig(config): + if not cCSP.openConfig(config, 1): print "Unable to open primary configuration file (%s)" % config sys.exit(0) Modified: trunk/CSP/CSPSim/Include/Config.h =================================================================== --- trunk/CSP/CSPSim/Include/Config.h 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/CSPSim/Include/Config.h 2005-08-28 22:46:03 UTC (rev 1619) @@ -37,7 +37,7 @@ /** * Open the global configuration file. */ -extern bool openConfig(std::string path, bool report_error=true); +extern bool openConfig(std::string path, bool report_error); //=true); /** * Get the main cache path. Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/SimData/CHANGES.current 2005-08-28 22:46:03 UTC (rev 1619) @@ -1,6 +1,11 @@ Version 0.4.0 (in progress) =========================== +2005-08-28: onsight + * Small tweaks to the SimData API (Random.h), typemaps, and + build scripts to workaround problems with swig 1.3.23 and + newer. Tested with swig 1.3.22-25 under Linux. + 2005-08-27: onsight * Extend warning pragma to MSVC Express 8, and disable 'deprecated' function warning. Modified: trunk/CSP/SimData/Include/SimData/LUT.i =================================================================== --- trunk/CSP/SimData/Include/SimData/LUT.i 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/SimData/Include/SimData/LUT.i 2005-08-28 22:46:03 UTC (rev 1619) @@ -44,38 +44,43 @@ */ %typemap(in) std::vector<std::vector<float> > const & (std::vector<std::vector<float> > temp) { - if (PyTuple_Check($input) || PyList_Check($input)) { - unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); - temp.resize(size); - $1 = &temp; - for (unsigned int i=0; i<size; i++) { - PyObject* o = PySequence_GetItem($input,i); - if (PyTuple_Check(o) || PyList_Check(o)) { - unsigned int size = (PyTuple_Check(o) ? PyTuple_Size(o) : PyList_Size(o)); - temp[i].resize(size); - for (unsigned int j=0; j<size; j++) { - PyObject* v = PySequence_GetItem(o,j); - if (SwigNumber_Check(v)) { - temp[i][j] = (float)(SwigNumber_AsDouble(v)); - Py_DECREF(v); - }else { - Py_DECREF(v); - PyErr_SetString(PyExc_TypeError, "vector<vector<float>> expected"); - SWIG_fail; + if (PyTuple_Check($input) || PyList_Check($input)) { + unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); + temp.resize(size); + $1 = &temp; + for (unsigned int i=0; i<size; i++) { + PyObject* o = PySequence_GetItem($input,i); + if (PyTuple_Check(o) || PyList_Check(o)) { + unsigned int size = (PyTuple_Check(o) ? PyTuple_Size(o) : PyList_Size(o)); + temp[i].resize(size); + for (unsigned int j=0; j<size; j++) { + PyObject* v = PySequence_GetItem(o,j); + if (PyFloat_Check(v)) { + temp[i][j] = static_cast<float>(PyFloat_AsDouble(v)); + Py_DECREF(v); + } else if (PyInt_Check(v)) { + temp[i][j] = static_cast<float>(PyInt_AsLong(v)); + Py_DECREF(v); + } else if (PyLong_Check(v)) { + temp[i][j] = static_cast<float>(PyLong_AsLong(v)); + Py_DECREF(v); + } else { + Py_DECREF(v); + PyErr_SetString(PyExc_TypeError, "vector<vector<float>> expected"); + SWIG_fail; + } } + Py_DECREF(o); + } else { + Py_DECREF(o); + PyErr_SetString(PyExc_TypeError, "vector<vector<float>> expected"); + SWIG_fail; } - Py_DECREF(o); - } else { - Py_DECREF(o); - PyErr_SetString(PyExc_TypeError, "vector<vector<float>> expected"); - SWIG_fail; } - - } - } else { - PyErr_SetString(PyExc_TypeError,"vector<vector<float>> expected"); - SWIG_fail; - } + } else { + PyErr_SetString(PyExc_TypeError,"vector<vector<float>> expected"); + SWIG_fail; + } } NAMESPACE_SIMDATA Modified: trunk/CSP/SimData/Include/SimData/Random.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Random.h 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/SimData/Include/SimData/Random.h 2005-08-28 22:46:03 UTC (rev 1619) @@ -382,15 +382,21 @@ /////////////////////////////////////////////////////////////////////////////////// // Random Number Generator Wrappers + +/** Base class for storing the state of a random number generator. + */ +class RandomStateWrapper: public Referenced { +protected: + RandomStateWrapper() {} + virtual ~RandomStateWrapper() {} +}; + + /** Abstract interface for random number generators and random distributions. */ class SIMDATA_EXPORT RandomInterface { -protected: - /** Base class for storing the state of a random number generator. - */ - struct _State: Referenced { virtual ~_State() {} }; public: - typedef Ref<_State> State; + typedef Ref<RandomStateWrapper> State; typedef unsigned long int SeedType; virtual ~RandomInterface(); @@ -455,10 +461,13 @@ /** Random number generator state. */ - struct RNGState: _State { + class RNGState: public RandomStateWrapper { + public: typename RNG::State _state; }; + RNG _gen; + public: /** Reseed the random number generator. * @@ -656,7 +665,8 @@ class RandomDistribution: public RandomDistributionInterface { /** Random number generator state. */ - struct RDState: _State { + class RDState: public RandomStateWrapper { + public: typename RD::State _state; }; RD _dist; Modified: trunk/CSP/SimData/Include/SimData/Random.i =================================================================== --- trunk/CSP/SimData/Include/SimData/Random.i 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/SimData/Include/SimData/Random.i 2005-08-28 22:46:03 UTC (rev 1619) @@ -29,10 +29,11 @@ NAMESPACE_SIMDATA + class RandomInterface { protected: public: - typedef Ref<_State> State; + typedef simdata::Ref<simdata::RandomStateWrapper> State; typedef unsigned long int SeedType; virtual ~RandomInterface(); virtual void setSeed(SeedType seed)=0; @@ -55,21 +56,7 @@ virtual unsigned long uniformUInt(unsigned long upper)=0; }; -/** - * Random number generator wrapper, implementing the random number - * generator interface. These generics provide a uniform interface - * to the underlying generators and generator state data. The - * performance penalty relative to using the raw generators is - * typically about 20%. - */ -%ignore _State; -%ignore RNGState; -struct _State {}; //: Referenced { }; template <class RNG> -struct RNGState: _State { - typename RNG::State _state; -}; -template <class RNG> class RandomNumberGenerator: public RandomNumberGeneratorInterface { RNG _gen; public: Modified: trunk/CSP/tools/build.py =================================================================== --- trunk/CSP/tools/build.py 2005-08-28 22:40:29 UTC (rev 1618) +++ trunk/CSP/tools/build.py 2005-08-28 22:46:03 UTC (rev 1619) @@ -220,7 +220,7 @@ _checking(context, 'swig') swig_in, swig_out, swig_err = os.popen3('%s -version' % context.env.get('SWIG', 'swig'), 't') if swig_err is not None: - output = swig_err.readlines() + output = swig_err.readlines() + swig_out.readlines() output = " ".join(map(lambda x: x.strip(), output)) match = re.search(r'SWIG Version (\d+\.\d+.\d+)', output) if match is not None: |