You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7574 lines
277 KiB

4 years ago
  1. /* Generated by Cython 0.29.1 */
  2. #define PY_SSIZE_T_CLEAN
  3. #include "Python.h"
  4. #ifndef Py_PYTHON_H
  5. #error Python headers needed to compile C extensions, please install development version of Python.
  6. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
  7. #error Cython requires Python 2.6+ or Python 3.3+.
  8. #else
  9. #define CYTHON_ABI "0_29_1"
  10. #define CYTHON_HEX_VERSION 0x001D01F0
  11. #define CYTHON_FUTURE_DIVISION 0
  12. #include <stddef.h>
  13. #ifndef offsetof
  14. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  15. #endif
  16. #if !defined(WIN32) && !defined(MS_WINDOWS)
  17. #ifndef __stdcall
  18. #define __stdcall
  19. #endif
  20. #ifndef __cdecl
  21. #define __cdecl
  22. #endif
  23. #ifndef __fastcall
  24. #define __fastcall
  25. #endif
  26. #endif
  27. #ifndef DL_IMPORT
  28. #define DL_IMPORT(t) t
  29. #endif
  30. #ifndef DL_EXPORT
  31. #define DL_EXPORT(t) t
  32. #endif
  33. #define __PYX_COMMA ,
  34. #ifndef HAVE_LONG_LONG
  35. #if PY_VERSION_HEX >= 0x02070000
  36. #define HAVE_LONG_LONG
  37. #endif
  38. #endif
  39. #ifndef PY_LONG_LONG
  40. #define PY_LONG_LONG LONG_LONG
  41. #endif
  42. #ifndef Py_HUGE_VAL
  43. #define Py_HUGE_VAL HUGE_VAL
  44. #endif
  45. #ifdef PYPY_VERSION
  46. #define CYTHON_COMPILING_IN_PYPY 1
  47. #define CYTHON_COMPILING_IN_PYSTON 0
  48. #define CYTHON_COMPILING_IN_CPYTHON 0
  49. #undef CYTHON_USE_TYPE_SLOTS
  50. #define CYTHON_USE_TYPE_SLOTS 0
  51. #undef CYTHON_USE_PYTYPE_LOOKUP
  52. #define CYTHON_USE_PYTYPE_LOOKUP 0
  53. #if PY_VERSION_HEX < 0x03050000
  54. #undef CYTHON_USE_ASYNC_SLOTS
  55. #define CYTHON_USE_ASYNC_SLOTS 0
  56. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  57. #define CYTHON_USE_ASYNC_SLOTS 1
  58. #endif
  59. #undef CYTHON_USE_PYLIST_INTERNALS
  60. #define CYTHON_USE_PYLIST_INTERNALS 0
  61. #undef CYTHON_USE_UNICODE_INTERNALS
  62. #define CYTHON_USE_UNICODE_INTERNALS 0
  63. #undef CYTHON_USE_UNICODE_WRITER
  64. #define CYTHON_USE_UNICODE_WRITER 0
  65. #undef CYTHON_USE_PYLONG_INTERNALS
  66. #define CYTHON_USE_PYLONG_INTERNALS 0
  67. #undef CYTHON_AVOID_BORROWED_REFS
  68. #define CYTHON_AVOID_BORROWED_REFS 1
  69. #undef CYTHON_ASSUME_SAFE_MACROS
  70. #define CYTHON_ASSUME_SAFE_MACROS 0
  71. #undef CYTHON_UNPACK_METHODS
  72. #define CYTHON_UNPACK_METHODS 0
  73. #undef CYTHON_FAST_THREAD_STATE
  74. #define CYTHON_FAST_THREAD_STATE 0
  75. #undef CYTHON_FAST_PYCALL
  76. #define CYTHON_FAST_PYCALL 0
  77. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  78. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  79. #undef CYTHON_USE_TP_FINALIZE
  80. #define CYTHON_USE_TP_FINALIZE 0
  81. #undef CYTHON_USE_DICT_VERSIONS
  82. #define CYTHON_USE_DICT_VERSIONS 0
  83. #undef CYTHON_USE_EXC_INFO_STACK
  84. #define CYTHON_USE_EXC_INFO_STACK 0
  85. #elif defined(PYSTON_VERSION)
  86. #define CYTHON_COMPILING_IN_PYPY 0
  87. #define CYTHON_COMPILING_IN_PYSTON 1
  88. #define CYTHON_COMPILING_IN_CPYTHON 0
  89. #ifndef CYTHON_USE_TYPE_SLOTS
  90. #define CYTHON_USE_TYPE_SLOTS 1
  91. #endif
  92. #undef CYTHON_USE_PYTYPE_LOOKUP
  93. #define CYTHON_USE_PYTYPE_LOOKUP 0
  94. #undef CYTHON_USE_ASYNC_SLOTS
  95. #define CYTHON_USE_ASYNC_SLOTS 0
  96. #undef CYTHON_USE_PYLIST_INTERNALS
  97. #define CYTHON_USE_PYLIST_INTERNALS 0
  98. #ifndef CYTHON_USE_UNICODE_INTERNALS
  99. #define CYTHON_USE_UNICODE_INTERNALS 1
  100. #endif
  101. #undef CYTHON_USE_UNICODE_WRITER
  102. #define CYTHON_USE_UNICODE_WRITER 0
  103. #undef CYTHON_USE_PYLONG_INTERNALS
  104. #define CYTHON_USE_PYLONG_INTERNALS 0
  105. #ifndef CYTHON_AVOID_BORROWED_REFS
  106. #define CYTHON_AVOID_BORROWED_REFS 0
  107. #endif
  108. #ifndef CYTHON_ASSUME_SAFE_MACROS
  109. #define CYTHON_ASSUME_SAFE_MACROS 1
  110. #endif
  111. #ifndef CYTHON_UNPACK_METHODS
  112. #define CYTHON_UNPACK_METHODS 1
  113. #endif
  114. #undef CYTHON_FAST_THREAD_STATE
  115. #define CYTHON_FAST_THREAD_STATE 0
  116. #undef CYTHON_FAST_PYCALL
  117. #define CYTHON_FAST_PYCALL 0
  118. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  119. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  120. #undef CYTHON_USE_TP_FINALIZE
  121. #define CYTHON_USE_TP_FINALIZE 0
  122. #undef CYTHON_USE_DICT_VERSIONS
  123. #define CYTHON_USE_DICT_VERSIONS 0
  124. #undef CYTHON_USE_EXC_INFO_STACK
  125. #define CYTHON_USE_EXC_INFO_STACK 0
  126. #else
  127. #define CYTHON_COMPILING_IN_PYPY 0
  128. #define CYTHON_COMPILING_IN_PYSTON 0
  129. #define CYTHON_COMPILING_IN_CPYTHON 1
  130. #ifndef CYTHON_USE_TYPE_SLOTS
  131. #define CYTHON_USE_TYPE_SLOTS 1
  132. #endif
  133. #if PY_VERSION_HEX < 0x02070000
  134. #undef CYTHON_USE_PYTYPE_LOOKUP
  135. #define CYTHON_USE_PYTYPE_LOOKUP 0
  136. #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
  137. #define CYTHON_USE_PYTYPE_LOOKUP 1
  138. #endif
  139. #if PY_MAJOR_VERSION < 3
  140. #undef CYTHON_USE_ASYNC_SLOTS
  141. #define CYTHON_USE_ASYNC_SLOTS 0
  142. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  143. #define CYTHON_USE_ASYNC_SLOTS 1
  144. #endif
  145. #if PY_VERSION_HEX < 0x02070000
  146. #undef CYTHON_USE_PYLONG_INTERNALS
  147. #define CYTHON_USE_PYLONG_INTERNALS 0
  148. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  149. #define CYTHON_USE_PYLONG_INTERNALS 1
  150. #endif
  151. #ifndef CYTHON_USE_PYLIST_INTERNALS
  152. #define CYTHON_USE_PYLIST_INTERNALS 1
  153. #endif
  154. #ifndef CYTHON_USE_UNICODE_INTERNALS
  155. #define CYTHON_USE_UNICODE_INTERNALS 1
  156. #endif
  157. #if PY_VERSION_HEX < 0x030300F0
  158. #undef CYTHON_USE_UNICODE_WRITER
  159. #define CYTHON_USE_UNICODE_WRITER 0
  160. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  161. #define CYTHON_USE_UNICODE_WRITER 1
  162. #endif
  163. #ifndef CYTHON_AVOID_BORROWED_REFS
  164. #define CYTHON_AVOID_BORROWED_REFS 0
  165. #endif
  166. #ifndef CYTHON_ASSUME_SAFE_MACROS
  167. #define CYTHON_ASSUME_SAFE_MACROS 1
  168. #endif
  169. #ifndef CYTHON_UNPACK_METHODS
  170. #define CYTHON_UNPACK_METHODS 1
  171. #endif
  172. #ifndef CYTHON_FAST_THREAD_STATE
  173. #define CYTHON_FAST_THREAD_STATE 1
  174. #endif
  175. #ifndef CYTHON_FAST_PYCALL
  176. #define CYTHON_FAST_PYCALL 1
  177. #endif
  178. #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
  179. #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  180. #endif
  181. #ifndef CYTHON_USE_TP_FINALIZE
  182. #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  183. #endif
  184. #ifndef CYTHON_USE_DICT_VERSIONS
  185. #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
  186. #endif
  187. #ifndef CYTHON_USE_EXC_INFO_STACK
  188. #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  189. #endif
  190. #endif
  191. #if !defined(CYTHON_FAST_PYCCALL)
  192. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  193. #endif
  194. #if CYTHON_USE_PYLONG_INTERNALS
  195. #include "longintrepr.h"
  196. #undef SHIFT
  197. #undef BASE
  198. #undef MASK
  199. #ifdef SIZEOF_VOID_P
  200. enum { __pyx_check_sizeof_voidp = 1/(SIZEOF_VOID_P == sizeof(void*)) };
  201. #endif
  202. #endif
  203. #ifndef __has_attribute
  204. #define __has_attribute(x) 0
  205. #endif
  206. #ifndef __has_cpp_attribute
  207. #define __has_cpp_attribute(x) 0
  208. #endif
  209. #ifndef CYTHON_RESTRICT
  210. #if defined(__GNUC__)
  211. #define CYTHON_RESTRICT __restrict__
  212. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  213. #define CYTHON_RESTRICT __restrict
  214. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  215. #define CYTHON_RESTRICT restrict
  216. #else
  217. #define CYTHON_RESTRICT
  218. #endif
  219. #endif
  220. #ifndef CYTHON_UNUSED
  221. # if defined(__GNUC__)
  222. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  223. # define CYTHON_UNUSED __attribute__ ((__unused__))
  224. # else
  225. # define CYTHON_UNUSED
  226. # endif
  227. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  228. # define CYTHON_UNUSED __attribute__ ((__unused__))
  229. # else
  230. # define CYTHON_UNUSED
  231. # endif
  232. #endif
  233. #ifndef CYTHON_MAYBE_UNUSED_VAR
  234. # if defined(__cplusplus)
  235. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  236. # else
  237. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  238. # endif
  239. #endif
  240. #ifndef CYTHON_NCP_UNUSED
  241. # if CYTHON_COMPILING_IN_CPYTHON
  242. # define CYTHON_NCP_UNUSED
  243. # else
  244. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  245. # endif
  246. #endif
  247. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  248. #ifdef _MSC_VER
  249. #ifndef _MSC_STDINT_H_
  250. #if _MSC_VER < 1300
  251. typedef unsigned char uint8_t;
  252. typedef unsigned int uint32_t;
  253. #else
  254. typedef unsigned __int8 uint8_t;
  255. typedef unsigned __int32 uint32_t;
  256. #endif
  257. #endif
  258. #else
  259. #include <stdint.h>
  260. #endif
  261. #ifndef CYTHON_FALLTHROUGH
  262. #if defined(__cplusplus) && __cplusplus >= 201103L
  263. #if __has_cpp_attribute(fallthrough)
  264. #define CYTHON_FALLTHROUGH [[fallthrough]]
  265. #elif __has_cpp_attribute(clang::fallthrough)
  266. #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
  267. #elif __has_cpp_attribute(gnu::fallthrough)
  268. #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
  269. #endif
  270. #endif
  271. #ifndef CYTHON_FALLTHROUGH
  272. #if __has_attribute(fallthrough)
  273. #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
  274. #else
  275. #define CYTHON_FALLTHROUGH
  276. #endif
  277. #endif
  278. #if defined(__clang__ ) && defined(__apple_build_version__)
  279. #if __apple_build_version__ < 7000000
  280. #undef CYTHON_FALLTHROUGH
  281. #define CYTHON_FALLTHROUGH
  282. #endif
  283. #endif
  284. #endif
  285. #ifndef __cplusplus
  286. #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
  287. #endif
  288. #ifndef CYTHON_INLINE
  289. #if defined(__clang__)
  290. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  291. #else
  292. #define CYTHON_INLINE inline
  293. #endif
  294. #endif
  295. template<typename T>
  296. void __Pyx_call_destructor(T& x) {
  297. x.~T();
  298. }
  299. template<typename T>
  300. class __Pyx_FakeReference {
  301. public:
  302. __Pyx_FakeReference() : ptr(NULL) { }
  303. __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
  304. T *operator->() { return ptr; }
  305. T *operator&() { return ptr; }
  306. operator T&() { return *ptr; }
  307. template<typename U> bool operator ==(U other) { return *ptr == other; }
  308. template<typename U> bool operator !=(U other) { return *ptr != other; }
  309. private:
  310. T *ptr;
  311. };
  312. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  313. #define Py_OptimizeFlag 0
  314. #endif
  315. #define __PYX_BUILD_PY_SSIZE_T "n"
  316. #define CYTHON_FORMAT_SSIZE_T "z"
  317. #if PY_MAJOR_VERSION < 3
  318. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  319. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  320. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  321. #define __Pyx_DefaultClassType PyClass_Type
  322. #else
  323. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  324. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  325. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  326. #define __Pyx_DefaultClassType PyType_Type
  327. #endif
  328. #ifndef Py_TPFLAGS_CHECKTYPES
  329. #define Py_TPFLAGS_CHECKTYPES 0
  330. #endif
  331. #ifndef Py_TPFLAGS_HAVE_INDEX
  332. #define Py_TPFLAGS_HAVE_INDEX 0
  333. #endif
  334. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  335. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  336. #endif
  337. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  338. #define Py_TPFLAGS_HAVE_FINALIZE 0
  339. #endif
  340. #ifndef METH_STACKLESS
  341. #define METH_STACKLESS 0
  342. #endif
  343. #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  344. #ifndef METH_FASTCALL
  345. #define METH_FASTCALL 0x80
  346. #endif
  347. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  348. typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
  349. Py_ssize_t nargs, PyObject *kwnames);
  350. #else
  351. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  352. #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  353. #endif
  354. #if CYTHON_FAST_PYCCALL
  355. #define __Pyx_PyFastCFunction_Check(func)\
  356. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
  357. #else
  358. #define __Pyx_PyFastCFunction_Check(func) 0
  359. #endif
  360. #if CYTHON_USE_DICT_VERSIONS
  361. #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
  362. #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
  363. (version_var) = __PYX_GET_DICT_VERSION(dict);\
  364. (cache_var) = (value);
  365. #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
  366. static PY_UINT64_T __pyx_dict_version = 0;\
  367. static PyObject *__pyx_dict_cached_value = NULL;\
  368. if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
  369. (VAR) = __pyx_dict_cached_value;\
  370. } else {\
  371. (VAR) = __pyx_dict_cached_value = (LOOKUP);\
  372. __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
  373. }\
  374. }
  375. #else
  376. #define __PYX_GET_DICT_VERSION(dict) (0)
  377. #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
  378. #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
  379. #endif
  380. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  381. #define PyObject_Malloc(s) PyMem_Malloc(s)
  382. #define PyObject_Free(p) PyMem_Free(p)
  383. #define PyObject_Realloc(p) PyMem_Realloc(p)
  384. #endif
  385. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
  386. #define PyMem_RawMalloc(n) PyMem_Malloc(n)
  387. #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
  388. #define PyMem_RawFree(p) PyMem_Free(p)
  389. #endif
  390. #if CYTHON_COMPILING_IN_PYSTON
  391. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  392. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  393. #else
  394. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  395. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  396. #endif
  397. #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  398. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  399. #elif PY_VERSION_HEX >= 0x03060000
  400. #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
  401. #elif PY_VERSION_HEX >= 0x03000000
  402. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  403. #else
  404. #define __Pyx_PyThreadState_Current _PyThreadState_Current
  405. #endif
  406. #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
  407. #include "pythread.h"
  408. #define Py_tss_NEEDS_INIT 0
  409. typedef int Py_tss_t;
  410. static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  411. *key = PyThread_create_key();
  412. return 0; // PyThread_create_key reports success always
  413. }
  414. static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  415. Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  416. *key = Py_tss_NEEDS_INIT;
  417. return key;
  418. }
  419. static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  420. PyObject_Free(key);
  421. }
  422. static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  423. return *key != Py_tss_NEEDS_INIT;
  424. }
  425. static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  426. PyThread_delete_key(*key);
  427. *key = Py_tss_NEEDS_INIT;
  428. }
  429. static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  430. return PyThread_set_key_value(*key, value);
  431. }
  432. static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  433. return PyThread_get_key_value(*key);
  434. }
  435. #endif // TSS (Thread Specific Storage) API
  436. #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
  437. #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
  438. #else
  439. #define __Pyx_PyDict_NewPresized(n) PyDict_New()
  440. #endif
  441. #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  442. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  443. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  444. #else
  445. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  446. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  447. #endif
  448. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
  449. #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
  450. #else
  451. #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
  452. #endif
  453. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  454. #define CYTHON_PEP393_ENABLED 1
  455. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
  456. 0 : _PyUnicode_Ready((PyObject *)(op)))
  457. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  458. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  459. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  460. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  461. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  462. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  463. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  464. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  465. #else
  466. #define CYTHON_PEP393_ENABLED 0
  467. #define PyUnicode_1BYTE_KIND 1
  468. #define PyUnicode_2BYTE_KIND 2
  469. #define PyUnicode_4BYTE_KIND 4
  470. #define __Pyx_PyUnicode_READY(op) (0)
  471. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  472. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  473. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  474. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  475. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  476. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  477. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  478. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  479. #endif
  480. #if CYTHON_COMPILING_IN_PYPY
  481. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  482. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  483. #else
  484. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  485. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
  486. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  487. #endif
  488. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  489. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  490. #endif
  491. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  492. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  493. #endif
  494. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  495. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  496. #endif
  497. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  498. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  499. #if PY_MAJOR_VERSION >= 3
  500. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  501. #else
  502. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  503. #endif
  504. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  505. #define PyObject_ASCII(o) PyObject_Repr(o)
  506. #endif
  507. #if PY_MAJOR_VERSION >= 3
  508. #define PyBaseString_Type PyUnicode_Type
  509. #define PyStringObject PyUnicodeObject
  510. #define PyString_Type PyUnicode_Type
  511. #define PyString_Check PyUnicode_Check
  512. #define PyString_CheckExact PyUnicode_CheckExact
  513. #define PyObject_Unicode PyObject_Str
  514. #endif
  515. #if PY_MAJOR_VERSION >= 3
  516. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  517. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  518. #else
  519. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  520. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  521. #endif
  522. #ifndef PySet_CheckExact
  523. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  524. #endif
  525. #if CYTHON_ASSUME_SAFE_MACROS
  526. #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
  527. #else
  528. #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
  529. #endif
  530. #if PY_MAJOR_VERSION >= 3
  531. #define PyIntObject PyLongObject
  532. #define PyInt_Type PyLong_Type
  533. #define PyInt_Check(op) PyLong_Check(op)
  534. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  535. #define PyInt_FromString PyLong_FromString
  536. #define PyInt_FromUnicode PyLong_FromUnicode
  537. #define PyInt_FromLong PyLong_FromLong
  538. #define PyInt_FromSize_t PyLong_FromSize_t
  539. #define PyInt_FromSsize_t PyLong_FromSsize_t
  540. #define PyInt_AsLong PyLong_AsLong
  541. #define PyInt_AS_LONG PyLong_AS_LONG
  542. #define PyInt_AsSsize_t PyLong_AsSsize_t
  543. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  544. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  545. #define PyNumber_Int PyNumber_Long
  546. #endif
  547. #if PY_MAJOR_VERSION >= 3
  548. #define PyBoolObject PyLongObject
  549. #endif
  550. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  551. #ifndef PyUnicode_InternFromString
  552. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  553. #endif
  554. #endif
  555. #if PY_VERSION_HEX < 0x030200A4
  556. typedef long Py_hash_t;
  557. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  558. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  559. #else
  560. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  561. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  562. #endif
  563. #if PY_MAJOR_VERSION >= 3
  564. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
  565. #else
  566. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  567. #endif
  568. #if CYTHON_USE_ASYNC_SLOTS
  569. #if PY_VERSION_HEX >= 0x030500B1
  570. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  571. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  572. #else
  573. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  574. #endif
  575. #else
  576. #define __Pyx_PyType_AsAsync(obj) NULL
  577. #endif
  578. #ifndef __Pyx_PyAsyncMethodsStruct
  579. typedef struct {
  580. unaryfunc am_await;
  581. unaryfunc am_aiter;
  582. unaryfunc am_anext;
  583. } __Pyx_PyAsyncMethodsStruct;
  584. #endif
  585. #if defined(WIN32) || defined(MS_WINDOWS)
  586. #define _USE_MATH_DEFINES
  587. #endif
  588. #include <math.h>
  589. #ifdef NAN
  590. #define __PYX_NAN() ((float) NAN)
  591. #else
  592. static CYTHON_INLINE float __PYX_NAN() {
  593. float value;
  594. memset(&value, 0xFF, sizeof(value));
  595. return value;
  596. }
  597. #endif
  598. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  599. #define __Pyx_truncl trunc
  600. #else
  601. #define __Pyx_truncl truncl
  602. #endif
  603. #define __PYX_ERR(f_index, lineno, Ln_error) \
  604. { \
  605. __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
  606. }
  607. #ifndef __PYX_EXTERN_C
  608. #ifdef __cplusplus
  609. #define __PYX_EXTERN_C extern "C"
  610. #else
  611. #define __PYX_EXTERN_C extern
  612. #endif
  613. #endif
  614. #define __PYX_HAVE__thinc__structs
  615. #define __PYX_HAVE_API__thinc__structs
  616. /* Early includes */
  617. #include <stdint.h>
  618. #include "ios"
  619. #include "new"
  620. #include "stdexcept"
  621. #include "typeinfo"
  622. #include <vector>
  623. #include <string.h>
  624. #include <stdlib.h>
  625. #include "math.h"
  626. #include "stdlib.h"
  627. #ifdef _OPENMP
  628. #include <omp.h>
  629. #endif /* _OPENMP */
  630. #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
  631. #define CYTHON_WITHOUT_ASSERTIONS
  632. #endif
  633. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  634. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
  635. #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
  636. #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
  637. #define __PYX_DEFAULT_STRING_ENCODING ""
  638. #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
  639. #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  640. #define __Pyx_uchar_cast(c) ((unsigned char)c)
  641. #define __Pyx_long_cast(x) ((long)x)
  642. #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
  643. (sizeof(type) < sizeof(Py_ssize_t)) ||\
  644. (sizeof(type) > sizeof(Py_ssize_t) &&\
  645. likely(v < (type)PY_SSIZE_T_MAX ||\
  646. v == (type)PY_SSIZE_T_MAX) &&\
  647. (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
  648. v == (type)PY_SSIZE_T_MIN))) ||\
  649. (sizeof(type) == sizeof(Py_ssize_t) &&\
  650. (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
  651. v == (type)PY_SSIZE_T_MAX))) )
  652. static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
  653. return (size_t) i < (size_t) limit;
  654. }
  655. #if defined (__cplusplus) && __cplusplus >= 201103L
  656. #include <cstdlib>
  657. #define __Pyx_sst_abs(value) std::abs(value)
  658. #elif SIZEOF_INT >= SIZEOF_SIZE_T
  659. #define __Pyx_sst_abs(value) abs(value)
  660. #elif SIZEOF_LONG >= SIZEOF_SIZE_T
  661. #define __Pyx_sst_abs(value) labs(value)
  662. #elif defined (_MSC_VER)
  663. #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
  664. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  665. #define __Pyx_sst_abs(value) llabs(value)
  666. #elif defined (__GNUC__)
  667. #define __Pyx_sst_abs(value) __builtin_llabs(value)
  668. #else
  669. #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
  670. #endif
  671. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
  672. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
  673. #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
  674. #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
  675. #define __Pyx_PyBytes_FromString PyBytes_FromString
  676. #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
  677. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
  678. #if PY_MAJOR_VERSION < 3
  679. #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
  680. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  681. #else
  682. #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
  683. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
  684. #endif
  685. #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
  686. #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
  687. #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
  688. #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
  689. #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
  690. #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
  691. #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
  692. #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
  693. #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
  694. #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
  695. #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
  696. #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
  697. #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
  698. #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
  699. #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
  700. #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
  701. static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
  702. const Py_UNICODE *u_end = u;
  703. while (*u_end++) ;
  704. return (size_t)(u_end - u - 1);
  705. }
  706. #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
  707. #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
  708. #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
  709. #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
  710. #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
  711. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
  712. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
  713. static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
  714. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
  715. #define __Pyx_PySequence_Tuple(obj)\
  716. (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
  717. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
  718. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
  719. #if CYTHON_ASSUME_SAFE_MACROS
  720. #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
  721. #else
  722. #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
  723. #endif
  724. #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
  725. #if PY_MAJOR_VERSION >= 3
  726. #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
  727. #else
  728. #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
  729. #endif
  730. #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
  731. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  732. static int __Pyx_sys_getdefaultencoding_not_ascii;
  733. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  734. PyObject* sys;
  735. PyObject* default_encoding = NULL;
  736. PyObject* ascii_chars_u = NULL;
  737. PyObject* ascii_chars_b = NULL;
  738. const char* default_encoding_c;
  739. sys = PyImport_ImportModule("sys");
  740. if (!sys) goto bad;
  741. default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
  742. Py_DECREF(sys);
  743. if (!default_encoding) goto bad;
  744. default_encoding_c = PyBytes_AsString(default_encoding);
  745. if (!default_encoding_c) goto bad;
  746. if (strcmp(default_encoding_c, "ascii") == 0) {
  747. __Pyx_sys_getdefaultencoding_not_ascii = 0;
  748. } else {
  749. char ascii_chars[128];
  750. int c;
  751. for (c = 0; c < 128; c++) {
  752. ascii_chars[c] = c;
  753. }
  754. __Pyx_sys_getdefaultencoding_not_ascii = 1;
  755. ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
  756. if (!ascii_chars_u) goto bad;
  757. ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
  758. if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
  759. PyErr_Format(
  760. PyExc_ValueError,
  761. "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
  762. default_encoding_c);
  763. goto bad;
  764. }
  765. Py_DECREF(ascii_chars_u);
  766. Py_DECREF(ascii_chars_b);
  767. }
  768. Py_DECREF(default_encoding);
  769. return 0;
  770. bad:
  771. Py_XDECREF(default_encoding);
  772. Py_XDECREF(ascii_chars_u);
  773. Py_XDECREF(ascii_chars_b);
  774. return -1;
  775. }
  776. #endif
  777. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
  778. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
  779. #else
  780. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
  781. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  782. static char* __PYX_DEFAULT_STRING_ENCODING;
  783. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  784. PyObject* sys;
  785. PyObject* default_encoding = NULL;
  786. char* default_encoding_c;
  787. sys = PyImport_ImportModule("sys");
  788. if (!sys) goto bad;
  789. default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
  790. Py_DECREF(sys);
  791. if (!default_encoding) goto bad;
  792. default_encoding_c = PyBytes_AsString(default_encoding);
  793. if (!default_encoding_c) goto bad;
  794. __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
  795. if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
  796. strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
  797. Py_DECREF(default_encoding);
  798. return 0;
  799. bad:
  800. Py_XDECREF(default_encoding);
  801. return -1;
  802. }
  803. #endif
  804. #endif
  805. /* Test for GCC > 2.95 */
  806. #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  807. #define likely(x) __builtin_expect(!!(x), 1)
  808. #define unlikely(x) __builtin_expect(!!(x), 0)
  809. #else /* !__GNUC__ or GCC < 2.95 */
  810. #define likely(x) (x)
  811. #define unlikely(x) (x)
  812. #endif /* __GNUC__ */
  813. static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
  814. static PyObject *__pyx_m = NULL;
  815. static PyObject *__pyx_d;
  816. static PyObject *__pyx_b;
  817. static PyObject *__pyx_cython_runtime = NULL;
  818. static PyObject *__pyx_empty_tuple;
  819. static PyObject *__pyx_empty_bytes;
  820. static PyObject *__pyx_empty_unicode;
  821. static int __pyx_lineno;
  822. static int __pyx_clineno = 0;
  823. static const char * __pyx_cfilenm= __FILE__;
  824. static const char *__pyx_filename;
  825. static const char *__pyx_f[] = {
  826. "structs.pxd",
  827. "structs.pyx",
  828. "cymem.pxd",
  829. "maps.pxd",
  830. "linalg.pxd",
  831. };
  832. /* None.proto */
  833. #if defined(__GNUC__)
  834. #define __Pyx_PACKED __attribute__((__packed__))
  835. #else
  836. #define __Pyx_PACKED
  837. #endif
  838. /* "preshed/maps.pxd":5
  839. *
  840. *
  841. * ctypedef uint64_t key_t # <<<<<<<<<<<<<<
  842. *
  843. *
  844. */
  845. typedef uint64_t __pyx_t_7preshed_4maps_key_t;
  846. /* "typedefs.pxd":7
  847. *
  848. *
  849. * ctypedef float weight_t # <<<<<<<<<<<<<<
  850. * ctypedef uint64_t atom_t
  851. * ctypedef uint64_t feat_t
  852. */
  853. typedef float __pyx_t_5thinc_8typedefs_weight_t;
  854. /* "typedefs.pxd":8
  855. *
  856. * ctypedef float weight_t
  857. * ctypedef uint64_t atom_t # <<<<<<<<<<<<<<
  858. * ctypedef uint64_t feat_t
  859. * ctypedef uint64_t hash_t
  860. */
  861. typedef uint64_t __pyx_t_5thinc_8typedefs_atom_t;
  862. /* "typedefs.pxd":9
  863. * ctypedef float weight_t
  864. * ctypedef uint64_t atom_t
  865. * ctypedef uint64_t feat_t # <<<<<<<<<<<<<<
  866. * ctypedef uint64_t hash_t
  867. * ctypedef int32_t class_t
  868. */
  869. typedef uint64_t __pyx_t_5thinc_8typedefs_feat_t;
  870. /* "typedefs.pxd":10
  871. * ctypedef uint64_t atom_t
  872. * ctypedef uint64_t feat_t
  873. * ctypedef uint64_t hash_t # <<<<<<<<<<<<<<
  874. * ctypedef int32_t class_t
  875. * ctypedef uint32_t count_t
  876. */
  877. typedef uint64_t __pyx_t_5thinc_8typedefs_hash_t;
  878. /* "typedefs.pxd":11
  879. * ctypedef uint64_t feat_t
  880. * ctypedef uint64_t hash_t
  881. * ctypedef int32_t class_t # <<<<<<<<<<<<<<
  882. * ctypedef uint32_t count_t
  883. * ctypedef uint32_t time_t
  884. */
  885. typedef int32_t __pyx_t_5thinc_8typedefs_class_t;
  886. /* "typedefs.pxd":12
  887. * ctypedef uint64_t hash_t
  888. * ctypedef int32_t class_t
  889. * ctypedef uint32_t count_t # <<<<<<<<<<<<<<
  890. * ctypedef uint32_t time_t
  891. * ctypedef int32_t len_t
  892. */
  893. typedef uint32_t __pyx_t_5thinc_8typedefs_count_t;
  894. /* "typedefs.pxd":13
  895. * ctypedef int32_t class_t
  896. * ctypedef uint32_t count_t
  897. * ctypedef uint32_t time_t # <<<<<<<<<<<<<<
  898. * ctypedef int32_t len_t
  899. * ctypedef int32_t idx_t
  900. */
  901. typedef uint32_t __pyx_t_5thinc_8typedefs_time_t;
  902. /* "typedefs.pxd":14
  903. * ctypedef uint32_t count_t
  904. * ctypedef uint32_t time_t
  905. * ctypedef int32_t len_t # <<<<<<<<<<<<<<
  906. * ctypedef int32_t idx_t
  907. *
  908. */
  909. typedef int32_t __pyx_t_5thinc_8typedefs_len_t;
  910. /* "typedefs.pxd":15
  911. * ctypedef uint32_t time_t
  912. * ctypedef int32_t len_t
  913. * ctypedef int32_t idx_t # <<<<<<<<<<<<<<
  914. *
  915. *
  916. */
  917. typedef int32_t __pyx_t_5thinc_8typedefs_idx_t;
  918. /*--- Type declarations ---*/
  919. struct __pyx_obj_5cymem_5cymem_PyMalloc;
  920. struct __pyx_obj_5cymem_5cymem_PyFree;
  921. struct __pyx_obj_5cymem_5cymem_Pool;
  922. struct __pyx_obj_5cymem_5cymem_Address;
  923. struct __pyx_obj_7preshed_4maps_PreshMap;
  924. struct __pyx_obj_7preshed_4maps_PreshMapArray;
  925. struct __pyx_obj_5thinc_6linalg_Matrix;
  926. struct __pyx_obj_5thinc_6linalg_Vec;
  927. struct __pyx_obj_5thinc_6linalg_VecVec;
  928. struct __pyx_obj_5thinc_6linalg_Mat;
  929. struct __pyx_obj_5thinc_6linalg_MatVec;
  930. struct __pyx_obj_5thinc_6linalg_MatMat;
  931. /* "cymem/cymem.pxd":1
  932. * ctypedef void* (*malloc_t)(size_t n) # <<<<<<<<<<<<<<
  933. * ctypedef void (*free_t)(void *p)
  934. *
  935. */
  936. typedef void *(*__pyx_t_5cymem_5cymem_malloc_t)(size_t);
  937. /* "cymem/cymem.pxd":2
  938. * ctypedef void* (*malloc_t)(size_t n)
  939. * ctypedef void (*free_t)(void *p) # <<<<<<<<<<<<<<
  940. *
  941. * cdef class PyMalloc:
  942. */
  943. typedef void (*__pyx_t_5cymem_5cymem_free_t)(void *);
  944. struct __pyx_t_7preshed_4maps_Cell;
  945. struct __pyx_t_7preshed_4maps_MapStruct;
  946. /* "preshed/maps.pxd":8
  947. *
  948. *
  949. * cdef struct Cell: # <<<<<<<<<<<<<<
  950. * key_t key
  951. * void* value
  952. */
  953. struct __pyx_t_7preshed_4maps_Cell {
  954. __pyx_t_7preshed_4maps_key_t key;
  955. void *value;
  956. };
  957. /* "preshed/maps.pxd":13
  958. *
  959. *
  960. * cdef struct MapStruct: # <<<<<<<<<<<<<<
  961. * Cell* cells
  962. * void* value_for_empty_key
  963. */
  964. struct __pyx_t_7preshed_4maps_MapStruct {
  965. struct __pyx_t_7preshed_4maps_Cell *cells;
  966. void *value_for_empty_key;
  967. void *value_for_del_key;
  968. __pyx_t_7preshed_4maps_key_t length;
  969. __pyx_t_7preshed_4maps_key_t filled;
  970. int is_empty_key_set;
  971. int is_del_key_set;
  972. };
  973. struct __pyx_t_5thinc_7structs_ConstantsC;
  974. struct __pyx_t_5thinc_7structs_EmbedC;
  975. struct __pyx_t_5thinc_7structs_NeuralNetC;
  976. struct __pyx_t_5thinc_7structs_ExampleC;
  977. struct __pyx_t_5thinc_7structs_MinibatchC;
  978. struct __pyx_t_5thinc_7structs_SparseArrayC;
  979. struct __pyx_t_5thinc_7structs_FeatureC;
  980. struct __pyx_t_5thinc_7structs_SparseAverageC;
  981. struct __pyx_t_5thinc_7structs_TemplateC;
  982. /* "thinc/structs.pxd":14
  983. * include "compile_time_constants.pxi"
  984. *
  985. * ctypedef vector[weight_t] vector_weight_t # <<<<<<<<<<<<<<
  986. *
  987. *
  988. */
  989. typedef std::vector<__pyx_t_5thinc_8typedefs_weight_t> __pyx_t_5thinc_7structs_vector_weight_t;
  990. /* "thinc/structs.pxd":17
  991. *
  992. *
  993. * ctypedef void (*do_update_t)( # <<<<<<<<<<<<<<
  994. * weight_t* weights,
  995. * weight_t* gradient,
  996. */
  997. typedef void (*__pyx_t_5thinc_7structs_do_update_t)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_len_t, struct __pyx_t_5thinc_7structs_ConstantsC const *);
  998. /* "thinc/structs.pxd":25
  999. *
  1000. *
  1001. * ctypedef void (*do_feed_fwd_t)( # <<<<<<<<<<<<<<
  1002. * weight_t** fwd,
  1003. * const weight_t* W,
  1004. */
  1005. typedef void (*__pyx_t_5thinc_7structs_do_feed_fwd_t)(__pyx_t_5thinc_8typedefs_weight_t **, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_len_t const *, int, int, struct __pyx_t_5thinc_7structs_ConstantsC const *);
  1006. /* "thinc/structs.pxd":35
  1007. *
  1008. *
  1009. * ctypedef void (*do_feed_bwd_t)( # <<<<<<<<<<<<<<
  1010. * weight_t* G,
  1011. * weight_t** bwd,
  1012. */
  1013. typedef void (*__pyx_t_5thinc_7structs_do_feed_bwd_t)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t **, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *const *, __pyx_t_5thinc_8typedefs_len_t const *, int, int, struct __pyx_t_5thinc_7structs_ConstantsC const *);
  1014. /* "thinc/structs.pxd":48
  1015. *
  1016. * # Alias this, so that it matches our naming scheme
  1017. * ctypedef MapStruct MapC # <<<<<<<<<<<<<<
  1018. *
  1019. *
  1020. */
  1021. typedef struct __pyx_t_7preshed_4maps_MapStruct __pyx_t_5thinc_7structs_MapC;
  1022. /* "thinc/structs.pxd":51
  1023. *
  1024. *
  1025. * cdef struct ConstantsC: # <<<<<<<<<<<<<<
  1026. * weight_t a
  1027. * weight_t b
  1028. */
  1029. struct __pyx_t_5thinc_7structs_ConstantsC {
  1030. __pyx_t_5thinc_8typedefs_weight_t a;
  1031. __pyx_t_5thinc_8typedefs_weight_t b;
  1032. __pyx_t_5thinc_8typedefs_weight_t c;
  1033. __pyx_t_5thinc_8typedefs_weight_t d;
  1034. __pyx_t_5thinc_8typedefs_weight_t e;
  1035. __pyx_t_5thinc_8typedefs_weight_t g;
  1036. __pyx_t_5thinc_8typedefs_weight_t h;
  1037. __pyx_t_5thinc_8typedefs_weight_t i;
  1038. __pyx_t_5thinc_8typedefs_weight_t j;
  1039. __pyx_t_5thinc_8typedefs_weight_t k;
  1040. __pyx_t_5thinc_8typedefs_weight_t l;
  1041. __pyx_t_5thinc_8typedefs_weight_t m;
  1042. __pyx_t_5thinc_8typedefs_weight_t n;
  1043. __pyx_t_5thinc_8typedefs_weight_t o;
  1044. __pyx_t_5thinc_8typedefs_weight_t p;
  1045. __pyx_t_5thinc_8typedefs_weight_t q;
  1046. __pyx_t_5thinc_8typedefs_weight_t r;
  1047. __pyx_t_5thinc_8typedefs_weight_t s;
  1048. __pyx_t_5thinc_8typedefs_weight_t t;
  1049. __pyx_t_5thinc_8typedefs_weight_t u;
  1050. __pyx_t_5thinc_8typedefs_weight_t w;
  1051. __pyx_t_5thinc_8typedefs_weight_t x;
  1052. __pyx_t_5thinc_8typedefs_weight_t y;
  1053. __pyx_t_5thinc_8typedefs_weight_t z;
  1054. };
  1055. /* "thinc/structs.pxd":78
  1056. *
  1057. *
  1058. * cdef struct EmbedC: # <<<<<<<<<<<<<<
  1059. * MapC** weights
  1060. * MapC** gradients
  1061. */
  1062. struct __pyx_t_5thinc_7structs_EmbedC {
  1063. __pyx_t_5thinc_7structs_MapC **weights;
  1064. __pyx_t_5thinc_7structs_MapC **gradients;
  1065. __pyx_t_5thinc_8typedefs_weight_t **defaults;
  1066. __pyx_t_5thinc_8typedefs_weight_t **d_defaults;
  1067. __pyx_t_5thinc_8typedefs_idx_t *offsets;
  1068. __pyx_t_5thinc_8typedefs_len_t *lengths;
  1069. __pyx_t_5thinc_8typedefs_len_t nr;
  1070. int nr_support;
  1071. };
  1072. /* "thinc/structs.pxd":89
  1073. *
  1074. *
  1075. * cdef struct NeuralNetC: # <<<<<<<<<<<<<<
  1076. * do_feed_fwd_t feed_fwd
  1077. * do_feed_bwd_t feed_bwd
  1078. */
  1079. struct __pyx_t_5thinc_7structs_NeuralNetC {
  1080. __pyx_t_5thinc_7structs_do_feed_fwd_t feed_fwd;
  1081. __pyx_t_5thinc_7structs_do_feed_bwd_t feed_bwd;
  1082. __pyx_t_5thinc_7structs_do_update_t update;
  1083. __pyx_t_5thinc_8typedefs_len_t *widths;
  1084. __pyx_t_5thinc_8typedefs_weight_t *weights;
  1085. __pyx_t_5thinc_8typedefs_weight_t *gradient;
  1086. struct __pyx_t_5thinc_7structs_EmbedC *embed;
  1087. __pyx_t_5thinc_8typedefs_len_t nr_layer;
  1088. __pyx_t_5thinc_8typedefs_len_t nr_weight;
  1089. __pyx_t_5thinc_8typedefs_len_t nr_node;
  1090. struct __pyx_t_5thinc_7structs_ConstantsC hp;
  1091. };
  1092. /* "thinc/structs.pxd":112
  1093. *
  1094. *
  1095. * cdef struct ExampleC: # <<<<<<<<<<<<<<
  1096. * int* is_valid
  1097. * weight_t* costs
  1098. */
  1099. struct __pyx_t_5thinc_7structs_ExampleC {
  1100. int *is_valid;
  1101. __pyx_t_5thinc_8typedefs_weight_t *costs;
  1102. uint64_t *atoms;
  1103. struct __pyx_t_5thinc_7structs_FeatureC *features;
  1104. __pyx_t_5thinc_8typedefs_weight_t *scores;
  1105. int nr_class;
  1106. int nr_atom;
  1107. int nr_feat;
  1108. };
  1109. struct __pyx_t_5thinc_7structs_MinibatchC {
  1110. /* "thinc/structs.pxd":124
  1111. *
  1112. *
  1113. * cdef cppclass MinibatchC: # <<<<<<<<<<<<<<
  1114. * weight_t** _fwd
  1115. * weight_t** _bwd
  1116. */
  1117. __pyx_t_5thinc_8typedefs_weight_t **_fwd;
  1118. __pyx_t_5thinc_8typedefs_weight_t **_bwd;
  1119. struct __pyx_t_5thinc_7structs_FeatureC **_feats;
  1120. __pyx_t_5thinc_8typedefs_len_t *_nr_feat;
  1121. __pyx_t_5thinc_8typedefs_weight_t *_costs;
  1122. int *_is_valid;
  1123. uint64_t *signatures;
  1124. __pyx_t_5thinc_8typedefs_len_t *widths;
  1125. int i;
  1126. int nr_layer;
  1127. int batch_size;
  1128. void __pyx_f___init__MinibatchC(__pyx_t_5thinc_8typedefs_len_t *, int, int);
  1129. void __pyx_f___dealloc__MinibatchC(void);
  1130. virtual void reset(void);
  1131. virtual int nr_in(void);
  1132. virtual int nr_out(void);
  1133. virtual int push_back(struct __pyx_t_5thinc_7structs_FeatureC const *, int, __pyx_t_5thinc_8typedefs_weight_t const *, int const *, uint64_t);
  1134. virtual struct __pyx_t_5thinc_7structs_FeatureC *features(int);
  1135. virtual int nr_feat(int);
  1136. virtual __pyx_t_5thinc_8typedefs_weight_t *fwd(int, int);
  1137. virtual __pyx_t_5thinc_8typedefs_weight_t *bwd(int, int);
  1138. virtual __pyx_t_5thinc_8typedefs_weight_t *scores(int);
  1139. virtual __pyx_t_5thinc_8typedefs_weight_t *losses(int);
  1140. virtual __pyx_t_5thinc_8typedefs_weight_t *costs(int);
  1141. virtual int *is_valid(int);
  1142. virtual int guess(int);
  1143. virtual int best(int);
  1144. __pyx_t_5thinc_7structs_MinibatchC(__pyx_t_5thinc_8typedefs_len_t *__pyx_v_widths, int __pyx_v_nr_layer, int __pyx_v_batch_size) {
  1145. __pyx_f___init__MinibatchC(__pyx_v_widths, __pyx_v_nr_layer, __pyx_v_batch_size);
  1146. }
  1147. virtual ~__pyx_t_5thinc_7structs_MinibatchC() {
  1148. __pyx_f___dealloc__MinibatchC();
  1149. }
  1150. };
  1151. /* "thinc/structs.pxd":258
  1152. *
  1153. *
  1154. * cdef packed struct SparseArrayC: # <<<<<<<<<<<<<<
  1155. * int32_t key
  1156. * weight_t val
  1157. */
  1158. #if defined(__SUNPRO_C)
  1159. #pragma pack(1)
  1160. #elif !defined(__GNUC__)
  1161. #pragma pack(push, 1)
  1162. #endif
  1163. struct __Pyx_PACKED __pyx_t_5thinc_7structs_SparseArrayC {
  1164. int32_t key;
  1165. __pyx_t_5thinc_8typedefs_weight_t val;
  1166. };
  1167. #if defined(__SUNPRO_C)
  1168. #pragma pack()
  1169. #elif !defined(__GNUC__)
  1170. #pragma pack(pop)
  1171. #endif
  1172. /* "thinc/structs.pxd":263
  1173. *
  1174. *
  1175. * cdef struct FeatureC: # <<<<<<<<<<<<<<
  1176. * int i
  1177. * uint64_t key
  1178. */
  1179. struct __pyx_t_5thinc_7structs_FeatureC {
  1180. int i;
  1181. uint64_t key;
  1182. __pyx_t_5thinc_8typedefs_weight_t value;
  1183. };
  1184. /* "thinc/structs.pxd":269
  1185. *
  1186. *
  1187. * cdef struct SparseAverageC: # <<<<<<<<<<<<<<
  1188. * SparseArrayC* curr
  1189. * SparseArrayC* mom1
  1190. */
  1191. struct __pyx_t_5thinc_7structs_SparseAverageC {
  1192. struct __pyx_t_5thinc_7structs_SparseArrayC *curr;
  1193. struct __pyx_t_5thinc_7structs_SparseArrayC *mom1;
  1194. struct __pyx_t_5thinc_7structs_SparseArrayC *mom2;
  1195. struct __pyx_t_5thinc_7structs_SparseArrayC *avgs;
  1196. struct __pyx_t_5thinc_7structs_SparseArrayC *times;
  1197. struct __pyx_t_5thinc_7structs_SparseArrayC *penalties;
  1198. __pyx_t_5thinc_8typedefs_weight_t penalty;
  1199. };
  1200. /* "thinc/structs.pxd":279
  1201. *
  1202. *
  1203. * cdef struct TemplateC: # <<<<<<<<<<<<<<
  1204. * int[MAX_TEMPLATE_LEN] indices
  1205. * int length
  1206. */
  1207. struct __pyx_t_5thinc_7structs_TemplateC {
  1208. int indices[10];
  1209. int length;
  1210. __pyx_t_5thinc_8typedefs_atom_t atoms[10];
  1211. };
  1212. /* "cymem/cymem.pxd":4
  1213. * ctypedef void (*free_t)(void *p)
  1214. *
  1215. * cdef class PyMalloc: # <<<<<<<<<<<<<<
  1216. * cdef malloc_t malloc
  1217. * cdef void _set(self, malloc_t malloc)
  1218. */
  1219. struct __pyx_obj_5cymem_5cymem_PyMalloc {
  1220. PyObject_HEAD
  1221. struct __pyx_vtabstruct_5cymem_5cymem_PyMalloc *__pyx_vtab;
  1222. __pyx_t_5cymem_5cymem_malloc_t malloc;
  1223. };
  1224. /* "cymem/cymem.pxd":10
  1225. * cdef PyMalloc WrapMalloc(malloc_t malloc)
  1226. *
  1227. * cdef class PyFree: # <<<<<<<<<<<<<<
  1228. * cdef free_t free
  1229. * cdef void _set(self, free_t free)
  1230. */
  1231. struct __pyx_obj_5cymem_5cymem_PyFree {
  1232. PyObject_HEAD
  1233. struct __pyx_vtabstruct_5cymem_5cymem_PyFree *__pyx_vtab;
  1234. __pyx_t_5cymem_5cymem_free_t free;
  1235. };
  1236. /* "cymem/cymem.pxd":16
  1237. * cdef PyFree WrapFree(free_t free)
  1238. *
  1239. * cdef class Pool: # <<<<<<<<<<<<<<
  1240. * cdef readonly size_t size
  1241. * cdef readonly dict addresses
  1242. */
  1243. struct __pyx_obj_5cymem_5cymem_Pool {
  1244. PyObject_HEAD
  1245. struct __pyx_vtabstruct_5cymem_5cymem_Pool *__pyx_vtab;
  1246. size_t size;
  1247. PyObject *addresses;
  1248. PyObject *refs;
  1249. struct __pyx_obj_5cymem_5cymem_PyMalloc *pymalloc;
  1250. struct __pyx_obj_5cymem_5cymem_PyFree *pyfree;
  1251. };
  1252. /* "cymem/cymem.pxd":28
  1253. *
  1254. *
  1255. * cdef class Address: # <<<<<<<<<<<<<<
  1256. * cdef void* ptr
  1257. * cdef readonly PyMalloc pymalloc
  1258. */
  1259. struct __pyx_obj_5cymem_5cymem_Address {
  1260. PyObject_HEAD
  1261. void *ptr;
  1262. struct __pyx_obj_5cymem_5cymem_PyMalloc *pymalloc;
  1263. struct __pyx_obj_5cymem_5cymem_PyFree *pyfree;
  1264. };
  1265. /* "preshed/maps.pxd":36
  1266. *
  1267. *
  1268. * cdef class PreshMap: # <<<<<<<<<<<<<<
  1269. * cdef MapStruct* c_map
  1270. * cdef Pool mem
  1271. */
  1272. struct __pyx_obj_7preshed_4maps_PreshMap {
  1273. PyObject_HEAD
  1274. struct __pyx_vtabstruct_7preshed_4maps_PreshMap *__pyx_vtab;
  1275. struct __pyx_t_7preshed_4maps_MapStruct *c_map;
  1276. struct __pyx_obj_5cymem_5cymem_Pool *mem;
  1277. };
  1278. /* "preshed/maps.pxd":44
  1279. *
  1280. *
  1281. * cdef class PreshMapArray: # <<<<<<<<<<<<<<
  1282. * cdef Pool mem
  1283. * cdef MapStruct* maps
  1284. */
  1285. struct __pyx_obj_7preshed_4maps_PreshMapArray {
  1286. PyObject_HEAD
  1287. struct __pyx_vtabstruct_7preshed_4maps_PreshMapArray *__pyx_vtab;
  1288. struct __pyx_obj_5cymem_5cymem_Pool *mem;
  1289. struct __pyx_t_7preshed_4maps_MapStruct *maps;
  1290. size_t length;
  1291. };
  1292. /* "linalg.pxd":22
  1293. *
  1294. *
  1295. * cdef class Matrix: # <<<<<<<<<<<<<<
  1296. * cdef readonly Pool mem
  1297. * cdef weight_t* data
  1298. */
  1299. struct __pyx_obj_5thinc_6linalg_Matrix {
  1300. PyObject_HEAD
  1301. struct __pyx_obj_5cymem_5cymem_Pool *mem;
  1302. __pyx_t_5thinc_8typedefs_weight_t *data;
  1303. int32_t nr_row;
  1304. int32_t nr_col;
  1305. };
  1306. /* "linalg.pxd":29
  1307. *
  1308. *
  1309. * cdef class Vec: # <<<<<<<<<<<<<<
  1310. * @staticmethod
  1311. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil:
  1312. */
  1313. struct __pyx_obj_5thinc_6linalg_Vec {
  1314. PyObject_HEAD
  1315. struct __pyx_vtabstruct_5thinc_6linalg_Vec *__pyx_vtab;
  1316. };
  1317. /* "linalg.pxd":140
  1318. *
  1319. *
  1320. * cdef class VecVec: # <<<<<<<<<<<<<<
  1321. * @staticmethod
  1322. * cdef inline void add(weight_t* output,
  1323. */
  1324. struct __pyx_obj_5thinc_6linalg_VecVec {
  1325. PyObject_HEAD
  1326. struct __pyx_vtabstruct_5thinc_6linalg_VecVec *__pyx_vtab;
  1327. };
  1328. /* "linalg.pxd":231
  1329. *
  1330. *
  1331. * cdef class Mat: # <<<<<<<<<<<<<<
  1332. * @staticmethod
  1333. * cdef inline void mean_row(weight_t* Ex,
  1334. */
  1335. struct __pyx_obj_5thinc_6linalg_Mat {
  1336. PyObject_HEAD
  1337. struct __pyx_vtabstruct_5thinc_6linalg_Mat *__pyx_vtab;
  1338. };
  1339. /* "linalg.pxd":259
  1340. *
  1341. *
  1342. * cdef class MatVec: # <<<<<<<<<<<<<<
  1343. * @staticmethod
  1344. * cdef inline void add_i(weight_t* mat,
  1345. */
  1346. struct __pyx_obj_5thinc_6linalg_MatVec {
  1347. PyObject_HEAD
  1348. struct __pyx_vtabstruct_5thinc_6linalg_MatVec *__pyx_vtab;
  1349. };
  1350. /* "linalg.pxd":425
  1351. *
  1352. *
  1353. * cdef class MatMat: # <<<<<<<<<<<<<<
  1354. * @staticmethod
  1355. * cdef inline void add(weight_t* output,
  1356. */
  1357. struct __pyx_obj_5thinc_6linalg_MatMat {
  1358. PyObject_HEAD
  1359. struct __pyx_vtabstruct_5thinc_6linalg_MatMat *__pyx_vtab;
  1360. };
  1361. /* "cymem/cymem.pxd":4
  1362. * ctypedef void (*free_t)(void *p)
  1363. *
  1364. * cdef class PyMalloc: # <<<<<<<<<<<<<<
  1365. * cdef malloc_t malloc
  1366. * cdef void _set(self, malloc_t malloc)
  1367. */
  1368. struct __pyx_vtabstruct_5cymem_5cymem_PyMalloc {
  1369. void (*_set)(struct __pyx_obj_5cymem_5cymem_PyMalloc *, __pyx_t_5cymem_5cymem_malloc_t);
  1370. };
  1371. static struct __pyx_vtabstruct_5cymem_5cymem_PyMalloc *__pyx_vtabptr_5cymem_5cymem_PyMalloc;
  1372. /* "cymem/cymem.pxd":10
  1373. * cdef PyMalloc WrapMalloc(malloc_t malloc)
  1374. *
  1375. * cdef class PyFree: # <<<<<<<<<<<<<<
  1376. * cdef free_t free
  1377. * cdef void _set(self, free_t free)
  1378. */
  1379. struct __pyx_vtabstruct_5cymem_5cymem_PyFree {
  1380. void (*_set)(struct __pyx_obj_5cymem_5cymem_PyFree *, __pyx_t_5cymem_5cymem_free_t);
  1381. };
  1382. static struct __pyx_vtabstruct_5cymem_5cymem_PyFree *__pyx_vtabptr_5cymem_5cymem_PyFree;
  1383. /* "cymem/cymem.pxd":16
  1384. * cdef PyFree WrapFree(free_t free)
  1385. *
  1386. * cdef class Pool: # <<<<<<<<<<<<<<
  1387. * cdef readonly size_t size
  1388. * cdef readonly dict addresses
  1389. */
  1390. struct __pyx_vtabstruct_5cymem_5cymem_Pool {
  1391. void *(*alloc)(struct __pyx_obj_5cymem_5cymem_Pool *, size_t, size_t);
  1392. void (*free)(struct __pyx_obj_5cymem_5cymem_Pool *, void *);
  1393. void *(*realloc)(struct __pyx_obj_5cymem_5cymem_Pool *, void *, size_t);
  1394. };
  1395. static struct __pyx_vtabstruct_5cymem_5cymem_Pool *__pyx_vtabptr_5cymem_5cymem_Pool;
  1396. /* "preshed/maps.pxd":36
  1397. *
  1398. *
  1399. * cdef class PreshMap: # <<<<<<<<<<<<<<
  1400. * cdef MapStruct* c_map
  1401. * cdef Pool mem
  1402. */
  1403. struct __pyx_vtabstruct_7preshed_4maps_PreshMap {
  1404. void *(*get)(struct __pyx_obj_7preshed_4maps_PreshMap *, __pyx_t_7preshed_4maps_key_t);
  1405. void (*set)(struct __pyx_obj_7preshed_4maps_PreshMap *, __pyx_t_7preshed_4maps_key_t, void *);
  1406. };
  1407. static struct __pyx_vtabstruct_7preshed_4maps_PreshMap *__pyx_vtabptr_7preshed_4maps_PreshMap;
  1408. /* "preshed/maps.pxd":44
  1409. *
  1410. *
  1411. * cdef class PreshMapArray: # <<<<<<<<<<<<<<
  1412. * cdef Pool mem
  1413. * cdef MapStruct* maps
  1414. */
  1415. struct __pyx_vtabstruct_7preshed_4maps_PreshMapArray {
  1416. void *(*get)(struct __pyx_obj_7preshed_4maps_PreshMapArray *, size_t, __pyx_t_7preshed_4maps_key_t);
  1417. void (*set)(struct __pyx_obj_7preshed_4maps_PreshMapArray *, size_t, __pyx_t_7preshed_4maps_key_t, void *);
  1418. };
  1419. static struct __pyx_vtabstruct_7preshed_4maps_PreshMapArray *__pyx_vtabptr_7preshed_4maps_PreshMapArray;
  1420. /* "linalg.pxd":29
  1421. *
  1422. *
  1423. * cdef class Vec: # <<<<<<<<<<<<<<
  1424. * @staticmethod
  1425. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil:
  1426. */
  1427. struct __pyx_vtabstruct_5thinc_6linalg_Vec {
  1428. int (*arg_max)(__pyx_t_5thinc_8typedefs_weight_t const *, int const );
  1429. __pyx_t_5thinc_8typedefs_weight_t (*max)(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1430. __pyx_t_5thinc_8typedefs_weight_t (*sum)(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1431. __pyx_t_5thinc_8typedefs_weight_t (*norm)(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1432. void (*add)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1433. void (*add_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1434. void (*mul)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1435. void (*mul_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1436. void (*pow)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1437. void (*pow_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const , int32_t);
  1438. void (*div)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1439. void (*div_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const , int32_t);
  1440. void (*exp)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1441. void (*exp_i)(__pyx_t_5thinc_8typedefs_weight_t *, int32_t);
  1442. void (*reciprocal_i)(__pyx_t_5thinc_8typedefs_weight_t *, int32_t);
  1443. };
  1444. static struct __pyx_vtabstruct_5thinc_6linalg_Vec *__pyx_vtabptr_5thinc_6linalg_Vec;
  1445. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_3Vec_arg_max(__pyx_t_5thinc_8typedefs_weight_t const *, int const );
  1446. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_max(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1447. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_sum(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1448. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_norm(__pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1449. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1450. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1451. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1452. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1453. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1454. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const , int32_t);
  1455. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1456. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const , int32_t);
  1457. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1458. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp_i(__pyx_t_5thinc_8typedefs_weight_t *, int32_t);
  1459. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_reciprocal_i(__pyx_t_5thinc_8typedefs_weight_t *, int32_t);
  1460. /* "linalg.pxd":140
  1461. *
  1462. *
  1463. * cdef class VecVec: # <<<<<<<<<<<<<<
  1464. * @staticmethod
  1465. * cdef inline void add(weight_t* output,
  1466. */
  1467. struct __pyx_vtabstruct_5thinc_6linalg_VecVec {
  1468. void (*add)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1469. void (*add_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1470. void (*batch_add_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t, int32_t);
  1471. void (*add_pow)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1472. void (*add_pow_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1473. void (*mul)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1474. void (*mul_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1475. __pyx_t_5thinc_8typedefs_weight_t (*dot)(__pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1476. int (*arg_max_if_true)(__pyx_t_5thinc_8typedefs_weight_t const *, int const *, int const );
  1477. int (*arg_max_if_zero)(__pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int const );
  1478. };
  1479. static struct __pyx_vtabstruct_5thinc_6linalg_VecVec *__pyx_vtabptr_5thinc_6linalg_VecVec;
  1480. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1481. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1482. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_batch_add_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t, int32_t);
  1483. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1484. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t);
  1485. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1486. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1487. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_6VecVec_dot(__pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t);
  1488. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_true(__pyx_t_5thinc_8typedefs_weight_t const *, int const *, int const );
  1489. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_zero(__pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int const );
  1490. /* "linalg.pxd":231
  1491. *
  1492. *
  1493. * cdef class Mat: # <<<<<<<<<<<<<<
  1494. * @staticmethod
  1495. * cdef inline void mean_row(weight_t* Ex,
  1496. */
  1497. struct __pyx_vtabstruct_5thinc_6linalg_Mat {
  1498. void (*mean_row)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1499. void (*var_row)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, __pyx_t_5thinc_8typedefs_weight_t);
  1500. };
  1501. static struct __pyx_vtabstruct_5thinc_6linalg_Mat *__pyx_vtabptr_5thinc_6linalg_Mat;
  1502. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_mean_row(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1503. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_var_row(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, __pyx_t_5thinc_8typedefs_weight_t);
  1504. /* "linalg.pxd":259
  1505. *
  1506. *
  1507. * cdef class MatVec: # <<<<<<<<<<<<<<
  1508. * @staticmethod
  1509. * cdef inline void add_i(weight_t* mat,
  1510. */
  1511. struct __pyx_vtabstruct_5thinc_6linalg_MatVec {
  1512. void (*add_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t, int32_t);
  1513. void (*mul)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1514. void (*mul_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1515. void (*dot)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1516. void (*batch_dot)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1517. void (*T_dot)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1518. void (*batch_T_dot)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1519. };
  1520. static struct __pyx_vtabstruct_5thinc_6linalg_MatVec *__pyx_vtabptr_5thinc_6linalg_MatVec;
  1521. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t, int32_t, int32_t);
  1522. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1523. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1524. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_dot(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1525. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_dot(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1526. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_T_dot(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1527. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_T_dot(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1528. /* "linalg.pxd":425
  1529. *
  1530. *
  1531. * cdef class MatMat: # <<<<<<<<<<<<<<
  1532. * @staticmethod
  1533. * cdef inline void add(weight_t* output,
  1534. */
  1535. struct __pyx_vtabstruct_5thinc_6linalg_MatMat {
  1536. void (*add)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1537. void (*add_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1538. void (*mul)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1539. void (*mul_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1540. void (*add_outer_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1541. void (*batch_add_outer_i)(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1542. };
  1543. static struct __pyx_vtabstruct_5thinc_6linalg_MatMat *__pyx_vtabptr_5thinc_6linalg_MatMat;
  1544. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1545. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1546. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1547. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1548. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t);
  1549. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_batch_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *, __pyx_t_5thinc_8typedefs_weight_t const *, __pyx_t_5thinc_8typedefs_weight_t const *, int32_t, int32_t, int32_t);
  1550. /* --- Runtime support code (head) --- */
  1551. /* Refnanny.proto */
  1552. #ifndef CYTHON_REFNANNY
  1553. #define CYTHON_REFNANNY 0
  1554. #endif
  1555. #if CYTHON_REFNANNY
  1556. typedef struct {
  1557. void (*INCREF)(void*, PyObject*, int);
  1558. void (*DECREF)(void*, PyObject*, int);
  1559. void (*GOTREF)(void*, PyObject*, int);
  1560. void (*GIVEREF)(void*, PyObject*, int);
  1561. void* (*SetupContext)(const char*, int, const char*);
  1562. void (*FinishContext)(void**);
  1563. } __Pyx_RefNannyAPIStruct;
  1564. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  1565. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  1566. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  1567. #ifdef WITH_THREAD
  1568. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  1569. if (acquire_gil) {\
  1570. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
  1571. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  1572. PyGILState_Release(__pyx_gilstate_save);\
  1573. } else {\
  1574. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  1575. }
  1576. #else
  1577. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  1578. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  1579. #endif
  1580. #define __Pyx_RefNannyFinishContext()\
  1581. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  1582. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  1583. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  1584. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  1585. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  1586. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  1587. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  1588. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  1589. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  1590. #else
  1591. #define __Pyx_RefNannyDeclarations
  1592. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  1593. #define __Pyx_RefNannyFinishContext()
  1594. #define __Pyx_INCREF(r) Py_INCREF(r)
  1595. #define __Pyx_DECREF(r) Py_DECREF(r)
  1596. #define __Pyx_GOTREF(r)
  1597. #define __Pyx_GIVEREF(r)
  1598. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  1599. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  1600. #define __Pyx_XGOTREF(r)
  1601. #define __Pyx_XGIVEREF(r)
  1602. #endif
  1603. #define __Pyx_XDECREF_SET(r, v) do {\
  1604. PyObject *tmp = (PyObject *) r;\
  1605. r = v; __Pyx_XDECREF(tmp);\
  1606. } while (0)
  1607. #define __Pyx_DECREF_SET(r, v) do {\
  1608. PyObject *tmp = (PyObject *) r;\
  1609. r = v; __Pyx_DECREF(tmp);\
  1610. } while (0)
  1611. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  1612. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  1613. /* PyObjectGetAttrStr.proto */
  1614. #if CYTHON_USE_TYPE_SLOTS
  1615. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
  1616. #else
  1617. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  1618. #endif
  1619. /* GetBuiltinName.proto */
  1620. static PyObject *__Pyx_GetBuiltinName(PyObject *name);
  1621. /* TypeImport.proto */
  1622. #ifndef __PYX_HAVE_RT_ImportType_proto
  1623. #define __PYX_HAVE_RT_ImportType_proto
  1624. enum __Pyx_ImportType_CheckSize {
  1625. __Pyx_ImportType_CheckSize_Error = 0,
  1626. __Pyx_ImportType_CheckSize_Warn = 1,
  1627. __Pyx_ImportType_CheckSize_Ignore = 2
  1628. };
  1629. static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
  1630. #endif
  1631. /* GetVTable.proto */
  1632. static void* __Pyx_GetVtable(PyObject *dict);
  1633. /* PyThreadStateGet.proto */
  1634. #if CYTHON_FAST_THREAD_STATE
  1635. #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
  1636. #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
  1637. #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
  1638. #else
  1639. #define __Pyx_PyThreadState_declare
  1640. #define __Pyx_PyThreadState_assign
  1641. #define __Pyx_PyErr_Occurred() PyErr_Occurred()
  1642. #endif
  1643. /* PyErrFetchRestore.proto */
  1644. #if CYTHON_FAST_THREAD_STATE
  1645. #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
  1646. #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
  1647. #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
  1648. #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
  1649. #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
  1650. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  1651. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  1652. #if CYTHON_COMPILING_IN_CPYTHON
  1653. #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
  1654. #else
  1655. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  1656. #endif
  1657. #else
  1658. #define __Pyx_PyErr_Clear() PyErr_Clear()
  1659. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  1660. #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
  1661. #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
  1662. #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
  1663. #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
  1664. #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
  1665. #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
  1666. #endif
  1667. /* CLineInTraceback.proto */
  1668. #ifdef CYTHON_CLINE_IN_TRACEBACK
  1669. #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
  1670. #else
  1671. static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
  1672. #endif
  1673. /* CodeObjectCache.proto */
  1674. typedef struct {
  1675. PyCodeObject* code_object;
  1676. int code_line;
  1677. } __Pyx_CodeObjectCacheEntry;
  1678. struct __Pyx_CodeObjectCache {
  1679. int count;
  1680. int max_count;
  1681. __Pyx_CodeObjectCacheEntry* entries;
  1682. };
  1683. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  1684. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  1685. static PyCodeObject *__pyx_find_code_object(int code_line);
  1686. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  1687. /* AddTraceback.proto */
  1688. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  1689. int py_line, const char *filename);
  1690. /* CIntToPy.proto */
  1691. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
  1692. /* CIntToPy.proto */
  1693. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);
  1694. /* CIntFromPy.proto */
  1695. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
  1696. /* CIntFromPy.proto */
  1697. static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);
  1698. /* CIntToPy.proto */
  1699. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
  1700. /* CIntFromPy.proto */
  1701. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
  1702. /* FastTypeChecks.proto */
  1703. #if CYTHON_COMPILING_IN_CPYTHON
  1704. #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
  1705. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
  1706. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
  1707. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
  1708. #else
  1709. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  1710. #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
  1711. #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
  1712. #endif
  1713. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  1714. /* CheckBinaryVersion.proto */
  1715. static int __Pyx_check_binary_version(void);
  1716. /* FunctionImport.proto */
  1717. static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);
  1718. /* InitStrings.proto */
  1719. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
  1720. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_3Vec_arg_max(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, int const __pyx_v_n_classes); /* proto*/
  1721. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_max(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, int32_t __pyx_v_nr); /* proto*/
  1722. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_sum(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr); /* proto*/
  1723. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_norm(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr); /* proto*/
  1724. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_inc, int32_t __pyx_v_nr); /* proto*/
  1725. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_inc, int32_t __pyx_v_nr); /* proto*/
  1726. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1727. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1728. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1729. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t const __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1730. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1731. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t const __pyx_v_scal, int32_t __pyx_v_nr); /* proto*/
  1732. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr); /* proto*/
  1733. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, int32_t __pyx_v_nr); /* proto*/
  1734. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_reciprocal_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, int32_t __pyx_v_nr); /* proto*/
  1735. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr); /* proto*/
  1736. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr); /* proto*/
  1737. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_batch_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr, int32_t __pyx_v_nr_batch); /* proto*/
  1738. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_power, int32_t __pyx_v_nr); /* proto*/
  1739. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_power, int32_t __pyx_v_nr); /* proto*/
  1740. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr); /* proto*/
  1741. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr); /* proto*/
  1742. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_6VecVec_dot(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr); /* proto*/
  1743. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_true(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, int const *__pyx_v_is_valid, int const __pyx_v_n_classes); /* proto*/
  1744. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_zero(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_costs, int const __pyx_v_n_classes); /* proto*/
  1745. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_mean_row(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_Ex, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1746. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_var_row(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_Vx, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_Ex, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_eps); /* proto*/
  1747. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1748. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1749. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1750. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1751. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch); /* proto*/
  1752. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_T_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1753. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_T_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch); /* proto*/
  1754. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1755. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1756. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1757. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1758. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col); /* proto*/
  1759. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_batch_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch); /* proto*/
  1760. /* Module declarations from 'libc.stdint' */
  1761. /* Module declarations from 'cymem.cymem' */
  1762. static PyTypeObject *__pyx_ptype_5cymem_5cymem_PyMalloc = 0;
  1763. static PyTypeObject *__pyx_ptype_5cymem_5cymem_PyFree = 0;
  1764. static PyTypeObject *__pyx_ptype_5cymem_5cymem_Pool = 0;
  1765. static PyTypeObject *__pyx_ptype_5cymem_5cymem_Address = 0;
  1766. /* Module declarations from 'preshed.maps' */
  1767. static PyTypeObject *__pyx_ptype_7preshed_4maps_PreshMap = 0;
  1768. static PyTypeObject *__pyx_ptype_7preshed_4maps_PreshMapArray = 0;
  1769. /* Module declarations from 'libcpp.vector' */
  1770. /* Module declarations from 'libc.string' */
  1771. /* Module declarations from 'libc.stdlib' */
  1772. /* Module declarations from 'murmurhash.mrmr' */
  1773. static uint64_t (*__pyx_f_10murmurhash_4mrmr_real_hash64)(void *, int, uint64_t); /*proto*/
  1774. /* Module declarations from 'thinc.typedefs' */
  1775. /* Module declarations from 'cython' */
  1776. /* Module declarations from 'thinc.linalg' */
  1777. static PyTypeObject *__pyx_ptype_5thinc_6linalg_Matrix = 0;
  1778. static PyTypeObject *__pyx_ptype_5thinc_6linalg_Vec = 0;
  1779. static PyTypeObject *__pyx_ptype_5thinc_6linalg_VecVec = 0;
  1780. static PyTypeObject *__pyx_ptype_5thinc_6linalg_Mat = 0;
  1781. static PyTypeObject *__pyx_ptype_5thinc_6linalg_MatVec = 0;
  1782. static PyTypeObject *__pyx_ptype_5thinc_6linalg_MatMat = 0;
  1783. /* Module declarations from 'thinc.structs' */
  1784. #define __Pyx_MODULE_NAME "thinc.structs"
  1785. extern int __pyx_module_is_main_thinc__structs;
  1786. int __pyx_module_is_main_thinc__structs = 0;
  1787. /* Implementation of 'thinc.structs' */
  1788. static PyObject *__pyx_builtin_range;
  1789. static const char __pyx_k_main[] = "__main__";
  1790. static const char __pyx_k_name[] = "__name__";
  1791. static const char __pyx_k_test[] = "__test__";
  1792. static const char __pyx_k_range[] = "range";
  1793. static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
  1794. static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
  1795. static PyObject *__pyx_n_s_cline_in_traceback;
  1796. static PyObject *__pyx_n_s_main;
  1797. static PyObject *__pyx_n_s_name;
  1798. static PyObject *__pyx_n_s_pyx_vtable;
  1799. static PyObject *__pyx_n_s_range;
  1800. static PyObject *__pyx_n_s_test;
  1801. /* Late includes */
  1802. /* "thinc/structs.pxd":140
  1803. * int batch_size
  1804. *
  1805. * __init__(len_t* widths, int nr_layer, int batch_size) nogil: # <<<<<<<<<<<<<<
  1806. * this.i = 0
  1807. * this.nr_layer = nr_layer
  1808. */
  1809. void __pyx_t_5thinc_7structs_MinibatchC::__pyx_f___init__MinibatchC(__pyx_t_5thinc_8typedefs_len_t *__pyx_v_widths, int __pyx_v_nr_layer, int __pyx_v_batch_size) {
  1810. int __pyx_v_i;
  1811. int __pyx_t_1;
  1812. int __pyx_t_2;
  1813. int __pyx_t_3;
  1814. /* "thinc/structs.pxd":141
  1815. *
  1816. * __init__(len_t* widths, int nr_layer, int batch_size) nogil:
  1817. * this.i = 0 # <<<<<<<<<<<<<<
  1818. * this.nr_layer = nr_layer
  1819. * this.batch_size = batch_size
  1820. */
  1821. this->i = 0;
  1822. /* "thinc/structs.pxd":142
  1823. * __init__(len_t* widths, int nr_layer, int batch_size) nogil:
  1824. * this.i = 0
  1825. * this.nr_layer = nr_layer # <<<<<<<<<<<<<<
  1826. * this.batch_size = batch_size
  1827. * this.widths = <len_t*>calloc(nr_layer, sizeof(len_t))
  1828. */
  1829. this->nr_layer = __pyx_v_nr_layer;
  1830. /* "thinc/structs.pxd":143
  1831. * this.i = 0
  1832. * this.nr_layer = nr_layer
  1833. * this.batch_size = batch_size # <<<<<<<<<<<<<<
  1834. * this.widths = <len_t*>calloc(nr_layer, sizeof(len_t))
  1835. * this._fwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1836. */
  1837. this->batch_size = __pyx_v_batch_size;
  1838. /* "thinc/structs.pxd":144
  1839. * this.nr_layer = nr_layer
  1840. * this.batch_size = batch_size
  1841. * this.widths = <len_t*>calloc(nr_layer, sizeof(len_t)) # <<<<<<<<<<<<<<
  1842. * this._fwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1843. * this._bwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1844. */
  1845. this->widths = ((__pyx_t_5thinc_8typedefs_len_t *)calloc(__pyx_v_nr_layer, (sizeof(__pyx_t_5thinc_8typedefs_len_t))));
  1846. /* "thinc/structs.pxd":145
  1847. * this.batch_size = batch_size
  1848. * this.widths = <len_t*>calloc(nr_layer, sizeof(len_t))
  1849. * this._fwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*)) # <<<<<<<<<<<<<<
  1850. * this._bwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1851. * for i in range(nr_layer):
  1852. */
  1853. this->_fwd = ((__pyx_t_5thinc_8typedefs_weight_t **)calloc(__pyx_v_nr_layer, (sizeof(__pyx_t_5thinc_8typedefs_weight_t *))));
  1854. /* "thinc/structs.pxd":146
  1855. * this.widths = <len_t*>calloc(nr_layer, sizeof(len_t))
  1856. * this._fwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1857. * this._bwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*)) # <<<<<<<<<<<<<<
  1858. * for i in range(nr_layer):
  1859. * this.widths[i] = widths[i]
  1860. */
  1861. this->_bwd = ((__pyx_t_5thinc_8typedefs_weight_t **)calloc(__pyx_v_nr_layer, (sizeof(__pyx_t_5thinc_8typedefs_weight_t *))));
  1862. /* "thinc/structs.pxd":147
  1863. * this._fwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1864. * this._bwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1865. * for i in range(nr_layer): # <<<<<<<<<<<<<<
  1866. * this.widths[i] = widths[i]
  1867. * this._fwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1868. */
  1869. __pyx_t_1 = __pyx_v_nr_layer;
  1870. __pyx_t_2 = __pyx_t_1;
  1871. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  1872. __pyx_v_i = __pyx_t_3;
  1873. /* "thinc/structs.pxd":148
  1874. * this._bwd = <weight_t**>calloc(nr_layer, sizeof(weight_t*))
  1875. * for i in range(nr_layer):
  1876. * this.widths[i] = widths[i] # <<<<<<<<<<<<<<
  1877. * this._fwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1878. * this._bwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1879. */
  1880. (this->widths[__pyx_v_i]) = (__pyx_v_widths[__pyx_v_i]);
  1881. /* "thinc/structs.pxd":149
  1882. * for i in range(nr_layer):
  1883. * this.widths[i] = widths[i]
  1884. * this._fwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t)) # <<<<<<<<<<<<<<
  1885. * this._bwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1886. * this._feats = <FeatureC**>calloc(batch_size, sizeof(void*))
  1887. */
  1888. (this->_fwd[__pyx_v_i]) = ((__pyx_t_5thinc_8typedefs_weight_t *)calloc(((this->widths[__pyx_v_i]) * __pyx_v_batch_size), (sizeof(__pyx_t_5thinc_8typedefs_weight_t))));
  1889. /* "thinc/structs.pxd":150
  1890. * this.widths[i] = widths[i]
  1891. * this._fwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1892. * this._bwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t)) # <<<<<<<<<<<<<<
  1893. * this._feats = <FeatureC**>calloc(batch_size, sizeof(void*))
  1894. * this._nr_feat = <len_t*>calloc(batch_size, sizeof(len_t))
  1895. */
  1896. (this->_bwd[__pyx_v_i]) = ((__pyx_t_5thinc_8typedefs_weight_t *)calloc(((this->widths[__pyx_v_i]) * __pyx_v_batch_size), (sizeof(__pyx_t_5thinc_8typedefs_weight_t))));
  1897. }
  1898. /* "thinc/structs.pxd":151
  1899. * this._fwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1900. * this._bwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1901. * this._feats = <FeatureC**>calloc(batch_size, sizeof(void*)) # <<<<<<<<<<<<<<
  1902. * this._nr_feat = <len_t*>calloc(batch_size, sizeof(len_t))
  1903. * this._is_valid = <int*>calloc(batch_size * widths[nr_layer-1], sizeof(int))
  1904. */
  1905. this->_feats = ((struct __pyx_t_5thinc_7structs_FeatureC **)calloc(__pyx_v_batch_size, (sizeof(void *))));
  1906. /* "thinc/structs.pxd":152
  1907. * this._bwd[i] = <weight_t*>calloc(this.widths[i] * batch_size, sizeof(weight_t))
  1908. * this._feats = <FeatureC**>calloc(batch_size, sizeof(void*))
  1909. * this._nr_feat = <len_t*>calloc(batch_size, sizeof(len_t)) # <<<<<<<<<<<<<<
  1910. * this._is_valid = <int*>calloc(batch_size * widths[nr_layer-1], sizeof(int))
  1911. * this._costs = <weight_t*>calloc(batch_size * widths[nr_layer-1], sizeof(weight_t))
  1912. */
  1913. this->_nr_feat = ((__pyx_t_5thinc_8typedefs_len_t *)calloc(__pyx_v_batch_size, (sizeof(__pyx_t_5thinc_8typedefs_len_t))));
  1914. /* "thinc/structs.pxd":153
  1915. * this._feats = <FeatureC**>calloc(batch_size, sizeof(void*))
  1916. * this._nr_feat = <len_t*>calloc(batch_size, sizeof(len_t))
  1917. * this._is_valid = <int*>calloc(batch_size * widths[nr_layer-1], sizeof(int)) # <<<<<<<<<<<<<<
  1918. * this._costs = <weight_t*>calloc(batch_size * widths[nr_layer-1], sizeof(weight_t))
  1919. * this.signatures = <uint64_t*>calloc(batch_size, sizeof(uint64_t))
  1920. */
  1921. this->_is_valid = ((int *)calloc((__pyx_v_batch_size * (__pyx_v_widths[(__pyx_v_nr_layer - 1)])), (sizeof(int))));
  1922. /* "thinc/structs.pxd":154
  1923. * this._nr_feat = <len_t*>calloc(batch_size, sizeof(len_t))
  1924. * this._is_valid = <int*>calloc(batch_size * widths[nr_layer-1], sizeof(int))
  1925. * this._costs = <weight_t*>calloc(batch_size * widths[nr_layer-1], sizeof(weight_t)) # <<<<<<<<<<<<<<
  1926. * this.signatures = <uint64_t*>calloc(batch_size, sizeof(uint64_t))
  1927. *
  1928. */
  1929. this->_costs = ((__pyx_t_5thinc_8typedefs_weight_t *)calloc((__pyx_v_batch_size * (__pyx_v_widths[(__pyx_v_nr_layer - 1)])), (sizeof(__pyx_t_5thinc_8typedefs_weight_t))));
  1930. /* "thinc/structs.pxd":155
  1931. * this._is_valid = <int*>calloc(batch_size * widths[nr_layer-1], sizeof(int))
  1932. * this._costs = <weight_t*>calloc(batch_size * widths[nr_layer-1], sizeof(weight_t))
  1933. * this.signatures = <uint64_t*>calloc(batch_size, sizeof(uint64_t)) # <<<<<<<<<<<<<<
  1934. *
  1935. * __dealloc__() nogil:
  1936. */
  1937. this->signatures = ((uint64_t *)calloc(__pyx_v_batch_size, (sizeof(uint64_t))));
  1938. /* "thinc/structs.pxd":140
  1939. * int batch_size
  1940. *
  1941. * __init__(len_t* widths, int nr_layer, int batch_size) nogil: # <<<<<<<<<<<<<<
  1942. * this.i = 0
  1943. * this.nr_layer = nr_layer
  1944. */
  1945. /* function exit code */
  1946. }
  1947. /* "thinc/structs.pxd":157
  1948. * this.signatures = <uint64_t*>calloc(batch_size, sizeof(uint64_t))
  1949. *
  1950. * __dealloc__() nogil: # <<<<<<<<<<<<<<
  1951. * free(this.widths)
  1952. * for i in range(this.nr_layer):
  1953. */
  1954. void __pyx_t_5thinc_7structs_MinibatchC::__pyx_f___dealloc__MinibatchC(void) {
  1955. int __pyx_v_i;
  1956. int __pyx_t_1;
  1957. int __pyx_t_2;
  1958. int __pyx_t_3;
  1959. /* "thinc/structs.pxd":158
  1960. *
  1961. * __dealloc__() nogil:
  1962. * free(this.widths) # <<<<<<<<<<<<<<
  1963. * for i in range(this.nr_layer):
  1964. * free(this._fwd[i])
  1965. */
  1966. free(this->widths);
  1967. /* "thinc/structs.pxd":159
  1968. * __dealloc__() nogil:
  1969. * free(this.widths)
  1970. * for i in range(this.nr_layer): # <<<<<<<<<<<<<<
  1971. * free(this._fwd[i])
  1972. * free(this._bwd[i])
  1973. */
  1974. __pyx_t_1 = this->nr_layer;
  1975. __pyx_t_2 = __pyx_t_1;
  1976. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  1977. __pyx_v_i = __pyx_t_3;
  1978. /* "thinc/structs.pxd":160
  1979. * free(this.widths)
  1980. * for i in range(this.nr_layer):
  1981. * free(this._fwd[i]) # <<<<<<<<<<<<<<
  1982. * free(this._bwd[i])
  1983. * for i in range(this.i):
  1984. */
  1985. free((this->_fwd[__pyx_v_i]));
  1986. /* "thinc/structs.pxd":161
  1987. * for i in range(this.nr_layer):
  1988. * free(this._fwd[i])
  1989. * free(this._bwd[i]) # <<<<<<<<<<<<<<
  1990. * for i in range(this.i):
  1991. * free(this._feats[i])
  1992. */
  1993. free((this->_bwd[__pyx_v_i]));
  1994. }
  1995. /* "thinc/structs.pxd":162
  1996. * free(this._fwd[i])
  1997. * free(this._bwd[i])
  1998. * for i in range(this.i): # <<<<<<<<<<<<<<
  1999. * free(this._feats[i])
  2000. * free(this._fwd)
  2001. */
  2002. __pyx_t_1 = this->i;
  2003. __pyx_t_2 = __pyx_t_1;
  2004. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  2005. __pyx_v_i = __pyx_t_3;
  2006. /* "thinc/structs.pxd":163
  2007. * free(this._bwd[i])
  2008. * for i in range(this.i):
  2009. * free(this._feats[i]) # <<<<<<<<<<<<<<
  2010. * free(this._fwd)
  2011. * free(this._bwd)
  2012. */
  2013. free((this->_feats[__pyx_v_i]));
  2014. }
  2015. /* "thinc/structs.pxd":164
  2016. * for i in range(this.i):
  2017. * free(this._feats[i])
  2018. * free(this._fwd) # <<<<<<<<<<<<<<
  2019. * free(this._bwd)
  2020. * free(this._feats)
  2021. */
  2022. free(this->_fwd);
  2023. /* "thinc/structs.pxd":165
  2024. * free(this._feats[i])
  2025. * free(this._fwd)
  2026. * free(this._bwd) # <<<<<<<<<<<<<<
  2027. * free(this._feats)
  2028. * free(this._nr_feat)
  2029. */
  2030. free(this->_bwd);
  2031. /* "thinc/structs.pxd":166
  2032. * free(this._fwd)
  2033. * free(this._bwd)
  2034. * free(this._feats) # <<<<<<<<<<<<<<
  2035. * free(this._nr_feat)
  2036. * free(this._is_valid)
  2037. */
  2038. free(this->_feats);
  2039. /* "thinc/structs.pxd":167
  2040. * free(this._bwd)
  2041. * free(this._feats)
  2042. * free(this._nr_feat) # <<<<<<<<<<<<<<
  2043. * free(this._is_valid)
  2044. * free(this._costs)
  2045. */
  2046. free(this->_nr_feat);
  2047. /* "thinc/structs.pxd":168
  2048. * free(this._feats)
  2049. * free(this._nr_feat)
  2050. * free(this._is_valid) # <<<<<<<<<<<<<<
  2051. * free(this._costs)
  2052. * free(this.signatures)
  2053. */
  2054. free(this->_is_valid);
  2055. /* "thinc/structs.pxd":169
  2056. * free(this._nr_feat)
  2057. * free(this._is_valid)
  2058. * free(this._costs) # <<<<<<<<<<<<<<
  2059. * free(this.signatures)
  2060. *
  2061. */
  2062. free(this->_costs);
  2063. /* "thinc/structs.pxd":170
  2064. * free(this._is_valid)
  2065. * free(this._costs)
  2066. * free(this.signatures) # <<<<<<<<<<<<<<
  2067. *
  2068. * void reset() nogil:
  2069. */
  2070. free(this->signatures);
  2071. /* "thinc/structs.pxd":157
  2072. * this.signatures = <uint64_t*>calloc(batch_size, sizeof(uint64_t))
  2073. *
  2074. * __dealloc__() nogil: # <<<<<<<<<<<<<<
  2075. * free(this.widths)
  2076. * for i in range(this.nr_layer):
  2077. */
  2078. /* function exit code */
  2079. }
  2080. /* "thinc/structs.pxd":172
  2081. * free(this.signatures)
  2082. *
  2083. * void reset() nogil: # <<<<<<<<<<<<<<
  2084. * for i in range(this.nr_layer):
  2085. * memset(this._fwd[i],
  2086. */
  2087. void __pyx_t_5thinc_7structs_MinibatchC::reset(void) {
  2088. int __pyx_v_i;
  2089. int __pyx_t_1;
  2090. int __pyx_t_2;
  2091. int __pyx_t_3;
  2092. /* "thinc/structs.pxd":173
  2093. *
  2094. * void reset() nogil:
  2095. * for i in range(this.nr_layer): # <<<<<<<<<<<<<<
  2096. * memset(this._fwd[i],
  2097. * 0, sizeof(this._fwd[i][0]) * this.batch_size * this.widths[i])
  2098. */
  2099. __pyx_t_1 = this->nr_layer;
  2100. __pyx_t_2 = __pyx_t_1;
  2101. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  2102. __pyx_v_i = __pyx_t_3;
  2103. /* "thinc/structs.pxd":174
  2104. * void reset() nogil:
  2105. * for i in range(this.nr_layer):
  2106. * memset(this._fwd[i], # <<<<<<<<<<<<<<
  2107. * 0, sizeof(this._fwd[i][0]) * this.batch_size * this.widths[i])
  2108. * memset(this._bwd[i],
  2109. */
  2110. (void)(memset((this->_fwd[__pyx_v_i]), 0, (((sizeof(((this->_fwd[__pyx_v_i])[0]))) * this->batch_size) * (this->widths[__pyx_v_i]))));
  2111. /* "thinc/structs.pxd":176
  2112. * memset(this._fwd[i],
  2113. * 0, sizeof(this._fwd[i][0]) * this.batch_size * this.widths[i])
  2114. * memset(this._bwd[i], # <<<<<<<<<<<<<<
  2115. * 0, sizeof(this._bwd[i][0]) * this.batch_size * this.widths[i])
  2116. * memset(this._nr_feat, 0, sizeof(this._nr_feat[0]) * this.batch_size)
  2117. */
  2118. (void)(memset((this->_bwd[__pyx_v_i]), 0, (((sizeof(((this->_bwd[__pyx_v_i])[0]))) * this->batch_size) * (this->widths[__pyx_v_i]))));
  2119. }
  2120. /* "thinc/structs.pxd":178
  2121. * memset(this._bwd[i],
  2122. * 0, sizeof(this._bwd[i][0]) * this.batch_size * this.widths[i])
  2123. * memset(this._nr_feat, 0, sizeof(this._nr_feat[0]) * this.batch_size) # <<<<<<<<<<<<<<
  2124. * memset(this.signatures, 0, sizeof(this.signatures[0]) * this.batch_size)
  2125. * memset(this._costs,
  2126. */
  2127. (void)(memset(this->_nr_feat, 0, ((sizeof((this->_nr_feat[0]))) * this->batch_size)));
  2128. /* "thinc/structs.pxd":179
  2129. * 0, sizeof(this._bwd[i][0]) * this.batch_size * this.widths[i])
  2130. * memset(this._nr_feat, 0, sizeof(this._nr_feat[0]) * this.batch_size)
  2131. * memset(this.signatures, 0, sizeof(this.signatures[0]) * this.batch_size) # <<<<<<<<<<<<<<
  2132. * memset(this._costs,
  2133. * 0, sizeof(this._costs[0]) * this.nr_out() * this.batch_size)
  2134. */
  2135. (void)(memset(this->signatures, 0, ((sizeof((this->signatures[0]))) * this->batch_size)));
  2136. /* "thinc/structs.pxd":180
  2137. * memset(this._nr_feat, 0, sizeof(this._nr_feat[0]) * this.batch_size)
  2138. * memset(this.signatures, 0, sizeof(this.signatures[0]) * this.batch_size)
  2139. * memset(this._costs, # <<<<<<<<<<<<<<
  2140. * 0, sizeof(this._costs[0]) * this.nr_out() * this.batch_size)
  2141. * memset(this._is_valid,
  2142. */
  2143. (void)(memset(this->_costs, 0, (((sizeof((this->_costs[0]))) * this->nr_out()) * this->batch_size)));
  2144. /* "thinc/structs.pxd":182
  2145. * memset(this._costs,
  2146. * 0, sizeof(this._costs[0]) * this.nr_out() * this.batch_size)
  2147. * memset(this._is_valid, # <<<<<<<<<<<<<<
  2148. * 0, sizeof(this._is_valid[0]) * this.nr_out() * this.batch_size)
  2149. * for i in range(this.i):
  2150. */
  2151. (void)(memset(this->_is_valid, 0, (((sizeof((this->_is_valid[0]))) * this->nr_out()) * this->batch_size)));
  2152. /* "thinc/structs.pxd":184
  2153. * memset(this._is_valid,
  2154. * 0, sizeof(this._is_valid[0]) * this.nr_out() * this.batch_size)
  2155. * for i in range(this.i): # <<<<<<<<<<<<<<
  2156. * free(this._feats[i])
  2157. * this._feats[i] = NULL
  2158. */
  2159. __pyx_t_1 = this->i;
  2160. __pyx_t_2 = __pyx_t_1;
  2161. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  2162. __pyx_v_i = __pyx_t_3;
  2163. /* "thinc/structs.pxd":185
  2164. * 0, sizeof(this._is_valid[0]) * this.nr_out() * this.batch_size)
  2165. * for i in range(this.i):
  2166. * free(this._feats[i]) # <<<<<<<<<<<<<<
  2167. * this._feats[i] = NULL
  2168. * this.i = 0
  2169. */
  2170. free((this->_feats[__pyx_v_i]));
  2171. /* "thinc/structs.pxd":186
  2172. * for i in range(this.i):
  2173. * free(this._feats[i])
  2174. * this._feats[i] = NULL # <<<<<<<<<<<<<<
  2175. * this.i = 0
  2176. *
  2177. */
  2178. (this->_feats[__pyx_v_i]) = NULL;
  2179. }
  2180. /* "thinc/structs.pxd":187
  2181. * free(this._feats[i])
  2182. * this._feats[i] = NULL
  2183. * this.i = 0 # <<<<<<<<<<<<<<
  2184. *
  2185. * int nr_in() nogil:
  2186. */
  2187. this->i = 0;
  2188. /* "thinc/structs.pxd":172
  2189. * free(this.signatures)
  2190. *
  2191. * void reset() nogil: # <<<<<<<<<<<<<<
  2192. * for i in range(this.nr_layer):
  2193. * memset(this._fwd[i],
  2194. */
  2195. /* function exit code */
  2196. }
  2197. /* "thinc/structs.pxd":189
  2198. * this.i = 0
  2199. *
  2200. * int nr_in() nogil: # <<<<<<<<<<<<<<
  2201. * return this.widths[0]
  2202. *
  2203. */
  2204. int __pyx_t_5thinc_7structs_MinibatchC::nr_in(void) {
  2205. int __pyx_r;
  2206. /* "thinc/structs.pxd":190
  2207. *
  2208. * int nr_in() nogil:
  2209. * return this.widths[0] # <<<<<<<<<<<<<<
  2210. *
  2211. * int nr_out() nogil:
  2212. */
  2213. __pyx_r = (this->widths[0]);
  2214. goto __pyx_L0;
  2215. /* "thinc/structs.pxd":189
  2216. * this.i = 0
  2217. *
  2218. * int nr_in() nogil: # <<<<<<<<<<<<<<
  2219. * return this.widths[0]
  2220. *
  2221. */
  2222. /* function exit code */
  2223. __pyx_L0:;
  2224. return __pyx_r;
  2225. }
  2226. /* "thinc/structs.pxd":192
  2227. * return this.widths[0]
  2228. *
  2229. * int nr_out() nogil: # <<<<<<<<<<<<<<
  2230. * return this.widths[this.nr_layer - 1]
  2231. *
  2232. */
  2233. int __pyx_t_5thinc_7structs_MinibatchC::nr_out(void) {
  2234. int __pyx_r;
  2235. /* "thinc/structs.pxd":193
  2236. *
  2237. * int nr_out() nogil:
  2238. * return this.widths[this.nr_layer - 1] # <<<<<<<<<<<<<<
  2239. *
  2240. * int push_back(const FeatureC* feats, int nr_feat,
  2241. */
  2242. __pyx_r = (this->widths[(this->nr_layer - 1)]);
  2243. goto __pyx_L0;
  2244. /* "thinc/structs.pxd":192
  2245. * return this.widths[0]
  2246. *
  2247. * int nr_out() nogil: # <<<<<<<<<<<<<<
  2248. * return this.widths[this.nr_layer - 1]
  2249. *
  2250. */
  2251. /* function exit code */
  2252. __pyx_L0:;
  2253. return __pyx_r;
  2254. }
  2255. /* "thinc/structs.pxd":195
  2256. * return this.widths[this.nr_layer - 1]
  2257. *
  2258. * int push_back(const FeatureC* feats, int nr_feat, # <<<<<<<<<<<<<<
  2259. * const weight_t* costs, const int* is_valid, uint64_t key) nogil:
  2260. * # Hash the features, to see if the batch has a matching input.
  2261. */
  2262. int __pyx_t_5thinc_7structs_MinibatchC::push_back(struct __pyx_t_5thinc_7structs_FeatureC const *__pyx_v_feats, int __pyx_v_nr_feat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_costs, int const *__pyx_v_is_valid, uint64_t __pyx_v_key) {
  2263. int __pyx_v_i;
  2264. int __pyx_r;
  2265. int __pyx_t_1;
  2266. int __pyx_t_2;
  2267. int __pyx_t_3;
  2268. int __pyx_t_4;
  2269. /* "thinc/structs.pxd":199
  2270. * # Hash the features, to see if the batch has a matching input.
  2271. * # If it does, just update the gradient for it.
  2272. * if key != 0: # <<<<<<<<<<<<<<
  2273. * for i in range(this.i):
  2274. * if this.signatures[i] == key:
  2275. */
  2276. __pyx_t_1 = ((__pyx_v_key != 0) != 0);
  2277. if (__pyx_t_1) {
  2278. /* "thinc/structs.pxd":200
  2279. * # If it does, just update the gradient for it.
  2280. * if key != 0:
  2281. * for i in range(this.i): # <<<<<<<<<<<<<<
  2282. * if this.signatures[i] == key:
  2283. * VecVec.add_i(this.costs(i),
  2284. */
  2285. __pyx_t_2 = this->i;
  2286. __pyx_t_3 = __pyx_t_2;
  2287. for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
  2288. __pyx_v_i = __pyx_t_4;
  2289. /* "thinc/structs.pxd":201
  2290. * if key != 0:
  2291. * for i in range(this.i):
  2292. * if this.signatures[i] == key: # <<<<<<<<<<<<<<
  2293. * VecVec.add_i(this.costs(i),
  2294. * costs, 1.0, this.nr_out())
  2295. */
  2296. __pyx_t_1 = (((this->signatures[__pyx_v_i]) == __pyx_v_key) != 0);
  2297. if (__pyx_t_1) {
  2298. /* "thinc/structs.pxd":202
  2299. * for i in range(this.i):
  2300. * if this.signatures[i] == key:
  2301. * VecVec.add_i(this.costs(i), # <<<<<<<<<<<<<<
  2302. * costs, 1.0, this.nr_out())
  2303. * return 0
  2304. */
  2305. __pyx_f_5thinc_6linalg_6VecVec_add_i(this->costs(__pyx_v_i), __pyx_v_costs, 1.0, this->nr_out());
  2306. /* "thinc/structs.pxd":204
  2307. * VecVec.add_i(this.costs(i),
  2308. * costs, 1.0, this.nr_out())
  2309. * return 0 # <<<<<<<<<<<<<<
  2310. * if this.i >= this.batch_size:
  2311. * this.reset()
  2312. */
  2313. __pyx_r = 0;
  2314. goto __pyx_L0;
  2315. /* "thinc/structs.pxd":201
  2316. * if key != 0:
  2317. * for i in range(this.i):
  2318. * if this.signatures[i] == key: # <<<<<<<<<<<<<<
  2319. * VecVec.add_i(this.costs(i),
  2320. * costs, 1.0, this.nr_out())
  2321. */
  2322. }
  2323. }
  2324. /* "thinc/structs.pxd":199
  2325. * # Hash the features, to see if the batch has a matching input.
  2326. * # If it does, just update the gradient for it.
  2327. * if key != 0: # <<<<<<<<<<<<<<
  2328. * for i in range(this.i):
  2329. * if this.signatures[i] == key:
  2330. */
  2331. }
  2332. /* "thinc/structs.pxd":205
  2333. * costs, 1.0, this.nr_out())
  2334. * return 0
  2335. * if this.i >= this.batch_size: # <<<<<<<<<<<<<<
  2336. * this.reset()
  2337. * this.i = 0 # This is done in reset() --- but make it obvious
  2338. */
  2339. __pyx_t_1 = ((this->i >= this->batch_size) != 0);
  2340. if (__pyx_t_1) {
  2341. /* "thinc/structs.pxd":206
  2342. * return 0
  2343. * if this.i >= this.batch_size:
  2344. * this.reset() # <<<<<<<<<<<<<<
  2345. * this.i = 0 # This is done in reset() --- but make it obvious
  2346. *
  2347. */
  2348. this->reset();
  2349. /* "thinc/structs.pxd":207
  2350. * if this.i >= this.batch_size:
  2351. * this.reset()
  2352. * this.i = 0 # This is done in reset() --- but make it obvious # <<<<<<<<<<<<<<
  2353. *
  2354. * this.signatures[this.i] = key
  2355. */
  2356. this->i = 0;
  2357. /* "thinc/structs.pxd":205
  2358. * costs, 1.0, this.nr_out())
  2359. * return 0
  2360. * if this.i >= this.batch_size: # <<<<<<<<<<<<<<
  2361. * this.reset()
  2362. * this.i = 0 # This is done in reset() --- but make it obvious
  2363. */
  2364. }
  2365. /* "thinc/structs.pxd":209
  2366. * this.i = 0 # This is done in reset() --- but make it obvious
  2367. *
  2368. * this.signatures[this.i] = key # <<<<<<<<<<<<<<
  2369. * this._nr_feat[this.i] = nr_feat
  2370. * this._feats[this.i] = <FeatureC*>calloc(nr_feat, sizeof(FeatureC))
  2371. */
  2372. (this->signatures[this->i]) = __pyx_v_key;
  2373. /* "thinc/structs.pxd":210
  2374. *
  2375. * this.signatures[this.i] = key
  2376. * this._nr_feat[this.i] = nr_feat # <<<<<<<<<<<<<<
  2377. * this._feats[this.i] = <FeatureC*>calloc(nr_feat, sizeof(FeatureC))
  2378. * memcpy(this._feats[this.i],
  2379. */
  2380. (this->_nr_feat[this->i]) = __pyx_v_nr_feat;
  2381. /* "thinc/structs.pxd":211
  2382. * this.signatures[this.i] = key
  2383. * this._nr_feat[this.i] = nr_feat
  2384. * this._feats[this.i] = <FeatureC*>calloc(nr_feat, sizeof(FeatureC)) # <<<<<<<<<<<<<<
  2385. * memcpy(this._feats[this.i],
  2386. * feats, nr_feat * sizeof(this._feats[this.i][0]))
  2387. */
  2388. (this->_feats[this->i]) = ((struct __pyx_t_5thinc_7structs_FeatureC *)calloc(__pyx_v_nr_feat, (sizeof(struct __pyx_t_5thinc_7structs_FeatureC))));
  2389. /* "thinc/structs.pxd":212
  2390. * this._nr_feat[this.i] = nr_feat
  2391. * this._feats[this.i] = <FeatureC*>calloc(nr_feat, sizeof(FeatureC))
  2392. * memcpy(this._feats[this.i], # <<<<<<<<<<<<<<
  2393. * feats, nr_feat * sizeof(this._feats[this.i][0]))
  2394. *
  2395. */
  2396. (void)(memcpy((this->_feats[this->i]), __pyx_v_feats, (__pyx_v_nr_feat * (sizeof(((this->_feats[this->i])[0]))))));
  2397. /* "thinc/structs.pxd":215
  2398. * feats, nr_feat * sizeof(this._feats[this.i][0]))
  2399. *
  2400. * memcpy(this.costs(this.i), # <<<<<<<<<<<<<<
  2401. * costs, this.nr_out() * sizeof(costs[0]))
  2402. * if is_valid is not NULL:
  2403. */
  2404. (void)(memcpy(this->costs(this->i), __pyx_v_costs, (this->nr_out() * (sizeof((__pyx_v_costs[0]))))));
  2405. /* "thinc/structs.pxd":217
  2406. * memcpy(this.costs(this.i),
  2407. * costs, this.nr_out() * sizeof(costs[0]))
  2408. * if is_valid is not NULL: # <<<<<<<<<<<<<<
  2409. * memcpy(this.is_valid(this.i),
  2410. * is_valid, this.nr_out() * sizeof(is_valid[0]))
  2411. */
  2412. __pyx_t_1 = ((__pyx_v_is_valid != NULL) != 0);
  2413. if (__pyx_t_1) {
  2414. /* "thinc/structs.pxd":218
  2415. * costs, this.nr_out() * sizeof(costs[0]))
  2416. * if is_valid is not NULL:
  2417. * memcpy(this.is_valid(this.i), # <<<<<<<<<<<<<<
  2418. * is_valid, this.nr_out() * sizeof(is_valid[0]))
  2419. * else:
  2420. */
  2421. (void)(memcpy(this->is_valid(this->i), __pyx_v_is_valid, (this->nr_out() * (sizeof((__pyx_v_is_valid[0]))))));
  2422. /* "thinc/structs.pxd":217
  2423. * memcpy(this.costs(this.i),
  2424. * costs, this.nr_out() * sizeof(costs[0]))
  2425. * if is_valid is not NULL: # <<<<<<<<<<<<<<
  2426. * memcpy(this.is_valid(this.i),
  2427. * is_valid, this.nr_out() * sizeof(is_valid[0]))
  2428. */
  2429. goto __pyx_L8;
  2430. }
  2431. /* "thinc/structs.pxd":221
  2432. * is_valid, this.nr_out() * sizeof(is_valid[0]))
  2433. * else:
  2434. * for i in range(this.nr_out()): # <<<<<<<<<<<<<<
  2435. * this.is_valid(this.i)[i] = 1
  2436. * this.i += 1
  2437. */
  2438. /*else*/ {
  2439. __pyx_t_2 = this->nr_out();
  2440. __pyx_t_3 = __pyx_t_2;
  2441. for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
  2442. __pyx_v_i = __pyx_t_4;
  2443. /* "thinc/structs.pxd":222
  2444. * else:
  2445. * for i in range(this.nr_out()):
  2446. * this.is_valid(this.i)[i] = 1 # <<<<<<<<<<<<<<
  2447. * this.i += 1
  2448. * return this.i >= this.batch_size
  2449. */
  2450. (this->is_valid(this->i)[__pyx_v_i]) = 1;
  2451. }
  2452. }
  2453. __pyx_L8:;
  2454. /* "thinc/structs.pxd":223
  2455. * for i in range(this.nr_out()):
  2456. * this.is_valid(this.i)[i] = 1
  2457. * this.i += 1 # <<<<<<<<<<<<<<
  2458. * return this.i >= this.batch_size
  2459. *
  2460. */
  2461. this->i = (this->i + 1);
  2462. /* "thinc/structs.pxd":224
  2463. * this.is_valid(this.i)[i] = 1
  2464. * this.i += 1
  2465. * return this.i >= this.batch_size # <<<<<<<<<<<<<<
  2466. *
  2467. * FeatureC* features(int i) nogil:
  2468. */
  2469. __pyx_r = (this->i >= this->batch_size);
  2470. goto __pyx_L0;
  2471. /* "thinc/structs.pxd":195
  2472. * return this.widths[this.nr_layer - 1]
  2473. *
  2474. * int push_back(const FeatureC* feats, int nr_feat, # <<<<<<<<<<<<<<
  2475. * const weight_t* costs, const int* is_valid, uint64_t key) nogil:
  2476. * # Hash the features, to see if the batch has a matching input.
  2477. */
  2478. /* function exit code */
  2479. __pyx_L0:;
  2480. return __pyx_r;
  2481. }
  2482. /* "thinc/structs.pxd":226
  2483. * return this.i >= this.batch_size
  2484. *
  2485. * FeatureC* features(int i) nogil: # <<<<<<<<<<<<<<
  2486. * return this._feats[i]
  2487. *
  2488. */
  2489. struct __pyx_t_5thinc_7structs_FeatureC *__pyx_t_5thinc_7structs_MinibatchC::features(int __pyx_v_i) {
  2490. struct __pyx_t_5thinc_7structs_FeatureC *__pyx_r;
  2491. /* "thinc/structs.pxd":227
  2492. *
  2493. * FeatureC* features(int i) nogil:
  2494. * return this._feats[i] # <<<<<<<<<<<<<<
  2495. *
  2496. * int nr_feat(int i) nogil:
  2497. */
  2498. __pyx_r = (this->_feats[__pyx_v_i]);
  2499. goto __pyx_L0;
  2500. /* "thinc/structs.pxd":226
  2501. * return this.i >= this.batch_size
  2502. *
  2503. * FeatureC* features(int i) nogil: # <<<<<<<<<<<<<<
  2504. * return this._feats[i]
  2505. *
  2506. */
  2507. /* function exit code */
  2508. __pyx_L0:;
  2509. return __pyx_r;
  2510. }
  2511. /* "thinc/structs.pxd":229
  2512. * return this._feats[i]
  2513. *
  2514. * int nr_feat(int i) nogil: # <<<<<<<<<<<<<<
  2515. * return this._nr_feat[i]
  2516. *
  2517. */
  2518. int __pyx_t_5thinc_7structs_MinibatchC::nr_feat(int __pyx_v_i) {
  2519. int __pyx_r;
  2520. /* "thinc/structs.pxd":230
  2521. *
  2522. * int nr_feat(int i) nogil:
  2523. * return this._nr_feat[i] # <<<<<<<<<<<<<<
  2524. *
  2525. * weight_t* fwd(int i, int j) nogil:
  2526. */
  2527. __pyx_r = (this->_nr_feat[__pyx_v_i]);
  2528. goto __pyx_L0;
  2529. /* "thinc/structs.pxd":229
  2530. * return this._feats[i]
  2531. *
  2532. * int nr_feat(int i) nogil: # <<<<<<<<<<<<<<
  2533. * return this._nr_feat[i]
  2534. *
  2535. */
  2536. /* function exit code */
  2537. __pyx_L0:;
  2538. return __pyx_r;
  2539. }
  2540. /* "thinc/structs.pxd":232
  2541. * return this._nr_feat[i]
  2542. *
  2543. * weight_t* fwd(int i, int j) nogil: # <<<<<<<<<<<<<<
  2544. * return this._fwd[i] + (j * this.widths[i])
  2545. *
  2546. */
  2547. __pyx_t_5thinc_8typedefs_weight_t *__pyx_t_5thinc_7structs_MinibatchC::fwd(int __pyx_v_i, int __pyx_v_j) {
  2548. __pyx_t_5thinc_8typedefs_weight_t *__pyx_r;
  2549. /* "thinc/structs.pxd":233
  2550. *
  2551. * weight_t* fwd(int i, int j) nogil:
  2552. * return this._fwd[i] + (j * this.widths[i]) # <<<<<<<<<<<<<<
  2553. *
  2554. * weight_t* bwd(int i, int j) nogil:
  2555. */
  2556. __pyx_r = ((this->_fwd[__pyx_v_i]) + (__pyx_v_j * (this->widths[__pyx_v_i])));
  2557. goto __pyx_L0;
  2558. /* "thinc/structs.pxd":232
  2559. * return this._nr_feat[i]
  2560. *
  2561. * weight_t* fwd(int i, int j) nogil: # <<<<<<<<<<<<<<
  2562. * return this._fwd[i] + (j * this.widths[i])
  2563. *
  2564. */
  2565. /* function exit code */
  2566. __pyx_L0:;
  2567. return __pyx_r;
  2568. }
  2569. /* "thinc/structs.pxd":235
  2570. * return this._fwd[i] + (j * this.widths[i])
  2571. *
  2572. * weight_t* bwd(int i, int j) nogil: # <<<<<<<<<<<<<<
  2573. * return this._bwd[i] + (j * this.widths[i])
  2574. *
  2575. */
  2576. __pyx_t_5thinc_8typedefs_weight_t *__pyx_t_5thinc_7structs_MinibatchC::bwd(int __pyx_v_i, int __pyx_v_j) {
  2577. __pyx_t_5thinc_8typedefs_weight_t *__pyx_r;
  2578. /* "thinc/structs.pxd":236
  2579. *
  2580. * weight_t* bwd(int i, int j) nogil:
  2581. * return this._bwd[i] + (j * this.widths[i]) # <<<<<<<<<<<<<<
  2582. *
  2583. * weight_t* scores(int i) nogil:
  2584. */
  2585. __pyx_r = ((this->_bwd[__pyx_v_i]) + (__pyx_v_j * (this->widths[__pyx_v_i])));
  2586. goto __pyx_L0;
  2587. /* "thinc/structs.pxd":235
  2588. * return this._fwd[i] + (j * this.widths[i])
  2589. *
  2590. * weight_t* bwd(int i, int j) nogil: # <<<<<<<<<<<<<<
  2591. * return this._bwd[i] + (j * this.widths[i])
  2592. *
  2593. */
  2594. /* function exit code */
  2595. __pyx_L0:;
  2596. return __pyx_r;
  2597. }
  2598. /* "thinc/structs.pxd":238
  2599. * return this._bwd[i] + (j * this.widths[i])
  2600. *
  2601. * weight_t* scores(int i) nogil: # <<<<<<<<<<<<<<
  2602. * return this.fwd(this.nr_layer-1, i)
  2603. *
  2604. */
  2605. __pyx_t_5thinc_8typedefs_weight_t *__pyx_t_5thinc_7structs_MinibatchC::scores(int __pyx_v_i) {
  2606. __pyx_t_5thinc_8typedefs_weight_t *__pyx_r;
  2607. /* "thinc/structs.pxd":239
  2608. *
  2609. * weight_t* scores(int i) nogil:
  2610. * return this.fwd(this.nr_layer-1, i) # <<<<<<<<<<<<<<
  2611. *
  2612. * weight_t* losses(int i) nogil:
  2613. */
  2614. __pyx_r = this->fwd((this->nr_layer - 1), __pyx_v_i);
  2615. goto __pyx_L0;
  2616. /* "thinc/structs.pxd":238
  2617. * return this._bwd[i] + (j * this.widths[i])
  2618. *
  2619. * weight_t* scores(int i) nogil: # <<<<<<<<<<<<<<
  2620. * return this.fwd(this.nr_layer-1, i)
  2621. *
  2622. */
  2623. /* function exit code */
  2624. __pyx_L0:;
  2625. return __pyx_r;
  2626. }
  2627. /* "thinc/structs.pxd":241
  2628. * return this.fwd(this.nr_layer-1, i)
  2629. *
  2630. * weight_t* losses(int i) nogil: # <<<<<<<<<<<<<<
  2631. * return this.bwd(this.nr_layer-1, i)
  2632. *
  2633. */
  2634. __pyx_t_5thinc_8typedefs_weight_t *__pyx_t_5thinc_7structs_MinibatchC::losses(int __pyx_v_i) {
  2635. __pyx_t_5thinc_8typedefs_weight_t *__pyx_r;
  2636. /* "thinc/structs.pxd":242
  2637. *
  2638. * weight_t* losses(int i) nogil:
  2639. * return this.bwd(this.nr_layer-1, i) # <<<<<<<<<<<<<<
  2640. *
  2641. * weight_t* costs(int i) nogil:
  2642. */
  2643. __pyx_r = this->bwd((this->nr_layer - 1), __pyx_v_i);
  2644. goto __pyx_L0;
  2645. /* "thinc/structs.pxd":241
  2646. * return this.fwd(this.nr_layer-1, i)
  2647. *
  2648. * weight_t* losses(int i) nogil: # <<<<<<<<<<<<<<
  2649. * return this.bwd(this.nr_layer-1, i)
  2650. *
  2651. */
  2652. /* function exit code */
  2653. __pyx_L0:;
  2654. return __pyx_r;
  2655. }
  2656. /* "thinc/structs.pxd":244
  2657. * return this.bwd(this.nr_layer-1, i)
  2658. *
  2659. * weight_t* costs(int i) nogil: # <<<<<<<<<<<<<<
  2660. * return this._costs + (i * this.nr_out())
  2661. *
  2662. */
  2663. __pyx_t_5thinc_8typedefs_weight_t *__pyx_t_5thinc_7structs_MinibatchC::costs(int __pyx_v_i) {
  2664. __pyx_t_5thinc_8typedefs_weight_t *__pyx_r;
  2665. /* "thinc/structs.pxd":245
  2666. *
  2667. * weight_t* costs(int i) nogil:
  2668. * return this._costs + (i * this.nr_out()) # <<<<<<<<<<<<<<
  2669. *
  2670. * int* is_valid(int i) nogil:
  2671. */
  2672. __pyx_r = (this->_costs + (__pyx_v_i * this->nr_out()));
  2673. goto __pyx_L0;
  2674. /* "thinc/structs.pxd":244
  2675. * return this.bwd(this.nr_layer-1, i)
  2676. *
  2677. * weight_t* costs(int i) nogil: # <<<<<<<<<<<<<<
  2678. * return this._costs + (i * this.nr_out())
  2679. *
  2680. */
  2681. /* function exit code */
  2682. __pyx_L0:;
  2683. return __pyx_r;
  2684. }
  2685. /* "thinc/structs.pxd":247
  2686. * return this._costs + (i * this.nr_out())
  2687. *
  2688. * int* is_valid(int i) nogil: # <<<<<<<<<<<<<<
  2689. * return this._is_valid + (i * this.nr_out())
  2690. *
  2691. */
  2692. int *__pyx_t_5thinc_7structs_MinibatchC::is_valid(int __pyx_v_i) {
  2693. int *__pyx_r;
  2694. /* "thinc/structs.pxd":248
  2695. *
  2696. * int* is_valid(int i) nogil:
  2697. * return this._is_valid + (i * this.nr_out()) # <<<<<<<<<<<<<<
  2698. *
  2699. * int guess(int i) nogil:
  2700. */
  2701. __pyx_r = (this->_is_valid + (__pyx_v_i * this->nr_out()));
  2702. goto __pyx_L0;
  2703. /* "thinc/structs.pxd":247
  2704. * return this._costs + (i * this.nr_out())
  2705. *
  2706. * int* is_valid(int i) nogil: # <<<<<<<<<<<<<<
  2707. * return this._is_valid + (i * this.nr_out())
  2708. *
  2709. */
  2710. /* function exit code */
  2711. __pyx_L0:;
  2712. return __pyx_r;
  2713. }
  2714. /* "thinc/structs.pxd":250
  2715. * return this._is_valid + (i * this.nr_out())
  2716. *
  2717. * int guess(int i) nogil: # <<<<<<<<<<<<<<
  2718. * return VecVec.arg_max_if_true(this.scores(i), this.is_valid(i), this.nr_out())
  2719. *
  2720. */
  2721. int __pyx_t_5thinc_7structs_MinibatchC::guess(int __pyx_v_i) {
  2722. int __pyx_r;
  2723. /* "thinc/structs.pxd":251
  2724. *
  2725. * int guess(int i) nogil:
  2726. * return VecVec.arg_max_if_true(this.scores(i), this.is_valid(i), this.nr_out()) # <<<<<<<<<<<<<<
  2727. *
  2728. * int best(int i) nogil:
  2729. */
  2730. __pyx_r = __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_true(this->scores(__pyx_v_i), this->is_valid(__pyx_v_i), this->nr_out());
  2731. goto __pyx_L0;
  2732. /* "thinc/structs.pxd":250
  2733. * return this._is_valid + (i * this.nr_out())
  2734. *
  2735. * int guess(int i) nogil: # <<<<<<<<<<<<<<
  2736. * return VecVec.arg_max_if_true(this.scores(i), this.is_valid(i), this.nr_out())
  2737. *
  2738. */
  2739. /* function exit code */
  2740. __pyx_L0:;
  2741. return __pyx_r;
  2742. }
  2743. /* "thinc/structs.pxd":253
  2744. * return VecVec.arg_max_if_true(this.scores(i), this.is_valid(i), this.nr_out())
  2745. *
  2746. * int best(int i) nogil: # <<<<<<<<<<<<<<
  2747. * return VecVec.arg_max_if_zero(this.scores(i), this.costs(i), this.nr_out())
  2748. *
  2749. */
  2750. int __pyx_t_5thinc_7structs_MinibatchC::best(int __pyx_v_i) {
  2751. int __pyx_r;
  2752. /* "thinc/structs.pxd":254
  2753. *
  2754. * int best(int i) nogil:
  2755. * return VecVec.arg_max_if_zero(this.scores(i), this.costs(i), this.nr_out()) # <<<<<<<<<<<<<<
  2756. *
  2757. *
  2758. */
  2759. __pyx_r = __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_zero(this->scores(__pyx_v_i), this->costs(__pyx_v_i), this->nr_out());
  2760. goto __pyx_L0;
  2761. /* "thinc/structs.pxd":253
  2762. * return VecVec.arg_max_if_true(this.scores(i), this.is_valid(i), this.nr_out())
  2763. *
  2764. * int best(int i) nogil: # <<<<<<<<<<<<<<
  2765. * return VecVec.arg_max_if_zero(this.scores(i), this.costs(i), this.nr_out())
  2766. *
  2767. */
  2768. /* function exit code */
  2769. __pyx_L0:;
  2770. return __pyx_r;
  2771. }
  2772. /* "linalg.pxd":31
  2773. * cdef class Vec:
  2774. * @staticmethod
  2775. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil: # <<<<<<<<<<<<<<
  2776. * if n_classes == 2:
  2777. * return 0 if scores[0] > scores[1] else 1
  2778. */
  2779. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_3Vec_arg_max(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, int const __pyx_v_n_classes) {
  2780. int __pyx_v_i;
  2781. int __pyx_v_best;
  2782. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_mode;
  2783. int __pyx_r;
  2784. int __pyx_t_1;
  2785. int __pyx_t_2;
  2786. int __pyx_t_3;
  2787. int __pyx_t_4;
  2788. /* "linalg.pxd":32
  2789. * @staticmethod
  2790. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil:
  2791. * if n_classes == 2: # <<<<<<<<<<<<<<
  2792. * return 0 if scores[0] > scores[1] else 1
  2793. * cdef int i
  2794. */
  2795. __pyx_t_1 = ((__pyx_v_n_classes == 2) != 0);
  2796. if (__pyx_t_1) {
  2797. /* "linalg.pxd":33
  2798. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil:
  2799. * if n_classes == 2:
  2800. * return 0 if scores[0] > scores[1] else 1 # <<<<<<<<<<<<<<
  2801. * cdef int i
  2802. * cdef int best = 0
  2803. */
  2804. if ((((__pyx_v_scores[0]) > (__pyx_v_scores[1])) != 0)) {
  2805. __pyx_t_2 = 0;
  2806. } else {
  2807. __pyx_t_2 = 1;
  2808. }
  2809. __pyx_r = __pyx_t_2;
  2810. goto __pyx_L0;
  2811. /* "linalg.pxd":32
  2812. * @staticmethod
  2813. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil:
  2814. * if n_classes == 2: # <<<<<<<<<<<<<<
  2815. * return 0 if scores[0] > scores[1] else 1
  2816. * cdef int i
  2817. */
  2818. }
  2819. /* "linalg.pxd":35
  2820. * return 0 if scores[0] > scores[1] else 1
  2821. * cdef int i
  2822. * cdef int best = 0 # <<<<<<<<<<<<<<
  2823. * cdef weight_t mode = scores[0]
  2824. * for i in range(1, n_classes):
  2825. */
  2826. __pyx_v_best = 0;
  2827. /* "linalg.pxd":36
  2828. * cdef int i
  2829. * cdef int best = 0
  2830. * cdef weight_t mode = scores[0] # <<<<<<<<<<<<<<
  2831. * for i in range(1, n_classes):
  2832. * if scores[i] > mode:
  2833. */
  2834. __pyx_v_mode = (__pyx_v_scores[0]);
  2835. /* "linalg.pxd":37
  2836. * cdef int best = 0
  2837. * cdef weight_t mode = scores[0]
  2838. * for i in range(1, n_classes): # <<<<<<<<<<<<<<
  2839. * if scores[i] > mode:
  2840. * mode = scores[i]
  2841. */
  2842. __pyx_t_2 = __pyx_v_n_classes;
  2843. __pyx_t_3 = __pyx_t_2;
  2844. for (__pyx_t_4 = 1; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
  2845. __pyx_v_i = __pyx_t_4;
  2846. /* "linalg.pxd":38
  2847. * cdef weight_t mode = scores[0]
  2848. * for i in range(1, n_classes):
  2849. * if scores[i] > mode: # <<<<<<<<<<<<<<
  2850. * mode = scores[i]
  2851. * best = i
  2852. */
  2853. __pyx_t_1 = (((__pyx_v_scores[__pyx_v_i]) > __pyx_v_mode) != 0);
  2854. if (__pyx_t_1) {
  2855. /* "linalg.pxd":39
  2856. * for i in range(1, n_classes):
  2857. * if scores[i] > mode:
  2858. * mode = scores[i] # <<<<<<<<<<<<<<
  2859. * best = i
  2860. * return best
  2861. */
  2862. __pyx_v_mode = (__pyx_v_scores[__pyx_v_i]);
  2863. /* "linalg.pxd":40
  2864. * if scores[i] > mode:
  2865. * mode = scores[i]
  2866. * best = i # <<<<<<<<<<<<<<
  2867. * return best
  2868. *
  2869. */
  2870. __pyx_v_best = __pyx_v_i;
  2871. /* "linalg.pxd":38
  2872. * cdef weight_t mode = scores[0]
  2873. * for i in range(1, n_classes):
  2874. * if scores[i] > mode: # <<<<<<<<<<<<<<
  2875. * mode = scores[i]
  2876. * best = i
  2877. */
  2878. }
  2879. }
  2880. /* "linalg.pxd":41
  2881. * mode = scores[i]
  2882. * best = i
  2883. * return best # <<<<<<<<<<<<<<
  2884. *
  2885. * @staticmethod
  2886. */
  2887. __pyx_r = __pyx_v_best;
  2888. goto __pyx_L0;
  2889. /* "linalg.pxd":31
  2890. * cdef class Vec:
  2891. * @staticmethod
  2892. * cdef inline int arg_max(const weight_t* scores, const int n_classes) nogil: # <<<<<<<<<<<<<<
  2893. * if n_classes == 2:
  2894. * return 0 if scores[0] > scores[1] else 1
  2895. */
  2896. /* function exit code */
  2897. __pyx_L0:;
  2898. return __pyx_r;
  2899. }
  2900. /* "linalg.pxd":44
  2901. *
  2902. * @staticmethod
  2903. * cdef inline weight_t max(const weight_t* x, int32_t nr) nogil: # <<<<<<<<<<<<<<
  2904. * if nr == 0:
  2905. * return 0
  2906. */
  2907. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_max(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, int32_t __pyx_v_nr) {
  2908. int __pyx_v_i;
  2909. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_mode;
  2910. __pyx_t_5thinc_8typedefs_weight_t __pyx_r;
  2911. int __pyx_t_1;
  2912. int32_t __pyx_t_2;
  2913. int32_t __pyx_t_3;
  2914. int __pyx_t_4;
  2915. /* "linalg.pxd":45
  2916. * @staticmethod
  2917. * cdef inline weight_t max(const weight_t* x, int32_t nr) nogil:
  2918. * if nr == 0: # <<<<<<<<<<<<<<
  2919. * return 0
  2920. * cdef int i
  2921. */
  2922. __pyx_t_1 = ((__pyx_v_nr == 0) != 0);
  2923. if (__pyx_t_1) {
  2924. /* "linalg.pxd":46
  2925. * cdef inline weight_t max(const weight_t* x, int32_t nr) nogil:
  2926. * if nr == 0:
  2927. * return 0 # <<<<<<<<<<<<<<
  2928. * cdef int i
  2929. * cdef weight_t mode = x[0]
  2930. */
  2931. __pyx_r = 0.0;
  2932. goto __pyx_L0;
  2933. /* "linalg.pxd":45
  2934. * @staticmethod
  2935. * cdef inline weight_t max(const weight_t* x, int32_t nr) nogil:
  2936. * if nr == 0: # <<<<<<<<<<<<<<
  2937. * return 0
  2938. * cdef int i
  2939. */
  2940. }
  2941. /* "linalg.pxd":48
  2942. * return 0
  2943. * cdef int i
  2944. * cdef weight_t mode = x[0] # <<<<<<<<<<<<<<
  2945. * for i in range(1, nr):
  2946. * if x[i] > mode:
  2947. */
  2948. __pyx_v_mode = (__pyx_v_x[0]);
  2949. /* "linalg.pxd":49
  2950. * cdef int i
  2951. * cdef weight_t mode = x[0]
  2952. * for i in range(1, nr): # <<<<<<<<<<<<<<
  2953. * if x[i] > mode:
  2954. * mode = x[i]
  2955. */
  2956. __pyx_t_2 = __pyx_v_nr;
  2957. __pyx_t_3 = __pyx_t_2;
  2958. for (__pyx_t_4 = 1; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
  2959. __pyx_v_i = __pyx_t_4;
  2960. /* "linalg.pxd":50
  2961. * cdef weight_t mode = x[0]
  2962. * for i in range(1, nr):
  2963. * if x[i] > mode: # <<<<<<<<<<<<<<
  2964. * mode = x[i]
  2965. * return mode
  2966. */
  2967. __pyx_t_1 = (((__pyx_v_x[__pyx_v_i]) > __pyx_v_mode) != 0);
  2968. if (__pyx_t_1) {
  2969. /* "linalg.pxd":51
  2970. * for i in range(1, nr):
  2971. * if x[i] > mode:
  2972. * mode = x[i] # <<<<<<<<<<<<<<
  2973. * return mode
  2974. *
  2975. */
  2976. __pyx_v_mode = (__pyx_v_x[__pyx_v_i]);
  2977. /* "linalg.pxd":50
  2978. * cdef weight_t mode = x[0]
  2979. * for i in range(1, nr):
  2980. * if x[i] > mode: # <<<<<<<<<<<<<<
  2981. * mode = x[i]
  2982. * return mode
  2983. */
  2984. }
  2985. }
  2986. /* "linalg.pxd":52
  2987. * if x[i] > mode:
  2988. * mode = x[i]
  2989. * return mode # <<<<<<<<<<<<<<
  2990. *
  2991. * @staticmethod
  2992. */
  2993. __pyx_r = __pyx_v_mode;
  2994. goto __pyx_L0;
  2995. /* "linalg.pxd":44
  2996. *
  2997. * @staticmethod
  2998. * cdef inline weight_t max(const weight_t* x, int32_t nr) nogil: # <<<<<<<<<<<<<<
  2999. * if nr == 0:
  3000. * return 0
  3001. */
  3002. /* function exit code */
  3003. __pyx_L0:;
  3004. return __pyx_r;
  3005. }
  3006. /* "linalg.pxd":55
  3007. *
  3008. * @staticmethod
  3009. * cdef inline weight_t sum(const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3010. * cdef int i
  3011. * cdef weight_t total = 0
  3012. */
  3013. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_sum(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr) {
  3014. int __pyx_v_i;
  3015. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_total;
  3016. __pyx_t_5thinc_8typedefs_weight_t __pyx_r;
  3017. int32_t __pyx_t_1;
  3018. int32_t __pyx_t_2;
  3019. int __pyx_t_3;
  3020. /* "linalg.pxd":57
  3021. * cdef inline weight_t sum(const weight_t* vec, int32_t nr) nogil:
  3022. * cdef int i
  3023. * cdef weight_t total = 0 # <<<<<<<<<<<<<<
  3024. * for i in range(nr):
  3025. * total += vec[i]
  3026. */
  3027. __pyx_v_total = 0.0;
  3028. /* "linalg.pxd":58
  3029. * cdef int i
  3030. * cdef weight_t total = 0
  3031. * for i in range(nr): # <<<<<<<<<<<<<<
  3032. * total += vec[i]
  3033. * return total
  3034. */
  3035. __pyx_t_1 = __pyx_v_nr;
  3036. __pyx_t_2 = __pyx_t_1;
  3037. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3038. __pyx_v_i = __pyx_t_3;
  3039. /* "linalg.pxd":59
  3040. * cdef weight_t total = 0
  3041. * for i in range(nr):
  3042. * total += vec[i] # <<<<<<<<<<<<<<
  3043. * return total
  3044. *
  3045. */
  3046. __pyx_v_total = (__pyx_v_total + (__pyx_v_vec[__pyx_v_i]));
  3047. }
  3048. /* "linalg.pxd":60
  3049. * for i in range(nr):
  3050. * total += vec[i]
  3051. * return total # <<<<<<<<<<<<<<
  3052. *
  3053. * @staticmethod
  3054. */
  3055. __pyx_r = __pyx_v_total;
  3056. goto __pyx_L0;
  3057. /* "linalg.pxd":55
  3058. *
  3059. * @staticmethod
  3060. * cdef inline weight_t sum(const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3061. * cdef int i
  3062. * cdef weight_t total = 0
  3063. */
  3064. /* function exit code */
  3065. __pyx_L0:;
  3066. return __pyx_r;
  3067. }
  3068. /* "linalg.pxd":63
  3069. *
  3070. * @staticmethod
  3071. * cdef inline weight_t norm(const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3072. * cdef weight_t total = 0
  3073. * for i in range(nr):
  3074. */
  3075. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_3Vec_norm(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr) {
  3076. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_total;
  3077. int32_t __pyx_v_i;
  3078. __pyx_t_5thinc_8typedefs_weight_t __pyx_r;
  3079. int32_t __pyx_t_1;
  3080. int32_t __pyx_t_2;
  3081. int32_t __pyx_t_3;
  3082. /* "linalg.pxd":64
  3083. * @staticmethod
  3084. * cdef inline weight_t norm(const weight_t* vec, int32_t nr) nogil:
  3085. * cdef weight_t total = 0 # <<<<<<<<<<<<<<
  3086. * for i in range(nr):
  3087. * total += vec[i] ** 2
  3088. */
  3089. __pyx_v_total = 0.0;
  3090. /* "linalg.pxd":65
  3091. * cdef inline weight_t norm(const weight_t* vec, int32_t nr) nogil:
  3092. * cdef weight_t total = 0
  3093. * for i in range(nr): # <<<<<<<<<<<<<<
  3094. * total += vec[i] ** 2
  3095. * return sqrt(total)
  3096. */
  3097. __pyx_t_1 = __pyx_v_nr;
  3098. __pyx_t_2 = __pyx_t_1;
  3099. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3100. __pyx_v_i = __pyx_t_3;
  3101. /* "linalg.pxd":66
  3102. * cdef weight_t total = 0
  3103. * for i in range(nr):
  3104. * total += vec[i] ** 2 # <<<<<<<<<<<<<<
  3105. * return sqrt(total)
  3106. *
  3107. */
  3108. __pyx_v_total = (__pyx_v_total + powf(((__pyx_t_5thinc_8typedefs_weight_t)(__pyx_v_vec[__pyx_v_i])), 2.0));
  3109. }
  3110. /* "linalg.pxd":67
  3111. * for i in range(nr):
  3112. * total += vec[i] ** 2
  3113. * return sqrt(total) # <<<<<<<<<<<<<<
  3114. *
  3115. * @staticmethod
  3116. */
  3117. __pyx_r = sqrt(__pyx_v_total);
  3118. goto __pyx_L0;
  3119. /* "linalg.pxd":63
  3120. *
  3121. * @staticmethod
  3122. * cdef inline weight_t norm(const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3123. * cdef weight_t total = 0
  3124. * for i in range(nr):
  3125. */
  3126. /* function exit code */
  3127. __pyx_L0:;
  3128. return __pyx_r;
  3129. }
  3130. /* "linalg.pxd":70
  3131. *
  3132. * @staticmethod
  3133. * cdef inline void add(weight_t* output, const weight_t* x, # <<<<<<<<<<<<<<
  3134. * weight_t inc, int32_t nr) nogil:
  3135. * memcpy(output, x, sizeof(output[0]) * nr)
  3136. */
  3137. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_inc, int32_t __pyx_v_nr) {
  3138. /* "linalg.pxd":72
  3139. * cdef inline void add(weight_t* output, const weight_t* x,
  3140. * weight_t inc, int32_t nr) nogil:
  3141. * memcpy(output, x, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3142. * Vec.add_i(output, inc, nr)
  3143. *
  3144. */
  3145. (void)(memcpy(__pyx_v_output, __pyx_v_x, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3146. /* "linalg.pxd":73
  3147. * weight_t inc, int32_t nr) nogil:
  3148. * memcpy(output, x, sizeof(output[0]) * nr)
  3149. * Vec.add_i(output, inc, nr) # <<<<<<<<<<<<<<
  3150. *
  3151. * @staticmethod
  3152. */
  3153. __pyx_f_5thinc_6linalg_3Vec_add_i(__pyx_v_output, __pyx_v_inc, __pyx_v_nr);
  3154. /* "linalg.pxd":70
  3155. *
  3156. * @staticmethod
  3157. * cdef inline void add(weight_t* output, const weight_t* x, # <<<<<<<<<<<<<<
  3158. * weight_t inc, int32_t nr) nogil:
  3159. * memcpy(output, x, sizeof(output[0]) * nr)
  3160. */
  3161. /* function exit code */
  3162. }
  3163. /* "linalg.pxd":76
  3164. *
  3165. * @staticmethod
  3166. * cdef inline void add_i(weight_t* vec, weight_t inc, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3167. * cdef int i
  3168. * for i in range(nr):
  3169. */
  3170. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_inc, int32_t __pyx_v_nr) {
  3171. int __pyx_v_i;
  3172. int32_t __pyx_t_1;
  3173. int32_t __pyx_t_2;
  3174. int __pyx_t_3;
  3175. int __pyx_t_4;
  3176. /* "linalg.pxd":78
  3177. * cdef inline void add_i(weight_t* vec, weight_t inc, int32_t nr) nogil:
  3178. * cdef int i
  3179. * for i in range(nr): # <<<<<<<<<<<<<<
  3180. * vec[i] += inc
  3181. *
  3182. */
  3183. __pyx_t_1 = __pyx_v_nr;
  3184. __pyx_t_2 = __pyx_t_1;
  3185. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3186. __pyx_v_i = __pyx_t_3;
  3187. /* "linalg.pxd":79
  3188. * cdef int i
  3189. * for i in range(nr):
  3190. * vec[i] += inc # <<<<<<<<<<<<<<
  3191. *
  3192. * @staticmethod
  3193. */
  3194. __pyx_t_4 = __pyx_v_i;
  3195. (__pyx_v_vec[__pyx_t_4]) = ((__pyx_v_vec[__pyx_t_4]) + __pyx_v_inc);
  3196. }
  3197. /* "linalg.pxd":76
  3198. *
  3199. * @staticmethod
  3200. * cdef inline void add_i(weight_t* vec, weight_t inc, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3201. * cdef int i
  3202. * for i in range(nr):
  3203. */
  3204. /* function exit code */
  3205. }
  3206. /* "linalg.pxd":82
  3207. *
  3208. * @staticmethod
  3209. * cdef inline void mul(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3210. * int32_t nr) nogil:
  3211. * memcpy(output, vec, sizeof(output[0]) * nr)
  3212. */
  3213. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr) {
  3214. /* "linalg.pxd":84
  3215. * cdef inline void mul(weight_t* output, const weight_t* vec, weight_t scal,
  3216. * int32_t nr) nogil:
  3217. * memcpy(output, vec, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3218. * Vec.mul_i(output, scal, nr)
  3219. *
  3220. */
  3221. (void)(memcpy(__pyx_v_output, __pyx_v_vec, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3222. /* "linalg.pxd":85
  3223. * int32_t nr) nogil:
  3224. * memcpy(output, vec, sizeof(output[0]) * nr)
  3225. * Vec.mul_i(output, scal, nr) # <<<<<<<<<<<<<<
  3226. *
  3227. * @staticmethod
  3228. */
  3229. __pyx_f_5thinc_6linalg_3Vec_mul_i(__pyx_v_output, __pyx_v_scal, __pyx_v_nr);
  3230. /* "linalg.pxd":82
  3231. *
  3232. * @staticmethod
  3233. * cdef inline void mul(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3234. * int32_t nr) nogil:
  3235. * memcpy(output, vec, sizeof(output[0]) * nr)
  3236. */
  3237. /* function exit code */
  3238. }
  3239. /* "linalg.pxd":88
  3240. *
  3241. * @staticmethod
  3242. * cdef inline void mul_i(weight_t* vec, weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3243. * cdef int i
  3244. * IF USE_BLAS:
  3245. */
  3246. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr) {
  3247. int __pyx_v_i;
  3248. int32_t __pyx_t_1;
  3249. int32_t __pyx_t_2;
  3250. int __pyx_t_3;
  3251. int __pyx_t_4;
  3252. /* "linalg.pxd":93
  3253. * blis.scalv(blis.NO_CONJUGATE, nr, scal, vec, 1)
  3254. * ELSE:
  3255. * for i in range(nr): # <<<<<<<<<<<<<<
  3256. * vec[i] *= scal
  3257. *
  3258. */
  3259. __pyx_t_1 = __pyx_v_nr;
  3260. __pyx_t_2 = __pyx_t_1;
  3261. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3262. __pyx_v_i = __pyx_t_3;
  3263. /* "linalg.pxd":94
  3264. * ELSE:
  3265. * for i in range(nr):
  3266. * vec[i] *= scal # <<<<<<<<<<<<<<
  3267. *
  3268. * @staticmethod
  3269. */
  3270. __pyx_t_4 = __pyx_v_i;
  3271. (__pyx_v_vec[__pyx_t_4]) = ((__pyx_v_vec[__pyx_t_4]) * __pyx_v_scal);
  3272. }
  3273. /* "linalg.pxd":88
  3274. *
  3275. * @staticmethod
  3276. * cdef inline void mul_i(weight_t* vec, weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3277. * cdef int i
  3278. * IF USE_BLAS:
  3279. */
  3280. /* function exit code */
  3281. }
  3282. /* "linalg.pxd":97
  3283. *
  3284. * @staticmethod
  3285. * cdef inline void pow(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3286. * int32_t nr) nogil:
  3287. * memcpy(output, vec, sizeof(output[0]) * nr)
  3288. */
  3289. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr) {
  3290. /* "linalg.pxd":99
  3291. * cdef inline void pow(weight_t* output, const weight_t* vec, weight_t scal,
  3292. * int32_t nr) nogil:
  3293. * memcpy(output, vec, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3294. * Vec.pow_i(output, scal, nr)
  3295. *
  3296. */
  3297. (void)(memcpy(__pyx_v_output, __pyx_v_vec, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3298. /* "linalg.pxd":100
  3299. * int32_t nr) nogil:
  3300. * memcpy(output, vec, sizeof(output[0]) * nr)
  3301. * Vec.pow_i(output, scal, nr) # <<<<<<<<<<<<<<
  3302. *
  3303. * @staticmethod
  3304. */
  3305. __pyx_f_5thinc_6linalg_3Vec_pow_i(__pyx_v_output, __pyx_v_scal, __pyx_v_nr);
  3306. /* "linalg.pxd":97
  3307. *
  3308. * @staticmethod
  3309. * cdef inline void pow(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3310. * int32_t nr) nogil:
  3311. * memcpy(output, vec, sizeof(output[0]) * nr)
  3312. */
  3313. /* function exit code */
  3314. }
  3315. /* "linalg.pxd":103
  3316. *
  3317. * @staticmethod
  3318. * cdef inline void pow_i(weight_t* vec, const weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3319. * cdef int i
  3320. * for i in range(nr):
  3321. */
  3322. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_pow_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t const __pyx_v_scal, int32_t __pyx_v_nr) {
  3323. int __pyx_v_i;
  3324. int32_t __pyx_t_1;
  3325. int32_t __pyx_t_2;
  3326. int __pyx_t_3;
  3327. int __pyx_t_4;
  3328. /* "linalg.pxd":105
  3329. * cdef inline void pow_i(weight_t* vec, const weight_t scal, int32_t nr) nogil:
  3330. * cdef int i
  3331. * for i in range(nr): # <<<<<<<<<<<<<<
  3332. * vec[i] **= scal
  3333. *
  3334. */
  3335. __pyx_t_1 = __pyx_v_nr;
  3336. __pyx_t_2 = __pyx_t_1;
  3337. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3338. __pyx_v_i = __pyx_t_3;
  3339. /* "linalg.pxd":106
  3340. * cdef int i
  3341. * for i in range(nr):
  3342. * vec[i] **= scal # <<<<<<<<<<<<<<
  3343. *
  3344. * @staticmethod
  3345. */
  3346. __pyx_t_4 = __pyx_v_i;
  3347. (__pyx_v_vec[__pyx_t_4]) = powf((__pyx_v_vec[__pyx_t_4]), ((__pyx_t_5thinc_8typedefs_weight_t)__pyx_v_scal));
  3348. }
  3349. /* "linalg.pxd":103
  3350. *
  3351. * @staticmethod
  3352. * cdef inline void pow_i(weight_t* vec, const weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3353. * cdef int i
  3354. * for i in range(nr):
  3355. */
  3356. /* function exit code */
  3357. }
  3358. /* "linalg.pxd":110
  3359. * @staticmethod
  3360. * @cython.cdivision(True)
  3361. * cdef inline void div(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3362. * int32_t nr) nogil:
  3363. * memcpy(output, vec, sizeof(output[0]) * nr)
  3364. */
  3365. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scal, int32_t __pyx_v_nr) {
  3366. /* "linalg.pxd":112
  3367. * cdef inline void div(weight_t* output, const weight_t* vec, weight_t scal,
  3368. * int32_t nr) nogil:
  3369. * memcpy(output, vec, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3370. * Vec.div_i(output, scal, nr)
  3371. *
  3372. */
  3373. (void)(memcpy(__pyx_v_output, __pyx_v_vec, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3374. /* "linalg.pxd":113
  3375. * int32_t nr) nogil:
  3376. * memcpy(output, vec, sizeof(output[0]) * nr)
  3377. * Vec.div_i(output, scal, nr) # <<<<<<<<<<<<<<
  3378. *
  3379. * @staticmethod
  3380. */
  3381. __pyx_f_5thinc_6linalg_3Vec_div_i(__pyx_v_output, __pyx_v_scal, __pyx_v_nr);
  3382. /* "linalg.pxd":110
  3383. * @staticmethod
  3384. * @cython.cdivision(True)
  3385. * cdef inline void div(weight_t* output, const weight_t* vec, weight_t scal, # <<<<<<<<<<<<<<
  3386. * int32_t nr) nogil:
  3387. * memcpy(output, vec, sizeof(output[0]) * nr)
  3388. */
  3389. /* function exit code */
  3390. }
  3391. /* "linalg.pxd":117
  3392. * @staticmethod
  3393. * @cython.cdivision(True)
  3394. * cdef inline void div_i(weight_t* vec, const weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3395. * cdef int i
  3396. * for i in range(nr):
  3397. */
  3398. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_div_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t const __pyx_v_scal, int32_t __pyx_v_nr) {
  3399. int __pyx_v_i;
  3400. int32_t __pyx_t_1;
  3401. int32_t __pyx_t_2;
  3402. int __pyx_t_3;
  3403. int __pyx_t_4;
  3404. /* "linalg.pxd":119
  3405. * cdef inline void div_i(weight_t* vec, const weight_t scal, int32_t nr) nogil:
  3406. * cdef int i
  3407. * for i in range(nr): # <<<<<<<<<<<<<<
  3408. * vec[i] /= scal
  3409. *
  3410. */
  3411. __pyx_t_1 = __pyx_v_nr;
  3412. __pyx_t_2 = __pyx_t_1;
  3413. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3414. __pyx_v_i = __pyx_t_3;
  3415. /* "linalg.pxd":120
  3416. * cdef int i
  3417. * for i in range(nr):
  3418. * vec[i] /= scal # <<<<<<<<<<<<<<
  3419. *
  3420. * @staticmethod
  3421. */
  3422. __pyx_t_4 = __pyx_v_i;
  3423. (__pyx_v_vec[__pyx_t_4]) = ((__pyx_v_vec[__pyx_t_4]) / __pyx_v_scal);
  3424. }
  3425. /* "linalg.pxd":117
  3426. * @staticmethod
  3427. * @cython.cdivision(True)
  3428. * cdef inline void div_i(weight_t* vec, const weight_t scal, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3429. * cdef int i
  3430. * for i in range(nr):
  3431. */
  3432. /* function exit code */
  3433. }
  3434. /* "linalg.pxd":123
  3435. *
  3436. * @staticmethod
  3437. * cdef inline void exp(weight_t* output, const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3438. * memcpy(output, vec, sizeof(output[0]) * nr)
  3439. * Vec.exp_i(output, nr)
  3440. */
  3441. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr) {
  3442. /* "linalg.pxd":124
  3443. * @staticmethod
  3444. * cdef inline void exp(weight_t* output, const weight_t* vec, int32_t nr) nogil:
  3445. * memcpy(output, vec, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3446. * Vec.exp_i(output, nr)
  3447. *
  3448. */
  3449. (void)(memcpy(__pyx_v_output, __pyx_v_vec, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3450. /* "linalg.pxd":125
  3451. * cdef inline void exp(weight_t* output, const weight_t* vec, int32_t nr) nogil:
  3452. * memcpy(output, vec, sizeof(output[0]) * nr)
  3453. * Vec.exp_i(output, nr) # <<<<<<<<<<<<<<
  3454. *
  3455. * @staticmethod
  3456. */
  3457. __pyx_f_5thinc_6linalg_3Vec_exp_i(__pyx_v_output, __pyx_v_nr);
  3458. /* "linalg.pxd":123
  3459. *
  3460. * @staticmethod
  3461. * cdef inline void exp(weight_t* output, const weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3462. * memcpy(output, vec, sizeof(output[0]) * nr)
  3463. * Vec.exp_i(output, nr)
  3464. */
  3465. /* function exit code */
  3466. }
  3467. /* "linalg.pxd":128
  3468. *
  3469. * @staticmethod
  3470. * cdef inline void exp_i(weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3471. * cdef int i
  3472. * for i in range(nr):
  3473. */
  3474. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_exp_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, int32_t __pyx_v_nr) {
  3475. int __pyx_v_i;
  3476. int32_t __pyx_t_1;
  3477. int32_t __pyx_t_2;
  3478. int __pyx_t_3;
  3479. /* "linalg.pxd":130
  3480. * cdef inline void exp_i(weight_t* vec, int32_t nr) nogil:
  3481. * cdef int i
  3482. * for i in range(nr): # <<<<<<<<<<<<<<
  3483. * vec[i] = exp(vec[i])
  3484. *
  3485. */
  3486. __pyx_t_1 = __pyx_v_nr;
  3487. __pyx_t_2 = __pyx_t_1;
  3488. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3489. __pyx_v_i = __pyx_t_3;
  3490. /* "linalg.pxd":131
  3491. * cdef int i
  3492. * for i in range(nr):
  3493. * vec[i] = exp(vec[i]) # <<<<<<<<<<<<<<
  3494. *
  3495. * @staticmethod
  3496. */
  3497. (__pyx_v_vec[__pyx_v_i]) = exp((__pyx_v_vec[__pyx_v_i]));
  3498. }
  3499. /* "linalg.pxd":128
  3500. *
  3501. * @staticmethod
  3502. * cdef inline void exp_i(weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3503. * cdef int i
  3504. * for i in range(nr):
  3505. */
  3506. /* function exit code */
  3507. }
  3508. /* "linalg.pxd":134
  3509. *
  3510. * @staticmethod
  3511. * cdef inline void reciprocal_i(weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3512. * cdef int i
  3513. * for i in range(nr):
  3514. */
  3515. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Vec_reciprocal_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_vec, int32_t __pyx_v_nr) {
  3516. int __pyx_v_i;
  3517. int32_t __pyx_t_1;
  3518. int32_t __pyx_t_2;
  3519. int __pyx_t_3;
  3520. /* "linalg.pxd":136
  3521. * cdef inline void reciprocal_i(weight_t* vec, int32_t nr) nogil:
  3522. * cdef int i
  3523. * for i in range(nr): # <<<<<<<<<<<<<<
  3524. * vec[i] = 1.0 / vec[i]
  3525. *
  3526. */
  3527. __pyx_t_1 = __pyx_v_nr;
  3528. __pyx_t_2 = __pyx_t_1;
  3529. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3530. __pyx_v_i = __pyx_t_3;
  3531. /* "linalg.pxd":137
  3532. * cdef int i
  3533. * for i in range(nr):
  3534. * vec[i] = 1.0 / vec[i] # <<<<<<<<<<<<<<
  3535. *
  3536. *
  3537. */
  3538. (__pyx_v_vec[__pyx_v_i]) = (1.0 / (__pyx_v_vec[__pyx_v_i]));
  3539. }
  3540. /* "linalg.pxd":134
  3541. *
  3542. * @staticmethod
  3543. * cdef inline void reciprocal_i(weight_t* vec, int32_t nr) nogil: # <<<<<<<<<<<<<<
  3544. * cdef int i
  3545. * for i in range(nr):
  3546. */
  3547. /* function exit code */
  3548. }
  3549. /* "linalg.pxd":142
  3550. * cdef class VecVec:
  3551. * @staticmethod
  3552. * cdef inline void add(weight_t* output, # <<<<<<<<<<<<<<
  3553. * const weight_t* x,
  3554. * const weight_t* y,
  3555. */
  3556. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr) {
  3557. /* "linalg.pxd":147
  3558. * weight_t scale,
  3559. * int32_t nr) nogil:
  3560. * memcpy(output, x, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3561. * VecVec.add_i(output, y, scale, nr)
  3562. *
  3563. */
  3564. (void)(memcpy(__pyx_v_output, __pyx_v_x, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3565. /* "linalg.pxd":148
  3566. * int32_t nr) nogil:
  3567. * memcpy(output, x, sizeof(output[0]) * nr)
  3568. * VecVec.add_i(output, y, scale, nr) # <<<<<<<<<<<<<<
  3569. *
  3570. * @staticmethod
  3571. */
  3572. __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_v_output, __pyx_v_y, __pyx_v_scale, __pyx_v_nr);
  3573. /* "linalg.pxd":142
  3574. * cdef class VecVec:
  3575. * @staticmethod
  3576. * cdef inline void add(weight_t* output, # <<<<<<<<<<<<<<
  3577. * const weight_t* x,
  3578. * const weight_t* y,
  3579. */
  3580. /* function exit code */
  3581. }
  3582. /* "linalg.pxd":151
  3583. *
  3584. * @staticmethod
  3585. * cdef inline void add_i(weight_t* x, # <<<<<<<<<<<<<<
  3586. * const weight_t* y,
  3587. * weight_t scale,
  3588. */
  3589. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr) {
  3590. int __pyx_v_i;
  3591. int32_t __pyx_t_1;
  3592. int32_t __pyx_t_2;
  3593. int __pyx_t_3;
  3594. int __pyx_t_4;
  3595. /* "linalg.pxd":159
  3596. * blis.axpyv(blis.NO_CONJUGATE, nr, scale, <weight_t*>y, 1, x, 1)
  3597. * ELSE:
  3598. * for i in range(nr): # <<<<<<<<<<<<<<
  3599. * x[i] += y[i] * scale
  3600. *
  3601. */
  3602. __pyx_t_1 = __pyx_v_nr;
  3603. __pyx_t_2 = __pyx_t_1;
  3604. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3605. __pyx_v_i = __pyx_t_3;
  3606. /* "linalg.pxd":160
  3607. * ELSE:
  3608. * for i in range(nr):
  3609. * x[i] += y[i] * scale # <<<<<<<<<<<<<<
  3610. *
  3611. * @staticmethod
  3612. */
  3613. __pyx_t_4 = __pyx_v_i;
  3614. (__pyx_v_x[__pyx_t_4]) = ((__pyx_v_x[__pyx_t_4]) + ((__pyx_v_y[__pyx_v_i]) * __pyx_v_scale));
  3615. }
  3616. /* "linalg.pxd":151
  3617. *
  3618. * @staticmethod
  3619. * cdef inline void add_i(weight_t* x, # <<<<<<<<<<<<<<
  3620. * const weight_t* y,
  3621. * weight_t scale,
  3622. */
  3623. /* function exit code */
  3624. }
  3625. /* "linalg.pxd":163
  3626. *
  3627. * @staticmethod
  3628. * cdef inline void batch_add_i(weight_t* x, # <<<<<<<<<<<<<<
  3629. * const weight_t* y,
  3630. * weight_t scale,
  3631. */
  3632. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_batch_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr, int32_t __pyx_v_nr_batch) {
  3633. CYTHON_UNUSED int __pyx_v__;
  3634. int32_t __pyx_t_1;
  3635. int32_t __pyx_t_2;
  3636. int __pyx_t_3;
  3637. /* "linalg.pxd":169
  3638. * # For fixed x, matrix of y
  3639. * cdef int i, _
  3640. * for _ in range(nr_batch): # <<<<<<<<<<<<<<
  3641. * VecVec.add_i(x,
  3642. * y, scale, nr)
  3643. */
  3644. __pyx_t_1 = __pyx_v_nr_batch;
  3645. __pyx_t_2 = __pyx_t_1;
  3646. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3647. __pyx_v__ = __pyx_t_3;
  3648. /* "linalg.pxd":170
  3649. * cdef int i, _
  3650. * for _ in range(nr_batch):
  3651. * VecVec.add_i(x, # <<<<<<<<<<<<<<
  3652. * y, scale, nr)
  3653. * y += nr
  3654. */
  3655. __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_v_x, __pyx_v_y, __pyx_v_scale, __pyx_v_nr);
  3656. /* "linalg.pxd":172
  3657. * VecVec.add_i(x,
  3658. * y, scale, nr)
  3659. * y += nr # <<<<<<<<<<<<<<
  3660. *
  3661. * @staticmethod
  3662. */
  3663. __pyx_v_y = (__pyx_v_y + __pyx_v_nr);
  3664. }
  3665. /* "linalg.pxd":163
  3666. *
  3667. * @staticmethod
  3668. * cdef inline void batch_add_i(weight_t* x, # <<<<<<<<<<<<<<
  3669. * const weight_t* y,
  3670. * weight_t scale,
  3671. */
  3672. /* function exit code */
  3673. }
  3674. /* "linalg.pxd":175
  3675. *
  3676. * @staticmethod
  3677. * cdef inline void add_pow(weight_t* output, # <<<<<<<<<<<<<<
  3678. * const weight_t* x, const weight_t* y, weight_t power, int32_t nr) nogil:
  3679. * memcpy(output, x, sizeof(output[0]) * nr)
  3680. */
  3681. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_power, int32_t __pyx_v_nr) {
  3682. /* "linalg.pxd":177
  3683. * cdef inline void add_pow(weight_t* output,
  3684. * const weight_t* x, const weight_t* y, weight_t power, int32_t nr) nogil:
  3685. * memcpy(output, x, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3686. * VecVec.add_pow_i(output, y, power, nr)
  3687. *
  3688. */
  3689. (void)(memcpy(__pyx_v_output, __pyx_v_x, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3690. /* "linalg.pxd":178
  3691. * const weight_t* x, const weight_t* y, weight_t power, int32_t nr) nogil:
  3692. * memcpy(output, x, sizeof(output[0]) * nr)
  3693. * VecVec.add_pow_i(output, y, power, nr) # <<<<<<<<<<<<<<
  3694. *
  3695. *
  3696. */
  3697. __pyx_f_5thinc_6linalg_6VecVec_add_pow_i(__pyx_v_output, __pyx_v_y, __pyx_v_power, __pyx_v_nr);
  3698. /* "linalg.pxd":175
  3699. *
  3700. * @staticmethod
  3701. * cdef inline void add_pow(weight_t* output, # <<<<<<<<<<<<<<
  3702. * const weight_t* x, const weight_t* y, weight_t power, int32_t nr) nogil:
  3703. * memcpy(output, x, sizeof(output[0]) * nr)
  3704. */
  3705. /* function exit code */
  3706. }
  3707. /* "linalg.pxd":182
  3708. *
  3709. * @staticmethod
  3710. * cdef inline void add_pow_i(weight_t* x, # <<<<<<<<<<<<<<
  3711. * const weight_t* y, weight_t power, int32_t nr) nogil:
  3712. * cdef int i
  3713. */
  3714. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_add_pow_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_power, int32_t __pyx_v_nr) {
  3715. int __pyx_v_i;
  3716. int32_t __pyx_t_1;
  3717. int32_t __pyx_t_2;
  3718. int __pyx_t_3;
  3719. int __pyx_t_4;
  3720. /* "linalg.pxd":185
  3721. * const weight_t* y, weight_t power, int32_t nr) nogil:
  3722. * cdef int i
  3723. * for i in range(nr): # <<<<<<<<<<<<<<
  3724. * x[i] += y[i] ** power
  3725. *
  3726. */
  3727. __pyx_t_1 = __pyx_v_nr;
  3728. __pyx_t_2 = __pyx_t_1;
  3729. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3730. __pyx_v_i = __pyx_t_3;
  3731. /* "linalg.pxd":186
  3732. * cdef int i
  3733. * for i in range(nr):
  3734. * x[i] += y[i] ** power # <<<<<<<<<<<<<<
  3735. *
  3736. * @staticmethod
  3737. */
  3738. __pyx_t_4 = __pyx_v_i;
  3739. (__pyx_v_x[__pyx_t_4]) = ((__pyx_v_x[__pyx_t_4]) + powf(((__pyx_t_5thinc_8typedefs_weight_t)(__pyx_v_y[__pyx_v_i])), __pyx_v_power));
  3740. }
  3741. /* "linalg.pxd":182
  3742. *
  3743. * @staticmethod
  3744. * cdef inline void add_pow_i(weight_t* x, # <<<<<<<<<<<<<<
  3745. * const weight_t* y, weight_t power, int32_t nr) nogil:
  3746. * cdef int i
  3747. */
  3748. /* function exit code */
  3749. }
  3750. /* "linalg.pxd":189
  3751. *
  3752. * @staticmethod
  3753. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  3754. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3755. * memcpy(output, x, sizeof(output[0]) * nr)
  3756. */
  3757. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr) {
  3758. /* "linalg.pxd":191
  3759. * cdef inline void mul(weight_t* output,
  3760. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3761. * memcpy(output, x, sizeof(output[0]) * nr) # <<<<<<<<<<<<<<
  3762. * VecVec.mul_i(output, y, nr)
  3763. *
  3764. */
  3765. (void)(memcpy(__pyx_v_output, __pyx_v_x, ((sizeof((__pyx_v_output[0]))) * __pyx_v_nr)));
  3766. /* "linalg.pxd":192
  3767. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3768. * memcpy(output, x, sizeof(output[0]) * nr)
  3769. * VecVec.mul_i(output, y, nr) # <<<<<<<<<<<<<<
  3770. *
  3771. * @staticmethod
  3772. */
  3773. __pyx_f_5thinc_6linalg_6VecVec_mul_i(__pyx_v_output, __pyx_v_y, __pyx_v_nr);
  3774. /* "linalg.pxd":189
  3775. *
  3776. * @staticmethod
  3777. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  3778. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3779. * memcpy(output, x, sizeof(output[0]) * nr)
  3780. */
  3781. /* function exit code */
  3782. }
  3783. /* "linalg.pxd":195
  3784. *
  3785. * @staticmethod
  3786. * cdef inline void mul_i(weight_t* x, # <<<<<<<<<<<<<<
  3787. * const weight_t* y, int32_t nr) nogil:
  3788. * cdef int i
  3789. */
  3790. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6VecVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr) {
  3791. int __pyx_v_i;
  3792. int32_t __pyx_t_1;
  3793. int32_t __pyx_t_2;
  3794. int __pyx_t_3;
  3795. int __pyx_t_4;
  3796. /* "linalg.pxd":198
  3797. * const weight_t* y, int32_t nr) nogil:
  3798. * cdef int i
  3799. * for i in range(nr): # <<<<<<<<<<<<<<
  3800. * x[i] *= y[i]
  3801. *
  3802. */
  3803. __pyx_t_1 = __pyx_v_nr;
  3804. __pyx_t_2 = __pyx_t_1;
  3805. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3806. __pyx_v_i = __pyx_t_3;
  3807. /* "linalg.pxd":199
  3808. * cdef int i
  3809. * for i in range(nr):
  3810. * x[i] *= y[i] # <<<<<<<<<<<<<<
  3811. *
  3812. * @staticmethod
  3813. */
  3814. __pyx_t_4 = __pyx_v_i;
  3815. (__pyx_v_x[__pyx_t_4]) = ((__pyx_v_x[__pyx_t_4]) * (__pyx_v_y[__pyx_v_i]));
  3816. }
  3817. /* "linalg.pxd":195
  3818. *
  3819. * @staticmethod
  3820. * cdef inline void mul_i(weight_t* x, # <<<<<<<<<<<<<<
  3821. * const weight_t* y, int32_t nr) nogil:
  3822. * cdef int i
  3823. */
  3824. /* function exit code */
  3825. }
  3826. /* "linalg.pxd":202
  3827. *
  3828. * @staticmethod
  3829. * cdef inline weight_t dot( # <<<<<<<<<<<<<<
  3830. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3831. * cdef int i
  3832. */
  3833. static CYTHON_INLINE __pyx_t_5thinc_8typedefs_weight_t __pyx_f_5thinc_6linalg_6VecVec_dot(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr) {
  3834. int __pyx_v_i;
  3835. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_total;
  3836. __pyx_t_5thinc_8typedefs_weight_t __pyx_r;
  3837. int32_t __pyx_t_1;
  3838. int32_t __pyx_t_2;
  3839. int __pyx_t_3;
  3840. /* "linalg.pxd":205
  3841. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3842. * cdef int i
  3843. * cdef weight_t total = 0 # <<<<<<<<<<<<<<
  3844. * for i in range(nr):
  3845. * total += x[i] * y[i]
  3846. */
  3847. __pyx_v_total = 0.0;
  3848. /* "linalg.pxd":206
  3849. * cdef int i
  3850. * cdef weight_t total = 0
  3851. * for i in range(nr): # <<<<<<<<<<<<<<
  3852. * total += x[i] * y[i]
  3853. * return total
  3854. */
  3855. __pyx_t_1 = __pyx_v_nr;
  3856. __pyx_t_2 = __pyx_t_1;
  3857. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3858. __pyx_v_i = __pyx_t_3;
  3859. /* "linalg.pxd":207
  3860. * cdef weight_t total = 0
  3861. * for i in range(nr):
  3862. * total += x[i] * y[i] # <<<<<<<<<<<<<<
  3863. * return total
  3864. *
  3865. */
  3866. __pyx_v_total = (__pyx_v_total + ((__pyx_v_x[__pyx_v_i]) * (__pyx_v_y[__pyx_v_i])));
  3867. }
  3868. /* "linalg.pxd":208
  3869. * for i in range(nr):
  3870. * total += x[i] * y[i]
  3871. * return total # <<<<<<<<<<<<<<
  3872. *
  3873. * @staticmethod
  3874. */
  3875. __pyx_r = __pyx_v_total;
  3876. goto __pyx_L0;
  3877. /* "linalg.pxd":202
  3878. *
  3879. * @staticmethod
  3880. * cdef inline weight_t dot( # <<<<<<<<<<<<<<
  3881. * const weight_t* x, const weight_t* y, int32_t nr) nogil:
  3882. * cdef int i
  3883. */
  3884. /* function exit code */
  3885. __pyx_L0:;
  3886. return __pyx_r;
  3887. }
  3888. /* "linalg.pxd":211
  3889. *
  3890. * @staticmethod
  3891. * cdef inline int arg_max_if_true( # <<<<<<<<<<<<<<
  3892. * const weight_t* scores, const int* is_valid, const int n_classes) nogil:
  3893. * cdef int i
  3894. */
  3895. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_true(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, int const *__pyx_v_is_valid, int const __pyx_v_n_classes) {
  3896. int __pyx_v_i;
  3897. int __pyx_v_best;
  3898. int __pyx_r;
  3899. int __pyx_t_1;
  3900. int __pyx_t_2;
  3901. int __pyx_t_3;
  3902. int __pyx_t_4;
  3903. int __pyx_t_5;
  3904. /* "linalg.pxd":214
  3905. * const weight_t* scores, const int* is_valid, const int n_classes) nogil:
  3906. * cdef int i
  3907. * cdef int best = -1 # <<<<<<<<<<<<<<
  3908. * for i in range(n_classes):
  3909. * if is_valid[i] and (best == -1 or scores[i] > scores[best]):
  3910. */
  3911. __pyx_v_best = -1;
  3912. /* "linalg.pxd":215
  3913. * cdef int i
  3914. * cdef int best = -1
  3915. * for i in range(n_classes): # <<<<<<<<<<<<<<
  3916. * if is_valid[i] and (best == -1 or scores[i] > scores[best]):
  3917. * best = i
  3918. */
  3919. __pyx_t_1 = __pyx_v_n_classes;
  3920. __pyx_t_2 = __pyx_t_1;
  3921. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  3922. __pyx_v_i = __pyx_t_3;
  3923. /* "linalg.pxd":216
  3924. * cdef int best = -1
  3925. * for i in range(n_classes):
  3926. * if is_valid[i] and (best == -1 or scores[i] > scores[best]): # <<<<<<<<<<<<<<
  3927. * best = i
  3928. * return best
  3929. */
  3930. __pyx_t_5 = ((__pyx_v_is_valid[__pyx_v_i]) != 0);
  3931. if (__pyx_t_5) {
  3932. } else {
  3933. __pyx_t_4 = __pyx_t_5;
  3934. goto __pyx_L6_bool_binop_done;
  3935. }
  3936. __pyx_t_5 = ((__pyx_v_best == -1L) != 0);
  3937. if (!__pyx_t_5) {
  3938. } else {
  3939. __pyx_t_4 = __pyx_t_5;
  3940. goto __pyx_L6_bool_binop_done;
  3941. }
  3942. __pyx_t_5 = (((__pyx_v_scores[__pyx_v_i]) > (__pyx_v_scores[__pyx_v_best])) != 0);
  3943. __pyx_t_4 = __pyx_t_5;
  3944. __pyx_L6_bool_binop_done:;
  3945. if (__pyx_t_4) {
  3946. /* "linalg.pxd":217
  3947. * for i in range(n_classes):
  3948. * if is_valid[i] and (best == -1 or scores[i] > scores[best]):
  3949. * best = i # <<<<<<<<<<<<<<
  3950. * return best
  3951. *
  3952. */
  3953. __pyx_v_best = __pyx_v_i;
  3954. /* "linalg.pxd":216
  3955. * cdef int best = -1
  3956. * for i in range(n_classes):
  3957. * if is_valid[i] and (best == -1 or scores[i] > scores[best]): # <<<<<<<<<<<<<<
  3958. * best = i
  3959. * return best
  3960. */
  3961. }
  3962. }
  3963. /* "linalg.pxd":218
  3964. * if is_valid[i] and (best == -1 or scores[i] > scores[best]):
  3965. * best = i
  3966. * return best # <<<<<<<<<<<<<<
  3967. *
  3968. * @staticmethod
  3969. */
  3970. __pyx_r = __pyx_v_best;
  3971. goto __pyx_L0;
  3972. /* "linalg.pxd":211
  3973. *
  3974. * @staticmethod
  3975. * cdef inline int arg_max_if_true( # <<<<<<<<<<<<<<
  3976. * const weight_t* scores, const int* is_valid, const int n_classes) nogil:
  3977. * cdef int i
  3978. */
  3979. /* function exit code */
  3980. __pyx_L0:;
  3981. return __pyx_r;
  3982. }
  3983. /* "linalg.pxd":221
  3984. *
  3985. * @staticmethod
  3986. * cdef inline int arg_max_if_zero( # <<<<<<<<<<<<<<
  3987. * const weight_t* scores, const weight_t* costs, const int n_classes) nogil:
  3988. * cdef int i
  3989. */
  3990. static CYTHON_INLINE int __pyx_f_5thinc_6linalg_6VecVec_arg_max_if_zero(__pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_scores, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_costs, int const __pyx_v_n_classes) {
  3991. int __pyx_v_i;
  3992. int __pyx_v_best;
  3993. int __pyx_r;
  3994. int __pyx_t_1;
  3995. int __pyx_t_2;
  3996. int __pyx_t_3;
  3997. int __pyx_t_4;
  3998. int __pyx_t_5;
  3999. /* "linalg.pxd":224
  4000. * const weight_t* scores, const weight_t* costs, const int n_classes) nogil:
  4001. * cdef int i
  4002. * cdef int best = -1 # <<<<<<<<<<<<<<
  4003. * for i in range(n_classes):
  4004. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]):
  4005. */
  4006. __pyx_v_best = -1;
  4007. /* "linalg.pxd":225
  4008. * cdef int i
  4009. * cdef int best = -1
  4010. * for i in range(n_classes): # <<<<<<<<<<<<<<
  4011. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]):
  4012. * best = i
  4013. */
  4014. __pyx_t_1 = __pyx_v_n_classes;
  4015. __pyx_t_2 = __pyx_t_1;
  4016. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4017. __pyx_v_i = __pyx_t_3;
  4018. /* "linalg.pxd":226
  4019. * cdef int best = -1
  4020. * for i in range(n_classes):
  4021. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]): # <<<<<<<<<<<<<<
  4022. * best = i
  4023. * return best
  4024. */
  4025. __pyx_t_5 = (((__pyx_v_costs[__pyx_v_i]) == 0.0) != 0);
  4026. if (__pyx_t_5) {
  4027. } else {
  4028. __pyx_t_4 = __pyx_t_5;
  4029. goto __pyx_L6_bool_binop_done;
  4030. }
  4031. __pyx_t_5 = ((__pyx_v_best == -1L) != 0);
  4032. if (!__pyx_t_5) {
  4033. } else {
  4034. __pyx_t_4 = __pyx_t_5;
  4035. goto __pyx_L6_bool_binop_done;
  4036. }
  4037. __pyx_t_5 = (((__pyx_v_scores[__pyx_v_i]) > (__pyx_v_scores[__pyx_v_best])) != 0);
  4038. __pyx_t_4 = __pyx_t_5;
  4039. __pyx_L6_bool_binop_done:;
  4040. if (__pyx_t_4) {
  4041. /* "linalg.pxd":227
  4042. * for i in range(n_classes):
  4043. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]):
  4044. * best = i # <<<<<<<<<<<<<<
  4045. * return best
  4046. *
  4047. */
  4048. __pyx_v_best = __pyx_v_i;
  4049. /* "linalg.pxd":226
  4050. * cdef int best = -1
  4051. * for i in range(n_classes):
  4052. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]): # <<<<<<<<<<<<<<
  4053. * best = i
  4054. * return best
  4055. */
  4056. }
  4057. }
  4058. /* "linalg.pxd":228
  4059. * if costs[i] == 0 and (best == -1 or scores[i] > scores[best]):
  4060. * best = i
  4061. * return best # <<<<<<<<<<<<<<
  4062. *
  4063. *
  4064. */
  4065. __pyx_r = __pyx_v_best;
  4066. goto __pyx_L0;
  4067. /* "linalg.pxd":221
  4068. *
  4069. * @staticmethod
  4070. * cdef inline int arg_max_if_zero( # <<<<<<<<<<<<<<
  4071. * const weight_t* scores, const weight_t* costs, const int n_classes) nogil:
  4072. * cdef int i
  4073. */
  4074. /* function exit code */
  4075. __pyx_L0:;
  4076. return __pyx_r;
  4077. }
  4078. /* "linalg.pxd":233
  4079. * cdef class Mat:
  4080. * @staticmethod
  4081. * cdef inline void mean_row(weight_t* Ex, # <<<<<<<<<<<<<<
  4082. * const weight_t* mat, int32_t nr_row, int32_t nr_col) nogil:
  4083. * memset(Ex, 0, sizeof(Ex[0]) * nr_col)
  4084. */
  4085. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_mean_row(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_Ex, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4086. int32_t __pyx_v_i;
  4087. int32_t __pyx_t_1;
  4088. int32_t __pyx_t_2;
  4089. int32_t __pyx_t_3;
  4090. /* "linalg.pxd":235
  4091. * cdef inline void mean_row(weight_t* Ex,
  4092. * const weight_t* mat, int32_t nr_row, int32_t nr_col) nogil:
  4093. * memset(Ex, 0, sizeof(Ex[0]) * nr_col) # <<<<<<<<<<<<<<
  4094. * for i in range(nr_row):
  4095. * VecVec.add_i(Ex, &mat[i * nr_col], 1.0, nr_col)
  4096. */
  4097. (void)(memset(__pyx_v_Ex, 0, ((sizeof((__pyx_v_Ex[0]))) * __pyx_v_nr_col)));
  4098. /* "linalg.pxd":236
  4099. * const weight_t* mat, int32_t nr_row, int32_t nr_col) nogil:
  4100. * memset(Ex, 0, sizeof(Ex[0]) * nr_col)
  4101. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4102. * VecVec.add_i(Ex, &mat[i * nr_col], 1.0, nr_col)
  4103. * Vec.mul_i(Ex, 1.0 / nr_row, nr_col)
  4104. */
  4105. __pyx_t_1 = __pyx_v_nr_row;
  4106. __pyx_t_2 = __pyx_t_1;
  4107. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4108. __pyx_v_i = __pyx_t_3;
  4109. /* "linalg.pxd":237
  4110. * memset(Ex, 0, sizeof(Ex[0]) * nr_col)
  4111. * for i in range(nr_row):
  4112. * VecVec.add_i(Ex, &mat[i * nr_col], 1.0, nr_col) # <<<<<<<<<<<<<<
  4113. * Vec.mul_i(Ex, 1.0 / nr_row, nr_col)
  4114. *
  4115. */
  4116. __pyx_f_5thinc_6linalg_6VecVec_add_i(__pyx_v_Ex, (&(__pyx_v_mat[(__pyx_v_i * __pyx_v_nr_col)])), 1.0, __pyx_v_nr_col);
  4117. }
  4118. /* "linalg.pxd":238
  4119. * for i in range(nr_row):
  4120. * VecVec.add_i(Ex, &mat[i * nr_col], 1.0, nr_col)
  4121. * Vec.mul_i(Ex, 1.0 / nr_row, nr_col) # <<<<<<<<<<<<<<
  4122. *
  4123. * @staticmethod
  4124. */
  4125. __pyx_f_5thinc_6linalg_3Vec_mul_i(__pyx_v_Ex, (1.0 / __pyx_v_nr_row), __pyx_v_nr_col);
  4126. /* "linalg.pxd":233
  4127. * cdef class Mat:
  4128. * @staticmethod
  4129. * cdef inline void mean_row(weight_t* Ex, # <<<<<<<<<<<<<<
  4130. * const weight_t* mat, int32_t nr_row, int32_t nr_col) nogil:
  4131. * memset(Ex, 0, sizeof(Ex[0]) * nr_col)
  4132. */
  4133. /* function exit code */
  4134. }
  4135. /* "linalg.pxd":241
  4136. *
  4137. * @staticmethod
  4138. * cdef inline void var_row(weight_t* Vx, # <<<<<<<<<<<<<<
  4139. * const weight_t* mat, const weight_t* Ex,
  4140. * int32_t nr_row, int32_t nr_col, weight_t eps) nogil:
  4141. */
  4142. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_3Mat_var_row(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_Vx, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_Ex, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_eps) {
  4143. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_sum_;
  4144. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_sum2;
  4145. int32_t __pyx_v_i;
  4146. int32_t __pyx_v_j;
  4147. __pyx_t_5thinc_8typedefs_weight_t __pyx_v_x;
  4148. int __pyx_t_1;
  4149. int __pyx_t_2;
  4150. int32_t __pyx_t_3;
  4151. int32_t __pyx_t_4;
  4152. int32_t __pyx_t_5;
  4153. int32_t __pyx_t_6;
  4154. int32_t __pyx_t_7;
  4155. int32_t __pyx_t_8;
  4156. /* "linalg.pxd":245
  4157. * int32_t nr_row, int32_t nr_col, weight_t eps) nogil:
  4158. * # From https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
  4159. * if nr_row == 0 or nr_col == 0: # <<<<<<<<<<<<<<
  4160. * return
  4161. * cdef weight_t sum_, sum2
  4162. */
  4163. __pyx_t_2 = ((__pyx_v_nr_row == 0) != 0);
  4164. if (!__pyx_t_2) {
  4165. } else {
  4166. __pyx_t_1 = __pyx_t_2;
  4167. goto __pyx_L4_bool_binop_done;
  4168. }
  4169. __pyx_t_2 = ((__pyx_v_nr_col == 0) != 0);
  4170. __pyx_t_1 = __pyx_t_2;
  4171. __pyx_L4_bool_binop_done:;
  4172. if (__pyx_t_1) {
  4173. /* "linalg.pxd":246
  4174. * # From https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
  4175. * if nr_row == 0 or nr_col == 0:
  4176. * return # <<<<<<<<<<<<<<
  4177. * cdef weight_t sum_, sum2
  4178. * for i in range(nr_col):
  4179. */
  4180. goto __pyx_L0;
  4181. /* "linalg.pxd":245
  4182. * int32_t nr_row, int32_t nr_col, weight_t eps) nogil:
  4183. * # From https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
  4184. * if nr_row == 0 or nr_col == 0: # <<<<<<<<<<<<<<
  4185. * return
  4186. * cdef weight_t sum_, sum2
  4187. */
  4188. }
  4189. /* "linalg.pxd":248
  4190. * return
  4191. * cdef weight_t sum_, sum2
  4192. * for i in range(nr_col): # <<<<<<<<<<<<<<
  4193. * sum_ = 0.0
  4194. * sum2 = 0.0
  4195. */
  4196. __pyx_t_3 = __pyx_v_nr_col;
  4197. __pyx_t_4 = __pyx_t_3;
  4198. for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
  4199. __pyx_v_i = __pyx_t_5;
  4200. /* "linalg.pxd":249
  4201. * cdef weight_t sum_, sum2
  4202. * for i in range(nr_col):
  4203. * sum_ = 0.0 # <<<<<<<<<<<<<<
  4204. * sum2 = 0.0
  4205. * for j in range(nr_row):
  4206. */
  4207. __pyx_v_sum_ = 0.0;
  4208. /* "linalg.pxd":250
  4209. * for i in range(nr_col):
  4210. * sum_ = 0.0
  4211. * sum2 = 0.0 # <<<<<<<<<<<<<<
  4212. * for j in range(nr_row):
  4213. * x = mat[j * nr_col + i]
  4214. */
  4215. __pyx_v_sum2 = 0.0;
  4216. /* "linalg.pxd":251
  4217. * sum_ = 0.0
  4218. * sum2 = 0.0
  4219. * for j in range(nr_row): # <<<<<<<<<<<<<<
  4220. * x = mat[j * nr_col + i]
  4221. * sum2 += (x - Ex[i]) ** 2
  4222. */
  4223. __pyx_t_6 = __pyx_v_nr_row;
  4224. __pyx_t_7 = __pyx_t_6;
  4225. for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
  4226. __pyx_v_j = __pyx_t_8;
  4227. /* "linalg.pxd":252
  4228. * sum2 = 0.0
  4229. * for j in range(nr_row):
  4230. * x = mat[j * nr_col + i] # <<<<<<<<<<<<<<
  4231. * sum2 += (x - Ex[i]) ** 2
  4232. * sum_ += x - Ex[i]
  4233. */
  4234. __pyx_v_x = (__pyx_v_mat[((__pyx_v_j * __pyx_v_nr_col) + __pyx_v_i)]);
  4235. /* "linalg.pxd":253
  4236. * for j in range(nr_row):
  4237. * x = mat[j * nr_col + i]
  4238. * sum2 += (x - Ex[i]) ** 2 # <<<<<<<<<<<<<<
  4239. * sum_ += x - Ex[i]
  4240. * Vx[i] = (sum2 - sum_**2 / nr_row) / nr_row
  4241. */
  4242. __pyx_v_sum2 = (__pyx_v_sum2 + powf((__pyx_v_x - (__pyx_v_Ex[__pyx_v_i])), 2.0));
  4243. /* "linalg.pxd":254
  4244. * x = mat[j * nr_col + i]
  4245. * sum2 += (x - Ex[i]) ** 2
  4246. * sum_ += x - Ex[i] # <<<<<<<<<<<<<<
  4247. * Vx[i] = (sum2 - sum_**2 / nr_row) / nr_row
  4248. * Vx[i] += eps
  4249. */
  4250. __pyx_v_sum_ = (__pyx_v_sum_ + (__pyx_v_x - (__pyx_v_Ex[__pyx_v_i])));
  4251. }
  4252. /* "linalg.pxd":255
  4253. * sum2 += (x - Ex[i]) ** 2
  4254. * sum_ += x - Ex[i]
  4255. * Vx[i] = (sum2 - sum_**2 / nr_row) / nr_row # <<<<<<<<<<<<<<
  4256. * Vx[i] += eps
  4257. *
  4258. */
  4259. (__pyx_v_Vx[__pyx_v_i]) = ((__pyx_v_sum2 - (powf(__pyx_v_sum_, 2.0) / __pyx_v_nr_row)) / __pyx_v_nr_row);
  4260. /* "linalg.pxd":256
  4261. * sum_ += x - Ex[i]
  4262. * Vx[i] = (sum2 - sum_**2 / nr_row) / nr_row
  4263. * Vx[i] += eps # <<<<<<<<<<<<<<
  4264. *
  4265. *
  4266. */
  4267. __pyx_t_6 = __pyx_v_i;
  4268. (__pyx_v_Vx[__pyx_t_6]) = ((__pyx_v_Vx[__pyx_t_6]) + __pyx_v_eps);
  4269. }
  4270. /* "linalg.pxd":241
  4271. *
  4272. * @staticmethod
  4273. * cdef inline void var_row(weight_t* Vx, # <<<<<<<<<<<<<<
  4274. * const weight_t* mat, const weight_t* Ex,
  4275. * int32_t nr_row, int32_t nr_col, weight_t eps) nogil:
  4276. */
  4277. /* function exit code */
  4278. __pyx_L0:;
  4279. }
  4280. /* "linalg.pxd":261
  4281. * cdef class MatVec:
  4282. * @staticmethod
  4283. * cdef inline void add_i(weight_t* mat, # <<<<<<<<<<<<<<
  4284. * const weight_t* vec, weight_t scale, int32_t nr_row, int32_t nr_col) nogil:
  4285. * cdef int i
  4286. */
  4287. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, __pyx_t_5thinc_8typedefs_weight_t __pyx_v_scale, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4288. int __pyx_v_i;
  4289. int32_t __pyx_t_1;
  4290. int32_t __pyx_t_2;
  4291. int __pyx_t_3;
  4292. /* "linalg.pxd":264
  4293. * const weight_t* vec, weight_t scale, int32_t nr_row, int32_t nr_col) nogil:
  4294. * cdef int i
  4295. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4296. * VecVec.add_i(mat + (i * nr_col),
  4297. * vec, scale, nr_col)
  4298. */
  4299. __pyx_t_1 = __pyx_v_nr_row;
  4300. __pyx_t_2 = __pyx_t_1;
  4301. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4302. __pyx_v_i = __pyx_t_3;
  4303. /* "linalg.pxd":265
  4304. * cdef int i
  4305. * for i in range(nr_row):
  4306. * VecVec.add_i(mat + (i * nr_col), # <<<<<<<<<<<<<<
  4307. * vec, scale, nr_col)
  4308. *
  4309. */
  4310. __pyx_f_5thinc_6linalg_6VecVec_add_i((__pyx_v_mat + (__pyx_v_i * __pyx_v_nr_col)), __pyx_v_vec, __pyx_v_scale, __pyx_v_nr_col);
  4311. }
  4312. /* "linalg.pxd":261
  4313. * cdef class MatVec:
  4314. * @staticmethod
  4315. * cdef inline void add_i(weight_t* mat, # <<<<<<<<<<<<<<
  4316. * const weight_t* vec, weight_t scale, int32_t nr_row, int32_t nr_col) nogil:
  4317. * cdef int i
  4318. */
  4319. /* function exit code */
  4320. }
  4321. /* "linalg.pxd":269
  4322. *
  4323. * @staticmethod
  4324. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  4325. * const weight_t* mat,
  4326. * const weight_t* vec,
  4327. */
  4328. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4329. /* "linalg.pxd":273
  4330. * const weight_t* vec,
  4331. * int32_t nr_row, int32_t nr_col) nogil:
  4332. * memcpy(output, mat, sizeof(output[0]) * nr_row * nr_col) # <<<<<<<<<<<<<<
  4333. * MatVec.mul_i(output, vec, nr_row, nr_col)
  4334. *
  4335. */
  4336. (void)(memcpy(__pyx_v_output, __pyx_v_mat, (((sizeof((__pyx_v_output[0]))) * __pyx_v_nr_row) * __pyx_v_nr_col)));
  4337. /* "linalg.pxd":274
  4338. * int32_t nr_row, int32_t nr_col) nogil:
  4339. * memcpy(output, mat, sizeof(output[0]) * nr_row * nr_col)
  4340. * MatVec.mul_i(output, vec, nr_row, nr_col) # <<<<<<<<<<<<<<
  4341. *
  4342. * @staticmethod
  4343. */
  4344. __pyx_f_5thinc_6linalg_6MatVec_mul_i(__pyx_v_output, __pyx_v_vec, __pyx_v_nr_row, __pyx_v_nr_col);
  4345. /* "linalg.pxd":269
  4346. *
  4347. * @staticmethod
  4348. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  4349. * const weight_t* mat,
  4350. * const weight_t* vec,
  4351. */
  4352. /* function exit code */
  4353. }
  4354. /* "linalg.pxd":277
  4355. *
  4356. * @staticmethod
  4357. * cdef inline void mul_i(weight_t* mat, # <<<<<<<<<<<<<<
  4358. * const weight_t* vec,
  4359. * int32_t nr_row, int32_t nr_col) nogil:
  4360. */
  4361. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4362. int __pyx_v_i;
  4363. int __pyx_v_row;
  4364. int __pyx_v_col;
  4365. int32_t __pyx_t_1;
  4366. int32_t __pyx_t_2;
  4367. int __pyx_t_3;
  4368. int32_t __pyx_t_4;
  4369. int32_t __pyx_t_5;
  4370. int __pyx_t_6;
  4371. int __pyx_t_7;
  4372. /* "linalg.pxd":281
  4373. * int32_t nr_row, int32_t nr_col) nogil:
  4374. * cdef int i, row, col
  4375. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4376. * row = i * nr_col
  4377. * for col in range(nr_col):
  4378. */
  4379. __pyx_t_1 = __pyx_v_nr_row;
  4380. __pyx_t_2 = __pyx_t_1;
  4381. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4382. __pyx_v_i = __pyx_t_3;
  4383. /* "linalg.pxd":282
  4384. * cdef int i, row, col
  4385. * for i in range(nr_row):
  4386. * row = i * nr_col # <<<<<<<<<<<<<<
  4387. * for col in range(nr_col):
  4388. * mat[row + col] *= vec[col]
  4389. */
  4390. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  4391. /* "linalg.pxd":283
  4392. * for i in range(nr_row):
  4393. * row = i * nr_col
  4394. * for col in range(nr_col): # <<<<<<<<<<<<<<
  4395. * mat[row + col] *= vec[col]
  4396. *
  4397. */
  4398. __pyx_t_4 = __pyx_v_nr_col;
  4399. __pyx_t_5 = __pyx_t_4;
  4400. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4401. __pyx_v_col = __pyx_t_6;
  4402. /* "linalg.pxd":284
  4403. * row = i * nr_col
  4404. * for col in range(nr_col):
  4405. * mat[row + col] *= vec[col] # <<<<<<<<<<<<<<
  4406. *
  4407. * @staticmethod
  4408. */
  4409. __pyx_t_7 = (__pyx_v_row + __pyx_v_col);
  4410. (__pyx_v_mat[__pyx_t_7]) = ((__pyx_v_mat[__pyx_t_7]) * (__pyx_v_vec[__pyx_v_col]));
  4411. }
  4412. }
  4413. /* "linalg.pxd":277
  4414. *
  4415. * @staticmethod
  4416. * cdef inline void mul_i(weight_t* mat, # <<<<<<<<<<<<<<
  4417. * const weight_t* vec,
  4418. * int32_t nr_row, int32_t nr_col) nogil:
  4419. */
  4420. /* function exit code */
  4421. }
  4422. /* "linalg.pxd":287
  4423. *
  4424. * @staticmethod
  4425. * cdef inline void dot(weight_t* output, # <<<<<<<<<<<<<<
  4426. * const weight_t* mat,
  4427. * const weight_t* vec,
  4428. */
  4429. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4430. int __pyx_v_i;
  4431. int __pyx_v_row;
  4432. int __pyx_v_col;
  4433. CYTHON_UNUSED double __pyx_v_zero;
  4434. int32_t __pyx_t_1;
  4435. int32_t __pyx_t_2;
  4436. int __pyx_t_3;
  4437. int32_t __pyx_t_4;
  4438. int32_t __pyx_t_5;
  4439. int __pyx_t_6;
  4440. int __pyx_t_7;
  4441. /* "linalg.pxd":292
  4442. * int32_t nr_row, int32_t nr_col) nogil:
  4443. * cdef int i, row, col
  4444. * cdef double zero = 0.0 # <<<<<<<<<<<<<<
  4445. * IF USE_BLAS:
  4446. * blis.gemv(
  4447. */
  4448. __pyx_v_zero = 0.0;
  4449. /* "linalg.pxd":306
  4450. * )
  4451. * ELSE:
  4452. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4453. * row = i * nr_col
  4454. * for col in range(nr_col):
  4455. */
  4456. __pyx_t_1 = __pyx_v_nr_row;
  4457. __pyx_t_2 = __pyx_t_1;
  4458. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4459. __pyx_v_i = __pyx_t_3;
  4460. /* "linalg.pxd":307
  4461. * ELSE:
  4462. * for i in range(nr_row):
  4463. * row = i * nr_col # <<<<<<<<<<<<<<
  4464. * for col in range(nr_col):
  4465. * output[i] += mat[row + col] * vec[col]
  4466. */
  4467. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  4468. /* "linalg.pxd":308
  4469. * for i in range(nr_row):
  4470. * row = i * nr_col
  4471. * for col in range(nr_col): # <<<<<<<<<<<<<<
  4472. * output[i] += mat[row + col] * vec[col]
  4473. *
  4474. */
  4475. __pyx_t_4 = __pyx_v_nr_col;
  4476. __pyx_t_5 = __pyx_t_4;
  4477. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4478. __pyx_v_col = __pyx_t_6;
  4479. /* "linalg.pxd":309
  4480. * row = i * nr_col
  4481. * for col in range(nr_col):
  4482. * output[i] += mat[row + col] * vec[col] # <<<<<<<<<<<<<<
  4483. *
  4484. * @staticmethod
  4485. */
  4486. __pyx_t_7 = __pyx_v_i;
  4487. (__pyx_v_output[__pyx_t_7]) = ((__pyx_v_output[__pyx_t_7]) + ((__pyx_v_mat[(__pyx_v_row + __pyx_v_col)]) * (__pyx_v_vec[__pyx_v_col])));
  4488. }
  4489. }
  4490. /* "linalg.pxd":287
  4491. *
  4492. * @staticmethod
  4493. * cdef inline void dot(weight_t* output, # <<<<<<<<<<<<<<
  4494. * const weight_t* mat,
  4495. * const weight_t* vec,
  4496. */
  4497. /* function exit code */
  4498. }
  4499. /* "linalg.pxd":312
  4500. *
  4501. * @staticmethod
  4502. * cdef inline void batch_dot(weight_t* output, # <<<<<<<<<<<<<<
  4503. * const weight_t* mat,
  4504. * const weight_t* vec,
  4505. */
  4506. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch) {
  4507. CYTHON_UNUSED double __pyx_v_one;
  4508. CYTHON_UNUSED int32_t __pyx_v_b;
  4509. int32_t __pyx_t_1;
  4510. int32_t __pyx_t_2;
  4511. int32_t __pyx_t_3;
  4512. /* "linalg.pxd":327
  4513. * # out: M * N
  4514. * cdef int i, row, col
  4515. * cdef double one = 1.0 # <<<<<<<<<<<<<<
  4516. * IF USE_BLAS:
  4517. * blis.gemm(
  4518. */
  4519. __pyx_v_one = 1.0;
  4520. /* "linalg.pxd":347
  4521. * 1)
  4522. * ELSE:
  4523. * for b in range(nr_batch): # <<<<<<<<<<<<<<
  4524. * MatVec.dot(output,
  4525. * mat, vec, nr_row, nr_col)
  4526. */
  4527. __pyx_t_1 = __pyx_v_nr_batch;
  4528. __pyx_t_2 = __pyx_t_1;
  4529. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4530. __pyx_v_b = __pyx_t_3;
  4531. /* "linalg.pxd":348
  4532. * ELSE:
  4533. * for b in range(nr_batch):
  4534. * MatVec.dot(output, # <<<<<<<<<<<<<<
  4535. * mat, vec, nr_row, nr_col)
  4536. * output += nr_row
  4537. */
  4538. __pyx_f_5thinc_6linalg_6MatVec_dot(__pyx_v_output, __pyx_v_mat, __pyx_v_vec, __pyx_v_nr_row, __pyx_v_nr_col);
  4539. /* "linalg.pxd":350
  4540. * MatVec.dot(output,
  4541. * mat, vec, nr_row, nr_col)
  4542. * output += nr_row # <<<<<<<<<<<<<<
  4543. * vec += nr_col
  4544. *
  4545. */
  4546. __pyx_v_output = (__pyx_v_output + __pyx_v_nr_row);
  4547. /* "linalg.pxd":351
  4548. * mat, vec, nr_row, nr_col)
  4549. * output += nr_row
  4550. * vec += nr_col # <<<<<<<<<<<<<<
  4551. *
  4552. * @staticmethod
  4553. */
  4554. __pyx_v_vec = (__pyx_v_vec + __pyx_v_nr_col);
  4555. }
  4556. /* "linalg.pxd":312
  4557. *
  4558. * @staticmethod
  4559. * cdef inline void batch_dot(weight_t* output, # <<<<<<<<<<<<<<
  4560. * const weight_t* mat,
  4561. * const weight_t* vec,
  4562. */
  4563. /* function exit code */
  4564. }
  4565. /* "linalg.pxd":354
  4566. *
  4567. * @staticmethod
  4568. * cdef inline void T_dot(weight_t* output, # <<<<<<<<<<<<<<
  4569. * const weight_t* mat,
  4570. * const weight_t* vec,
  4571. */
  4572. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_T_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4573. int __pyx_v_row;
  4574. int __pyx_v_col;
  4575. CYTHON_UNUSED double __pyx_v_zero;
  4576. CYTHON_UNUSED double __pyx_v_one;
  4577. int32_t __pyx_t_1;
  4578. int32_t __pyx_t_2;
  4579. int __pyx_t_3;
  4580. int32_t __pyx_t_4;
  4581. int32_t __pyx_t_5;
  4582. int __pyx_t_6;
  4583. int __pyx_t_7;
  4584. /* "linalg.pxd":360
  4585. * int32_t nr_col) nogil:
  4586. * cdef int i, row, col
  4587. * cdef double zero = 0.0 # <<<<<<<<<<<<<<
  4588. * cdef double one = 1.0
  4589. * IF USE_BLAS:
  4590. */
  4591. __pyx_v_zero = 0.0;
  4592. /* "linalg.pxd":361
  4593. * cdef int i, row, col
  4594. * cdef double zero = 0.0
  4595. * cdef double one = 1.0 # <<<<<<<<<<<<<<
  4596. * IF USE_BLAS:
  4597. * blis.gemv(
  4598. */
  4599. __pyx_v_one = 1.0;
  4600. /* "linalg.pxd":374
  4601. * )
  4602. * ELSE:
  4603. * for row in range(nr_row): # <<<<<<<<<<<<<<
  4604. * for col in range(nr_col):
  4605. * output[col] += vec[row] * mat[(row * nr_col) + col]
  4606. */
  4607. __pyx_t_1 = __pyx_v_nr_row;
  4608. __pyx_t_2 = __pyx_t_1;
  4609. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4610. __pyx_v_row = __pyx_t_3;
  4611. /* "linalg.pxd":375
  4612. * ELSE:
  4613. * for row in range(nr_row):
  4614. * for col in range(nr_col): # <<<<<<<<<<<<<<
  4615. * output[col] += vec[row] * mat[(row * nr_col) + col]
  4616. *
  4617. */
  4618. __pyx_t_4 = __pyx_v_nr_col;
  4619. __pyx_t_5 = __pyx_t_4;
  4620. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4621. __pyx_v_col = __pyx_t_6;
  4622. /* "linalg.pxd":376
  4623. * for row in range(nr_row):
  4624. * for col in range(nr_col):
  4625. * output[col] += vec[row] * mat[(row * nr_col) + col] # <<<<<<<<<<<<<<
  4626. *
  4627. * @staticmethod
  4628. */
  4629. __pyx_t_7 = __pyx_v_col;
  4630. (__pyx_v_output[__pyx_t_7]) = ((__pyx_v_output[__pyx_t_7]) + ((__pyx_v_vec[__pyx_v_row]) * (__pyx_v_mat[((__pyx_v_row * __pyx_v_nr_col) + __pyx_v_col)])));
  4631. }
  4632. }
  4633. /* "linalg.pxd":354
  4634. *
  4635. * @staticmethod
  4636. * cdef inline void T_dot(weight_t* output, # <<<<<<<<<<<<<<
  4637. * const weight_t* mat,
  4638. * const weight_t* vec,
  4639. */
  4640. /* function exit code */
  4641. }
  4642. /* "linalg.pxd":379
  4643. *
  4644. * @staticmethod
  4645. * cdef inline void batch_T_dot(weight_t* output, # <<<<<<<<<<<<<<
  4646. * const weight_t* mat,
  4647. * const weight_t* vec,
  4648. */
  4649. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatVec_batch_T_dot(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_vec, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch) {
  4650. CYTHON_UNUSED int __pyx_v__;
  4651. CYTHON_UNUSED double __pyx_v_one;
  4652. int32_t __pyx_t_1;
  4653. int32_t __pyx_t_2;
  4654. int __pyx_t_3;
  4655. /* "linalg.pxd":386
  4656. * int32_t nr_batch) nogil:
  4657. * cdef int _
  4658. * cdef double one = 1.0 # <<<<<<<<<<<<<<
  4659. * IF USE_BLAS:
  4660. * # output is (nr_batch, nr_col)
  4661. */
  4662. __pyx_v_one = 1.0;
  4663. /* "linalg.pxd":418
  4664. * 1)
  4665. * ELSE:
  4666. * for _ in range(nr_batch): # <<<<<<<<<<<<<<
  4667. * MatVec.T_dot(output,
  4668. * mat, vec, nr_row, nr_col)
  4669. */
  4670. __pyx_t_1 = __pyx_v_nr_batch;
  4671. __pyx_t_2 = __pyx_t_1;
  4672. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4673. __pyx_v__ = __pyx_t_3;
  4674. /* "linalg.pxd":419
  4675. * ELSE:
  4676. * for _ in range(nr_batch):
  4677. * MatVec.T_dot(output, # <<<<<<<<<<<<<<
  4678. * mat, vec, nr_row, nr_col)
  4679. * output += nr_col
  4680. */
  4681. __pyx_f_5thinc_6linalg_6MatVec_T_dot(__pyx_v_output, __pyx_v_mat, __pyx_v_vec, __pyx_v_nr_row, __pyx_v_nr_col);
  4682. /* "linalg.pxd":421
  4683. * MatVec.T_dot(output,
  4684. * mat, vec, nr_row, nr_col)
  4685. * output += nr_col # <<<<<<<<<<<<<<
  4686. * vec += nr_row
  4687. *
  4688. */
  4689. __pyx_v_output = (__pyx_v_output + __pyx_v_nr_col);
  4690. /* "linalg.pxd":422
  4691. * mat, vec, nr_row, nr_col)
  4692. * output += nr_col
  4693. * vec += nr_row # <<<<<<<<<<<<<<
  4694. *
  4695. *
  4696. */
  4697. __pyx_v_vec = (__pyx_v_vec + __pyx_v_nr_row);
  4698. }
  4699. /* "linalg.pxd":379
  4700. *
  4701. * @staticmethod
  4702. * cdef inline void batch_T_dot(weight_t* output, # <<<<<<<<<<<<<<
  4703. * const weight_t* mat,
  4704. * const weight_t* vec,
  4705. */
  4706. /* function exit code */
  4707. }
  4708. /* "linalg.pxd":427
  4709. * cdef class MatMat:
  4710. * @staticmethod
  4711. * cdef inline void add(weight_t* output, # <<<<<<<<<<<<<<
  4712. * const weight_t* x,
  4713. * const weight_t* y,
  4714. */
  4715. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4716. /* "linalg.pxd":431
  4717. * const weight_t* y,
  4718. * int32_t nr_row, int32_t nr_col) nogil:
  4719. * memcpy(output, x, sizeof(output[0]) * nr_row * nr_col) # <<<<<<<<<<<<<<
  4720. * MatMat.add_i(output, y, nr_row, nr_col)
  4721. *
  4722. */
  4723. (void)(memcpy(__pyx_v_output, __pyx_v_x, (((sizeof((__pyx_v_output[0]))) * __pyx_v_nr_row) * __pyx_v_nr_col)));
  4724. /* "linalg.pxd":432
  4725. * int32_t nr_row, int32_t nr_col) nogil:
  4726. * memcpy(output, x, sizeof(output[0]) * nr_row * nr_col)
  4727. * MatMat.add_i(output, y, nr_row, nr_col) # <<<<<<<<<<<<<<
  4728. *
  4729. * @staticmethod
  4730. */
  4731. __pyx_f_5thinc_6linalg_6MatMat_add_i(__pyx_v_output, __pyx_v_y, __pyx_v_nr_row, __pyx_v_nr_col);
  4732. /* "linalg.pxd":427
  4733. * cdef class MatMat:
  4734. * @staticmethod
  4735. * cdef inline void add(weight_t* output, # <<<<<<<<<<<<<<
  4736. * const weight_t* x,
  4737. * const weight_t* y,
  4738. */
  4739. /* function exit code */
  4740. }
  4741. /* "linalg.pxd":435
  4742. *
  4743. * @staticmethod
  4744. * cdef inline void add_i(weight_t* x, # <<<<<<<<<<<<<<
  4745. * const weight_t* y,
  4746. * int32_t nr_row, int32_t nr_col) nogil:
  4747. */
  4748. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4749. int __pyx_v_i;
  4750. int __pyx_v_row;
  4751. int __pyx_v_col;
  4752. int32_t __pyx_t_1;
  4753. int32_t __pyx_t_2;
  4754. int __pyx_t_3;
  4755. int32_t __pyx_t_4;
  4756. int32_t __pyx_t_5;
  4757. int __pyx_t_6;
  4758. int __pyx_t_7;
  4759. /* "linalg.pxd":439
  4760. * int32_t nr_row, int32_t nr_col) nogil:
  4761. * cdef int i, row, col
  4762. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4763. * row = i * nr_col
  4764. * for col in range(nr_col):
  4765. */
  4766. __pyx_t_1 = __pyx_v_nr_row;
  4767. __pyx_t_2 = __pyx_t_1;
  4768. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4769. __pyx_v_i = __pyx_t_3;
  4770. /* "linalg.pxd":440
  4771. * cdef int i, row, col
  4772. * for i in range(nr_row):
  4773. * row = i * nr_col # <<<<<<<<<<<<<<
  4774. * for col in range(nr_col):
  4775. * x[row + col] += y[row + col]
  4776. */
  4777. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  4778. /* "linalg.pxd":441
  4779. * for i in range(nr_row):
  4780. * row = i * nr_col
  4781. * for col in range(nr_col): # <<<<<<<<<<<<<<
  4782. * x[row + col] += y[row + col]
  4783. *
  4784. */
  4785. __pyx_t_4 = __pyx_v_nr_col;
  4786. __pyx_t_5 = __pyx_t_4;
  4787. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4788. __pyx_v_col = __pyx_t_6;
  4789. /* "linalg.pxd":442
  4790. * row = i * nr_col
  4791. * for col in range(nr_col):
  4792. * x[row + col] += y[row + col] # <<<<<<<<<<<<<<
  4793. *
  4794. * @staticmethod
  4795. */
  4796. __pyx_t_7 = (__pyx_v_row + __pyx_v_col);
  4797. (__pyx_v_x[__pyx_t_7]) = ((__pyx_v_x[__pyx_t_7]) + (__pyx_v_y[(__pyx_v_row + __pyx_v_col)]));
  4798. }
  4799. }
  4800. /* "linalg.pxd":435
  4801. *
  4802. * @staticmethod
  4803. * cdef inline void add_i(weight_t* x, # <<<<<<<<<<<<<<
  4804. * const weight_t* y,
  4805. * int32_t nr_row, int32_t nr_col) nogil:
  4806. */
  4807. /* function exit code */
  4808. }
  4809. /* "linalg.pxd":445
  4810. *
  4811. * @staticmethod
  4812. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  4813. * const weight_t* x,
  4814. * const weight_t* y,
  4815. */
  4816. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4817. /* "linalg.pxd":449
  4818. * const weight_t* y,
  4819. * int32_t nr_row, int32_t nr_col) nogil:
  4820. * memcpy(output, x, sizeof(output[0]) * nr_row * nr_col) # <<<<<<<<<<<<<<
  4821. * MatMat.mul_i(output, y, nr_row, nr_col)
  4822. *
  4823. */
  4824. (void)(memcpy(__pyx_v_output, __pyx_v_x, (((sizeof((__pyx_v_output[0]))) * __pyx_v_nr_row) * __pyx_v_nr_col)));
  4825. /* "linalg.pxd":450
  4826. * int32_t nr_row, int32_t nr_col) nogil:
  4827. * memcpy(output, x, sizeof(output[0]) * nr_row * nr_col)
  4828. * MatMat.mul_i(output, y, nr_row, nr_col) # <<<<<<<<<<<<<<
  4829. *
  4830. * @staticmethod
  4831. */
  4832. __pyx_f_5thinc_6linalg_6MatMat_mul_i(__pyx_v_output, __pyx_v_y, __pyx_v_nr_row, __pyx_v_nr_col);
  4833. /* "linalg.pxd":445
  4834. *
  4835. * @staticmethod
  4836. * cdef inline void mul(weight_t* output, # <<<<<<<<<<<<<<
  4837. * const weight_t* x,
  4838. * const weight_t* y,
  4839. */
  4840. /* function exit code */
  4841. }
  4842. /* "linalg.pxd":453
  4843. *
  4844. * @staticmethod
  4845. * cdef inline void mul_i(weight_t* x, # <<<<<<<<<<<<<<
  4846. * const weight_t* y,
  4847. * int32_t nr_row, int32_t nr_col) nogil:
  4848. */
  4849. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_mul_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4850. int __pyx_v_i;
  4851. int __pyx_v_row;
  4852. int __pyx_v_col;
  4853. int32_t __pyx_t_1;
  4854. int32_t __pyx_t_2;
  4855. int __pyx_t_3;
  4856. int32_t __pyx_t_4;
  4857. int32_t __pyx_t_5;
  4858. int __pyx_t_6;
  4859. int __pyx_t_7;
  4860. /* "linalg.pxd":457
  4861. * int32_t nr_row, int32_t nr_col) nogil:
  4862. * cdef int i, row, col
  4863. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4864. * row = i * nr_col
  4865. * for col in range(nr_col):
  4866. */
  4867. __pyx_t_1 = __pyx_v_nr_row;
  4868. __pyx_t_2 = __pyx_t_1;
  4869. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4870. __pyx_v_i = __pyx_t_3;
  4871. /* "linalg.pxd":458
  4872. * cdef int i, row, col
  4873. * for i in range(nr_row):
  4874. * row = i * nr_col # <<<<<<<<<<<<<<
  4875. * for col in range(nr_col):
  4876. * x[row + col] *= y[row + col]
  4877. */
  4878. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  4879. /* "linalg.pxd":459
  4880. * for i in range(nr_row):
  4881. * row = i * nr_col
  4882. * for col in range(nr_col): # <<<<<<<<<<<<<<
  4883. * x[row + col] *= y[row + col]
  4884. *
  4885. */
  4886. __pyx_t_4 = __pyx_v_nr_col;
  4887. __pyx_t_5 = __pyx_t_4;
  4888. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4889. __pyx_v_col = __pyx_t_6;
  4890. /* "linalg.pxd":460
  4891. * row = i * nr_col
  4892. * for col in range(nr_col):
  4893. * x[row + col] *= y[row + col] # <<<<<<<<<<<<<<
  4894. *
  4895. * @staticmethod
  4896. */
  4897. __pyx_t_7 = (__pyx_v_row + __pyx_v_col);
  4898. (__pyx_v_x[__pyx_t_7]) = ((__pyx_v_x[__pyx_t_7]) * (__pyx_v_y[(__pyx_v_row + __pyx_v_col)]));
  4899. }
  4900. }
  4901. /* "linalg.pxd":453
  4902. *
  4903. * @staticmethod
  4904. * cdef inline void mul_i(weight_t* x, # <<<<<<<<<<<<<<
  4905. * const weight_t* y,
  4906. * int32_t nr_row, int32_t nr_col) nogil:
  4907. */
  4908. /* function exit code */
  4909. }
  4910. /* "linalg.pxd":463
  4911. *
  4912. * @staticmethod
  4913. * cdef inline void add_outer_i(weight_t* mat, # <<<<<<<<<<<<<<
  4914. * const weight_t* x,
  4915. * const weight_t* y,
  4916. */
  4917. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_mat, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col) {
  4918. int __pyx_v_i;
  4919. int __pyx_v_j;
  4920. int __pyx_v_row;
  4921. CYTHON_UNUSED double __pyx_v_one;
  4922. int32_t __pyx_t_1;
  4923. int32_t __pyx_t_2;
  4924. int __pyx_t_3;
  4925. int32_t __pyx_t_4;
  4926. int32_t __pyx_t_5;
  4927. int __pyx_t_6;
  4928. int __pyx_t_7;
  4929. /* "linalg.pxd":469
  4930. * int32_t nr_col) nogil:
  4931. * cdef int i, j, row
  4932. * cdef double one = 1.0 # <<<<<<<<<<<<<<
  4933. * IF USE_BLAS:
  4934. * blis.ger(
  4935. */
  4936. __pyx_v_one = 1.0;
  4937. /* "linalg.pxd":480
  4938. * )
  4939. * ELSE:
  4940. * for i in range(nr_row): # <<<<<<<<<<<<<<
  4941. * row = i * nr_col
  4942. * for j in range(nr_col):
  4943. */
  4944. __pyx_t_1 = __pyx_v_nr_row;
  4945. __pyx_t_2 = __pyx_t_1;
  4946. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  4947. __pyx_v_i = __pyx_t_3;
  4948. /* "linalg.pxd":481
  4949. * ELSE:
  4950. * for i in range(nr_row):
  4951. * row = i * nr_col # <<<<<<<<<<<<<<
  4952. * for j in range(nr_col):
  4953. * mat[row + j] += x[i] * y[j]
  4954. */
  4955. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  4956. /* "linalg.pxd":482
  4957. * for i in range(nr_row):
  4958. * row = i * nr_col
  4959. * for j in range(nr_col): # <<<<<<<<<<<<<<
  4960. * mat[row + j] += x[i] * y[j]
  4961. *
  4962. */
  4963. __pyx_t_4 = __pyx_v_nr_col;
  4964. __pyx_t_5 = __pyx_t_4;
  4965. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  4966. __pyx_v_j = __pyx_t_6;
  4967. /* "linalg.pxd":483
  4968. * row = i * nr_col
  4969. * for j in range(nr_col):
  4970. * mat[row + j] += x[i] * y[j] # <<<<<<<<<<<<<<
  4971. *
  4972. * @staticmethod
  4973. */
  4974. __pyx_t_7 = (__pyx_v_row + __pyx_v_j);
  4975. (__pyx_v_mat[__pyx_t_7]) = ((__pyx_v_mat[__pyx_t_7]) + ((__pyx_v_x[__pyx_v_i]) * (__pyx_v_y[__pyx_v_j])));
  4976. }
  4977. }
  4978. /* "linalg.pxd":463
  4979. *
  4980. * @staticmethod
  4981. * cdef inline void add_outer_i(weight_t* mat, # <<<<<<<<<<<<<<
  4982. * const weight_t* x,
  4983. * const weight_t* y,
  4984. */
  4985. /* function exit code */
  4986. }
  4987. /* "linalg.pxd":486
  4988. *
  4989. * @staticmethod
  4990. * cdef inline void batch_add_outer_i(weight_t* output, # <<<<<<<<<<<<<<
  4991. * const weight_t* x,
  4992. * const weight_t* y,
  4993. */
  4994. static CYTHON_INLINE void __pyx_f_5thinc_6linalg_6MatMat_batch_add_outer_i(__pyx_t_5thinc_8typedefs_weight_t *__pyx_v_output, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_x, __pyx_t_5thinc_8typedefs_weight_t const *__pyx_v_y, int32_t __pyx_v_nr_row, int32_t __pyx_v_nr_col, int32_t __pyx_v_nr_batch) {
  4995. CYTHON_UNUSED double __pyx_v_one;
  4996. CYTHON_UNUSED int32_t __pyx_v__;
  4997. int32_t __pyx_v_i;
  4998. int32_t __pyx_v_row;
  4999. int32_t __pyx_v_j;
  5000. int32_t __pyx_t_1;
  5001. int32_t __pyx_t_2;
  5002. int32_t __pyx_t_3;
  5003. int32_t __pyx_t_4;
  5004. int32_t __pyx_t_5;
  5005. int32_t __pyx_t_6;
  5006. int32_t __pyx_t_7;
  5007. int32_t __pyx_t_8;
  5008. int32_t __pyx_t_9;
  5009. int32_t __pyx_t_10;
  5010. /* "linalg.pxd":504
  5011. * # y: K * N
  5012. * # out: M * N
  5013. * cdef double one = 1.0 # <<<<<<<<<<<<<<
  5014. * IF USE_BLAS:
  5015. * blis.gemm(
  5016. */
  5017. __pyx_v_one = 1.0;
  5018. /* "linalg.pxd":524
  5019. * 1)
  5020. * ELSE:
  5021. * for _ in range(nr_batch): # <<<<<<<<<<<<<<
  5022. * for i in range(nr_row):
  5023. * row = i * nr_col
  5024. */
  5025. __pyx_t_1 = __pyx_v_nr_batch;
  5026. __pyx_t_2 = __pyx_t_1;
  5027. for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
  5028. __pyx_v__ = __pyx_t_3;
  5029. /* "linalg.pxd":525
  5030. * ELSE:
  5031. * for _ in range(nr_batch):
  5032. * for i in range(nr_row): # <<<<<<<<<<<<<<
  5033. * row = i * nr_col
  5034. * for j in range(nr_col):
  5035. */
  5036. __pyx_t_4 = __pyx_v_nr_row;
  5037. __pyx_t_5 = __pyx_t_4;
  5038. for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
  5039. __pyx_v_i = __pyx_t_6;
  5040. /* "linalg.pxd":526
  5041. * for _ in range(nr_batch):
  5042. * for i in range(nr_row):
  5043. * row = i * nr_col # <<<<<<<<<<<<<<
  5044. * for j in range(nr_col):
  5045. * output[row + j] += x[i] * y[j]
  5046. */
  5047. __pyx_v_row = (__pyx_v_i * __pyx_v_nr_col);
  5048. /* "linalg.pxd":527
  5049. * for i in range(nr_row):
  5050. * row = i * nr_col
  5051. * for j in range(nr_col): # <<<<<<<<<<<<<<
  5052. * output[row + j] += x[i] * y[j]
  5053. * x += nr_row
  5054. */
  5055. __pyx_t_7 = __pyx_v_nr_col;
  5056. __pyx_t_8 = __pyx_t_7;
  5057. for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
  5058. __pyx_v_j = __pyx_t_9;
  5059. /* "linalg.pxd":528
  5060. * row = i * nr_col
  5061. * for j in range(nr_col):
  5062. * output[row + j] += x[i] * y[j] # <<<<<<<<<<<<<<
  5063. * x += nr_row
  5064. * y += nr_col
  5065. */
  5066. __pyx_t_10 = (__pyx_v_row + __pyx_v_j);
  5067. (__pyx_v_output[__pyx_t_10]) = ((__pyx_v_output[__pyx_t_10]) + ((__pyx_v_x[__pyx_v_i]) * (__pyx_v_y[__pyx_v_j])));
  5068. }
  5069. }
  5070. /* "linalg.pxd":529
  5071. * for j in range(nr_col):
  5072. * output[row + j] += x[i] * y[j]
  5073. * x += nr_row # <<<<<<<<<<<<<<
  5074. * y += nr_col
  5075. */
  5076. __pyx_v_x = (__pyx_v_x + __pyx_v_nr_row);
  5077. /* "linalg.pxd":530
  5078. * output[row + j] += x[i] * y[j]
  5079. * x += nr_row
  5080. * y += nr_col # <<<<<<<<<<<<<<
  5081. */
  5082. __pyx_v_y = (__pyx_v_y + __pyx_v_nr_col);
  5083. }
  5084. /* "linalg.pxd":486
  5085. *
  5086. * @staticmethod
  5087. * cdef inline void batch_add_outer_i(weight_t* output, # <<<<<<<<<<<<<<
  5088. * const weight_t* x,
  5089. * const weight_t* y,
  5090. */
  5091. /* function exit code */
  5092. }
  5093. static PyMethodDef __pyx_methods[] = {
  5094. {0, 0, 0, 0}
  5095. };
  5096. #if PY_MAJOR_VERSION >= 3
  5097. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5098. static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
  5099. static int __pyx_pymod_exec_structs(PyObject* module); /*proto*/
  5100. static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  5101. {Py_mod_create, (void*)__pyx_pymod_create},
  5102. {Py_mod_exec, (void*)__pyx_pymod_exec_structs},
  5103. {0, NULL}
  5104. };
  5105. #endif
  5106. static struct PyModuleDef __pyx_moduledef = {
  5107. PyModuleDef_HEAD_INIT,
  5108. "structs",
  5109. 0, /* m_doc */
  5110. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5111. 0, /* m_size */
  5112. #else
  5113. -1, /* m_size */
  5114. #endif
  5115. __pyx_methods /* m_methods */,
  5116. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5117. __pyx_moduledef_slots, /* m_slots */
  5118. #else
  5119. NULL, /* m_reload */
  5120. #endif
  5121. NULL, /* m_traverse */
  5122. NULL, /* m_clear */
  5123. NULL /* m_free */
  5124. };
  5125. #endif
  5126. #ifndef CYTHON_SMALL_CODE
  5127. #if defined(__clang__)
  5128. #define CYTHON_SMALL_CODE
  5129. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  5130. #define CYTHON_SMALL_CODE __attribute__((cold))
  5131. #else
  5132. #define CYTHON_SMALL_CODE
  5133. #endif
  5134. #endif
  5135. static __Pyx_StringTabEntry __pyx_string_tab[] = {
  5136. {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  5137. {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  5138. {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  5139. {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  5140. {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  5141. {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  5142. {0, 0, 0, 0, 0, 0, 0}
  5143. };
  5144. static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  5145. __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 147, __pyx_L1_error)
  5146. return 0;
  5147. __pyx_L1_error:;
  5148. return -1;
  5149. }
  5150. static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  5151. __Pyx_RefNannyDeclarations
  5152. __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
  5153. __Pyx_RefNannyFinishContext();
  5154. return 0;
  5155. }
  5156. static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  5157. if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
  5158. return 0;
  5159. __pyx_L1_error:;
  5160. return -1;
  5161. }
  5162. static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
  5163. static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
  5164. static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
  5165. static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
  5166. static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
  5167. static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
  5168. static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
  5169. static int __Pyx_modinit_global_init_code(void) {
  5170. __Pyx_RefNannyDeclarations
  5171. __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  5172. /*--- Global init code ---*/
  5173. __Pyx_RefNannyFinishContext();
  5174. return 0;
  5175. }
  5176. static int __Pyx_modinit_variable_export_code(void) {
  5177. __Pyx_RefNannyDeclarations
  5178. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  5179. /*--- Variable export code ---*/
  5180. __Pyx_RefNannyFinishContext();
  5181. return 0;
  5182. }
  5183. static int __Pyx_modinit_function_export_code(void) {
  5184. __Pyx_RefNannyDeclarations
  5185. __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  5186. /*--- Function export code ---*/
  5187. __Pyx_RefNannyFinishContext();
  5188. return 0;
  5189. }
  5190. static int __Pyx_modinit_type_init_code(void) {
  5191. __Pyx_RefNannyDeclarations
  5192. __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  5193. /*--- Type init code ---*/
  5194. __Pyx_RefNannyFinishContext();
  5195. return 0;
  5196. }
  5197. static int __Pyx_modinit_type_import_code(void) {
  5198. __Pyx_RefNannyDeclarations
  5199. PyObject *__pyx_t_1 = NULL;
  5200. __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  5201. /*--- Type import code ---*/
  5202. __pyx_t_1 = PyImport_ImportModule("cymem.cymem"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
  5203. __Pyx_GOTREF(__pyx_t_1);
  5204. __pyx_ptype_5cymem_5cymem_PyMalloc = __Pyx_ImportType(__pyx_t_1, "cymem.cymem", "PyMalloc", sizeof(struct __pyx_obj_5cymem_5cymem_PyMalloc), __Pyx_ImportType_CheckSize_Warn);
  5205. if (!__pyx_ptype_5cymem_5cymem_PyMalloc) __PYX_ERR(2, 4, __pyx_L1_error)
  5206. __pyx_vtabptr_5cymem_5cymem_PyMalloc = (struct __pyx_vtabstruct_5cymem_5cymem_PyMalloc*)__Pyx_GetVtable(__pyx_ptype_5cymem_5cymem_PyMalloc->tp_dict); if (unlikely(!__pyx_vtabptr_5cymem_5cymem_PyMalloc)) __PYX_ERR(2, 4, __pyx_L1_error)
  5207. __pyx_ptype_5cymem_5cymem_PyFree = __Pyx_ImportType(__pyx_t_1, "cymem.cymem", "PyFree", sizeof(struct __pyx_obj_5cymem_5cymem_PyFree), __Pyx_ImportType_CheckSize_Warn);
  5208. if (!__pyx_ptype_5cymem_5cymem_PyFree) __PYX_ERR(2, 10, __pyx_L1_error)
  5209. __pyx_vtabptr_5cymem_5cymem_PyFree = (struct __pyx_vtabstruct_5cymem_5cymem_PyFree*)__Pyx_GetVtable(__pyx_ptype_5cymem_5cymem_PyFree->tp_dict); if (unlikely(!__pyx_vtabptr_5cymem_5cymem_PyFree)) __PYX_ERR(2, 10, __pyx_L1_error)
  5210. __pyx_ptype_5cymem_5cymem_Pool = __Pyx_ImportType(__pyx_t_1, "cymem.cymem", "Pool", sizeof(struct __pyx_obj_5cymem_5cymem_Pool), __Pyx_ImportType_CheckSize_Warn);
  5211. if (!__pyx_ptype_5cymem_5cymem_Pool) __PYX_ERR(2, 16, __pyx_L1_error)
  5212. __pyx_vtabptr_5cymem_5cymem_Pool = (struct __pyx_vtabstruct_5cymem_5cymem_Pool*)__Pyx_GetVtable(__pyx_ptype_5cymem_5cymem_Pool->tp_dict); if (unlikely(!__pyx_vtabptr_5cymem_5cymem_Pool)) __PYX_ERR(2, 16, __pyx_L1_error)
  5213. __pyx_ptype_5cymem_5cymem_Address = __Pyx_ImportType(__pyx_t_1, "cymem.cymem", "Address", sizeof(struct __pyx_obj_5cymem_5cymem_Address), __Pyx_ImportType_CheckSize_Warn);
  5214. if (!__pyx_ptype_5cymem_5cymem_Address) __PYX_ERR(2, 28, __pyx_L1_error)
  5215. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5216. __pyx_t_1 = PyImport_ImportModule("preshed.maps"); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 36, __pyx_L1_error)
  5217. __Pyx_GOTREF(__pyx_t_1);
  5218. __pyx_ptype_7preshed_4maps_PreshMap = __Pyx_ImportType(__pyx_t_1, "preshed.maps", "PreshMap", sizeof(struct __pyx_obj_7preshed_4maps_PreshMap), __Pyx_ImportType_CheckSize_Warn);
  5219. if (!__pyx_ptype_7preshed_4maps_PreshMap) __PYX_ERR(3, 36, __pyx_L1_error)
  5220. __pyx_vtabptr_7preshed_4maps_PreshMap = (struct __pyx_vtabstruct_7preshed_4maps_PreshMap*)__Pyx_GetVtable(__pyx_ptype_7preshed_4maps_PreshMap->tp_dict); if (unlikely(!__pyx_vtabptr_7preshed_4maps_PreshMap)) __PYX_ERR(3, 36, __pyx_L1_error)
  5221. __pyx_ptype_7preshed_4maps_PreshMapArray = __Pyx_ImportType(__pyx_t_1, "preshed.maps", "PreshMapArray", sizeof(struct __pyx_obj_7preshed_4maps_PreshMapArray), __Pyx_ImportType_CheckSize_Warn);
  5222. if (!__pyx_ptype_7preshed_4maps_PreshMapArray) __PYX_ERR(3, 44, __pyx_L1_error)
  5223. __pyx_vtabptr_7preshed_4maps_PreshMapArray = (struct __pyx_vtabstruct_7preshed_4maps_PreshMapArray*)__Pyx_GetVtable(__pyx_ptype_7preshed_4maps_PreshMapArray->tp_dict); if (unlikely(!__pyx_vtabptr_7preshed_4maps_PreshMapArray)) __PYX_ERR(3, 44, __pyx_L1_error)
  5224. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5225. __pyx_t_1 = PyImport_ImportModule("thinc.linalg"); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 22, __pyx_L1_error)
  5226. __Pyx_GOTREF(__pyx_t_1);
  5227. __pyx_ptype_5thinc_6linalg_Matrix = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "Matrix", sizeof(struct __pyx_obj_5thinc_6linalg_Matrix), __Pyx_ImportType_CheckSize_Warn);
  5228. if (!__pyx_ptype_5thinc_6linalg_Matrix) __PYX_ERR(4, 22, __pyx_L1_error)
  5229. __pyx_ptype_5thinc_6linalg_Vec = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "Vec", sizeof(struct __pyx_obj_5thinc_6linalg_Vec), __Pyx_ImportType_CheckSize_Warn);
  5230. if (!__pyx_ptype_5thinc_6linalg_Vec) __PYX_ERR(4, 29, __pyx_L1_error)
  5231. __pyx_vtabptr_5thinc_6linalg_Vec = (struct __pyx_vtabstruct_5thinc_6linalg_Vec*)__Pyx_GetVtable(__pyx_ptype_5thinc_6linalg_Vec->tp_dict); if (unlikely(!__pyx_vtabptr_5thinc_6linalg_Vec)) __PYX_ERR(4, 29, __pyx_L1_error)
  5232. __pyx_ptype_5thinc_6linalg_VecVec = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "VecVec", sizeof(struct __pyx_obj_5thinc_6linalg_VecVec), __Pyx_ImportType_CheckSize_Warn);
  5233. if (!__pyx_ptype_5thinc_6linalg_VecVec) __PYX_ERR(4, 140, __pyx_L1_error)
  5234. __pyx_vtabptr_5thinc_6linalg_VecVec = (struct __pyx_vtabstruct_5thinc_6linalg_VecVec*)__Pyx_GetVtable(__pyx_ptype_5thinc_6linalg_VecVec->tp_dict); if (unlikely(!__pyx_vtabptr_5thinc_6linalg_VecVec)) __PYX_ERR(4, 140, __pyx_L1_error)
  5235. __pyx_ptype_5thinc_6linalg_Mat = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "Mat", sizeof(struct __pyx_obj_5thinc_6linalg_Mat), __Pyx_ImportType_CheckSize_Warn);
  5236. if (!__pyx_ptype_5thinc_6linalg_Mat) __PYX_ERR(4, 231, __pyx_L1_error)
  5237. __pyx_vtabptr_5thinc_6linalg_Mat = (struct __pyx_vtabstruct_5thinc_6linalg_Mat*)__Pyx_GetVtable(__pyx_ptype_5thinc_6linalg_Mat->tp_dict); if (unlikely(!__pyx_vtabptr_5thinc_6linalg_Mat)) __PYX_ERR(4, 231, __pyx_L1_error)
  5238. __pyx_ptype_5thinc_6linalg_MatVec = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "MatVec", sizeof(struct __pyx_obj_5thinc_6linalg_MatVec), __Pyx_ImportType_CheckSize_Warn);
  5239. if (!__pyx_ptype_5thinc_6linalg_MatVec) __PYX_ERR(4, 259, __pyx_L1_error)
  5240. __pyx_vtabptr_5thinc_6linalg_MatVec = (struct __pyx_vtabstruct_5thinc_6linalg_MatVec*)__Pyx_GetVtable(__pyx_ptype_5thinc_6linalg_MatVec->tp_dict); if (unlikely(!__pyx_vtabptr_5thinc_6linalg_MatVec)) __PYX_ERR(4, 259, __pyx_L1_error)
  5241. __pyx_ptype_5thinc_6linalg_MatMat = __Pyx_ImportType(__pyx_t_1, "thinc.linalg", "MatMat", sizeof(struct __pyx_obj_5thinc_6linalg_MatMat), __Pyx_ImportType_CheckSize_Warn);
  5242. if (!__pyx_ptype_5thinc_6linalg_MatMat) __PYX_ERR(4, 425, __pyx_L1_error)
  5243. __pyx_vtabptr_5thinc_6linalg_MatMat = (struct __pyx_vtabstruct_5thinc_6linalg_MatMat*)__Pyx_GetVtable(__pyx_ptype_5thinc_6linalg_MatMat->tp_dict); if (unlikely(!__pyx_vtabptr_5thinc_6linalg_MatMat)) __PYX_ERR(4, 425, __pyx_L1_error)
  5244. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5245. __Pyx_RefNannyFinishContext();
  5246. return 0;
  5247. __pyx_L1_error:;
  5248. __Pyx_XDECREF(__pyx_t_1);
  5249. __Pyx_RefNannyFinishContext();
  5250. return -1;
  5251. }
  5252. static int __Pyx_modinit_variable_import_code(void) {
  5253. __Pyx_RefNannyDeclarations
  5254. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  5255. /*--- Variable import code ---*/
  5256. __Pyx_RefNannyFinishContext();
  5257. return 0;
  5258. }
  5259. static int __Pyx_modinit_function_import_code(void) {
  5260. __Pyx_RefNannyDeclarations
  5261. PyObject *__pyx_t_1 = NULL;
  5262. __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  5263. /*--- Function import code ---*/
  5264. __pyx_t_1 = PyImport_ImportModule("murmurhash.mrmr"); if (!__pyx_t_1) __PYX_ERR(1, 1, __pyx_L1_error)
  5265. if (__Pyx_ImportFunction(__pyx_t_1, "real_hash64", (void (**)(void))&__pyx_f_10murmurhash_4mrmr_real_hash64, "uint64_t (void *, int, uint64_t)") < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5266. Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5267. __Pyx_RefNannyFinishContext();
  5268. return 0;
  5269. __pyx_L1_error:;
  5270. __Pyx_XDECREF(__pyx_t_1);
  5271. __Pyx_RefNannyFinishContext();
  5272. return -1;
  5273. }
  5274. #if PY_MAJOR_VERSION < 3
  5275. #ifdef CYTHON_NO_PYINIT_EXPORT
  5276. #define __Pyx_PyMODINIT_FUNC void
  5277. #else
  5278. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  5279. #endif
  5280. #else
  5281. #ifdef CYTHON_NO_PYINIT_EXPORT
  5282. #define __Pyx_PyMODINIT_FUNC PyObject *
  5283. #else
  5284. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  5285. #endif
  5286. #endif
  5287. #if PY_MAJOR_VERSION < 3
  5288. __Pyx_PyMODINIT_FUNC initstructs(void) CYTHON_SMALL_CODE; /*proto*/
  5289. __Pyx_PyMODINIT_FUNC initstructs(void)
  5290. #else
  5291. __Pyx_PyMODINIT_FUNC PyInit_structs(void) CYTHON_SMALL_CODE; /*proto*/
  5292. __Pyx_PyMODINIT_FUNC PyInit_structs(void)
  5293. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5294. {
  5295. return PyModuleDef_Init(&__pyx_moduledef);
  5296. }
  5297. static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
  5298. #if PY_VERSION_HEX >= 0x030700A1
  5299. static PY_INT64_T main_interpreter_id = -1;
  5300. PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
  5301. if (main_interpreter_id == -1) {
  5302. main_interpreter_id = current_id;
  5303. return (unlikely(current_id == -1)) ? -1 : 0;
  5304. } else if (unlikely(main_interpreter_id != current_id))
  5305. #else
  5306. static PyInterpreterState *main_interpreter = NULL;
  5307. PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
  5308. if (!main_interpreter) {
  5309. main_interpreter = current_interpreter;
  5310. } else if (unlikely(main_interpreter != current_interpreter))
  5311. #endif
  5312. {
  5313. PyErr_SetString(
  5314. PyExc_ImportError,
  5315. "Interpreter change detected - this module can only be loaded into one interpreter per process.");
  5316. return -1;
  5317. }
  5318. return 0;
  5319. }
  5320. static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
  5321. PyObject *value = PyObject_GetAttrString(spec, from_name);
  5322. int result = 0;
  5323. if (likely(value)) {
  5324. if (allow_none || value != Py_None) {
  5325. result = PyDict_SetItemString(moddict, to_name, value);
  5326. }
  5327. Py_DECREF(value);
  5328. } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  5329. PyErr_Clear();
  5330. } else {
  5331. result = -1;
  5332. }
  5333. return result;
  5334. }
  5335. static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
  5336. PyObject *module = NULL, *moddict, *modname;
  5337. if (__Pyx_check_single_interpreter())
  5338. return NULL;
  5339. if (__pyx_m)
  5340. return __Pyx_NewRef(__pyx_m);
  5341. modname = PyObject_GetAttrString(spec, "name");
  5342. if (unlikely(!modname)) goto bad;
  5343. module = PyModule_NewObject(modname);
  5344. Py_DECREF(modname);
  5345. if (unlikely(!module)) goto bad;
  5346. moddict = PyModule_GetDict(module);
  5347. if (unlikely(!moddict)) goto bad;
  5348. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
  5349. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
  5350. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
  5351. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
  5352. return module;
  5353. bad:
  5354. Py_XDECREF(module);
  5355. return NULL;
  5356. }
  5357. static CYTHON_SMALL_CODE int __pyx_pymod_exec_structs(PyObject *__pyx_pyinit_module)
  5358. #endif
  5359. #endif
  5360. {
  5361. PyObject *__pyx_t_1 = NULL;
  5362. __Pyx_RefNannyDeclarations
  5363. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5364. if (__pyx_m) {
  5365. if (__pyx_m == __pyx_pyinit_module) return 0;
  5366. PyErr_SetString(PyExc_RuntimeError, "Module 'structs' has already been imported. Re-initialisation is not supported.");
  5367. return -1;
  5368. }
  5369. #elif PY_MAJOR_VERSION >= 3
  5370. if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  5371. #endif
  5372. #if CYTHON_REFNANNY
  5373. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  5374. if (!__Pyx_RefNanny) {
  5375. PyErr_Clear();
  5376. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  5377. if (!__Pyx_RefNanny)
  5378. Py_FatalError("failed to import 'refnanny' module");
  5379. }
  5380. #endif
  5381. __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_structs(void)", 0);
  5382. if (__Pyx_check_binary_version() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5383. #ifdef __Pxy_PyFrame_Initialize_Offsets
  5384. __Pxy_PyFrame_Initialize_Offsets();
  5385. #endif
  5386. __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(1, 1, __pyx_L1_error)
  5387. __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(1, 1, __pyx_L1_error)
  5388. __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(1, 1, __pyx_L1_error)
  5389. #ifdef __Pyx_CyFunction_USED
  5390. if (__pyx_CyFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5391. #endif
  5392. #ifdef __Pyx_FusedFunction_USED
  5393. if (__pyx_FusedFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5394. #endif
  5395. #ifdef __Pyx_Coroutine_USED
  5396. if (__pyx_Coroutine_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5397. #endif
  5398. #ifdef __Pyx_Generator_USED
  5399. if (__pyx_Generator_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5400. #endif
  5401. #ifdef __Pyx_AsyncGen_USED
  5402. if (__pyx_AsyncGen_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5403. #endif
  5404. #ifdef __Pyx_StopAsyncIteration_USED
  5405. if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5406. #endif
  5407. /*--- Library function declarations ---*/
  5408. /*--- Threads initialization code ---*/
  5409. #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  5410. #ifdef WITH_THREAD /* Python build with threading support? */
  5411. PyEval_InitThreads();
  5412. #endif
  5413. #endif
  5414. /*--- Module creation code ---*/
  5415. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5416. __pyx_m = __pyx_pyinit_module;
  5417. Py_INCREF(__pyx_m);
  5418. #else
  5419. #if PY_MAJOR_VERSION < 3
  5420. __pyx_m = Py_InitModule4("structs", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  5421. #else
  5422. __pyx_m = PyModule_Create(&__pyx_moduledef);
  5423. #endif
  5424. if (unlikely(!__pyx_m)) __PYX_ERR(1, 1, __pyx_L1_error)
  5425. #endif
  5426. __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(1, 1, __pyx_L1_error)
  5427. Py_INCREF(__pyx_d);
  5428. __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(1, 1, __pyx_L1_error)
  5429. __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(1, 1, __pyx_L1_error)
  5430. #if CYTHON_COMPILING_IN_PYPY
  5431. Py_INCREF(__pyx_b);
  5432. #endif
  5433. if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
  5434. /*--- Initialize various global constants etc. ---*/
  5435. if (__Pyx_InitGlobals() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5436. #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  5437. if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5438. #endif
  5439. if (__pyx_module_is_main_thinc__structs) {
  5440. if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5441. }
  5442. #if PY_MAJOR_VERSION >= 3
  5443. {
  5444. PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(1, 1, __pyx_L1_error)
  5445. if (!PyDict_GetItemString(modules, "thinc.structs")) {
  5446. if (unlikely(PyDict_SetItemString(modules, "thinc.structs", __pyx_m) < 0)) __PYX_ERR(1, 1, __pyx_L1_error)
  5447. }
  5448. }
  5449. #endif
  5450. /*--- Builtin init code ---*/
  5451. if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5452. /*--- Constants init code ---*/
  5453. if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5454. /*--- Global type/function init code ---*/
  5455. (void)__Pyx_modinit_global_init_code();
  5456. (void)__Pyx_modinit_variable_export_code();
  5457. (void)__Pyx_modinit_function_export_code();
  5458. (void)__Pyx_modinit_type_init_code();
  5459. if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  5460. (void)__Pyx_modinit_variable_import_code();
  5461. if (unlikely(__Pyx_modinit_function_import_code() != 0)) goto __pyx_L1_error;
  5462. /*--- Execution code ---*/
  5463. #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  5464. if (__Pyx_patch_abc() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5465. #endif
  5466. /* "thinc/structs.pyx":1
  5467. # <<<<<<<<<<<<<<
  5468. */
  5469. __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error)
  5470. __Pyx_GOTREF(__pyx_t_1);
  5471. if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  5472. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5473. /* "linalg.pxd":486
  5474. *
  5475. * @staticmethod
  5476. * cdef inline void batch_add_outer_i(weight_t* output, # <<<<<<<<<<<<<<
  5477. * const weight_t* x,
  5478. * const weight_t* y,
  5479. */
  5480. /*--- Wrapped vars code ---*/
  5481. goto __pyx_L0;
  5482. __pyx_L1_error:;
  5483. __Pyx_XDECREF(__pyx_t_1);
  5484. if (__pyx_m) {
  5485. if (__pyx_d) {
  5486. __Pyx_AddTraceback("init thinc.structs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  5487. }
  5488. Py_CLEAR(__pyx_m);
  5489. } else if (!PyErr_Occurred()) {
  5490. PyErr_SetString(PyExc_ImportError, "init thinc.structs");
  5491. }
  5492. __pyx_L0:;
  5493. __Pyx_RefNannyFinishContext();
  5494. #if CYTHON_PEP489_MULTI_PHASE_INIT
  5495. return (__pyx_m != NULL) ? 0 : -1;
  5496. #elif PY_MAJOR_VERSION >= 3
  5497. return __pyx_m;
  5498. #else
  5499. return;
  5500. #endif
  5501. }
  5502. /* --- Runtime support code --- */
  5503. /* Refnanny */
  5504. #if CYTHON_REFNANNY
  5505. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  5506. PyObject *m = NULL, *p = NULL;
  5507. void *r = NULL;
  5508. m = PyImport_ImportModule(modname);
  5509. if (!m) goto end;
  5510. p = PyObject_GetAttrString(m, "RefNannyAPI");
  5511. if (!p) goto end;
  5512. r = PyLong_AsVoidPtr(p);
  5513. end:
  5514. Py_XDECREF(p);
  5515. Py_XDECREF(m);
  5516. return (__Pyx_RefNannyAPIStruct *)r;
  5517. }
  5518. #endif
  5519. /* PyObjectGetAttrStr */
  5520. #if CYTHON_USE_TYPE_SLOTS
  5521. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  5522. PyTypeObject* tp = Py_TYPE(obj);
  5523. if (likely(tp->tp_getattro))
  5524. return tp->tp_getattro(obj, attr_name);
  5525. #if PY_MAJOR_VERSION < 3
  5526. if (likely(tp->tp_getattr))
  5527. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  5528. #endif
  5529. return PyObject_GetAttr(obj, attr_name);
  5530. }
  5531. #endif
  5532. /* GetBuiltinName */
  5533. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  5534. PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
  5535. if (unlikely(!result)) {
  5536. PyErr_Format(PyExc_NameError,
  5537. #if PY_MAJOR_VERSION >= 3
  5538. "name '%U' is not defined", name);
  5539. #else
  5540. "name '%.200s' is not defined", PyString_AS_STRING(name));
  5541. #endif
  5542. }
  5543. return result;
  5544. }
  5545. /* TypeImport */
  5546. #ifndef __PYX_HAVE_RT_ImportType
  5547. #define __PYX_HAVE_RT_ImportType
  5548. static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
  5549. size_t size, enum __Pyx_ImportType_CheckSize check_size)
  5550. {
  5551. PyObject *result = 0;
  5552. char warning[200];
  5553. Py_ssize_t basicsize;
  5554. #ifdef Py_LIMITED_API
  5555. PyObject *py_basicsize;
  5556. #endif
  5557. result = PyObject_GetAttrString(module, class_name);
  5558. if (!result)
  5559. goto bad;
  5560. if (!PyType_Check(result)) {
  5561. PyErr_Format(PyExc_TypeError,
  5562. "%.200s.%.200s is not a type object",
  5563. module_name, class_name);
  5564. goto bad;
  5565. }
  5566. #ifndef Py_LIMITED_API
  5567. basicsize = ((PyTypeObject *)result)->tp_basicsize;
  5568. #else
  5569. py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
  5570. if (!py_basicsize)
  5571. goto bad;
  5572. basicsize = PyLong_AsSsize_t(py_basicsize);
  5573. Py_DECREF(py_basicsize);
  5574. py_basicsize = 0;
  5575. if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
  5576. goto bad;
  5577. #endif
  5578. if ((size_t)basicsize < size) {
  5579. PyErr_Format(PyExc_ValueError,
  5580. "%.200s.%.200s size changed, may indicate binary incompatibility. "
  5581. "Expected %zd from C header, got %zd from PyObject",
  5582. module_name, class_name, size, basicsize);
  5583. goto bad;
  5584. }
  5585. if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
  5586. PyErr_Format(PyExc_ValueError,
  5587. "%.200s.%.200s size changed, may indicate binary incompatibility. "
  5588. "Expected %zd from C header, got %zd from PyObject",
  5589. module_name, class_name, size, basicsize);
  5590. goto bad;
  5591. }
  5592. else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
  5593. PyOS_snprintf(warning, sizeof(warning),
  5594. "%s.%s size changed, may indicate binary incompatibility. "
  5595. "Expected %zd from C header, got %zd from PyObject",
  5596. module_name, class_name, size, basicsize);
  5597. if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
  5598. }
  5599. return (PyTypeObject *)result;
  5600. bad:
  5601. Py_XDECREF(result);
  5602. return NULL;
  5603. }
  5604. #endif
  5605. /* GetVTable */
  5606. static void* __Pyx_GetVtable(PyObject *dict) {
  5607. void* ptr;
  5608. PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
  5609. if (!ob)
  5610. goto bad;
  5611. #if PY_VERSION_HEX >= 0x02070000
  5612. ptr = PyCapsule_GetPointer(ob, 0);
  5613. #else
  5614. ptr = PyCObject_AsVoidPtr(ob);
  5615. #endif
  5616. if (!ptr && !PyErr_Occurred())
  5617. PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
  5618. Py_DECREF(ob);
  5619. return ptr;
  5620. bad:
  5621. Py_XDECREF(ob);
  5622. return NULL;
  5623. }
  5624. /* PyErrFetchRestore */
  5625. #if CYTHON_FAST_THREAD_STATE
  5626. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  5627. PyObject *tmp_type, *tmp_value, *tmp_tb;
  5628. tmp_type = tstate->curexc_type;
  5629. tmp_value = tstate->curexc_value;
  5630. tmp_tb = tstate->curexc_traceback;
  5631. tstate->curexc_type = type;
  5632. tstate->curexc_value = value;
  5633. tstate->curexc_traceback = tb;
  5634. Py_XDECREF(tmp_type);
  5635. Py_XDECREF(tmp_value);
  5636. Py_XDECREF(tmp_tb);
  5637. }
  5638. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  5639. *type = tstate->curexc_type;
  5640. *value = tstate->curexc_value;
  5641. *tb = tstate->curexc_traceback;
  5642. tstate->curexc_type = 0;
  5643. tstate->curexc_value = 0;
  5644. tstate->curexc_traceback = 0;
  5645. }
  5646. #endif
  5647. /* CLineInTraceback */
  5648. #ifndef CYTHON_CLINE_IN_TRACEBACK
  5649. static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
  5650. PyObject *use_cline;
  5651. PyObject *ptype, *pvalue, *ptraceback;
  5652. #if CYTHON_COMPILING_IN_CPYTHON
  5653. PyObject **cython_runtime_dict;
  5654. #endif
  5655. if (unlikely(!__pyx_cython_runtime)) {
  5656. return c_line;
  5657. }
  5658. __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
  5659. #if CYTHON_COMPILING_IN_CPYTHON
  5660. cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
  5661. if (likely(cython_runtime_dict)) {
  5662. __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
  5663. use_cline, *cython_runtime_dict,
  5664. __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
  5665. } else
  5666. #endif
  5667. {
  5668. PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
  5669. if (use_cline_obj) {
  5670. use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
  5671. Py_DECREF(use_cline_obj);
  5672. } else {
  5673. PyErr_Clear();
  5674. use_cline = NULL;
  5675. }
  5676. }
  5677. if (!use_cline) {
  5678. c_line = 0;
  5679. PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
  5680. }
  5681. else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
  5682. c_line = 0;
  5683. }
  5684. __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
  5685. return c_line;
  5686. }
  5687. #endif
  5688. /* CodeObjectCache */
  5689. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  5690. int start = 0, mid = 0, end = count - 1;
  5691. if (end >= 0 && code_line > entries[end].code_line) {
  5692. return count;
  5693. }
  5694. while (start < end) {
  5695. mid = start + (end - start) / 2;
  5696. if (code_line < entries[mid].code_line) {
  5697. end = mid;
  5698. } else if (code_line > entries[mid].code_line) {
  5699. start = mid + 1;
  5700. } else {
  5701. return mid;
  5702. }
  5703. }
  5704. if (code_line <= entries[mid].code_line) {
  5705. return mid;
  5706. } else {
  5707. return mid + 1;
  5708. }
  5709. }
  5710. static PyCodeObject *__pyx_find_code_object(int code_line) {
  5711. PyCodeObject* code_object;
  5712. int pos;
  5713. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  5714. return NULL;
  5715. }
  5716. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  5717. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  5718. return NULL;
  5719. }
  5720. code_object = __pyx_code_cache.entries[pos].code_object;
  5721. Py_INCREF(code_object);
  5722. return code_object;
  5723. }
  5724. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  5725. int pos, i;
  5726. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  5727. if (unlikely(!code_line)) {
  5728. return;
  5729. }
  5730. if (unlikely(!entries)) {
  5731. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  5732. if (likely(entries)) {
  5733. __pyx_code_cache.entries = entries;
  5734. __pyx_code_cache.max_count = 64;
  5735. __pyx_code_cache.count = 1;
  5736. entries[0].code_line = code_line;
  5737. entries[0].code_object = code_object;
  5738. Py_INCREF(code_object);
  5739. }
  5740. return;
  5741. }
  5742. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  5743. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  5744. PyCodeObject* tmp = entries[pos].code_object;
  5745. entries[pos].code_object = code_object;
  5746. Py_DECREF(tmp);
  5747. return;
  5748. }
  5749. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  5750. int new_max = __pyx_code_cache.max_count + 64;
  5751. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  5752. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  5753. if (unlikely(!entries)) {
  5754. return;
  5755. }
  5756. __pyx_code_cache.entries = entries;
  5757. __pyx_code_cache.max_count = new_max;
  5758. }
  5759. for (i=__pyx_code_cache.count; i>pos; i--) {
  5760. entries[i] = entries[i-1];
  5761. }
  5762. entries[pos].code_line = code_line;
  5763. entries[pos].code_object = code_object;
  5764. __pyx_code_cache.count++;
  5765. Py_INCREF(code_object);
  5766. }
  5767. /* AddTraceback */
  5768. #include "compile.h"
  5769. #include "frameobject.h"
  5770. #include "traceback.h"
  5771. static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
  5772. const char *funcname, int c_line,
  5773. int py_line, const char *filename) {
  5774. PyCodeObject *py_code = 0;
  5775. PyObject *py_srcfile = 0;
  5776. PyObject *py_funcname = 0;
  5777. #if PY_MAJOR_VERSION < 3
  5778. py_srcfile = PyString_FromString(filename);
  5779. #else
  5780. py_srcfile = PyUnicode_FromString(filename);
  5781. #endif
  5782. if (!py_srcfile) goto bad;
  5783. if (c_line) {
  5784. #if PY_MAJOR_VERSION < 3
  5785. py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  5786. #else
  5787. py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  5788. #endif
  5789. }
  5790. else {
  5791. #if PY_MAJOR_VERSION < 3
  5792. py_funcname = PyString_FromString(funcname);
  5793. #else
  5794. py_funcname = PyUnicode_FromString(funcname);
  5795. #endif
  5796. }
  5797. if (!py_funcname) goto bad;
  5798. py_code = __Pyx_PyCode_New(
  5799. 0,
  5800. 0,
  5801. 0,
  5802. 0,
  5803. 0,
  5804. __pyx_empty_bytes, /*PyObject *code,*/
  5805. __pyx_empty_tuple, /*PyObject *consts,*/
  5806. __pyx_empty_tuple, /*PyObject *names,*/
  5807. __pyx_empty_tuple, /*PyObject *varnames,*/
  5808. __pyx_empty_tuple, /*PyObject *freevars,*/
  5809. __pyx_empty_tuple, /*PyObject *cellvars,*/
  5810. py_srcfile, /*PyObject *filename,*/
  5811. py_funcname, /*PyObject *name,*/
  5812. py_line,
  5813. __pyx_empty_bytes /*PyObject *lnotab*/
  5814. );
  5815. Py_DECREF(py_srcfile);
  5816. Py_DECREF(py_funcname);
  5817. return py_code;
  5818. bad:
  5819. Py_XDECREF(py_srcfile);
  5820. Py_XDECREF(py_funcname);
  5821. return NULL;
  5822. }
  5823. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  5824. int py_line, const char *filename) {
  5825. PyCodeObject *py_code = 0;
  5826. PyFrameObject *py_frame = 0;
  5827. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  5828. if (c_line) {
  5829. c_line = __Pyx_CLineForTraceback(tstate, c_line);
  5830. }
  5831. py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
  5832. if (!py_code) {
  5833. py_code = __Pyx_CreateCodeObjectForTraceback(
  5834. funcname, c_line, py_line, filename);
  5835. if (!py_code) goto bad;
  5836. __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
  5837. }
  5838. py_frame = PyFrame_New(
  5839. tstate, /*PyThreadState *tstate,*/
  5840. py_code, /*PyCodeObject *code,*/
  5841. __pyx_d, /*PyObject *globals,*/
  5842. 0 /*PyObject *locals*/
  5843. );
  5844. if (!py_frame) goto bad;
  5845. __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
  5846. PyTraceBack_Here(py_frame);
  5847. bad:
  5848. Py_XDECREF(py_code);
  5849. Py_XDECREF(py_frame);
  5850. }
  5851. /* CIntToPy */
  5852. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
  5853. const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
  5854. const int is_unsigned = neg_one > const_zero;
  5855. if (is_unsigned) {
  5856. if (sizeof(int) < sizeof(long)) {
  5857. return PyInt_FromLong((long) value);
  5858. } else if (sizeof(int) <= sizeof(unsigned long)) {
  5859. return PyLong_FromUnsignedLong((unsigned long) value);
  5860. #ifdef HAVE_LONG_LONG
  5861. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  5862. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  5863. #endif
  5864. }
  5865. } else {
  5866. if (sizeof(int) <= sizeof(long)) {
  5867. return PyInt_FromLong((long) value);
  5868. #ifdef HAVE_LONG_LONG
  5869. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  5870. return PyLong_FromLongLong((PY_LONG_LONG) value);
  5871. #endif
  5872. }
  5873. }
  5874. {
  5875. int one = 1; int little = (int)*(unsigned char *)&one;
  5876. unsigned char *bytes = (unsigned char *)&value;
  5877. return _PyLong_FromByteArray(bytes, sizeof(int),
  5878. little, !is_unsigned);
  5879. }
  5880. }
  5881. /* CIntFromPyVerify */
  5882. #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
  5883. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
  5884. #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
  5885. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
  5886. #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
  5887. {\
  5888. func_type value = func_value;\
  5889. if (sizeof(target_type) < sizeof(func_type)) {\
  5890. if (unlikely(value != (func_type) (target_type) value)) {\
  5891. func_type zero = 0;\
  5892. if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
  5893. return (target_type) -1;\
  5894. if (is_unsigned && unlikely(value < zero))\
  5895. goto raise_neg_overflow;\
  5896. else\
  5897. goto raise_overflow;\
  5898. }\
  5899. }\
  5900. return (target_type) value;\
  5901. }
  5902. /* CIntToPy */
  5903. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
  5904. const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
  5905. const int is_unsigned = neg_one > const_zero;
  5906. if (is_unsigned) {
  5907. if (sizeof(int32_t) < sizeof(long)) {
  5908. return PyInt_FromLong((long) value);
  5909. } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
  5910. return PyLong_FromUnsignedLong((unsigned long) value);
  5911. #ifdef HAVE_LONG_LONG
  5912. } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
  5913. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  5914. #endif
  5915. }
  5916. } else {
  5917. if (sizeof(int32_t) <= sizeof(long)) {
  5918. return PyInt_FromLong((long) value);
  5919. #ifdef HAVE_LONG_LONG
  5920. } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
  5921. return PyLong_FromLongLong((PY_LONG_LONG) value);
  5922. #endif
  5923. }
  5924. }
  5925. {
  5926. int one = 1; int little = (int)*(unsigned char *)&one;
  5927. unsigned char *bytes = (unsigned char *)&value;
  5928. return _PyLong_FromByteArray(bytes, sizeof(int32_t),
  5929. little, !is_unsigned);
  5930. }
  5931. }
  5932. /* CIntFromPy */
  5933. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
  5934. const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
  5935. const int is_unsigned = neg_one > const_zero;
  5936. #if PY_MAJOR_VERSION < 3
  5937. if (likely(PyInt_Check(x))) {
  5938. if (sizeof(int) < sizeof(long)) {
  5939. __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
  5940. } else {
  5941. long val = PyInt_AS_LONG(x);
  5942. if (is_unsigned && unlikely(val < 0)) {
  5943. goto raise_neg_overflow;
  5944. }
  5945. return (int) val;
  5946. }
  5947. } else
  5948. #endif
  5949. if (likely(PyLong_Check(x))) {
  5950. if (is_unsigned) {
  5951. #if CYTHON_USE_PYLONG_INTERNALS
  5952. const digit* digits = ((PyLongObject*)x)->ob_digit;
  5953. switch (Py_SIZE(x)) {
  5954. case 0: return (int) 0;
  5955. case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
  5956. case 2:
  5957. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  5958. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  5959. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  5960. } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
  5961. return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  5962. }
  5963. }
  5964. break;
  5965. case 3:
  5966. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  5967. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  5968. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  5969. } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
  5970. return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  5971. }
  5972. }
  5973. break;
  5974. case 4:
  5975. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  5976. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  5977. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  5978. } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
  5979. return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  5980. }
  5981. }
  5982. break;
  5983. }
  5984. #endif
  5985. #if CYTHON_COMPILING_IN_CPYTHON
  5986. if (unlikely(Py_SIZE(x) < 0)) {
  5987. goto raise_neg_overflow;
  5988. }
  5989. #else
  5990. {
  5991. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  5992. if (unlikely(result < 0))
  5993. return (int) -1;
  5994. if (unlikely(result == 1))
  5995. goto raise_neg_overflow;
  5996. }
  5997. #endif
  5998. if (sizeof(int) <= sizeof(unsigned long)) {
  5999. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
  6000. #ifdef HAVE_LONG_LONG
  6001. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  6002. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  6003. #endif
  6004. }
  6005. } else {
  6006. #if CYTHON_USE_PYLONG_INTERNALS
  6007. const digit* digits = ((PyLongObject*)x)->ob_digit;
  6008. switch (Py_SIZE(x)) {
  6009. case 0: return (int) 0;
  6010. case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
  6011. case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
  6012. case -2:
  6013. if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
  6014. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6015. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6016. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  6017. return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6018. }
  6019. }
  6020. break;
  6021. case 2:
  6022. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  6023. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6024. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6025. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  6026. return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6027. }
  6028. }
  6029. break;
  6030. case -3:
  6031. if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  6032. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6033. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6034. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  6035. return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6036. }
  6037. }
  6038. break;
  6039. case 3:
  6040. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  6041. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6042. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6043. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  6044. return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6045. }
  6046. }
  6047. break;
  6048. case -4:
  6049. if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  6050. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6051. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6052. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  6053. return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6054. }
  6055. }
  6056. break;
  6057. case 4:
  6058. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  6059. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6060. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6061. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  6062. return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  6063. }
  6064. }
  6065. break;
  6066. }
  6067. #endif
  6068. if (sizeof(int) <= sizeof(long)) {
  6069. __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
  6070. #ifdef HAVE_LONG_LONG
  6071. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  6072. __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
  6073. #endif
  6074. }
  6075. }
  6076. {
  6077. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  6078. PyErr_SetString(PyExc_RuntimeError,
  6079. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  6080. #else
  6081. int val;
  6082. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  6083. #if PY_MAJOR_VERSION < 3
  6084. if (likely(v) && !PyLong_Check(v)) {
  6085. PyObject *tmp = v;
  6086. v = PyNumber_Long(tmp);
  6087. Py_DECREF(tmp);
  6088. }
  6089. #endif
  6090. if (likely(v)) {
  6091. int one = 1; int is_little = (int)*(unsigned char *)&one;
  6092. unsigned char *bytes = (unsigned char *)&val;
  6093. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  6094. bytes, sizeof(val),
  6095. is_little, !is_unsigned);
  6096. Py_DECREF(v);
  6097. if (likely(!ret))
  6098. return val;
  6099. }
  6100. #endif
  6101. return (int) -1;
  6102. }
  6103. } else {
  6104. int val;
  6105. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  6106. if (!tmp) return (int) -1;
  6107. val = __Pyx_PyInt_As_int(tmp);
  6108. Py_DECREF(tmp);
  6109. return val;
  6110. }
  6111. raise_overflow:
  6112. PyErr_SetString(PyExc_OverflowError,
  6113. "value too large to convert to int");
  6114. return (int) -1;
  6115. raise_neg_overflow:
  6116. PyErr_SetString(PyExc_OverflowError,
  6117. "can't convert negative value to int");
  6118. return (int) -1;
  6119. }
  6120. /* CIntFromPy */
  6121. static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
  6122. const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
  6123. const int is_unsigned = neg_one > const_zero;
  6124. #if PY_MAJOR_VERSION < 3
  6125. if (likely(PyInt_Check(x))) {
  6126. if (sizeof(int32_t) < sizeof(long)) {
  6127. __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(x))
  6128. } else {
  6129. long val = PyInt_AS_LONG(x);
  6130. if (is_unsigned && unlikely(val < 0)) {
  6131. goto raise_neg_overflow;
  6132. }
  6133. return (int32_t) val;
  6134. }
  6135. } else
  6136. #endif
  6137. if (likely(PyLong_Check(x))) {
  6138. if (is_unsigned) {
  6139. #if CYTHON_USE_PYLONG_INTERNALS
  6140. const digit* digits = ((PyLongObject*)x)->ob_digit;
  6141. switch (Py_SIZE(x)) {
  6142. case 0: return (int32_t) 0;
  6143. case 1: __PYX_VERIFY_RETURN_INT(int32_t, digit, digits[0])
  6144. case 2:
  6145. if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
  6146. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6147. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6148. } else if (8 * sizeof(int32_t) >= 2 * PyLong_SHIFT) {
  6149. return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
  6150. }
  6151. }
  6152. break;
  6153. case 3:
  6154. if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
  6155. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6156. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6157. } else if (8 * sizeof(int32_t) >= 3 * PyLong_SHIFT) {
  6158. return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
  6159. }
  6160. }
  6161. break;
  6162. case 4:
  6163. if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
  6164. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6165. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6166. } else if (8 * sizeof(int32_t) >= 4 * PyLong_SHIFT) {
  6167. return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
  6168. }
  6169. }
  6170. break;
  6171. }
  6172. #endif
  6173. #if CYTHON_COMPILING_IN_CPYTHON
  6174. if (unlikely(Py_SIZE(x) < 0)) {
  6175. goto raise_neg_overflow;
  6176. }
  6177. #else
  6178. {
  6179. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  6180. if (unlikely(result < 0))
  6181. return (int32_t) -1;
  6182. if (unlikely(result == 1))
  6183. goto raise_neg_overflow;
  6184. }
  6185. #endif
  6186. if (sizeof(int32_t) <= sizeof(unsigned long)) {
  6187. __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
  6188. #ifdef HAVE_LONG_LONG
  6189. } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
  6190. __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  6191. #endif
  6192. }
  6193. } else {
  6194. #if CYTHON_USE_PYLONG_INTERNALS
  6195. const digit* digits = ((PyLongObject*)x)->ob_digit;
  6196. switch (Py_SIZE(x)) {
  6197. case 0: return (int32_t) 0;
  6198. case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
  6199. case 1: __PYX_VERIFY_RETURN_INT(int32_t, digit, +digits[0])
  6200. case -2:
  6201. if (8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT) {
  6202. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6203. __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6204. } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
  6205. return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6206. }
  6207. }
  6208. break;
  6209. case 2:
  6210. if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
  6211. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6212. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6213. } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
  6214. return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6215. }
  6216. }
  6217. break;
  6218. case -3:
  6219. if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
  6220. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6221. __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6222. } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
  6223. return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6224. }
  6225. }
  6226. break;
  6227. case 3:
  6228. if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
  6229. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6230. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6231. } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
  6232. return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6233. }
  6234. }
  6235. break;
  6236. case -4:
  6237. if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
  6238. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6239. __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6240. } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
  6241. return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6242. }
  6243. }
  6244. break;
  6245. case 4:
  6246. if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
  6247. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6248. __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6249. } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
  6250. return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
  6251. }
  6252. }
  6253. break;
  6254. }
  6255. #endif
  6256. if (sizeof(int32_t) <= sizeof(long)) {
  6257. __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
  6258. #ifdef HAVE_LONG_LONG
  6259. } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
  6260. __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
  6261. #endif
  6262. }
  6263. }
  6264. {
  6265. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  6266. PyErr_SetString(PyExc_RuntimeError,
  6267. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  6268. #else
  6269. int32_t val;
  6270. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  6271. #if PY_MAJOR_VERSION < 3
  6272. if (likely(v) && !PyLong_Check(v)) {
  6273. PyObject *tmp = v;
  6274. v = PyNumber_Long(tmp);
  6275. Py_DECREF(tmp);
  6276. }
  6277. #endif
  6278. if (likely(v)) {
  6279. int one = 1; int is_little = (int)*(unsigned char *)&one;
  6280. unsigned char *bytes = (unsigned char *)&val;
  6281. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  6282. bytes, sizeof(val),
  6283. is_little, !is_unsigned);
  6284. Py_DECREF(v);
  6285. if (likely(!ret))
  6286. return val;
  6287. }
  6288. #endif
  6289. return (int32_t) -1;
  6290. }
  6291. } else {
  6292. int32_t val;
  6293. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  6294. if (!tmp) return (int32_t) -1;
  6295. val = __Pyx_PyInt_As_int32_t(tmp);
  6296. Py_DECREF(tmp);
  6297. return val;
  6298. }
  6299. raise_overflow:
  6300. PyErr_SetString(PyExc_OverflowError,
  6301. "value too large to convert to int32_t");
  6302. return (int32_t) -1;
  6303. raise_neg_overflow:
  6304. PyErr_SetString(PyExc_OverflowError,
  6305. "can't convert negative value to int32_t");
  6306. return (int32_t) -1;
  6307. }
  6308. /* CIntToPy */
  6309. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
  6310. const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
  6311. const int is_unsigned = neg_one > const_zero;
  6312. if (is_unsigned) {
  6313. if (sizeof(long) < sizeof(long)) {
  6314. return PyInt_FromLong((long) value);
  6315. } else if (sizeof(long) <= sizeof(unsigned long)) {
  6316. return PyLong_FromUnsignedLong((unsigned long) value);
  6317. #ifdef HAVE_LONG_LONG
  6318. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  6319. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  6320. #endif
  6321. }
  6322. } else {
  6323. if (sizeof(long) <= sizeof(long)) {
  6324. return PyInt_FromLong((long) value);
  6325. #ifdef HAVE_LONG_LONG
  6326. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  6327. return PyLong_FromLongLong((PY_LONG_LONG) value);
  6328. #endif
  6329. }
  6330. }
  6331. {
  6332. int one = 1; int little = (int)*(unsigned char *)&one;
  6333. unsigned char *bytes = (unsigned char *)&value;
  6334. return _PyLong_FromByteArray(bytes, sizeof(long),
  6335. little, !is_unsigned);
  6336. }
  6337. }
  6338. /* CIntFromPy */
  6339. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
  6340. const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
  6341. const int is_unsigned = neg_one > const_zero;
  6342. #if PY_MAJOR_VERSION < 3
  6343. if (likely(PyInt_Check(x))) {
  6344. if (sizeof(long) < sizeof(long)) {
  6345. __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
  6346. } else {
  6347. long val = PyInt_AS_LONG(x);
  6348. if (is_unsigned && unlikely(val < 0)) {
  6349. goto raise_neg_overflow;
  6350. }
  6351. return (long) val;
  6352. }
  6353. } else
  6354. #endif
  6355. if (likely(PyLong_Check(x))) {
  6356. if (is_unsigned) {
  6357. #if CYTHON_USE_PYLONG_INTERNALS
  6358. const digit* digits = ((PyLongObject*)x)->ob_digit;
  6359. switch (Py_SIZE(x)) {
  6360. case 0: return (long) 0;
  6361. case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
  6362. case 2:
  6363. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  6364. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6365. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6366. } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
  6367. return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  6368. }
  6369. }
  6370. break;
  6371. case 3:
  6372. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  6373. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6374. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6375. } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
  6376. return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  6377. }
  6378. }
  6379. break;
  6380. case 4:
  6381. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  6382. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6383. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6384. } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
  6385. return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  6386. }
  6387. }
  6388. break;
  6389. }
  6390. #endif
  6391. #if CYTHON_COMPILING_IN_CPYTHON
  6392. if (unlikely(Py_SIZE(x) < 0)) {
  6393. goto raise_neg_overflow;
  6394. }
  6395. #else
  6396. {
  6397. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  6398. if (unlikely(result < 0))
  6399. return (long) -1;
  6400. if (unlikely(result == 1))
  6401. goto raise_neg_overflow;
  6402. }
  6403. #endif
  6404. if (sizeof(long) <= sizeof(unsigned long)) {
  6405. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
  6406. #ifdef HAVE_LONG_LONG
  6407. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  6408. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  6409. #endif
  6410. }
  6411. } else {
  6412. #if CYTHON_USE_PYLONG_INTERNALS
  6413. const digit* digits = ((PyLongObject*)x)->ob_digit;
  6414. switch (Py_SIZE(x)) {
  6415. case 0: return (long) 0;
  6416. case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
  6417. case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
  6418. case -2:
  6419. if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
  6420. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6421. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6422. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  6423. return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6424. }
  6425. }
  6426. break;
  6427. case 2:
  6428. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  6429. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  6430. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6431. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  6432. return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6433. }
  6434. }
  6435. break;
  6436. case -3:
  6437. if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  6438. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6439. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6440. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  6441. return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6442. }
  6443. }
  6444. break;
  6445. case 3:
  6446. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  6447. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  6448. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6449. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  6450. return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6451. }
  6452. }
  6453. break;
  6454. case -4:
  6455. if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  6456. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6457. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6458. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  6459. return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6460. }
  6461. }
  6462. break;
  6463. case 4:
  6464. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  6465. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  6466. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  6467. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  6468. return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  6469. }
  6470. }
  6471. break;
  6472. }
  6473. #endif
  6474. if (sizeof(long) <= sizeof(long)) {
  6475. __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
  6476. #ifdef HAVE_LONG_LONG
  6477. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  6478. __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
  6479. #endif
  6480. }
  6481. }
  6482. {
  6483. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  6484. PyErr_SetString(PyExc_RuntimeError,
  6485. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  6486. #else
  6487. long val;
  6488. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  6489. #if PY_MAJOR_VERSION < 3
  6490. if (likely(v) && !PyLong_Check(v)) {
  6491. PyObject *tmp = v;
  6492. v = PyNumber_Long(tmp);
  6493. Py_DECREF(tmp);
  6494. }
  6495. #endif
  6496. if (likely(v)) {
  6497. int one = 1; int is_little = (int)*(unsigned char *)&one;
  6498. unsigned char *bytes = (unsigned char *)&val;
  6499. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  6500. bytes, sizeof(val),
  6501. is_little, !is_unsigned);
  6502. Py_DECREF(v);
  6503. if (likely(!ret))
  6504. return val;
  6505. }
  6506. #endif
  6507. return (long) -1;
  6508. }
  6509. } else {
  6510. long val;
  6511. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  6512. if (!tmp) return (long) -1;
  6513. val = __Pyx_PyInt_As_long(tmp);
  6514. Py_DECREF(tmp);
  6515. return val;
  6516. }
  6517. raise_overflow:
  6518. PyErr_SetString(PyExc_OverflowError,
  6519. "value too large to convert to long");
  6520. return (long) -1;
  6521. raise_neg_overflow:
  6522. PyErr_SetString(PyExc_OverflowError,
  6523. "can't convert negative value to long");
  6524. return (long) -1;
  6525. }
  6526. /* FastTypeChecks */
  6527. #if CYTHON_COMPILING_IN_CPYTHON
  6528. static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
  6529. while (a) {
  6530. a = a->tp_base;
  6531. if (a == b)
  6532. return 1;
  6533. }
  6534. return b == &PyBaseObject_Type;
  6535. }
  6536. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
  6537. PyObject *mro;
  6538. if (a == b) return 1;
  6539. mro = a->tp_mro;
  6540. if (likely(mro)) {
  6541. Py_ssize_t i, n;
  6542. n = PyTuple_GET_SIZE(mro);
  6543. for (i = 0; i < n; i++) {
  6544. if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
  6545. return 1;
  6546. }
  6547. return 0;
  6548. }
  6549. return __Pyx_InBases(a, b);
  6550. }
  6551. #if PY_MAJOR_VERSION == 2
  6552. static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
  6553. PyObject *exception, *value, *tb;
  6554. int res;
  6555. __Pyx_PyThreadState_declare
  6556. __Pyx_PyThreadState_assign
  6557. __Pyx_ErrFetch(&exception, &value, &tb);
  6558. res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
  6559. if (unlikely(res == -1)) {
  6560. PyErr_WriteUnraisable(err);
  6561. res = 0;
  6562. }
  6563. if (!res) {
  6564. res = PyObject_IsSubclass(err, exc_type2);
  6565. if (unlikely(res == -1)) {
  6566. PyErr_WriteUnraisable(err);
  6567. res = 0;
  6568. }
  6569. }
  6570. __Pyx_ErrRestore(exception, value, tb);
  6571. return res;
  6572. }
  6573. #else
  6574. static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
  6575. int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
  6576. if (!res) {
  6577. res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
  6578. }
  6579. return res;
  6580. }
  6581. #endif
  6582. static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
  6583. Py_ssize_t i, n;
  6584. assert(PyExceptionClass_Check(exc_type));
  6585. n = PyTuple_GET_SIZE(tuple);
  6586. #if PY_MAJOR_VERSION >= 3
  6587. for (i=0; i<n; i++) {
  6588. if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
  6589. }
  6590. #endif
  6591. for (i=0; i<n; i++) {
  6592. PyObject *t = PyTuple_GET_ITEM(tuple, i);
  6593. #if PY_MAJOR_VERSION < 3
  6594. if (likely(exc_type == t)) return 1;
  6595. #endif
  6596. if (likely(PyExceptionClass_Check(t))) {
  6597. if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
  6598. } else {
  6599. }
  6600. }
  6601. return 0;
  6602. }
  6603. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
  6604. if (likely(err == exc_type)) return 1;
  6605. if (likely(PyExceptionClass_Check(err))) {
  6606. if (likely(PyExceptionClass_Check(exc_type))) {
  6607. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
  6608. } else if (likely(PyTuple_Check(exc_type))) {
  6609. return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
  6610. } else {
  6611. }
  6612. }
  6613. return PyErr_GivenExceptionMatches(err, exc_type);
  6614. }
  6615. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
  6616. assert(PyExceptionClass_Check(exc_type1));
  6617. assert(PyExceptionClass_Check(exc_type2));
  6618. if (likely(err == exc_type1 || err == exc_type2)) return 1;
  6619. if (likely(PyExceptionClass_Check(err))) {
  6620. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
  6621. }
  6622. return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
  6623. }
  6624. #endif
  6625. /* CheckBinaryVersion */
  6626. static int __Pyx_check_binary_version(void) {
  6627. char ctversion[4], rtversion[4];
  6628. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  6629. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  6630. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  6631. char message[200];
  6632. PyOS_snprintf(message, sizeof(message),
  6633. "compiletime version %s of module '%.100s' "
  6634. "does not match runtime version %s",
  6635. ctversion, __Pyx_MODULE_NAME, rtversion);
  6636. return PyErr_WarnEx(NULL, message, 1);
  6637. }
  6638. return 0;
  6639. }
  6640. /* FunctionImport */
  6641. #ifndef __PYX_HAVE_RT_ImportFunction
  6642. #define __PYX_HAVE_RT_ImportFunction
  6643. static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
  6644. PyObject *d = 0;
  6645. PyObject *cobj = 0;
  6646. union {
  6647. void (*fp)(void);
  6648. void *p;
  6649. } tmp;
  6650. d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
  6651. if (!d)
  6652. goto bad;
  6653. cobj = PyDict_GetItemString(d, funcname);
  6654. if (!cobj) {
  6655. PyErr_Format(PyExc_ImportError,
  6656. "%.200s does not export expected C function %.200s",
  6657. PyModule_GetName(module), funcname);
  6658. goto bad;
  6659. }
  6660. #if PY_VERSION_HEX >= 0x02070000
  6661. if (!PyCapsule_IsValid(cobj, sig)) {
  6662. PyErr_Format(PyExc_TypeError,
  6663. "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
  6664. PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
  6665. goto bad;
  6666. }
  6667. tmp.p = PyCapsule_GetPointer(cobj, sig);
  6668. #else
  6669. {const char *desc, *s1, *s2;
  6670. desc = (const char *)PyCObject_GetDesc(cobj);
  6671. if (!desc)
  6672. goto bad;
  6673. s1 = desc; s2 = sig;
  6674. while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
  6675. if (*s1 != *s2) {
  6676. PyErr_Format(PyExc_TypeError,
  6677. "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
  6678. PyModule_GetName(module), funcname, sig, desc);
  6679. goto bad;
  6680. }
  6681. tmp.p = PyCObject_AsVoidPtr(cobj);}
  6682. #endif
  6683. *f = tmp.fp;
  6684. if (!(*f))
  6685. goto bad;
  6686. Py_DECREF(d);
  6687. return 0;
  6688. bad:
  6689. Py_XDECREF(d);
  6690. return -1;
  6691. }
  6692. #endif
  6693. /* InitStrings */
  6694. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
  6695. while (t->p) {
  6696. #if PY_MAJOR_VERSION < 3
  6697. if (t->is_unicode) {
  6698. *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
  6699. } else if (t->intern) {
  6700. *t->p = PyString_InternFromString(t->s);
  6701. } else {
  6702. *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
  6703. }
  6704. #else
  6705. if (t->is_unicode | t->is_str) {
  6706. if (t->intern) {
  6707. *t->p = PyUnicode_InternFromString(t->s);
  6708. } else if (t->encoding) {
  6709. *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
  6710. } else {
  6711. *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
  6712. }
  6713. } else {
  6714. *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
  6715. }
  6716. #endif
  6717. if (!*t->p)
  6718. return -1;
  6719. if (PyObject_Hash(*t->p) == -1)
  6720. return -1;
  6721. ++t;
  6722. }
  6723. return 0;
  6724. }
  6725. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
  6726. return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
  6727. }
  6728. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
  6729. Py_ssize_t ignore;
  6730. return __Pyx_PyObject_AsStringAndSize(o, &ignore);
  6731. }
  6732. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  6733. #if !CYTHON_PEP393_ENABLED
  6734. static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  6735. char* defenc_c;
  6736. PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
  6737. if (!defenc) return NULL;
  6738. defenc_c = PyBytes_AS_STRING(defenc);
  6739. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  6740. {
  6741. char* end = defenc_c + PyBytes_GET_SIZE(defenc);
  6742. char* c;
  6743. for (c = defenc_c; c < end; c++) {
  6744. if ((unsigned char) (*c) >= 128) {
  6745. PyUnicode_AsASCIIString(o);
  6746. return NULL;
  6747. }
  6748. }
  6749. }
  6750. #endif
  6751. *length = PyBytes_GET_SIZE(defenc);
  6752. return defenc_c;
  6753. }
  6754. #else
  6755. static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  6756. if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
  6757. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  6758. if (likely(PyUnicode_IS_ASCII(o))) {
  6759. *length = PyUnicode_GET_LENGTH(o);
  6760. return PyUnicode_AsUTF8(o);
  6761. } else {
  6762. PyUnicode_AsASCIIString(o);
  6763. return NULL;
  6764. }
  6765. #else
  6766. return PyUnicode_AsUTF8AndSize(o, length);
  6767. #endif
  6768. }
  6769. #endif
  6770. #endif
  6771. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  6772. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  6773. if (
  6774. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  6775. __Pyx_sys_getdefaultencoding_not_ascii &&
  6776. #endif
  6777. PyUnicode_Check(o)) {
  6778. return __Pyx_PyUnicode_AsStringAndSize(o, length);
  6779. } else
  6780. #endif
  6781. #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
  6782. if (PyByteArray_Check(o)) {
  6783. *length = PyByteArray_GET_SIZE(o);
  6784. return PyByteArray_AS_STRING(o);
  6785. } else
  6786. #endif
  6787. {
  6788. char* result;
  6789. int r = PyBytes_AsStringAndSize(o, &result, length);
  6790. if (unlikely(r < 0)) {
  6791. return NULL;
  6792. } else {
  6793. return result;
  6794. }
  6795. }
  6796. }
  6797. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
  6798. int is_true = x == Py_True;
  6799. if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
  6800. else return PyObject_IsTrue(x);
  6801. }
  6802. static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
  6803. int retval;
  6804. if (unlikely(!x)) return -1;
  6805. retval = __Pyx_PyObject_IsTrue(x);
  6806. Py_DECREF(x);
  6807. return retval;
  6808. }
  6809. static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
  6810. #if PY_MAJOR_VERSION >= 3
  6811. if (PyLong_Check(result)) {
  6812. if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
  6813. "__int__ returned non-int (type %.200s). "
  6814. "The ability to return an instance of a strict subclass of int "
  6815. "is deprecated, and may be removed in a future version of Python.",
  6816. Py_TYPE(result)->tp_name)) {
  6817. Py_DECREF(result);
  6818. return NULL;
  6819. }
  6820. return result;
  6821. }
  6822. #endif
  6823. PyErr_Format(PyExc_TypeError,
  6824. "__%.4s__ returned non-%.4s (type %.200s)",
  6825. type_name, type_name, Py_TYPE(result)->tp_name);
  6826. Py_DECREF(result);
  6827. return NULL;
  6828. }
  6829. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  6830. #if CYTHON_USE_TYPE_SLOTS
  6831. PyNumberMethods *m;
  6832. #endif
  6833. const char *name = NULL;
  6834. PyObject *res = NULL;
  6835. #if PY_MAJOR_VERSION < 3
  6836. if (likely(PyInt_Check(x) || PyLong_Check(x)))
  6837. #else
  6838. if (likely(PyLong_Check(x)))
  6839. #endif
  6840. return __Pyx_NewRef(x);
  6841. #if CYTHON_USE_TYPE_SLOTS
  6842. m = Py_TYPE(x)->tp_as_number;
  6843. #if PY_MAJOR_VERSION < 3
  6844. if (m && m->nb_int) {
  6845. name = "int";
  6846. res = m->nb_int(x);
  6847. }
  6848. else if (m && m->nb_long) {
  6849. name = "long";
  6850. res = m->nb_long(x);
  6851. }
  6852. #else
  6853. if (likely(m && m->nb_int)) {
  6854. name = "int";
  6855. res = m->nb_int(x);
  6856. }
  6857. #endif
  6858. #else
  6859. if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
  6860. res = PyNumber_Int(x);
  6861. }
  6862. #endif
  6863. if (likely(res)) {
  6864. #if PY_MAJOR_VERSION < 3
  6865. if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
  6866. #else
  6867. if (unlikely(!PyLong_CheckExact(res))) {
  6868. #endif
  6869. return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
  6870. }
  6871. }
  6872. else if (!PyErr_Occurred()) {
  6873. PyErr_SetString(PyExc_TypeError,
  6874. "an integer is required");
  6875. }
  6876. return res;
  6877. }
  6878. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  6879. Py_ssize_t ival;
  6880. PyObject *x;
  6881. #if PY_MAJOR_VERSION < 3
  6882. if (likely(PyInt_CheckExact(b))) {
  6883. if (sizeof(Py_ssize_t) >= sizeof(long))
  6884. return PyInt_AS_LONG(b);
  6885. else
  6886. return PyInt_AsSsize_t(b);
  6887. }
  6888. #endif
  6889. if (likely(PyLong_CheckExact(b))) {
  6890. #if CYTHON_USE_PYLONG_INTERNALS
  6891. const digit* digits = ((PyLongObject*)b)->ob_digit;
  6892. const Py_ssize_t size = Py_SIZE(b);
  6893. if (likely(__Pyx_sst_abs(size) <= 1)) {
  6894. ival = likely(size) ? digits[0] : 0;
  6895. if (size == -1) ival = -ival;
  6896. return ival;
  6897. } else {
  6898. switch (size) {
  6899. case 2:
  6900. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  6901. return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6902. }
  6903. break;
  6904. case -2:
  6905. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  6906. return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6907. }
  6908. break;
  6909. case 3:
  6910. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  6911. return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6912. }
  6913. break;
  6914. case -3:
  6915. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  6916. return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6917. }
  6918. break;
  6919. case 4:
  6920. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  6921. return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6922. }
  6923. break;
  6924. case -4:
  6925. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  6926. return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  6927. }
  6928. break;
  6929. }
  6930. }
  6931. #endif
  6932. return PyLong_AsSsize_t(b);
  6933. }
  6934. x = PyNumber_Index(b);
  6935. if (!x) return -1;
  6936. ival = PyInt_AsSsize_t(x);
  6937. Py_DECREF(x);
  6938. return ival;
  6939. }
  6940. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  6941. return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
  6942. }
  6943. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
  6944. return PyInt_FromSize_t(ival);
  6945. }
  6946. #endif /* Py_PYTHON_H */