Generated by Cython 0.12.1 on Fri Jun 25 00:04:05 2010
Raw output: _Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0.c
1:
2: include "interrupt.pxi" # ctrl-c interrupt block support
3: include "stdsage.pxi" # ctrl-c interrupt block support
4:
5: include "cdefs.pxi"
6: import cython
7: from numpy cimport ndarray
8:
9: cdef bint is_prime3(int n):
static int __pyx_f_76_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0_is_prime3(int __pyx_v_n) {
int __pyx_v_k;
int __pyx_r;
__Pyx_RefNannySetupContext("is_prime3");
10: if n == 2: return True
__pyx_t_1 = (__pyx_v_n == 2);
if (__pyx_t_1) {
__pyx_r = 1;
goto __pyx_L0;
goto __pyx_L3;
}
__pyx_L3:;
11: if n % 2 == 0 or n < 2: return False
__pyx_t_1 = (__Pyx_mod_long(__pyx_v_n, 2) == 0);
if (!__pyx_t_1) {
__pyx_t_2 = (__pyx_v_n < 2);
__pyx_t_3 = __pyx_t_2;
} else {
__pyx_t_3 = __pyx_t_1;
}
if (__pyx_t_3) {
__pyx_r = 0;
goto __pyx_L0;
goto __pyx_L4;
}
__pyx_L4:;
12: cdef int k = 3
__pyx_v_k = 3;
13: while k*k <= n:
while (1) {
__pyx_t_3 = ((__pyx_v_k * __pyx_v_k) <= __pyx_v_n);
if (!__pyx_t_3) break;
14: if n % k == 0: return False
if (unlikely(__pyx_v_k == 0)) {
PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero");
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_3 = (__Pyx_mod_int(__pyx_v_n, __pyx_v_k) == 0);
if (__pyx_t_3) {
__pyx_r = 0;
goto __pyx_L0;
goto __pyx_L7;
}
__pyx_L7:;
15: k += 2
__pyx_v_k += 2;
}
16: return True
__pyx_r = 1;
goto __pyx_L0;
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_WriteUnraisable("_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0.is_prime3");
__pyx_r = 0;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
17:
18: def is_prime_array(ndarray[int, ndim=1] L):
static PyObject *__pyx_pf_76_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0_is_prime_array(PyObject *__pyx_self, PyObject *__pyx_v_L); /*proto*/
static char __pyx_doc_76_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0_is_prime_array[] = "File: _Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0.pyx (starting at line 18)";
static PyObject *__pyx_pf_76_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0_is_prime_array(PyObject *__pyx_self, PyObject *__pyx_v_L) {
PyArrayObject *__pyx_v_res = 0;
int __pyx_v_i;
Py_buffer __pyx_bstruct_res;
Py_ssize_t __pyx_bstride_0_res = 0;
Py_ssize_t __pyx_bshape_0_res = 0;
Py_buffer __pyx_bstruct_L;
Py_ssize_t __pyx_bstride_0_L = 0;
Py_ssize_t __pyx_bshape_0_L = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannySetupContext("is_prime_array");
__pyx_self = __pyx_self;
__Pyx_INCREF((PyObject *)__pyx_v_L);
__pyx_bstruct_res.buf = NULL;
__pyx_bstruct_L.buf = NULL;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_L), __pyx_ptype_5numpy_ndarray, 1, "L", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_L, (PyObject*)__pyx_v_L, &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_bstride_0_L = __pyx_bstruct_L.strides[0];
__pyx_bshape_0_L = __pyx_bstruct_L.shape[0];
19: cdef ndarray[int, ndim=1] res = ndarray(shape=(L.shape[0],), dtype=int)
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__pyx_t_2 = __Pyx_PyInt_to_py_npy_intp((((PyArrayObject *)__pyx_v_L)->dimensions[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
__pyx_t_2 = 0;
if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__shape), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_t_3 = PyEval_CallObjectWithKeywords(((PyObject *)((PyObject*)__pyx_ptype_5numpy_ndarray)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_res, (PyObject*)((PyArrayObject *)__pyx_t_3), &__Pyx_TypeInfo_int, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
__pyx_v_res = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_res.buf = NULL;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} else {__pyx_bstride_0_res = __pyx_bstruct_res.strides[0];
__pyx_bshape_0_res = __pyx_bstruct_res.shape[0];
}
}
__pyx_v_res = ((PyArrayObject *)__pyx_t_3);
__pyx_t_3 = 0;
20: cdef int i
21: for i in range(L.shape[0]):
__pyx_t_4 = (((PyArrayObject *)__pyx_v_L)->dimensions[0]);
for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
__pyx_v_i = __pyx_t_5;
22: res[i] = is_prime3(L[i])
__pyx_t_6 = __pyx_v_i;
__pyx_t_7 = -1;
if (__pyx_t_6 < 0) {
__pyx_t_6 += __pyx_bshape_0_L;
if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
} else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_L)) __pyx_t_7 = 0;
if (unlikely(__pyx_t_7 != -1)) {
__Pyx_RaiseBufferIndexError(__pyx_t_7);
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_7 = __pyx_v_i;
__pyx_t_8 = -1;
if (__pyx_t_7 < 0) {
__pyx_t_7 += __pyx_bshape_0_res;
if (unlikely(__pyx_t_7 < 0)) __pyx_t_8 = 0;
} else if (unlikely(__pyx_t_7 >= __pyx_bshape_0_res)) __pyx_t_8 = 0;
if (unlikely(__pyx_t_8 != -1)) {
__Pyx_RaiseBufferIndexError(__pyx_t_8);
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
*__Pyx_BufPtrStrided1d(int *, __pyx_bstruct_res.buf, __pyx_t_7, __pyx_bstride_0_res) = __pyx_f_76_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0_is_prime3((*__Pyx_BufPtrStrided1d(int *, __pyx_bstruct_L.buf, __pyx_t_6, __pyx_bstride_0_L)));
}
23: return res
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(((PyObject *)__pyx_v_res));
__pyx_r = ((PyObject *)__pyx_v_res);
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_res);
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_L);
__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
__Pyx_AddTraceback("_Users_robertwb__sage_sage_notebook_sagenb_home_admin_97_code_sage114_spyx_0.is_prime_array");
__pyx_r = NULL;
goto __pyx_L2;
__pyx_L0:;
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_res);
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_L);
__pyx_L2:;
__Pyx_XDECREF((PyObject *)__pyx_v_res);
__Pyx_DECREF((PyObject *)__pyx_v_L);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}