comparison vampy-main.cpp @ 80:049de1137eab vampyhost

Patch from Simon Black for NumPy >1.9 compatibility
author Chris Cannam
date Tue, 15 Mar 2016 16:58:38 +0000
parents 6c755f3e1173
children
comparison
equal deleted inserted replaced
75:2a9fb03458d7 80:049de1137eab
28 28
29 // this is not part of the API, but we will require it for a bug workaround 29 // this is not part of the API, but we will require it for a bug workaround
30 // define this symbol if you use another version of numpy in the makefile 30 // define this symbol if you use another version of numpy in the makefile
31 // Vampy will not attempt to load a lower version than specified 31 // Vampy will not attempt to load a lower version than specified
32 #ifdef HAVE_NUMPY 32 #ifdef HAVE_NUMPY
33 #ifndef NUMPY_SHORTVERSION 33 #ifndef NUMPY_MAJORVERSION
34 #define NUMPY_SHORTVERSION 1.9 34 #define NUMPY_MAJORVERSION 1
35 #endif 35 #endif
36 #ifndef NUMPY_MINORVERSION
37 #define NUMPY_MINORVERSION 9
38 #endif
39
36 #endif 40 #endif
37 41
38 #include "vamp/vamp.h" 42 #include "vamp/vamp.h"
39 #include "vamp-sdk/PluginAdapter.h" 43 #include "vamp-sdk/PluginAdapter.h"
40 #include "PyPlugScanner.h" 44 #include "PyPlugScanner.h"
115 (below is a horrible workaround) 119 (below is a horrible workaround)
116 */ 120 */
117 121
118 #ifdef HAVE_NUMPY 122 #ifdef HAVE_NUMPY
119 123
120 string ver; 124 string ver, majorver, minorver;
121 std::istringstream verStream; 125 std::istringstream verStream;
122 float numpyVersion; 126 int numpyVersionMajor, numpyVersionMinor;
123 127
124 /// attmept to test numpy version before importing the array API 128 /// attmept to test numpy version before importing the array API
125 DSTREAM << "Numpy build information: ABI level: " << NPY_VERSION 129 DSTREAM << "Numpy build information: ABI level: " << NPY_VERSION
126 << " Numpy version: " << NUMPY_SHORTVERSION << endl; 130 << " Numpy version: " << NUMPY_MAJORVERSION << "." << NUMPY_MINORVERSION << endl;
127 131
128 PyObject *pyModule, *pyDict, *pyVer; 132 PyObject *pyModule, *pyDict, *pyVer;
129 133
130 pyModule = PyImport_ImportModule("numpy"); //numpy.core.multiarray 134 pyModule = PyImport_ImportModule("numpy"); //numpy.core.multiarray
131 if (!pyModule) { 135 if (!pyModule) {
148 goto numpyFailure; 152 goto numpyFailure;
149 } 153 }
150 154
151 ver = PyString_AsString(pyVer); 155 ver = PyString_AsString(pyVer);
152 ver = ver.substr(0,ver.rfind(".")); 156 ver = ver.substr(0,ver.rfind("."));
153 157 majorver = ver.substr(0,ver.rfind("."));
158 minorver = ver.substr(ver.rfind(".")+1);
159
154 // parse version string to float 160 // parse version string to float
155 verStream.str(ver); 161 verStream.str(majorver);
156 verStream >> numpyVersion; 162 verStream >> numpyVersionMajor;
157 163 verStream.str(minorver);
158 DSTREAM << "Numpy runtime version: " << numpyVersion << endl; 164 verStream >> numpyVersionMinor;
159 if (numpyVersion < (float) NUMPY_SHORTVERSION) { 165
160 cerr << "ERROR: Incompatible Numpy version found: " << numpyVersion << endl; 166 DSTREAM << "Numpy runtime version: " << numpyVersionMajor << "." << numpyVersionMinor << endl;
167
168 if(numpyVersionMajor < NUMPY_MAJORVERSION ||
169 (numpyVersionMajor < NUMPY_MAJORVERSION &&
170 numpyVersionMinor < NUMPY_MINORVERSION)) {
171 cerr << "ERROR: Incompatible Numpy version found: " << ver << endl;
161 goto numpyFailure; 172 goto numpyFailure;
162 } 173 }
163 174
164 Py_DECREF(pyModule); 175 Py_DECREF(pyModule);
165 176
178 return; 189 return;
179 } 190 }
180 191
181 192
182 numpyFailure: 193 numpyFailure:
183 cerr << "Please make sure you have Numpy " << NUMPY_SHORTVERSION << " or greater installed." << endl; 194 cerr << "Please make sure you have Numpy " << NUMPY_MAJORVERSION << "." << NUMPY_MINORVERSION << " or greater installed." << endl;
184 cerr << "Vampy: Numpy support disabled." << endl; 195 cerr << "Vampy: Numpy support disabled." << endl;
185 numpyInstalled = false; 196 numpyInstalled = false;
186 arrayApiInitialised = true; 197 arrayApiInitialised = true;
187 if (pyModule) Py_XDECREF(pyModule); 198 if (pyModule) Py_XDECREF(pyModule);
188 return; 199 return;