-
# HG changeset patch
# User Mitesh Patel <qed777@gmail.com>
# Date 1286444585 25200
# Node ID 6217f5d97aecc3c1c09d3b35fa1142fd331d5a7b
# Parent bc10678f636e82f2c78203db82abccb6d6f3babf
#9828: Upgrade to Cython 0.13
* * *
[mq]: 8_alpha_fixes.patch
* * *
[mq]: hudson-results
* * *
Use bint not bool.
* * *
Implicit object conversion fix.
* * *
Small type fixes.
* * *
Remove some extraneous explicit types.
* * *
Fix some incorrect import statements.
* * *
Turn off autodict generation for Cython files.
* * *
Explicitly type string literals as bytes objects to make Cython happy.
* * *
Fix setup.py for new Cython.
diff --git a/sage/categories/morphism.pxd b/sage/categories/morphism.pxd
a
|
b
|
cdef class Morphism(Map): |
7 | 7 | |
8 | 8 | cdef class SetMorphism(Morphism): |
9 | 9 | cdef object _function |
10 | | cpdef bool _eq_c_impl(left, Element right) |
| 10 | cpdef bint _eq_c_impl(left, Element right) |
-
diff --git a/sage/categories/morphism.pyx b/sage/categories/morphism.pyx
a
|
b
|
cdef class SetMorphism(Morphism): |
286 | 286 | self._function = _slots['_function'] |
287 | 287 | Map._update_slots(self, _slots) |
288 | 288 | |
289 | | cpdef bool _eq_c_impl(self, Element other): |
| 289 | cpdef bint _eq_c_impl(self, Element other): |
290 | 290 | """ |
291 | 291 | Equality test |
292 | 292 | |
-
diff --git a/sage/graphs/base/c_graph.pyx b/sage/graphs/base/c_graph.pyx
a
|
b
|
cdef class Search_iterator: |
2543 | 2543 | cdef int direction |
2544 | 2544 | cdef list stack |
2545 | 2545 | cdef bitset_t seen |
2546 | | cdef bool test_out |
2547 | | cdef bool test_in |
| 2546 | cdef bint test_out |
| 2547 | cdef bint test_in |
2548 | 2548 | |
2549 | 2549 | def __init__(self, graph, v, direction=0, reverse=False, |
2550 | 2550 | ignore_direction=False): |
-
diff --git a/sage/graphs/cliquer.pxd b/sage/graphs/cliquer.pxd
a
|
b
|
cdef extern from "cliquer/cliquer.h": |
8 | 8 | |
9 | 9 | |
10 | 10 | cdef extern from "cliquer/reorder.h": |
11 | | cdef int *reorder_by_greedy_coloring(graph_t *g, bool weighted) |
12 | | cdef int *reorder_by_degree(graph_t *g, bool weighted) |
| 11 | cdef int *reorder_by_greedy_coloring(graph_t *g, bint weighted) |
| 12 | cdef int *reorder_by_degree(graph_t *g, bint weighted) |
13 | 13 | |
14 | 14 | cdef extern from "cliquer/cliquer.h": |
15 | | bool clique_print_time(intlevel, int i, int n, int max, double cputime, double realtime, clique_options *opts) |
| 15 | bint clique_print_time(intlevel, int i, int n, int max, double cputime, double realtime, clique_options *opts) |
16 | 16 | |
17 | 17 | |
18 | 18 | cdef extern from "cliquer/cl.h": |
-
diff --git a/sage/graphs/generic_graph_pyx.pxd b/sage/graphs/generic_graph_pyx.pxd
a
|
b
|
cdef class SubgraphSearch: |
23 | 23 | cdef int **line_h_in |
24 | 24 | cdef list g_vertices |
25 | 25 | cdef int i |
26 | | cdef bool directed |
| 26 | cdef bint directed |
27 | 27 | |
28 | 28 | |
29 | 29 | cdef inline bint vectors_equal(int n, int *a, int *b) |
-
diff --git a/sage/graphs/generic_graph_pyx.pyx b/sage/graphs/generic_graph_pyx.pyx
a
|
b
|
cdef class SubgraphSearch: |
682 | 682 | _sig_on |
683 | 683 | cdef int *tmp_array_out |
684 | 684 | cdef int *tmp_array_in |
685 | | cdef bool is_admissible |
| 685 | cdef bint is_admissible |
686 | 686 | |
687 | 687 | # as long as there is a non-void partial copy of H in G |
688 | 688 | while self.active >= 0: |
-
diff --git a/sage/libs/flint/fmpz_poly.pyx b/sage/libs/flint/fmpz_poly.pyx
a
|
b
|
cdef class Fmpz_poly(SageObject): |
115 | 115 | 8 0 0 0 0 0 0 0 1 |
116 | 116 | """ |
117 | 117 | cdef char* ss = fmpz_poly_to_string(self.poly) |
118 | | s = ss |
| 118 | cdef object s = ss |
119 | 119 | free(ss) |
120 | 120 | return s |
121 | 121 | |
-
diff --git a/sage/libs/pari/gen.pyx b/sage/libs/pari/gen.pyx
a
|
b
|
cdef class gen(sage.structure.element.Ri |
1392 | 1392 | if signe(x) < 0: |
1393 | 1393 | sp = sp-1 |
1394 | 1394 | sp[0] = c'-' |
1395 | | k = sp |
| 1395 | k = <object>sp |
1396 | 1396 | sage_free(s) |
1397 | 1397 | return k |
1398 | 1398 | |
… |
… |
cdef class PariInstance(sage.structure.p |
9063 | 9063 | if PyObject_TypeCheck(s, gen): |
9064 | 9064 | return s |
9065 | 9065 | elif PyObject_TypeCheck(s, Integer): |
9066 | | return self.new_gen_from_mpz_t(<mpz_t>(<void *>s + mpz_t_offset)) |
| 9066 | return self.new_gen_from_mpz_t(<void *>s + mpz_t_offset) |
9067 | 9067 | elif PyObject_HasAttrString(s, "_pari_"): |
9068 | 9068 | return s._pari_() |
9069 | 9069 | elif isinstance(s, (types.ListType, types.XRangeType, |
-
diff --git a/sage/matrix/matrix_mod2_dense.pyx b/sage/matrix/matrix_mod2_dense.pyx
a
|
b
|
cdef class Matrix_mod2_dense(matrix_dens |
463 | 463 | cdef list row_div, col_div |
464 | 464 | if self.subdivisions is not None: |
465 | 465 | row_s = empty_row |
466 | | div_s = row_divider = "[%s]" % ("-" * (self._ncols*2-1)) |
| 466 | div_s = row_divider = b"[%s]" % ("-" * (self._ncols*2-1)) |
467 | 467 | row_div, col_div = self.get_subdivisions() |
468 | 468 | last_i = 0 |
469 | 469 | for i in col_div: |
… |
… |
cdef class Matrix_mod2_dense(matrix_dens |
475 | 475 | last_i = i |
476 | 476 | |
477 | 477 | for i from 0 <= i < self._nrows: |
478 | | row_s = row = "[%s]" % empty_row |
| 478 | row_s = row = b"[%s]" % empty_row |
479 | 479 | for j from 0 <= j < self._ncols: |
480 | 480 | row_s[1+2*j] = c'0' + mzd_read_bit(self._entries,i,j) |
481 | 481 | s.append(row) |
-
diff --git a/sage/misc/bitset.pxi b/sage/misc/bitset.pxi
a
|
b
|
cdef bitset_string(bitset_t bits): |
669 | 669 | Return a python string representing the bitset. |
670 | 670 | """ |
671 | 671 | cdef char* s = bitset_chars(NULL, bits) |
| 672 | cdef object py_s |
672 | 673 | py_s = s |
673 | 674 | sage_free(s) |
674 | 675 | return py_s |
-
diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
a
|
b
|
def __internal_tests(): |
1055 | 1055 | sage: sage_getdef(sage.rings.integer.Integer.factor, obj_name='factor') |
1056 | 1056 | "factor(algorithm='pari', proof=True, limit=None)" |
1057 | 1057 | |
1058 | | A cython method without an embedded position can lead to surprising errors:: |
1059 | | |
1060 | | sage: sage_getsource(sage.rings.integer.Integer.__init__, is_binary=True) |
1061 | | Traceback (most recent call last): |
1062 | | ... |
1063 | | TypeError: arg is not a module, class, method, function, traceback, frame, or code object |
1064 | | |
1065 | 1058 | sage: sage_getdef(sage.rings.integer.Integer.__init__, obj_name='__init__') |
1066 | | '__init__( [noargspec] )' |
1067 | | |
| 1059 | '__init__(x=None, base=0)' |
| 1060 | |
1068 | 1061 | Test _extract_source with some likely configurations, including no trailing |
1069 | 1062 | newline at the end of the file:: |
1070 | 1063 | |
-
diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
a
|
b
|
class LinearFunction: |
1715 | 1715 | 5 x_2 +2 x_3 |
1716 | 1716 | """ |
1717 | 1717 | cdef dict d = deepcopy(self._f) |
1718 | | cdef bool first = True |
| 1718 | cdef bint first = True |
1719 | 1719 | t = "" |
1720 | 1720 | |
1721 | 1721 | if d.has_key(-1): |
-
diff --git a/sage/numerical/mip_glpk.pyx b/sage/numerical/mip_glpk.pyx
a
|
b
|
def write_lp(self, filename): |
181 | 181 | |
182 | 182 | glp_write_lp(lp,NULL,filename) |
183 | 183 | |
184 | | cdef int build_glp_prob(c_glp_prob * lp, c_glp_iocp * iocp, LP, int log, bool names) except -1: |
| 184 | cdef int build_glp_prob(c_glp_prob * lp, c_glp_iocp * iocp, LP, int log, bint names) except -1: |
185 | 185 | """ |
186 | 186 | Builds the GLPK structure corresponding to the LP |
187 | 187 | |
-
diff --git a/sage/numerical/osi_interface.pxd b/sage/numerical/osi_interface.pxd
a
|
b
|
cdef extern from "../../local/include/co |
10 | 10 | ctypedef struct c_CoinPackedMatrix "CoinPackedMatrix": |
11 | 11 | void setDimensions(int, int) |
12 | 12 | void appendRow(c_CoinPackedVector) |
13 | | c_CoinPackedMatrix *new_c_CoinPackedMatrix "new CoinPackedMatrix" (bool, double, double) |
| 13 | c_CoinPackedMatrix *new_c_CoinPackedMatrix "new CoinPackedMatrix" (bint, double, double) |
14 | 14 | void del_CoinPackedMatrix "delete" (c_CoinPackedMatrix *) |
15 | 15 | |
16 | 16 | cdef extern from "../../local/include/coin/CoinMessageHandler.hpp": |
… |
… |
cdef extern from "../../local/include/co |
86 | 86 | void del_OsiCbcSolverInterface "delete" (c_OsiCbcSolverInterface *) |
87 | 87 | |
88 | 88 | cdef class Osi_interface: |
89 | | cdef float osi_solve(self, LP, c_OsiSolverInterface * si,bool objective_only, bool is_cplex) except? -687654 |
| 89 | cdef float osi_solve(self, LP, c_OsiSolverInterface * si, bint objective_only, bint is_cplex) except? -687654 |
-
diff --git a/sage/numerical/osi_interface.pyx b/sage/numerical/osi_interface.pyx
a
|
b
|
cdef int REAL = -1 |
6 | 6 | cdef int INTEGER = 0 |
7 | 7 | |
8 | 8 | cdef class Osi_interface: |
9 | | cdef float osi_solve(self, LP, c_OsiSolverInterface * si,bool objective_only, bool is_cplex): |
| 9 | cdef float osi_solve(self, LP, c_OsiSolverInterface * si, bint objective_only, bint is_cplex): |
10 | 10 | from itertools import izip |
11 | 11 | n_cols = len(LP._variables_type); |
12 | 12 | |
-
diff --git a/sage/rings/complex_interval.pyx b/sage/rings/complex_interval.pyx
a
|
b
|
cdef class ComplexIntervalFieldElement(s |
95 | 95 | R = parent._real_field() |
96 | 96 | rr = R(real) |
97 | 97 | ii = R(imag) |
98 | | mpfi_set(self.__re, <mpfi_t> rr.value) |
99 | | mpfi_set(self.__im, <mpfi_t> ii.value) |
| 98 | mpfi_set(self.__re, rr.value) |
| 99 | mpfi_set(self.__im, ii.value) |
100 | 100 | except TypeError: |
101 | 101 | raise TypeError, "unable to coerce to a ComplexIntervalFieldElement" |
102 | 102 | |
… |
… |
cdef class ComplexIntervalFieldElement(s |
246 | 246 | True |
247 | 247 | """ |
248 | 248 | cdef ComplexIntervalFieldElement a00 = self._new() |
249 | | mpfr_set(<mpfr_t> &a00.__re.left, <mpfr_t> &self.__re.left, GMP_RNDN) |
250 | | mpfi_mid(<mpfr_t> &a00.__re.right, self.__re) |
251 | | mpfr_set(<mpfr_t> &a00.__im.left, <mpfr_t> &self.__im.left, GMP_RNDN) |
252 | | mpfi_mid(<mpfr_t> &a00.__im.right, self.__im) |
| 249 | mpfr_set(&a00.__re.left, &self.__re.left, GMP_RNDN) |
| 250 | mpfi_mid(&a00.__re.right, self.__re) |
| 251 | mpfr_set(&a00.__im.left, &self.__im.left, GMP_RNDN) |
| 252 | mpfi_mid(&a00.__im.right, self.__im) |
253 | 253 | |
254 | 254 | cdef ComplexIntervalFieldElement a01 = self._new() |
255 | | mpfr_set(<mpfr_t> &a01.__re.left, <mpfr_t> &a00.__re.right, GMP_RNDN) |
256 | | mpfr_set(<mpfr_t> &a01.__re.right, <mpfr_t> &self.__re.right, GMP_RNDN) |
| 255 | mpfr_set(&a01.__re.left, &a00.__re.right, GMP_RNDN) |
| 256 | mpfr_set(&a01.__re.right, &self.__re.right, GMP_RNDN) |
257 | 257 | mpfi_set(a01.__im, a00.__im) |
258 | 258 | |
259 | 259 | cdef ComplexIntervalFieldElement a10 = self._new() |
260 | 260 | mpfi_set(a10.__re, a00.__re) |
261 | | mpfi_mid(<mpfr_t> &a10.__im.left, self.__im) |
262 | | mpfr_set(<mpfr_t> &a10.__im.right, <mpfr_t> &self.__im.right, GMP_RNDN) |
| 261 | mpfi_mid(&a10.__im.left, self.__im) |
| 262 | mpfr_set(&a10.__im.right, &self.__im.right, GMP_RNDN) |
263 | 263 | |
264 | 264 | cdef ComplexIntervalFieldElement a11 = self._new() |
265 | 265 | mpfi_set(a11.__re, a01.__re) |
… |
… |
cdef class ComplexIntervalFieldElement(s |
469 | 469 | mpfi_sqr(t0, self.__re) |
470 | 470 | mpfi_sqr(t1, self.__im) |
471 | 471 | |
472 | | mpfi_add(<mpfi_t> x.value, t0, t1) |
| 472 | mpfi_add(x.value, t0, t1) |
473 | 473 | |
474 | 474 | mpfi_clear(t0) |
475 | 475 | mpfi_clear(t1) |
… |
… |
cdef class ComplexIntervalFieldElement(s |
486 | 486 | mpfi_sqr(t0, self.__re) |
487 | 487 | mpfi_sqr(t1, self.__im) |
488 | 488 | |
489 | | mpfi_add(<mpfi_t> x.value, t0, t1) |
490 | | mpfi_sqrt(<mpfi_t> x.value, <mpfi_t> x.value) |
| 489 | mpfi_add(x.value, t0, t1) |
| 490 | mpfi_sqrt(x.value, x.value) |
491 | 491 | |
492 | 492 | mpfi_clear(t0) |
493 | 493 | mpfi_clear(t1) |
-
diff --git a/sage/rings/complex_number.pyx b/sage/rings/complex_number.pyx
a
|
b
|
cdef class ComplexNumber(sage.structure. |
154 | 154 | R = parent._real_field() |
155 | 155 | rr = R(real) |
156 | 156 | ii = R(imag) |
157 | | mpfr_set(self.__re, <mpfr_t> rr.value, rnd) |
158 | | mpfr_set(self.__im, <mpfr_t> ii.value, rnd) |
| 157 | mpfr_set(self.__re, rr.value, rnd) |
| 158 | mpfr_set(self.__im, ii.value, rnd) |
159 | 159 | except TypeError: |
160 | 160 | raise TypeError, "unable to coerce to a ComplexNumber: %s" % type(real) |
161 | 161 | |
… |
… |
cdef class ComplexNumber(sage.structure. |
604 | 604 | mpfr_mul(t0, self.__re, self.__re, rnd) |
605 | 605 | mpfr_mul(t1, self.__im, self.__im, rnd) |
606 | 606 | |
607 | | mpfr_add(<mpfr_t> x.value, t0, t1, rnd) |
| 607 | mpfr_add(x.value, t0, t1, rnd) |
608 | 608 | |
609 | 609 | mpfr_clear(t0) |
610 | 610 | mpfr_clear(t1) |
… |
… |
cdef class ComplexNumber(sage.structure. |
621 | 621 | mpfr_mul(t0, self.__re, self.__re, rnd) |
622 | 622 | mpfr_mul(t1, self.__im, self.__im, rnd) |
623 | 623 | |
624 | | mpfr_add(<mpfr_t> x.value, t0, t1, rnd) |
625 | | mpfr_sqrt(<mpfr_t> x.value, <mpfr_t> x.value, rnd) |
| 624 | mpfr_add(x.value, t0, t1, rnd) |
| 625 | mpfr_sqrt(x.value, x.value, rnd) |
626 | 626 | |
627 | 627 | mpfr_clear(t0) |
628 | 628 | mpfr_clear(t1) |
… |
… |
cdef class ComplexNumber(sage.structure. |
772 | 772 | """ |
773 | 773 | cdef real_mpfr.RealNumber x |
774 | 774 | x = real_mpfr.RealNumber(self._parent._real_field(), None) |
775 | | mpfr_set(<mpfr_t> x.value, self.__re, rnd) |
| 775 | mpfr_set(x.value, self.__re, rnd) |
776 | 776 | return x |
777 | 777 | |
778 | 778 | real_part = real |
… |
… |
cdef class ComplexNumber(sage.structure. |
794 | 794 | """ |
795 | 795 | cdef real_mpfr.RealNumber x |
796 | 796 | x = real_mpfr.RealNumber(self._parent._real_field(), None) |
797 | | mpfr_set(<mpfr_t> x.value, self.__im, rnd) |
| 797 | mpfr_set(x.value, self.__im, rnd) |
798 | 798 | return x |
799 | 799 | |
800 | 800 | imag_part = imag |
… |
… |
cdef class ComplexNumber(sage.structure. |
963 | 963 | 1.4142135623730951 |
964 | 964 | """ |
965 | 965 | if mpfr_zero_p(self.__im): |
966 | | return mpfr_get_d(<mpfr_t> self.__re, rnd) |
| 966 | return mpfr_get_d(self.__re, rnd) |
967 | 967 | else: |
968 | 968 | raise TypeError, "Unable to convert %s to float; use abs() or real_part() as desired"%self |
969 | 969 | |
… |
… |
cdef class ComplexNumber(sage.structure. |
1710 | 1710 | """ |
1711 | 1711 | cdef real_mpfr.RealNumber x |
1712 | 1712 | x = real_mpfr.RealNumber(self._parent._real_field(), None) |
1713 | | mpfr_atan2(<mpfr_t> x.value, self.__im, self.__re, rnd) |
| 1713 | mpfr_atan2(x.value, self.__im, self.__re, rnd) |
1714 | 1714 | return x |
1715 | 1715 | |
1716 | 1716 | |
… |
… |
cdef class ComplexNumber(sage.structure. |
2016 | 2016 | rho = abs(self) |
2017 | 2017 | arg = self.argument() / n |
2018 | 2018 | mpfr_init2(r, self._prec) |
2019 | | mpfr_root(r, <mpfr_t> rho.value, n, rnd) |
| 2019 | mpfr_root(r, rho.value, n, rnd) |
2020 | 2020 | |
2021 | | mpfr_sin_cos(z.__im, z.__re, <mpfr_t> arg.value, rnd) |
| 2021 | mpfr_sin_cos(z.__im, z.__re, arg.value, rnd) |
2022 | 2022 | mpfr_mul(z.__re, z.__re, r, rnd) |
2023 | 2023 | mpfr_mul(z.__im, z.__im, r, rnd) |
2024 | 2024 | |
… |
… |
cdef class ComplexNumber(sage.structure. |
2033 | 2033 | for k in range(1, n): |
2034 | 2034 | z = self._new() |
2035 | 2035 | arg += theta |
2036 | | mpfr_sin_cos(z.__im, z.__re, <mpfr_t> arg.value, rnd) |
| 2036 | mpfr_sin_cos(z.__im, z.__re, arg.value, rnd) |
2037 | 2037 | mpfr_mul(z.__re, z.__re, r, rnd) |
2038 | 2038 | mpfr_mul(z.__im, z.__im, r, rnd) |
2039 | 2039 | zlist.append(z) |
-
diff --git a/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/sage/rings/polynomial/multi_polynomial_libsingular.pyx
a
|
b
|
cdef class MPolynomial_libsingular(sage. |
2773 | 2773 | _p = p_Head(self._poly, _ring) |
2774 | 2774 | _n = p_GetCoeff(_p, _ring) |
2775 | 2775 | |
2776 | | ret = (not self._poly.next) and n_IsOne(_n, _ring) |
| 2776 | ret = bool((not self._poly.next) and n_IsOne(_n, _ring)) |
2777 | 2777 | |
2778 | 2778 | p_Delete(&_p, _ring) |
2779 | 2779 | return ret |
-
diff --git a/sage/rings/polynomial/pbori.pyx b/sage/rings/polynomial/pbori.pyx
a
|
b
|
cdef class GroebnerStrategy: |
6202 | 6202 | elif name is 'extended_product_criterions': |
6203 | 6203 | return self._strat.extendedProductCriterions |
6204 | 6204 | elif name is 'matrix_prefix': |
6205 | | _tmp = <char *>self._strat.matrixPrefix.c_str() |
6206 | | return _tmp |
| 6205 | return self._strat.matrixPrefix.c_str() |
6207 | 6206 | |
6208 | 6207 | raise AttributeError, name |
6209 | 6208 | |
-
diff --git a/sage/rings/polynomial/real_roots.pxd b/sage/rings/polynomial/real_roots.pxd
a
|
b
|
|
1 | | from rational import Rational |
| 1 | from sage.rings.rational import Rational |
2 | 2 | from sage.rings.rational cimport Rational |
3 | 3 | |
4 | 4 | from sage.modules.vector_integer_dense cimport Vector_integer_dense |
5 | 5 | |
6 | 6 | from sage.modules.vector_real_double_dense cimport Vector_real_double_dense |
7 | 7 | |
8 | | from real_mpfi import RealIntervalFieldElement |
| 8 | from sage.rings.real_mpfi import RealIntervalFieldElement |
9 | 9 | from sage.rings.real_mpfi cimport RealIntervalFieldElement |
10 | 10 | |
11 | 11 | cdef class interval_bernstein_polynomial: |
-
diff --git a/sage/rings/real_mpfi.pyx b/sage/rings/real_mpfi.pyx
a
|
b
|
cdef class RealIntervalFieldElement(sage |
986 | 986 | mpfi_set(self.value, _x.value) |
987 | 987 | elif PY_TYPE_CHECK(x, RealNumber): |
988 | 988 | rn = x |
989 | | mpfi_set_fr(self.value, <mpfr_t> rn.value) |
| 989 | mpfi_set_fr(self.value, rn.value) |
990 | 990 | elif PY_TYPE_CHECK(x, Rational): |
991 | 991 | rat = x |
992 | 992 | mpfi_set_q(self.value, <mpq_t> rat.value) |
… |
… |
cdef class RealIntervalFieldElement(sage |
1004 | 1004 | if PY_TYPE_CHECK(a, RealNumber) and PY_TYPE_CHECK(b, RealNumber): |
1005 | 1005 | rn = a |
1006 | 1006 | rn1 = b |
1007 | | mpfi_interv_fr(self.value, <mpfr_t> rn.value, <mpfr_t> rn1.value) |
| 1007 | mpfi_interv_fr(self.value, rn.value, rn1.value) |
1008 | 1008 | elif PY_TYPE_CHECK(a, RealDoubleElement) and PY_TYPE_CHECK(b, RealDoubleElement): |
1009 | 1009 | dx = a |
1010 | 1010 | dx1 = b |
… |
… |
cdef class RealIntervalFieldElement(sage |
1025 | 1025 | else: # generic fallback |
1026 | 1026 | rn = self._parent(a).lower() |
1027 | 1027 | rn1 = self._parent(b).upper() |
1028 | | mpfi_interv_fr(self.value, <mpfr_t> rn.value, <mpfr_t> rn1.value) |
| 1028 | mpfi_interv_fr(self.value, rn.value, rn1.value) |
1029 | 1029 | |
1030 | 1030 | elif isinstance(x, sage.rings.qqbar.AlgebraicReal): |
1031 | 1031 | d = x.interval(self._parent) |
… |
… |
cdef class RealIntervalFieldElement(sage |
1050 | 1050 | rn1 = self._parent._upper_field()(x) |
1051 | 1051 | except TypeError: |
1052 | 1052 | raise TypeError, "Unable to convert number to real interval." |
1053 | | mpfi_interv_fr(self.value, <mpfr_t> rn.value, <mpfr_t> rn1.value) |
| 1053 | mpfi_interv_fr(self.value, rn.value, rn1.value) |
1054 | 1054 | |
1055 | 1055 | def __reduce__(self): |
1056 | 1056 | """ |
… |
… |
cdef class RealIntervalFieldElement(sage |
1944 | 1944 | x = (<RealIntervalField_class>self._parent).__lower_field._new() |
1945 | 1945 | else: |
1946 | 1946 | x = (<RealField_class>(self._parent._real_field(rnd)))._new() |
1947 | | mpfi_get_left(<mpfr_t> x.value, self.value) |
| 1947 | mpfi_get_left(x.value, self.value) |
1948 | 1948 | return x |
1949 | 1949 | |
1950 | 1950 | def upper(self, rnd =None): |
… |
… |
cdef class RealIntervalFieldElement(sage |
1994 | 1994 | x = (<RealIntervalField_class>self._parent).__upper_field._new() |
1995 | 1995 | else: |
1996 | 1996 | x = ((<RealField_class>self._parent._real_field(rnd)))._new() |
1997 | | mpfi_get_right(<mpfr_t> x.value, self.value) |
| 1997 | mpfi_get_right(x.value, self.value) |
1998 | 1998 | return x |
1999 | 1999 | |
2000 | 2000 | def endpoints(self, rnd=None): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2030 | 2030 | """ |
2031 | 2031 | cdef RealNumber x |
2032 | 2032 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2033 | | mpfi_diam_abs(<mpfr_t> x.value, self.value) |
| 2033 | mpfi_diam_abs(x.value, self.value) |
2034 | 2034 | return x |
2035 | 2035 | |
2036 | 2036 | def relative_diameter(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2045 | 2045 | """ |
2046 | 2046 | cdef RealNumber x |
2047 | 2047 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2048 | | mpfi_diam_rel(<mpfr_t> x.value, self.value) |
| 2048 | mpfi_diam_rel(x.value, self.value) |
2049 | 2049 | return x |
2050 | 2050 | |
2051 | 2051 | def diameter(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2076 | 2076 | """ |
2077 | 2077 | cdef RealNumber x |
2078 | 2078 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2079 | | mpfi_diam(<mpfr_t> x.value, self.value) |
| 2079 | mpfi_diam(x.value, self.value) |
2080 | 2080 | return x |
2081 | 2081 | |
2082 | 2082 | def fp_rank_diameter(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2135 | 2135 | """ |
2136 | 2136 | cdef RealNumber x |
2137 | 2137 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2138 | | mpfi_mag(<mpfr_t> x.value, self.value) |
| 2138 | mpfi_mag(x.value, self.value) |
2139 | 2139 | return x |
2140 | 2140 | |
2141 | 2141 | def mignitude(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2153 | 2153 | """ |
2154 | 2154 | cdef RealNumber x |
2155 | 2155 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2156 | | mpfi_mig(<mpfr_t> x.value, self.value) |
| 2156 | mpfi_mig(x.value, self.value) |
2157 | 2157 | return x |
2158 | 2158 | |
2159 | 2159 | def center(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2167 | 2167 | """ |
2168 | 2168 | cdef RealNumber x |
2169 | 2169 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2170 | | mpfi_mid(<mpfr_t> x.value, self.value) |
| 2170 | mpfi_mid(x.value, self.value) |
2171 | 2171 | return x |
2172 | 2172 | |
2173 | 2173 | def bisection(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2192 | 2192 | """ |
2193 | 2193 | cdef RealIntervalFieldElement left = self._new() |
2194 | 2194 | cdef RealIntervalFieldElement right = self._new() |
2195 | | mpfr_set(<mpfr_t> &left.value.left, <mpfr_t> &self.value.left, GMP_RNDN) |
2196 | | mpfi_mid(<mpfr_t> &left.value.right, self.value) |
2197 | | mpfi_interv_fr(right.value, <mpfr_t> &left.value.right, <mpfr_t> &self.value.right) |
| 2195 | mpfr_set(&left.value.left, &self.value.left, GMP_RNDN) |
| 2196 | mpfi_mid(&left.value.right, self.value) |
| 2197 | mpfi_interv_fr(right.value, &left.value.right, &self.value.right) |
2198 | 2198 | return left, right |
2199 | 2199 | |
2200 | 2200 | def alea(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
2209 | 2209 | """ |
2210 | 2210 | cdef RealNumber x |
2211 | 2211 | x = (<RealIntervalField_class>self._parent).__middle_field._new() |
2212 | | mpfi_alea(<mpfr_t> x.value, self.value) |
| 2212 | mpfi_alea(x.value, self.value) |
2213 | 2213 | return x |
2214 | 2214 | |
2215 | 2215 | # def integer_part(self): |
… |
… |
cdef class RealIntervalFieldElement(sage |
3086 | 3086 | return mpfi_is_inside(other_intv.value, self.value) |
3087 | 3087 | elif PY_TYPE_CHECK(other, RealNumber): |
3088 | 3088 | other_rn = other |
3089 | | return mpfi_is_inside_fr(<mpfr_t> other_rn.value, self.value) |
| 3089 | return mpfi_is_inside_fr(other_rn.value, self.value) |
3090 | 3090 | try: |
3091 | 3091 | other_intv = self._parent(other) |
3092 | 3092 | return mpfi_is_inside(other_intv.value, self.value) |
… |
… |
cdef class RealIntervalFieldElement(sage |
3191 | 3191 | elif PY_TYPE_CHECK(other, RealNumber): |
3192 | 3192 | other_rn = other |
3193 | 3193 | mpfi_set(x.value, self.value) |
3194 | | mpfi_put_fr(x.value, <mpfr_t> other_rn.value) |
| 3194 | mpfi_put_fr(x.value, other_rn.value) |
3195 | 3195 | else: |
3196 | 3196 | # Let type errors from _coerce_ propagate... |
3197 | 3197 | other_intv = self._parent(other) |
-
diff --git a/setup.py b/setup.py
a
|
b
|
if not os.environ.has_key('SAGE_VERSION' |
38 | 38 | else: |
39 | 39 | SAGE_VERSION = os.environ['SAGE_VERSION'] |
40 | 40 | |
| 41 | try: |
| 42 | compile_result_dir = os.environ['XML_RESULTS'] |
| 43 | keep_going = True |
| 44 | except KeyError: |
| 45 | compile_result_dir = None |
| 46 | keep_going = False |
| 47 | |
41 | 48 | SITE_PACKAGES = '%s/lib/python/site-packages/'%SAGE_LOCAL |
42 | 49 | if not os.path.exists(SITE_PACKAGES): |
43 | 50 | SITE_PACKAGES = '%s/lib/python2.5/site-packages/'%SAGE_LOCAL |
… |
… |
sage.ext.gen_interpreters.rebuild(SAGE_D |
110 | 117 | ext_modules = ext_modules + sage.ext.gen_interpreters.modules |
111 | 118 | |
112 | 119 | |
| 120 | ######################################################### |
| 121 | ### Testing related stuff |
| 122 | ######################################################### |
| 123 | |
| 124 | |
| 125 | class CompileRecorder(object): |
| 126 | |
| 127 | def __init__(self, f): |
| 128 | self._f = f |
| 129 | self._obj = None |
| 130 | |
| 131 | def __get__(self, obj, type=None): |
| 132 | # Act like a method... |
| 133 | self._obj = obj |
| 134 | return self |
| 135 | |
| 136 | def __call__(self, *args): |
| 137 | t = time.time() |
| 138 | try: |
| 139 | if self._obj: |
| 140 | res = self._f(self._obj, *args) |
| 141 | else: |
| 142 | res = self._f(*args) |
| 143 | except Exception, ex: |
| 144 | print ex |
| 145 | res = ex |
| 146 | t = time.time() - t |
| 147 | |
| 148 | errors = failures = 0 |
| 149 | if self._f is compile_command0: |
| 150 | name = "cythonize." + args[0][1].name |
| 151 | failures = int(bool(res)) |
| 152 | else: |
| 153 | name = "gcc." + args[0][1].name |
| 154 | errors = int(bool(res)) |
| 155 | if errors or failures: |
| 156 | type = "failure" if failures else "error" |
| 157 | failure_item = """<%(type)s/>""" % locals() |
| 158 | else: |
| 159 | failure_item = "" |
| 160 | output = open("%s/%s.xml" % (compile_result_dir, name), "w") |
| 161 | output.write(""" |
| 162 | <?xml version="1.0" ?> |
| 163 | <testsuite name="%(name)s" errors="%(errors)s" failures="%(failures)s" tests="1" time="%(t)s"> |
| 164 | <testcase classname="%(name)s" name="compile"> |
| 165 | %(failure_item)s |
| 166 | </testcase> |
| 167 | </testsuite> |
| 168 | """.strip() % locals()) |
| 169 | output.close() |
| 170 | return res |
| 171 | |
| 172 | if compile_result_dir: |
| 173 | record_compile = CompileRecorder |
| 174 | else: |
| 175 | record_compile = lambda x: x |
| 176 | |
| 177 | |
113 | 178 | ###################################################################### |
114 | 179 | # CODE for generating C/C++ code from Cython and doing dependency |
115 | 180 | # checking, etc. In theory distutils would run Cython, but I don't |
… |
… |
ext_modules = ext_modules + sage.ext.gen |
120 | 185 | |
121 | 186 | for m in ext_modules: |
122 | 187 | m.libraries = ['csage'] + m.libraries + ['stdc++', 'ntl'] |
123 | | m.extra_compile_args += extra_compile_args |
| 188 | m.extra_compile_args += extra_compile_args # + ["-DCYTHON_REFNANNY"] |
124 | 189 | if os.environ.has_key('SAGE_DEBIAN'): |
125 | 190 | m.library_dirs += ['/usr/lib','/usr/lib/eclib','/usr/lib/singular','/usr/lib/R/lib','%s/lib' % SAGE_LOCAL] |
126 | 191 | else: |
… |
… |
def execute_list_of_commands_in_serial(c |
141 | 206 | |
142 | 207 | OUTPUT: |
143 | 208 | the given list of commands are all executed in serial |
144 | | """ |
145 | | for f,v in command_list: |
146 | | r = f(v) |
147 | | if r != 0: |
148 | | print "Error running command, failed with status %s."%r |
149 | | sys.exit(1) |
| 209 | """ |
| 210 | process_command_results(f(v) for f,v in command_list) |
150 | 211 | |
151 | 212 | def run_command(cmd): |
152 | 213 | """ |
… |
… |
def execute_list_of_commands_in_parallel |
188 | 249 | from multiprocessing import Pool |
189 | 250 | import twisted.persisted.styles #doing this import will allow instancemethods to be pickable |
190 | 251 | p = Pool(nthreads) |
191 | | for r in p.imap(apply_pair, command_list): |
| 252 | process_command_results(p.imap(apply_pair, command_list)) |
| 253 | |
| 254 | def process_command_results(result_values): |
| 255 | error = None |
| 256 | for r in result_values: |
192 | 257 | if r: |
193 | | print "Parallel build failed with status %s."%r |
194 | | sys.exit(1) |
| 258 | print "Error running command, failed with status %s."%r |
| 259 | if not keep_going: |
| 260 | sys.exit(1) |
| 261 | error = r |
| 262 | if error: |
| 263 | sys.exit(1) |
195 | 264 | |
196 | 265 | def number_of_threads(): |
197 | 266 | """ |
… |
… |
class sage_build_ext(build_ext): |
283 | 352 | # First, sanity-check the 'extensions' list |
284 | 353 | self.check_extensions_list(self.extensions) |
285 | 354 | |
286 | | # We require MAKE to be set to decide how many cpus are |
287 | | # requested. |
288 | | if not os.environ.has_key('MAKE'): |
289 | | ncpus = 1 |
290 | | else: |
291 | | MAKE = os.environ['MAKE'] |
292 | | z = [w[2:] for w in MAKE.split() if w.startswith('-j')] |
293 | | if len(z) == 0: # no command line option |
294 | | ncpus = 1 |
295 | | else: |
296 | | # Determine number of cpus from command line argument. |
297 | | # Also, use the OS to cap the number of cpus, in case |
298 | | # user annoyingly makes a typo and asks to use 10000 |
299 | | # cpus at once. |
300 | | try: |
301 | | ncpus = int(z[0]) |
302 | | n = 2*number_of_threads() |
303 | | if n: # prevent dumb typos. |
304 | | ncpus = min(ncpus, n) |
305 | | except ValueError: |
306 | | ncpus = 1 |
307 | | |
308 | 355 | import time |
309 | 356 | t = time.time() |
310 | | |
311 | | if ncpus > 1: |
312 | | |
313 | | # First, decide *which* extensions need rebuilt at |
314 | | # all. |
315 | | extensions_to_compile = [] |
316 | | for ext in self.extensions: |
317 | | need_to_compile, p = self.prepare_extension(ext) |
318 | | if need_to_compile: |
319 | | extensions_to_compile.append(p) |
320 | | |
321 | | # If there were any extensions that needed to be |
322 | | # rebuilt, dispatch them using pyprocessing. |
323 | | if extensions_to_compile: |
324 | | from multiprocessing import Pool |
325 | | import twisted.persisted.styles #doing this import will allow instancemethods to be pickable |
326 | | p = Pool(min(ncpus, len(extensions_to_compile))) |
327 | | for r in p.imap(self.build_extension, extensions_to_compile): |
328 | | pass |
329 | | |
330 | | else: |
331 | | for ext in self.extensions: |
332 | | need_to_compile, p = self.prepare_extension(ext) |
333 | | if need_to_compile: |
334 | | self.build_extension(p) |
| 357 | |
| 358 | compile_commands = [] |
| 359 | for ext in self.extensions: |
| 360 | need_to_compile, p = self.prepare_extension(ext) |
| 361 | if need_to_compile: |
| 362 | compile_commands.append((record_compile(self.build_extension), p)) |
| 363 | |
| 364 | execute_list_of_commands(compile_commands) |
335 | 365 | |
336 | 366 | print "Total time spent compiling C/C++ extensions: ", time.time() - t, "seconds." |
337 | 367 | |
… |
… |
class sage_build_ext(build_ext): |
464 | 494 | ###### Dependency checking |
465 | 495 | ############################################# |
466 | 496 | |
467 | | CYTHON_INCLUDE_DIRS=[ SAGE_LOCAL + '/lib/python/site-packages/Cython/Includes/' ] |
| 497 | CYTHON_INCLUDE_DIRS=[ |
| 498 | SAGE_LOCAL + '/lib/python/site-packages/Cython/Includes/', |
| 499 | SAGE_LOCAL + '/lib/python/site-packages/Cython/Includes/Deprecated/', |
| 500 | ] |
468 | 501 | |
469 | 502 | # matches any dependency |
470 | 503 | import re |
… |
… |
class DependencyTree: |
574 | 607 | deps.add(new_path) |
575 | 608 | found_include = True |
576 | 609 | break |
| 610 | new_path = os.path.normpath(idir + base_dependency_name[:-4] + "/__init__.pxd") |
| 611 | if os.path.exists(new_path): |
| 612 | deps.add(new_path) |
| 613 | found_include = True |
| 614 | break |
577 | 615 | # so we really couldn't find the dependency -- raise |
578 | 616 | # an exception. |
579 | 617 | if not found_include: |
… |
… |
def process_filename(f, m): |
646 | 684 | else: |
647 | 685 | return f |
648 | 686 | |
649 | | def compile_command(p): |
| 687 | def compile_command0(p): |
650 | 688 | """ |
651 | 689 | Given a pair p = (f, m), with a .pyx file f which is a part the |
652 | 690 | module m, call Cython on f |
… |
… |
def compile_command(p): |
669 | 707 | outfile += ".c" |
670 | 708 | |
671 | 709 | # call cython, abort if it failed |
672 | | cmd = "python `which cython` --embed-positions --directive cdivision=True -I%s -o %s %s"%(os.getcwd(), outfile, f) |
| 710 | cmd = "python `which cython` --embed-positions --directive cdivision=True,autotestdict=False -I%s -o %s %s"%(os.getcwd(), outfile, f) |
673 | 711 | r = run_command(cmd) |
674 | 712 | if r: |
675 | 713 | return r |
… |
… |
def compile_command(p): |
697 | 735 | |
698 | 736 | return r |
699 | 737 | |
| 738 | # Can't pickle decorated functions. |
| 739 | compile_command = record_compile(compile_command0) |
| 740 | |
| 741 | |
700 | 742 | def compile_command_list(ext_modules, deps): |
701 | 743 | """ |
702 | 744 | Computes a list of commands needed to compile and link the |