Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.35 KB | None | 0 0
  1. 00001 #include <Python.h>
  2. 00002 #include "theano_mod_helper.h"
  3. 00003 #include "structmember.h"
  4. 00004 #include <sys/time.h>
  5. 00005
  6. 00006 #if PY_VERSION_HEX >= 0x03000000
  7. 00007 #include "numpy/npy_3kcompat.h"
  8. 00008 #define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
  9. 00009 #define PyCObject_GetDesc NpyCapsule_GetDesc
  10. 00010 #define PyCObject_Check NpyCapsule_Check
  11. 00011 #endif
  12. 00012
  13. 00013 #ifndef Py_TYPE
  14. 00014 #define Py_TYPE(obj) obj->ob_type
  15. 00015 #endif
  16. 00016
  17. 00017 /**
  18. 00018
  19. 00019 TODO:
  20. 00020 - Check max supported depth of recursion
  21. 00021 - CLazyLinker should add context information to errors caught during evaluation. Say what node we were on, add the traceback attached to the node.
  22. 00022 - Clear containers of fully-useed intermediate results if allow_gc is 1
  23. 00023 - Add timers for profiling
  24. 00024 - Add support for profiling space used.
  25. 00025
  26. 00026
  27. 00027 */
  28. 00028 static double pytime(const struct timeval * tv)
  29. 00029 {
  30. 00030 struct timeval t;
  31. 00031 if (!tv)
  32. 00032 {
  33. 00033 tv = &t;
  34. 00034 gettimeofday(&t, NULL);
  35. 00035 }
  36. 00036 return (double) tv->tv_sec + (double) tv->tv_usec / 1000000.0;
  37. 00037 }
  38. 00038
  39. 00039 /**
  40. 00040 Helper routine to convert a PyList of integers to a c array of integers.
  41. 00041 */
  42. 00042 static int unpack_list_of_ssize_t(PyObject * pylist, Py_ssize_t **dst, Py_ssize_t *len,
  43. 00043 const char* kwname)
  44. 00044 {
  45. 00045 Py_ssize_t buflen, *buf;
  46. 00046 if (!PyList_Check(pylist))
  47. 00047 {
  48. 00048 PyErr_Format(PyExc_TypeError, "%s must be list", kwname);
  49. 00049 return -1;
  50. 00050 }
  51. 00051 assert (NULL == *dst);
  52. 00052 *len = buflen = PyList_Size(pylist);
  53. 00053 *dst = buf = (Py_ssize_t*)calloc(buflen, sizeof(Py_ssize_t));
  54. 00054 assert(buf);
  55. 00055 for (int ii = 0; ii < buflen; ++ii)
  56. 00056 {
  57. 00057 PyObject * el_i = PyList_GetItem(pylist, ii);
  58. 00058 Py_ssize_t n_i = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
  59. 00059 if (PyErr_Occurred())
  60. 00060 {
  61. 00061 free(buf);
  62. 00062 *dst = NULL;
  63. 00063 return -1;
  64. 00064 }
  65. 00065 buf[ii] = n_i;
  66. 00066 }
  67. 00067 return 0;
  68. 00068 }
  69. 00069
  70. 00070 /**
  71. 00071
  72. 00072 CLazyLinker
  73. 00073
  74. 00074
  75. 00075 */
  76. 00076 typedef struct {
  77. 00077 PyObject_HEAD
  78. 00078 /* Type-specific fields go here. */
  79. 00079 PyObject * nodes; // the python list of nodes
  80. 00080 PyObject * thunks; // python list of thunks
  81. 00081 PyObject * pre_call_clear; //list of cells to clear on call.
  82. 00082 int allow_gc;
  83. 00083 Py_ssize_t n_applies;
  84. 00084 int n_vars; // number of variables in the graph
  85. 00085 int * var_computed; // 1 or 0 for every variable
  86. 00086 PyObject ** var_computed_cells;
  87. 00087 PyObject ** var_value_cells;
  88. 00088 Py_ssize_t **dependencies; // list of vars dependencies for GC
  89. 00089 Py_ssize_t *n_dependencies;
  90. 00090
  91. 00091 Py_ssize_t n_output_vars;
  92. 00092 Py_ssize_t * output_vars; // variables that *must* be evaluated by call
  93. 00093
  94. 00094 int * is_lazy; // 1 or 0 for every thunk
  95. 00095
  96. 00096 Py_ssize_t * var_owner; // nodes[[var_owner[var_idx]]] is var[var_idx]->owner
  97. 00097 int * var_has_owner; // 1 or 0
  98. 00098
  99. 00099 Py_ssize_t * node_n_inputs;
  100. 00100 Py_ssize_t * node_n_outputs;
  101. 00101 Py_ssize_t ** node_inputs;
  102. 00102 Py_ssize_t ** node_outputs;
  103. 00103 Py_ssize_t * node_inputs_outputs_base; // node_inputs and node_outputs point into this
  104. 00104 Py_ssize_t * node_n_prereqs;
  105. 00105 Py_ssize_t ** node_prereqs;
  106. 00106
  107. 00107 Py_ssize_t * update_storage; // input cells to update with the last outputs in output_vars
  108. 00108 Py_ssize_t n_updates;
  109. 00109
  110. 00110 void ** thunk_cptr_fn;
  111. 00111 void ** thunk_cptr_data;
  112. 00112 PyObject * call_times;
  113. 00113 PyObject * call_counts;
  114. 00114 int do_timing;
  115. 00115 int need_update_inputs;
  116. 00116 int position_of_error; // -1 for no error, otw the index into `thunks` that failed.
  117. 00117 } CLazyLinker;
  118. 00118
  119. 00119
  120. 00120 static void
  121. 00121 CLazyLinker_dealloc(PyObject* _self)
  122. 00122 {
  123. 00123 CLazyLinker* self = (CLazyLinker *) _self;
  124. 00124 free(self->thunk_cptr_fn);
  125. 00125 free(self->thunk_cptr_data);
  126. 00126
  127. 00127 free(self->is_lazy);
  128. 00128
  129. 00129 free(self->update_storage);
  130. 00130
  131. 00131 if (self->node_n_prereqs)
  132. 00132 {
  133. 00133 for (int i = 0; i < self->n_applies; ++i)
  134. 00134 {
  135. 00135 free(self->node_prereqs[i]);
  136. 00136 }
  137. 00137 }
  138. 00138 free(self->node_n_prereqs);
  139. 00139 free(self->node_prereqs);
  140. 00140 free(self->node_inputs_outputs_base);
  141. 00141 free(self->node_n_inputs);
  142. 00142 free(self->node_n_outputs);
  143. 00143 free(self->node_inputs);
  144. 00144 free(self->node_outputs);
  145. 00145
  146. 00146 if (self->dependencies)
  147. 00147 {
  148. 00148 for (int i = 0; i < self->n_vars; ++i)
  149. 00149 {
  150. 00150 free(self->dependencies[i]);
  151. 00151 }
  152. 00152 free(self->dependencies);
  153. 00153 free(self->n_dependencies);
  154. 00154 }
  155. 00155
  156. 00156 free(self->var_owner);
  157. 00157 free(self->var_has_owner);
  158. 00158 free(self->var_computed);
  159. 00159 if (self->var_computed_cells)
  160. 00160 {
  161. 00161 for (int i = 0; i < self->n_vars; ++i)
  162. 00162 {
  163. 00163 Py_DECREF(self->var_computed_cells[i]);
  164. 00164 Py_DECREF(self->var_value_cells[i]);
  165. 00165 }
  166. 00166 }
  167. 00167 free(self->var_computed_cells);
  168. 00168 free(self->var_value_cells);
  169. 00169 free(self->output_vars);
  170. 00170
  171. 00171 Py_XDECREF(self->nodes);
  172. 00172 Py_XDECREF(self->thunks);
  173. 00173 Py_XDECREF(self->call_times);
  174. 00174 Py_XDECREF(self->call_counts);
  175. 00175 Py_XDECREF(self->pre_call_clear);
  176. 00176 Py_TYPE(self)->tp_free((PyObject*)self);
  177. 00177 }
  178. 00178 static PyObject *
  179. 00179 CLazyLinker_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  180. 00180 {
  181. 00181 CLazyLinker *self;
  182. 00182
  183. 00183 self = (CLazyLinker *)type->tp_alloc(type, 0);
  184. 00184 if (self != NULL) {
  185. 00185 self->nodes = NULL;
  186. 00186 self->thunks = NULL;
  187. 00187 self->pre_call_clear = NULL;
  188. 00188
  189. 00189 self->allow_gc = 1;
  190. 00190 self->n_applies = 0;
  191. 00191 self->n_vars = 0;
  192. 00192 self->var_computed = NULL;
  193. 00193 self->var_computed_cells = NULL;
  194. 00194 self->var_value_cells = NULL;
  195. 00195 self->dependencies = NULL;
  196. 00196 self->n_dependencies = NULL;
  197. 00197
  198. 00198 self->n_output_vars = 0;
  199. 00199 self->output_vars = NULL;
  200. 00200
  201. 00201 self->is_lazy = NULL;
  202. 00202
  203. 00203 self->var_owner = NULL;
  204. 00204 self->var_has_owner = NULL;
  205. 00205
  206. 00206 self->node_n_inputs = NULL;
  207. 00207 self->node_n_outputs = NULL;
  208. 00208 self->node_inputs = NULL;
  209. 00209 self->node_outputs = NULL;
  210. 00210 self->node_inputs_outputs_base = NULL;
  211. 00211 self->node_prereqs = NULL;
  212. 00212 self->node_n_prereqs = NULL;
  213. 00213
  214. 00214 self->update_storage = NULL;
  215. 00215 self->n_updates = 0;
  216. 00216
  217. 00217 self->thunk_cptr_data = NULL;
  218. 00218 self->thunk_cptr_fn = NULL;
  219. 00219 self->call_times = NULL;
  220. 00220 self->call_counts = NULL;
  221. 00221 self->do_timing = 0;
  222. 00222
  223. 00223 self->need_update_inputs = 0;
  224. 00224 self->position_of_error = -1;
  225. 00225 }
  226. 00226 return (PyObject *)self;
  227. 00227 }
  228. 00228
  229. 00229 static int
  230. 00230 CLazyLinker_init(CLazyLinker *self, PyObject *args, PyObject *kwds)
  231. 00231 {
  232. 00232 static char *kwlist[] = {
  233. 00233 (char*)"nodes",
  234. 00234 (char*)"thunks",
  235. 00235 (char*)"pre_call_clear",
  236. 00236 (char*)"allow_gc",
  237. 00237 (char*)"call_counts",
  238. 00238 (char*)"call_times",
  239. 00239 (char*)"compute_map_list",
  240. 00240 (char*)"storage_map_list",
  241. 00241 (char*)"base_input_output_list",
  242. 00242 (char*)"node_n_inputs",
  243. 00243 (char*)"node_n_outputs",
  244. 00244 (char*)"node_input_offset",
  245. 00245 (char*)"node_output_offset",
  246. 00246 (char*)"var_owner",
  247. 00247 (char*)"is_lazy_list",
  248. 00248 (char*)"output_vars",
  249. 00249 (char*)"node_prereqs",
  250. 00250 (char*)"node_output_size",
  251. 00251 (char*)"update_storage",
  252. 00252 (char*)"dependencies",
  253. 00253 NULL};
  254. 00254
  255. 00255 PyObject *compute_map_list=NULL,
  256. 00256 *storage_map_list=NULL,
  257. 00257 *base_input_output_list=NULL,
  258. 00258 *node_n_inputs=NULL,
  259. 00259 *node_n_outputs=NULL,
  260. 00260 *node_input_offset=NULL,
  261. 00261 *node_output_offset=NULL,
  262. 00262 *var_owner=NULL,
  263. 00263 *is_lazy=NULL,
  264. 00264 *output_vars=NULL,
  265. 00265 *node_prereqs=NULL,
  266. 00266 *node_output_size=NULL,
  267. 00267 *update_storage=NULL,
  268. 00268 *dependencies=NULL;
  269. 00269
  270. 00270 assert(!self->nodes);
  271. 00271 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOOiOOOOOOOOOOOOOOOO", kwlist,
  272. 00272 &self->nodes,
  273. 00273 &self->thunks,
  274. 00274 &self->pre_call_clear,
  275. 00275 &self->allow_gc,
  276. 00276 &self->call_counts,
  277. 00277 &self->call_times,
  278. 00278 &compute_map_list,
  279. 00279 &storage_map_list,
  280. 00280 &base_input_output_list,
  281. 00281 &node_n_inputs,
  282. 00282 &node_n_outputs,
  283. 00283 &node_input_offset,
  284. 00284 &node_output_offset,
  285. 00285 &var_owner,
  286. 00286 &is_lazy,
  287. 00287 &output_vars,
  288. 00288 &node_prereqs,
  289. 00289 &node_output_size,
  290. 00290 &update_storage,
  291. 00291 &dependencies
  292. 00292 ))
  293. 00293 return -1;
  294. 00294 Py_INCREF(self->nodes);
  295. 00295 Py_INCREF(self->thunks);
  296. 00296 Py_INCREF(self->pre_call_clear);
  297. 00297 Py_INCREF(self->call_counts);
  298. 00298 Py_INCREF(self->call_times);
  299. 00299
  300. 00300 Py_ssize_t n_applies = PyList_Size(self->nodes);
  301. 00301
  302. 00302 self->n_applies = n_applies;
  303. 00303 self->n_vars = PyList_Size(var_owner);
  304. 00304
  305. 00305 if (PyList_Size(self->thunks) != n_applies) return -1;
  306. 00306 if (PyList_Size(self->call_counts) != n_applies) return -1;
  307. 00307 if (PyList_Size(self->call_times) != n_applies) return -1;
  308. 00308
  309. 00309 // allocated and initialize thunk_cptr_data and thunk_cptr_fn
  310. 00310 if (n_applies)
  311. 00311 {
  312. 00312 self->thunk_cptr_data = (void**)calloc(n_applies, sizeof(void*));
  313. 00313 self->thunk_cptr_fn = (void**)calloc(n_applies, sizeof(void*));
  314. 00314 self->is_lazy = (int*)calloc(n_applies, sizeof(int));
  315. 00315 self->node_prereqs = (Py_ssize_t**)calloc(n_applies, sizeof(Py_ssize_t*));
  316. 00316 self->node_n_prereqs = (Py_ssize_t*)calloc(n_applies, sizeof(Py_ssize_t));
  317. 00317 assert(self->node_prereqs);
  318. 00318 assert(self->node_n_prereqs);
  319. 00319 assert(self->is_lazy);
  320. 00320 assert(self->thunk_cptr_fn);
  321. 00321 assert(self->thunk_cptr_data);
  322. 00322
  323. 00323 for (int i = 0; i < n_applies; ++i)
  324. 00324 {
  325. 00325 PyObject * thunk = PyList_GetItem(self->thunks, i);
  326. 00326 //thunk is borrowed
  327. 00327 if (PyObject_HasAttrString(thunk, "cthunk"))
  328. 00328 {
  329. 00329 PyObject * cthunk = PyObject_GetAttrString(thunk, "cthunk");
  330. 00330 //new reference
  331. 00331 assert (cthunk && PyCObject_Check(cthunk));
  332. 00332 self->thunk_cptr_fn[i] = PyCObject_AsVoidPtr(cthunk);
  333. 00333 self->thunk_cptr_data[i] = PyCObject_GetDesc(cthunk);
  334. 00334 Py_DECREF(cthunk);
  335. 00335 // cthunk is kept alive by membership in self->thunks
  336. 00336 }
  337. 00337
  338. 00338 PyObject * el_i = PyList_GetItem(is_lazy, i);
  339. 00339 self->is_lazy[i] = PyNumber_AsSsize_t(el_i, NULL);
  340. 00340
  341. 00341 /* now get the prereqs */
  342. 00342 el_i = PyList_GetItem(node_prereqs, i);
  343. 00343 assert (PyList_Check(el_i));
  344. 00344 self->node_n_prereqs[i] = PyList_Size(el_i);
  345. 00345 if (self->node_n_prereqs[i])
  346. 00346 {
  347. 00347 self->node_prereqs[i] = (Py_ssize_t*)malloc(
  348. 00348 PyList_Size(el_i)*sizeof(Py_ssize_t));
  349. 00349 for (int j = 0; j < PyList_Size(el_i); ++j)
  350. 00350 {
  351. 00351 PyObject * el_ij = PyList_GetItem(el_i, j);
  352. 00352 Py_ssize_t N = PyNumber_AsSsize_t(el_ij, PyExc_IndexError);
  353. 00353 if (PyErr_Occurred())
  354. 00354 return -1;
  355. 00355 // N < n. variables
  356. 00356 assert(N < PyList_Size(var_owner));
  357. 00357 self->node_prereqs[i][j] = N;
  358. 00358 }
  359. 00359 }
  360. 00360 }
  361. 00361 }
  362. 00362 if (PyList_Check(base_input_output_list))
  363. 00363 {
  364. 00364 Py_ssize_t n_inputs_outputs_base = PyList_Size(base_input_output_list);
  365. 00365 self->node_inputs_outputs_base = (Py_ssize_t*)calloc(n_inputs_outputs_base,sizeof(Py_ssize_t));
  366. 00366 assert(self->node_inputs_outputs_base);
  367. 00367 for (int i = 0; i < n_inputs_outputs_base; ++i)
  368. 00368 {
  369. 00369 PyObject *el_i = PyList_GetItem(base_input_output_list, i);
  370. 00370 Py_ssize_t idx = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
  371. 00371 if (PyErr_Occurred()) return -1;
  372. 00372 self->node_inputs_outputs_base[i] = idx;
  373. 00373 }
  374. 00374 self->node_n_inputs = (Py_ssize_t*)calloc(n_applies,sizeof(Py_ssize_t));
  375. 00375 assert(self->node_n_inputs);
  376. 00376 self->node_n_outputs = (Py_ssize_t*)calloc(n_applies,sizeof(Py_ssize_t));
  377. 00377 assert(self->node_n_outputs);
  378. 00378 self->node_inputs = (Py_ssize_t**)calloc(n_applies,sizeof(Py_ssize_t*));
  379. 00379 assert(self->node_inputs);
  380. 00380 self->node_outputs = (Py_ssize_t**)calloc(n_applies,sizeof(Py_ssize_t*));
  381. 00381 assert(self->node_outputs);
  382. 00382 for (int i = 0; i < n_applies; ++i)
  383. 00383 {
  384. 00384 Py_ssize_t N;
  385. 00385 N = PyNumber_AsSsize_t(PyList_GetItem(node_n_inputs, i),PyExc_IndexError);
  386. 00386 if (PyErr_Occurred()) return -1;
  387. 00387 assert (N <= n_inputs_outputs_base);
  388. 00388 self->node_n_inputs[i] = N;
  389. 00389 N = PyNumber_AsSsize_t(PyList_GetItem(node_n_outputs, i),PyExc_IndexError);
  390. 00390 if (PyErr_Occurred()) return -1;
  391. 00391 assert (N <= n_inputs_outputs_base);
  392. 00392 self->node_n_outputs[i] = N;
  393. 00393 N = PyNumber_AsSsize_t(PyList_GetItem(node_input_offset, i),PyExc_IndexError);
  394. 00394 if (PyErr_Occurred()) return -1;
  395. 00395 assert (N <= n_inputs_outputs_base);
  396. 00396 self->node_inputs[i] = &self->node_inputs_outputs_base[N];
  397. 00397 N = PyNumber_AsSsize_t(PyList_GetItem(node_output_offset, i),PyExc_IndexError);
  398. 00398 if (PyErr_Occurred()) return -1;
  399. 00399 assert (N <= n_inputs_outputs_base);
  400. 00400 self->node_outputs[i] = &self->node_inputs_outputs_base[N];
  401. 00401 }
  402. 00402 }
  403. 00403 else
  404. 00404 {
  405. 00405 PyErr_SetString(PyExc_TypeError, "base_input_output_list must be list");
  406. 00406 return -1;
  407. 00407 }
  408. 00408
  409. 00409 // allocation for var_owner
  410. 00410 if (PyList_Check(var_owner))
  411. 00411 {
  412. 00412 self->var_owner = (Py_ssize_t*)calloc(self->n_vars,sizeof(Py_ssize_t));
  413. 00413 self->var_has_owner = (int*)calloc(self->n_vars,sizeof(int));
  414. 00414 self->var_computed = (int*)calloc(self->n_vars,sizeof(int));
  415. 00415 self->var_computed_cells = (PyObject**)calloc(self->n_vars,sizeof(PyObject*));
  416. 00416 self->var_value_cells = (PyObject**)calloc(self->n_vars,sizeof(PyObject*));
  417. 00417 for (int i = 0; i < self->n_vars; ++i)
  418. 00418 {
  419. 00419 PyObject * el_i = PyList_GetItem(var_owner, i);
  420. 00420 if (el_i == Py_None)
  421. 00421 {
  422. 00422 self->var_has_owner[i] = 0;
  423. 00423 }
  424. 00424 else
  425. 00425 {
  426. 00426 Py_ssize_t N = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
  427. 00427 if (PyErr_Occurred()) return -1;
  428. 00428 assert (N <= n_applies);
  429. 00429 self->var_owner[i] = N;
  430. 00430 self->var_has_owner[i] = 1;
  431. 00431 }
  432. 00432 self->var_computed_cells[i] = PyList_GetItem(compute_map_list, i);
  433. 00433 Py_INCREF(self->var_computed_cells[i]);
  434. 00434 self->var_value_cells[i] = PyList_GetItem(storage_map_list, i);
  435. 00435 Py_INCREF(self->var_value_cells[i]);
  436. 00436 }
  437. 00437 }
  438. 00438 else
  439. 00439 {
  440. 00440 PyErr_SetString(PyExc_TypeError, "var_owner must be list");
  441. 00441 return -1;
  442. 00442 }
  443. 00443
  444. 00444 if (dependencies != Py_None)
  445. 00445 {
  446. 00446 self->dependencies = (Py_ssize_t**)calloc(self->n_vars, sizeof(Py_ssize_t *));
  447. 00447 self->n_dependencies = (Py_ssize_t*)calloc(self->n_vars, sizeof(Py_ssize_t));
  448. 00448 assert(self->dependencies);
  449. 00449 assert(self->n_dependencies);
  450. 00450
  451. 00451 for (int i = 0; i < self->n_vars; ++i)
  452. 00452 {
  453. 00453 PyObject *tmp = PyList_GetItem(dependencies, i);
  454. 00454 // refcounting - tmp is borrowed
  455. 00455 if (unpack_list_of_ssize_t(tmp, &self->dependencies[i], &self->n_dependencies[i],
  456. 00456 "dependencies"))
  457. 00457 return -1;
  458. 00458 }
  459. 00459 }
  460. 00460
  461. 00461 if (unpack_list_of_ssize_t(output_vars, &self->output_vars, &self->n_output_vars,
  462. 00462 "output_vars"))
  463. 00463 return -1;
  464. 00464 for (int i = 0; i < self->n_output_vars; ++i)
  465. 00465 {
  466. 00466 assert(self->output_vars[i] < self->n_vars);
  467. 00467 }
  468. 00468 if (unpack_list_of_ssize_t(update_storage, &self->update_storage, &self->n_updates,
  469. 00469 "updates_storage"))
  470. 00470 return -1;
  471. 00471 return 0;
  472. 00472 }
  473. 00473 static void set_position_of_error(CLazyLinker * self, int owner_idx)
  474. 00474 {
  475. 00475 if (self->position_of_error == -1)
  476. 00476 {
  477. 00477 self->position_of_error = owner_idx;
  478. 00478 }
  479. 00479 }
  480. 00480 static PyObject * pycall(CLazyLinker * self, Py_ssize_t node_idx, int verbose)
  481. 00481 {
  482. 00482 // call thunk to see which inputs it wants
  483. 00483 PyObject * thunk = PyList_GetItem(self->thunks, node_idx);
  484. 00484 // refcounting - thunk is borrowed
  485. 00485 PyObject * rval = NULL;
  486. 00486 if (self->do_timing)
  487. 00487 {
  488. 00488 double t0 = pytime(NULL);
  489. 00489 if (verbose) fprintf(stderr, "calling via Python (node %i)\n", (int)node_idx);
  490. 00490 rval = PyObject_CallObject(thunk, NULL);
  491. 00491 if (rval)
  492. 00492 {
  493. 00493 double t1 = pytime(NULL);
  494. 00494 double ti = PyFloat_AsDouble(
  495. 00495 PyList_GetItem(self->call_times, node_idx));
  496. 00496 PyList_SetItem(self->call_times, node_idx,
  497. 00497 PyFloat_FromDouble(t1 - t0 + ti));
  498. 00498 PyObject * count = PyList_GetItem(self->call_counts, node_idx);
  499. 00499 long icount = PyInt_AsLong(count);
  500. 00500 PyList_SetItem(self->call_counts, node_idx,
  501. 00501 PyInt_FromLong(icount + 1));
  502. 00502 }
  503. 00503 }
  504. 00504 else
  505. 00505 {
  506. 00506 if (verbose)
  507. 00507 {
  508. 00508 fprintf(stderr, "calling via Python (node %i)\n", (int)node_idx);
  509. 00509 }
  510. 00510 rval = PyObject_CallObject(thunk, NULL);
  511. 00511 }
  512. 00512 return rval;
  513. 00513 }
  514. 00514 static int c_call(CLazyLinker * self, Py_ssize_t node_idx, int verbose)
  515. 00515 {
  516. 00516 void * ptr_addr = self->thunk_cptr_fn[node_idx];
  517. 00517 int (*fn)(void*) = (int (*)(void*))(ptr_addr);
  518. 00518 if (verbose) fprintf(stderr, "calling non-lazy shortcut (node %i)\n", (int)node_idx);
  519. 00519 int err = 0;
  520. 00520 if (self->do_timing)
  521. 00521 {
  522. 00522 double t0 = pytime(NULL);
  523. 00523 err = fn(self->thunk_cptr_data[node_idx]);
  524. 00524 double t1 = pytime(NULL);
  525. 00525 double ti = PyFloat_AsDouble(PyList_GetItem(self->call_times, node_idx));
  526. 00526 PyList_SetItem(self->call_times, node_idx, PyFloat_FromDouble(t1 - t0 + ti));
  527. 00527 PyObject * count = PyList_GetItem(self->call_counts, node_idx);
  528. 00528 long icount = PyInt_AsLong(count);
  529. 00529 PyList_SetItem(self->call_counts, node_idx, PyInt_FromLong(icount+1));
  530. 00530 }
  531. 00531 else
  532. 00532 {
  533. 00533 err = fn(self->thunk_cptr_data[node_idx]);
  534. 00534 }
  535. 00535
  536. 00536 if (err)
  537. 00537 {
  538. 00538 // cast the argument to a PyList (as described near line 226 of cc.py)
  539. 00539 PyObject * __ERROR = ((PyObject**)self->thunk_cptr_data[node_idx])[0];
  540. 00540 assert (PyList_Check(__ERROR));
  541. 00541 assert (PyList_Size(__ERROR) == 3);
  542. 00542 PyObject * err_type = PyList_GetItem(__ERROR, 0); //stolen ref
  543. 00543 PyObject * err_msg = PyList_GetItem(__ERROR, 1); //stolen ref
  544. 00544 PyObject * err_trace = PyList_GetItem(__ERROR, 2); //stolen ref
  545. 00545 PyList_SET_ITEM(__ERROR, 0, Py_None); Py_INCREF(Py_None); //clobbers old ref
  546. 00546 PyList_SET_ITEM(__ERROR, 1, Py_None); Py_INCREF(Py_None); //clobbers old ref
  547. 00547 PyList_SET_ITEM(__ERROR, 2, Py_None); Py_INCREF(Py_None); //clobbers old ref
  548. 00548
  549. 00549 assert(!PyErr_Occurred()); // because CLinker hid the exception in __ERROR aka data
  550. 00550 PyErr_Restore(err_type, err_msg, err_trace); //steals refs to args
  551. 00551 }
  552. 00552 if (err) set_position_of_error(self, node_idx);
  553. 00553 return err;
  554. 00554 }
  555. 00555 static
  556. 00556 int lazy_rec_eval(CLazyLinker * self, Py_ssize_t var_idx, PyObject*one, PyObject*zero)
  557. 00557 {
  558. 00558 PyObject *rval = NULL;
  559. 00559 int verbose = 0;
  560. 00560 int err = 0;
  561. 00561
  562. 00562 if (verbose) fprintf(stderr, "lazy_rec computing %i\n", (int)var_idx);
  563. 00563
  564. 00564 if (self->var_computed[var_idx] || !self->var_has_owner[var_idx])
  565. 00565 return 0;
  566. 00566
  567. 00567 Py_ssize_t owner_idx = self->var_owner[var_idx];
  568. 00568
  569. 00569 // STEP 1: compute the pre-requirements of the node
  570. 00570 // Includes input nodes for non-lazy ops.
  571. 00571 for (int i = 0; i < self->node_n_prereqs[owner_idx]; ++i)
  572. 00572 {
  573. 00573 Py_ssize_t prereq_idx = self->node_prereqs[owner_idx][i];
  574. 00574 if (!self->var_computed[prereq_idx])
  575. 00575 {
  576. 00576 err = lazy_rec_eval(self, prereq_idx, one, zero);
  577. 00577 if (err) return err;
  578. 00578 }
  579. 00579 assert (self->var_computed[prereq_idx]);
  580. 00580 }
  581. 00581
  582. 00582 // STEP 2: compute the node itself
  583. 00583 if (self->is_lazy[owner_idx])
  584. 00584 {
  585. 00585 // update the compute_map cells corresponding to the inputs of this thunk
  586. 00586 for (int i = 0; i < self->node_n_inputs[owner_idx]; ++i)
  587. 00587 {
  588. 00588 int in_idx = self->node_inputs[owner_idx][i];
  589. 00589 if (self->var_computed[in_idx])
  590. 00590 {
  591. 00591 Py_INCREF(one);
  592. 00592 err = PyList_SetItem(self->var_computed_cells[in_idx], 0, one);
  593. 00593 }
  594. 00594 else
  595. 00595 {
  596. 00596 Py_INCREF(zero);
  597. 00597 err = PyList_SetItem(self->var_computed_cells[in_idx], 0, zero);
  598. 00598 }
  599. 00599 if (err) goto fail;
  600. 00600 }
  601. 00601
  602. 00602 rval = pycall(self, owner_idx, verbose);
  603. 00603 // refcounting - rval is new ref
  604. 00604 //TODO: to prevent infinite loops
  605. 00605 // - consider check that a thunk does not ask for an input that is already computed
  606. 00606 if (rval == NULL)
  607. 00607 {
  608. 00608 assert (PyErr_Occurred());
  609. 00609 err = 1;
  610. 00610 goto fail;
  611. 00611 }
  612. 00612
  613. 00613 //update the computed-ness of any output cells
  614. 00614 for (int i = 0; i < self->node_n_outputs[owner_idx]; ++i)
  615. 00615 {
  616. 00616 int out_idx = self->node_outputs[owner_idx][i];
  617. 00617 PyObject * el_i = PyList_GetItem(self->var_computed_cells[out_idx], 0);
  618. 00618 Py_ssize_t N = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
  619. 00619 if (PyErr_Occurred())
  620. 00620 {
  621. 00621 err = -1;
  622. 00622 goto pyfail;
  623. 00623 }
  624. 00624 assert (N==0 || N==1);
  625. 00625 self->var_computed[out_idx] = N;
  626. 00626 }
  627. 00627 if (!self->var_computed[var_idx])
  628. 00628 {
  629. 00629 /*
  630. 00630 * If self is not computed after the call, this means that some
  631. 00631 * inputs are needed. Compute the ones on the returned list
  632. 00632 * and try to compute the current node again (with recursive call).
  633. 00633 * This allows a node to request more nodes more than once before
  634. 00634 * finally yielding a result.
  635. 00635 */
  636. 00636 if (!PyList_Check(rval))
  637. 00637 {
  638. 00638 //TODO: More helpful error to help find *which node* made this
  639. 00639 // bad thunk
  640. 00640 PyErr_SetString(PyExc_TypeError,
  641. 00641 "lazy thunk should return a list");
  642. 00642 err = 1;
  643. 00643 goto pyfail;
  644. 00644 }
  645. 00645
  646. 00646 if (!PyList_Size(rval))
  647. 00647 {
  648. 00648 PyErr_SetString(PyExc_ValueError,
  649. 00649 "lazy thunk returned empty list without computing output");
  650. 00650 err = 1;
  651. 00651 goto pyfail;
  652. 00652 }
  653. 00653
  654. 00654 for (int i = 0; i < PyList_Size(rval); ++i)
  655. 00655 {
  656. 00656 PyObject * el_i = PyList_GetItem(rval, i);
  657. 00657 Py_ssize_t N = PyNumber_AsSsize_t(el_i, PyExc_IndexError);
  658. 00658 if (PyErr_Occurred())
  659. 00659 {
  660. 00660 err = 1;
  661. 00661 goto pyfail;
  662. 00662 }
  663. 00663 assert (N <= self->node_n_inputs[owner_idx]);
  664. 00664 Py_ssize_t input_idx = self->node_inputs[owner_idx][N];
  665. 00665 err = lazy_rec_eval(self, input_idx, one, zero);
  666. 00666 if (err) goto pyfail;
  667. 00667 }
  668. 00668
  669. 00669 Py_DECREF(rval);
  670. 00670 /*
  671. 00671 * We intentionally skip all the end-of-function processing
  672. 00672 * (mark outputs, GC) as it will be performed by the call
  673. 00673 * that actually manages to compute the result.
  674. 00674 */
  675. 00675 return lazy_rec_eval(self, var_idx, one, zero);
  676. 00676 }
  677. 00677
  678. 00678 Py_DECREF(rval);
  679. 00679 }
  680. 00680 else //owner is not a lazy op. Ensure all intputs are evaluated.
  681. 00681 {
  682. 00682 // loop over inputs to owner
  683. 00683 // call lazy_rec_eval on each one that is not computed.
  684. 00684 // if there's an error, pass it up the stack
  685. 00685 for (int i = 0; i < self->node_n_inputs[owner_idx]; ++i)
  686. 00686 {
  687. 00687 Py_ssize_t input_idx = self->node_inputs[owner_idx][i];
  688. 00688 if (!self->var_computed[input_idx])
  689. 00689 {
  690. 00690 err = lazy_rec_eval(self, input_idx, one, zero);
  691. 00691 if (err) return err;
  692. 00692 }
  693. 00693 assert (self->var_computed[input_idx]);
  694. 00694 }
  695. 00695
  696. 00696 // call the thunk for this owner.
  697. 00697 if (self->thunk_cptr_fn[owner_idx])
  698. 00698 {
  699. 00699 err = c_call(self, owner_idx, verbose);
  700. 00700 if (err) goto fail;
  701. 00701 }
  702. 00702 else
  703. 00703 {
  704. 00704 rval = pycall(self, owner_idx, verbose);
  705. 00705 //rval is new ref
  706. 00706 if (rval) //pycall returned normally (no exception)
  707. 00707 {
  708. 00708 if (rval == Py_None)
  709. 00709 {
  710. 00710 Py_DECREF(rval); //ignore a return of None
  711. 00711 }
  712. 00712 else if (PyList_Check(rval))
  713. 00713 {
  714. 00714 PyErr_SetString(PyExc_TypeError,
  715. 00715 "non-lazy thunk should return None, not list");
  716. 00716 err = 1;
  717. 00717 goto pyfail;
  718. 00718 }
  719. 00719 else // don't know what it returned, but it wasn't right.
  720. 00720 {
  721. 00721 PyErr_SetObject(PyExc_TypeError, rval);
  722. 00722 err = 1;
  723. 00723 // We don't release rval since we put it in the error above
  724. 00724 goto fail;
  725. 00725 }
  726. 00726 }
  727. 00727 else // pycall returned NULL (internal error)
  728. 00728 {
  729. 00729 err = 1;
  730. 00730 goto fail;
  731. 00731 }
  732. 00732 }
  733. 00733 }
  734. 00734
  735. 00735 // loop over all outputs and mark them as computed
  736. 00736 for (int i = 0; i < self->node_n_outputs[owner_idx]; ++i)
  737. 00737 {
  738. 00738 self->var_computed[self->node_outputs[owner_idx][i]] = 1;
  739. 00739 }
  740. 00740
  741. 00741 // Free vars that are not needed anymore
  742. 00742 if (self->allow_gc)
  743. 00743 {
  744. 00744 for (int i = 0; i < self->node_n_inputs[owner_idx]; ++i)
  745. 00745 {
  746. 00746 int cleanup = 1;
  747. 00747 Py_ssize_t i_idx = self->node_inputs[owner_idx][i];
  748. 00748 if (!self->var_has_owner[i_idx])
  749. 00749 continue;
  750. 00750
  751. 00751 for (int j = 0; j < self->n_output_vars; ++j)
  752. 00752 {
  753. 00753 if (i_idx == self->output_vars[j])
  754. 00754 {
  755. 00755 cleanup = 0;
  756. 00756 break;
  757. 00757 }
  758. 00758 }
  759. 00759 if (!cleanup) continue;
  760. 00760
  761. 00761 for (int j = 0; j < self->n_dependencies[i_idx]; ++j)
  762. 00762 {
  763. 00763 if (!self->var_computed[self->dependencies[i_idx][j]])
  764. 00764 {
  765. 00765 cleanup = 0;
  766. 00766 break;
  767. 00767 }
  768. 00768 }
  769. 00769 if (!cleanup) continue;
  770. 00770
  771. 00771 Py_INCREF(Py_None);
  772. 00772 err = PyList_SetItem(self->var_value_cells[i_idx], 0, Py_None);
  773. 00773 //See the Stack gc implementation for why we change it to 2 and not 0.
  774. 00774 self->var_computed[i_idx] = 2;
  775. 00775 if (err) goto fail;
  776. 00776 }
  777. 00777 }
  778. 00778
  779. 00779 return 0;
  780. 00780 pyfail:
  781. 00781 Py_DECREF(rval);
  782. 00782 fail:
  783. 00783 set_position_of_error(self, owner_idx);
  784. 00784 return err;
  785. 00785 }
  786. 00786
  787. 00787 static PyObject *
  788. 00788 CLazyLinker_call(PyObject *_self, PyObject *args, PyObject *kwds)
  789. 00789 {
  790. 00790 CLazyLinker * self = (CLazyLinker*)_self;
  791. 00791 static char *kwlist[] = {
  792. 00792 (char *)"time_thunks",
  793. 00793 (char *)"n_calls",
  794. 00794 (char *)"output_subset",
  795. 00795 NULL};
  796. 00796 int n_calls=1;
  797. 00797 PyObject *output_subset_ptr = NULL;
  798. 00798 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiO", kwlist,
  799. 00799 &self->do_timing,
  800. 00800 &n_calls,
  801. 00801 &output_subset_ptr))
  802. 00802 return NULL;
  803. 00803
  804. 00804 int err = 0;
  805. 00805 // parse an output_subset list
  806. 00806 // it is stored as a bool list of length n_output_vars: calculate a var or not
  807. 00807 char *output_subset = NULL;
  808. 00808 int output_subset_size = -1;
  809. 00809 if (output_subset_ptr != NULL)
  810. 00810 {
  811. 00811 if (! PyList_Check(output_subset_ptr))
  812. 00812 {
  813. 00813 err = 1;
  814. 00814 PyErr_SetString(PyExc_RuntimeError, "Output_subset is not a list");
  815. 00815 }
  816. 00816 else
  817. 00817 {
  818. 00818 output_subset_size = PyList_Size(output_subset_ptr);
  819. 00819 output_subset = (char*)calloc(self->n_output_vars, sizeof(char));
  820. 00820 for (int it = 0; it < output_subset_size; ++it)
  821. 00821 {
  822. 00822 PyObject *elem = PyList_GetItem(output_subset_ptr, it);
  823. 00823 if (! PyInt_Check(elem))
  824. 00824 {
  825. 00825 err = 1;
  826. 00826 PyErr_SetString(PyExc_RuntimeError, "Some elements of output_subset list are not int");
  827. 00827 }
  828. 00828 output_subset[PyInt_AsLong(elem)] = 1;
  829. 00829 }
  830. 00830 }
  831. 00831 }
  832. 00832
  833. 00833 self->position_of_error = -1;
  834. 00834 // create constants used to fill the var_compute_cells
  835. 00835 PyObject * one = PyInt_FromLong(1);
  836. 00836 PyObject * zero = PyInt_FromLong(0);
  837. 00837
  838. 00838 // pre-allocate our return value
  839. 00839 Py_INCREF(Py_None);
  840. 00840 PyObject * rval = Py_None;
  841. 00841 //clear storage of pre_call_clear elements
  842. 00842 for (int call_i = 0; call_i < n_calls && (!err); ++call_i)
  843. 00843 {
  844. 00844 Py_ssize_t n_pre_call_clear = PyList_Size(self->pre_call_clear);
  845. 00845 assert(PyList_Check(self->pre_call_clear));
  846. 00846 for (int i = 0; i < n_pre_call_clear; ++i)
  847. 00847 {
  848. 00848 PyObject * el_i = PyList_GetItem(self->pre_call_clear, i);
  849. 00849 Py_INCREF(Py_None);
  850. 00850 PyList_SetItem(el_i, 0, Py_None);
  851. 00851 }
  852. 00852 //clear the computed flag out of all non-input vars
  853. 00853 for (int i = 0; i < self->n_vars; ++i)
  854. 00854 {
  855. 00855 self->var_computed[i] = !self->var_has_owner[i];
  856. 00856 if (self->var_computed[i])
  857. 00857 {
  858. 00858 Py_INCREF(one);
  859. 00859 PyList_SetItem(self->var_computed_cells[i], 0, one);
  860. 00860 }
  861. 00861 else
  862. 00862 {
  863. 00863 Py_INCREF(zero);
  864. 00864 PyList_SetItem(self->var_computed_cells[i], 0, zero);
  865. 00865 }
  866. 00866 }
  867. 00867
  868. 00868 int first_updated = self->n_output_vars - self->n_updates;
  869. 00869 for (int i = 0; i < self->n_output_vars && (!err); ++i)
  870. 00870 {
  871. 00871 if (i >= first_updated || output_subset == NULL || output_subset[i] == 1)
  872. 00872 {
  873. 00873 err = lazy_rec_eval(self, self->output_vars[i], one, zero);
  874. 00874 }
  875. 00875 }
  876. 00876
  877. 00877 if (!err)
  878. 00878 {
  879. 00879 // save references to outputs prior to updating storage containers
  880. 00880 assert (self->n_output_vars >= self->n_updates);
  881. 00881 Py_DECREF(rval);
  882. 00882 rval = PyList_New(self->n_output_vars);
  883. 00883 for (int i = 0; i < (self->n_output_vars); ++i)
  884. 00884 {
  885. 00885 Py_ssize_t src = self->output_vars[i];
  886. 00886 PyObject * item = PyList_GetItem(self->var_value_cells[src], 0);
  887. 00887 if ((output_subset == NULL || output_subset[i]) &&
  888. 00888 self->var_computed[src] != 1)
  889. 00889 {
  890. 00890 err = 1;
  891. 00891 PyErr_Format(PyExc_AssertionError,
  892. 00892 "The compute map of output %d should contain "
  893. 00893 "1 at the end of execution, not %d.",
  894. 00894 i, self->var_computed[src]);
  895. 00895 break;
  896. 00896 }
  897. 00897 Py_INCREF(item);
  898. 00898 PyList_SetItem(rval, i, item);
  899. 00899 }
  900. 00900 }
  901. 00901
  902. 00902 if (!err)
  903. 00903 {
  904. 00904 // Update the inputs that have an update rule
  905. 00905 for (int i = 0; i < self->n_updates; ++i)
  906. 00906 {
  907. 00907 PyObject* tmp = PyList_GetItem(rval, self->n_output_vars - self->n_updates + i);
  908. 00908 Py_INCREF(tmp);
  909. 00909 Py_ssize_t dst = self->update_storage[i];
  910. 00910 PyList_SetItem(self->var_value_cells[dst], 0, tmp);
  911. 00911 }
  912. 00912 }
  913. 00913 }
  914. 00914
  915. 00915 /*
  916. 00916 Clear everything that is left and not an output. This is needed
  917. 00917 for lazy evaluation since the current GC algo is too conservative
  918. 00918 with lazy graphs.
  919. 00919 */
  920. 00920 if (self->allow_gc && !err)
  921. 00921 {
  922. 00922 for (Py_ssize_t i = 0; i < self->n_vars; ++i)
  923. 00923 {
  924. 00924 int do_cleanup = 1;
  925. 00925 if (!self->var_has_owner[i] || !self->var_computed[i])
  926. 00926 continue;
  927. 00927 for (int j = 0; j < self->n_output_vars; ++j)
  928. 00928 {
  929. 00929 if (i == self->output_vars[j])
  930. 00930 {
  931. 00931 do_cleanup = 0;
  932. 00932 break;
  933. 00933 }
  934. 00934 }
  935. 00935 if (!do_cleanup)
  936. 00936 continue;
  937. 00937 Py_INCREF(Py_None);
  938. 00938 PyList_SetItem(self->var_value_cells[i], 0, Py_None);
  939. 00939 }
  940. 00940 }
  941. 00941 if (output_subset != NULL)
  942. 00942 free(output_subset);
  943. 00943
  944. 00944 Py_DECREF(one);
  945. 00945 Py_DECREF(zero);
  946. 00946 if (err)
  947. 00947 {
  948. 00948 Py_DECREF(rval);
  949. 00949 return NULL;
  950. 00950 }
  951. 00951 return rval;
  952. 00952 }
  953. 00953
  954. 00954 #if 0
  955. 00955 static PyMethodDef CLazyLinker_methods[] = {
  956. 00956 {
  957. 00957 //"name", (PyCFunction)CLazyLinker_accept, METH_VARARGS, "Return the name, combining the first and last name"
  958. 00958 },
  959. 00959 {NULL} /* Sentinel */
  960. 00960 };
  961. 00961 #endif
  962. 00962
  963. 00963
  964. 00964 static PyObject *
  965. 00965 CLazyLinker_get_allow_gc(CLazyLinker *self, void *closure)
  966. 00966 {
  967. 00967 return PyBool_FromLong(self->allow_gc);
  968. 00968 }
  969. 00969
  970. 00970 static int
  971. 00971 CLazyLinker_set_allow_gc(CLazyLinker *self, PyObject *value, void *closure)
  972. 00972 {
  973. 00973 if(!PyBool_Check(value))
  974. 00974 return -1;
  975. 00975
  976. 00976 if (value == Py_True)
  977. 00977 self->allow_gc = true;
  978. 00978 else
  979. 00979 self->allow_gc = false;
  980. 00980 return 0;
  981. 00981 }
  982. 00982
  983. 00983 static PyGetSetDef CLazyLinker_getset[] = {
  984. 00984 {(char*)"allow_gc",
  985. 00985 (getter)CLazyLinker_get_allow_gc,
  986. 00986 (setter)CLazyLinker_set_allow_gc,
  987. 00987 (char*)"do this function support allow_gc",
  988. 00988 NULL},
  989. 00989 {NULL, NULL, NULL, NULL} /* Sentinel */
  990. 00990 };
  991. 00991 static PyMemberDef CLazyLinker_members[] = {
  992. 00992 {(char*)"nodes", T_OBJECT_EX, offsetof(CLazyLinker, nodes), 0,
  993. 00993 (char*)"list of nodes"},
  994. 00994 {(char*)"thunks", T_OBJECT_EX, offsetof(CLazyLinker, thunks), 0,
  995. 00995 (char*)"list of thunks in program"},
  996. 00996 {(char*)"call_counts", T_OBJECT_EX, offsetof(CLazyLinker, call_counts), 0,
  997. 00997 (char*)"number of calls of each thunk"},
  998. 00998 {(char*)"call_times", T_OBJECT_EX, offsetof(CLazyLinker, call_times), 0,
  999. 00999 (char*)"total runtime in each thunk"},
  1000. 01000 {(char*)"position_of_error", T_INT, offsetof(CLazyLinker, position_of_error), 0,
  1001. 01001 (char*)"position of failed thunk"},
  1002. 01002 {(char*)"time_thunks", T_INT, offsetof(CLazyLinker, do_timing), 0,
  1003. 01003 (char*)"bool: nonzero means call will time thunks"},
  1004. 01004 {(char*)"need_update_inputs", T_INT, offsetof(CLazyLinker, need_update_inputs), 0,
  1005. 01005 (char*)"bool: nonzero means Function.__call__ must implement update mechanism"},
  1006. 01006 {NULL} /* Sentinel */
  1007. 01007 };
  1008. 01008
  1009. 01009 static PyTypeObject lazylinker_ext_CLazyLinkerType = {
  1010. 01010 #if defined(NPY_PY3K)
  1011. 01011 PyVarObject_HEAD_INIT(NULL, 0)
  1012. 01012 #else
  1013. 01013 PyObject_HEAD_INIT(NULL)
  1014. 01014 0, /*ob_size*/
  1015. 01015 #endif
  1016. 01016 "lazylinker_ext.CLazyLinker", /*tp_name*/
  1017. 01017 sizeof(CLazyLinker), /*tp_basicsize*/
  1018. 01018 0, /*tp_itemsize*/
  1019. 01019 CLazyLinker_dealloc, /*tp_dealloc*/
  1020. 01020 0, /*tp_print*/
  1021. 01021 0, /*tp_getattr*/
  1022. 01022 0, /*tp_setattr*/
  1023. 01023 0, /*tp_compare*/
  1024. 01024 0, /*tp_repr*/
  1025. 01025 0, /*tp_as_number*/
  1026. 01026 0, /*tp_as_sequence*/
  1027. 01027 0, /*tp_as_mapping*/
  1028. 01028 0, /*tp_hash */
  1029. 01029 CLazyLinker_call, /*tp_call*/
  1030. 01030 0, /*tp_str*/
  1031. 01031 0, /*tp_getattro*/
  1032. 01032 0, /*tp_setattro*/
  1033. 01033 0, /*tp_as_buffer*/
  1034. 01034 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  1035. 01035 "CLazyLinker object", /* tp_doc */
  1036. 01036 0, /* tp_traverse */
  1037. 01037 0, /* tp_clear */
  1038. 01038 0, /* tp_richcompare */
  1039. 01039 0, /* tp_weaklistoffset */
  1040. 01040 0, /* tp_iter */
  1041. 01041 0, /* tp_iternext */
  1042. 01042 0,//CLazyLinker_methods, /* tp_methods */
  1043. 01043 CLazyLinker_members, /* tp_members */
  1044. 01044 CLazyLinker_getset, /* tp_getset */
  1045. 01045 0, /* tp_base */
  1046. 01046 0, /* tp_dict */
  1047. 01047 0, /* tp_descr_get */
  1048. 01048 0, /* tp_descr_set */
  1049. 01049 0, /* tp_dictoffset */
  1050. 01050 (initproc)CLazyLinker_init,/* tp_init */
  1051. 01051 0, /* tp_alloc */
  1052. 01052 CLazyLinker_new, /* tp_new */
  1053. 01053 };
  1054. 01054
  1055. 01055 static PyObject * get_version(PyObject *dummy, PyObject *args)
  1056. 01056 {
  1057. 01057 PyObject *result = PyFloat_FromDouble(0.211);
  1058. 01058 return result;
  1059. 01059 }
  1060. 01060
  1061. 01061 static PyMethodDef lazylinker_ext_methods[] = {
  1062. 01062 {"get_version", get_version, METH_VARARGS, "Get extension version."},
  1063. 01063 {NULL, NULL, 0, NULL} /* Sentinel */
  1064. 01064 };
  1065. 01065
  1066. 01066 #if defined(NPY_PY3K)
  1067. 01067 static struct PyModuleDef moduledef = {
  1068. 01068 PyModuleDef_HEAD_INIT,
  1069. 01069 "lazylinker_ext",
  1070. 01070 NULL,
  1071. 01071 -1,
  1072. 01072 lazylinker_ext_methods,
  1073. 01073 NULL,
  1074. 01074 NULL,
  1075. 01075 NULL,
  1076. 01076 NULL
  1077. 01077 };
  1078. 01078 #endif
  1079. 01079 #if defined(NPY_PY3K)
  1080. 01080 #define RETVAL m
  1081. 01081 PyMODINIT_FUNC
  1082. 01082 PyInit_lazylinker_ext(void) {
  1083. 01083 #else
  1084. 01084 #define RETVAL
  1085. 01085 PyMODINIT_FUNC
  1086. 01086 initlazylinker_ext(void)
  1087. 01087 {
  1088. 01088 #endif
  1089. 01089 PyObject* m;
  1090. ===============================
  1091. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `_import_array':
  1092. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1460: undefined reference to `__imp_PyExc_ImportError'
  1093. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1466: undefined reference to `__imp_PyExc_AttributeError'
  1094. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1471: undefined reference to `__imp_PyCapsule_Type'
  1095. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1472: undefined reference to `__imp_PyExc_RuntimeError'
  1096. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1487: undefined reference to `__imp_PyExc_RuntimeError'
  1097. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1495: undefined reference to `__imp_PyExc_RuntimeError'
  1098. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1501: undefined reference to `__imp_PyExc_RuntimeError'
  1099. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1511: undefined reference to `__imp_PyExc_RuntimeError'
  1100. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o:C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1523: more undefined references to `__imp_PyExc_RuntimeError' follow
  1101. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `NpyCapsule_Check':
  1102. C:/Users/pc1010101/Anaconda3/envs/tensorflow/lib/site-packages/numpy/core/include/numpy/npy_3kcompat.h:456: undefined reference to `__imp_PyCapsule_Type'
  1103. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `unpack_list_of_ssize_t':
  1104. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:48: undefined reference to `__imp_PyExc_TypeError'
  1105. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:58: undefined reference to `__imp_PyExc_IndexError'
  1106. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `CLazyLinker_init':
  1107. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:352: undefined reference to `__imp_PyExc_IndexError'
  1108. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:370: undefined reference to `__imp_PyExc_IndexError'
  1109. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:385: undefined reference to `__imp_PyExc_IndexError'
  1110. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:389: undefined reference to `__imp_PyExc_IndexError'
  1111. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o:C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:393: more undefined references to `__imp_PyExc_IndexError' follow
  1112. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `CLazyLinker_init':
  1113. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:405: undefined reference to `__imp_PyExc_TypeError'
  1114. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:420: undefined reference to `__imp__Py_NoneStruct'
  1115. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:426: undefined reference to `__imp_PyExc_IndexError'
  1116. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:440: undefined reference to `__imp_PyExc_TypeError'
  1117. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:444: undefined reference to `__imp__Py_NoneStruct'
  1118. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `c_call':
  1119. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
  1120. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
  1121. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
  1122. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:546: undefined reference to `__imp__Py_NoneStruct'
  1123. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o:C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:546: more undefined references to `__imp__Py_NoneStruct' follow
  1124. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `lazy_rec_eval':
  1125. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:618: undefined reference to `__imp_PyExc_IndexError'
  1126. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:641: undefined reference to `__imp_PyExc_TypeError'
  1127. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:649: undefined reference to `__imp_PyExc_ValueError'
  1128. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:657: undefined reference to `__imp_PyExc_IndexError'
  1129. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:708: undefined reference to `__imp__Py_NoneStruct'
  1130. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:715: undefined reference to `__imp_PyExc_TypeError'
  1131. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:721: undefined reference to `__imp_PyExc_TypeError'
  1132. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:771: undefined reference to `__imp__Py_NoneStruct'
  1133. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:771: undefined reference to `__imp__Py_NoneStruct'
  1134. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:772: undefined reference to `__imp__Py_NoneStruct'
  1135. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `CLazyLinker_call':
  1136. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:814: undefined reference to `__imp_PyExc_RuntimeError'
  1137. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:826: undefined reference to `__imp_PyExc_RuntimeError'
  1138. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:839: undefined reference to `__imp__Py_NoneStruct'
  1139. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:839: undefined reference to `__imp__Py_NoneStruct'
  1140. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:840: undefined reference to `__imp__Py_NoneStruct'
  1141. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:849: undefined reference to `__imp__Py_NoneStruct'
  1142. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:849: undefined reference to `__imp__Py_NoneStruct'
  1143. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o:C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:850: more undefined references to `__imp__Py_NoneStruct' follow
  1144. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `CLazyLinker_call':
  1145. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:894: undefined reference to `__imp_PyExc_AssertionError'
  1146. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:937: undefined reference to `__imp__Py_NoneStruct'
  1147. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:937: undefined reference to `__imp__Py_NoneStruct'
  1148. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:938: undefined reference to `__imp__Py_NoneStruct'
  1149. C:\Users\PC1010~1\AppData\Local\Temp\ccth1eZh.o: In function `CLazyLinker_set_allow_gc':
  1150. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:973: undefined reference to `__imp_PyBool_Type'
  1151. C:/Users/pc1010101/AppData/Local/Theano/compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:976: undefined reference to `__imp__Py_TrueStruct'
  1152. collect2.exe: error: ld returned 1 exit status
  1153.  
  1154.  
  1155. 01090
  1156. 01091 lazylinker_ext_CLazyLinkerType.tp_new = PyType_GenericNew;
  1157. 01092 if (PyType_Ready(&lazylinker_ext_CLazyLinkerType) < 0)
  1158. 01093 return RETVAL;
  1159. 01094 #if defined(NPY_PY3K)
  1160. 01095 m = PyModule_Create(&moduledef);
  1161. 01096 #else
  1162. 01097 m = Py_InitModule3("lazylinker_ext", lazylinker_ext_methods,
  1163. 01098 "Example module that creates an extension type.");
  1164. 01099 #endif
  1165. 01100 Py_INCREF(&lazylinker_ext_CLazyLinkerType);
  1166. 01101 PyModule_AddObject(m, "CLazyLinker", (PyObject *)&lazylinker_ext_CLazyLinkerType);
  1167. 01102
  1168. 01103 return RETVAL;
  1169. 01104 }
  1170. 01105
  1171. Problem occurred during compilation with the command line below:
  1172. "C:\Users\pc1010101\Anaconda3\envs\tensorflow\Library\mingw-w64\bin\g++.exe" -shared -g -march=ivybridge -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -maes -mno-sha -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-clwb -mno-pcommit -mno-mwaitx --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=ivybridge -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I"C:\Users\pc1010101\Anaconda3\envs\tensorflow\lib\site-packages\numpy\core\include" -I"C:\Users\pc1010101\Anaconda3\envs\tensorflow\include" -I"C:\Users\pc1010101\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof" -L"C:\Users\pc1010101\Anaconda3\envs\tensorflow\libs" -L"C:\Users\pc1010101\Anaconda3\envs\tensorflow" -o C:\Users\pc1010101\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\pc1010101\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64\lazylinker_ext\mod.cpp -lpython35
  1173. ---------------------------------------------------------------------------
  1174. ImportError Traceback (most recent call last)
  1175. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
  1176. 74 if version != getattr(lazylinker_ext, '_version', None):
  1177. ---> 75 raise ImportError()
  1178. 76 except ImportError:
  1179.  
  1180. ImportError:
  1181.  
  1182. During handling of the above exception, another exception occurred:
  1183.  
  1184. ImportError Traceback (most recent call last)
  1185. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
  1186. 91 if version != getattr(lazylinker_ext, '_version', None):
  1187. ---> 92 raise ImportError()
  1188. 93 except ImportError:
  1189.  
  1190. ImportError:
  1191.  
  1192. During handling of the above exception, another exception occurred:
  1193.  
  1194. Exception Traceback (most recent call last)
  1195. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\vm.py in <module>()
  1196. 661 raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
  1197. --> 662 from . import lazylinker_c
  1198. 663
  1199.  
  1200. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
  1201. 126 cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
  1202. --> 127 preargs=args)
  1203. 128 # Save version into the __init__.py file.
  1204.  
  1205. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
  1206. 2315 raise Exception('Compilation failed (return status=%s): %s' %
  1207. -> 2316 (status, compile_stderr.replace('\n', '. ')))
  1208. 2317 elif config.cmodule.compilation_warning and compile_stderr:
  1209.  
  1210. . collect2.exe: error: ld returned 1 exit statusedir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.4-64/lazylinker_ext/mod.cpp:976: undefined reference to `__imp__Py_TrueStruct'Error'e undefined references to `__imp__Py_NoneStruct' followow
  1211.  
  1212. During handling of the above exception, another exception occurred:
  1213.  
  1214. AttributeError Traceback (most recent call last)
  1215. <ipython-input-3-42edb271ea64> in <module>()
  1216. ----> 1 from keras.utils import np_utils
  1217.  
  1218. ~\Anaconda3\envs\tensorflow\lib\site-packages\keras\__init__.py in <module>()
  1219. 1 from __future__ import absolute_import
  1220. 2
  1221. ----> 3 from . import utils
  1222. 4 from . import activations
  1223. 5 from . import applications
  1224.  
  1225. ~\Anaconda3\envs\tensorflow\lib\site-packages\keras\utils\__init__.py in <module>()
  1226. 4 from . import data_utils
  1227. 5 from . import io_utils
  1228. ----> 6 from . import conv_utils
  1229. 7
  1230. 8 # Globally-importable utils.
  1231.  
  1232. ~\Anaconda3\envs\tensorflow\lib\site-packages\keras\utils\conv_utils.py in <module>()
  1233. 1 from six.moves import range
  1234. 2 import numpy as np
  1235. ----> 3 from .. import backend as K
  1236. 4
  1237. 5
  1238.  
  1239. ~\Anaconda3\envs\tensorflow\lib\site-packages\keras\backend\__init__.py in <module>()
  1240. 78 elif _BACKEND == 'theano':
  1241. 79 sys.stderr.write('Using Theano backend.\n')
  1242. ---> 80 from .theano_backend import *
  1243. 81 elif _BACKEND == 'tensorflow':
  1244. 82 sys.stderr.write('Using TensorFlow backend.\n')
  1245.  
  1246. ~\Anaconda3\envs\tensorflow\lib\site-packages\keras\backend\theano_backend.py in <module>()
  1247. 1 from collections import defaultdict
  1248. 2 from contextlib import contextmanager
  1249. ----> 3 import theano
  1250. 4 from theano import tensor as T
  1251. 5 from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
  1252.  
  1253. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\__init__.py in <module>()
  1254. 64 object2, utils)
  1255. 65
  1256. ---> 66 from theano.compile import (
  1257. 67 SymbolicInput, In,
  1258. 68 SymbolicOutput, Out,
  1259.  
  1260. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\compile\__init__.py in <module>()
  1261. 8 SpecifyShape, specify_shape, register_specify_shape_c_code)
  1262. 9
  1263. ---> 10 from theano.compile.function_module import *
  1264. 11
  1265. 12 from theano.compile.mode import *
  1266.  
  1267. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\compile\function_module.py in <module>()
  1268. 19 from theano.compat import izip
  1269. 20 from theano.gof import graph
  1270. ---> 21 import theano.compile.mode
  1271. 22 import theano.compile.profiling
  1272. 23 from theano.compile.io import (
  1273.  
  1274. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\compile\mode.py in <module>()
  1275. 8 import theano
  1276. 9 from theano import gof
  1277. ---> 10 import theano.gof.vm
  1278. 11 from theano.configparser import config
  1279. 12 from theano.compile.ops import _output_guard
  1280.  
  1281. ~\Anaconda3\envs\tensorflow\lib\site-packages\theano\gof\vm.py in <module>()
  1282. 669 except ImportError:
  1283. 670 pass
  1284. --> 671 except (OSError, theano.gof.cmodule.MissingGXX) as e:
  1285. 672 # OSError happens when g++ is not installed. In that case, we
  1286. 673 # already changed the default linker to something else then CVM.
  1287.  
  1288. AttributeError: module 'theano' has no attribute 'gof'
  1289.  
  1290. In [ ]:
  1291.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement