Generated by Cython 0.13 on Mon Oct 4 15:14:58 2010
Raw output: integrate_hints.c
1: # This code still runs under Python!
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":1 * # This code still runs under Python! #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * # cython: cdivision=True */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1));
2:
3: # cython: cdivision=True
4:
5: from __future__ import division
6: import cython
7:
8: @cython.locals(x=cython.double)
9: def f(x):
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":9 * * @cython.locals(x=cython.double) * def f(x): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* # Note: x**4 translates to slow code in Cython * # Use x*x*x*x to avoid calling 'pow' */ static PyObject *__pyx_pf_15integrate_hints_f(PyObject *__pyx_self, PyObject *__pyx_arg_x); /*proto*/ static PyObject *__pyx_pf_15integrate_hints_f(PyObject *__pyx_self, PyObject *__pyx_arg_x) { double __pyx_v_x; PyObject *__pyx_r = NULL; __Pyx_RefNannySetupContext("f"); __pyx_self = __pyx_self; assert(__pyx_arg_x); { __pyx_v_x = __pyx_PyFloat_AsDouble(__pyx_arg_x); if (unlikely((__pyx_v_x == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("integrate_hints.f"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:;
10: # Note: x**4 translates to slow code in Cython
11: # Use x*x*x*x to avoid calling 'pow'
12: return x**4 - 3 * x
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":12 * # Note: x**4 translates to slow code in Cython * # Use x*x*x*x to avoid calling 'pow' * return x**4 - 3 * x #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * @cython.locals(a=cython.double, b=cython.double, */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble((pow(__pyx_v_x, 4.0) - (3.0 * __pyx_v_x))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("integrate_hints.f"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
13:
14: @cython.locals(a=cython.double, b=cython.double,
15: N=cython.int, s=cython.double,
16: dx=cython.double, i=cython.int)
17: def integrate_f(a, b, N):
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":17 * N=cython.int, s=cython.double, * dx=cython.double, i=cython.int) * def integrate_f(a, b, N): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """Rectangle integration of a function. * */ static PyObject *__pyx_pf_15integrate_hints_integrate_f(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_15integrate_hints_integrate_f[] = "Rectangle integration of a function.\n\n Parameters\n ----------\n a, b : ints\n Interval over which to integrate.\n N : int\n Number of intervals to use in the discretisation.\n\n "; static PyObject *__pyx_pf_15integrate_hints_integrate_f(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { double __pyx_v_a; double __pyx_v_b; int __pyx_v_N; int __pyx_v_i; double __pyx_v_s; double __pyx_v_dx; PyObject *__pyx_r = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__a,&__pyx_n_s__b,&__pyx_n_s__N,0}; __Pyx_RefNannySetupContext("integrate_f"); __pyx_self = __pyx_self; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[3] = {0,0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__b); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("integrate_f", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__N); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("integrate_f", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "integrate_f")<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_a = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_a == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_b = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_b == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_N = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { __pyx_v_a = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_a == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_b = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_b == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_N = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("integrate_f", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("integrate_hints.integrate_f"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:;
18: """Rectangle integration of a function.
19:
20: Parameters
21: ----------
22: a, b : ints
23: Interval over which to integrate.
24: N : int
25: Number of intervals to use in the discretisation.
26:
27: """
28: s = 0
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":28 * * """ * s = 0 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* dx = (b - a) / N * for i in range(N): */ __pyx_v_s = 0.0;
29: dx = (b - a) / N
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":29 * """ * s = 0 * dx = (b - a) / N #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i in range(N): * s += f(a + i * dx) */ __pyx_v_dx = ((__pyx_v_b - __pyx_v_a) / ((double)__pyx_v_N));
30: for i in range(N):
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":30 * s = 0 * dx = (b - a) / N * for i in range(N): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* s += f(a + i * dx) * return s * dx */ __pyx_t_1 = __pyx_v_N; for (__pyx_t_2 = 0; __pyx_t_2<
__pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2;
31: s += f(a + i * dx)
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":31 * dx = (b - a) / N * for i in range(N): * s += f(a + i * dx) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* return s * dx * */ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyFloat_FromDouble((__pyx_v_a + (__pyx_v_i * __pyx_v_dx))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_s += __pyx_t_6; }
32: return s * dx
/* "/home/stefan/akad/voordragte/2010/trento/cython/demos/integrate/integrate_hints.py":32 * for i in range(N): * s += f(a + i * dx) * return s * dx #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* */ __Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyFloat_FromDouble((__pyx_v_s * __pyx_v_dx)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("integrate_hints.integrate_f"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
33: