From 6138f5d5eb286f7f4e252da27ef681b6f6d0a9cd Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 5 Nov 2018 11:02:56 +0100 Subject: [PATCH 01/13] sage: 8.4 -> 8.5.beta0 --- .../math/sage/patches/numpy-1.15.1.patch | 911 ------------------ .../science/math/sage/sage-src.nix | 7 +- 2 files changed, 2 insertions(+), 916 deletions(-) delete mode 100644 pkgs/applications/science/math/sage/patches/numpy-1.15.1.patch diff --git a/pkgs/applications/science/math/sage/patches/numpy-1.15.1.patch b/pkgs/applications/science/math/sage/patches/numpy-1.15.1.patch deleted file mode 100644 index 9e855ba4ad94..000000000000 --- a/pkgs/applications/science/math/sage/patches/numpy-1.15.1.patch +++ /dev/null @@ -1,911 +0,0 @@ -diff --git a/src/doc/en/faq/faq-usage.rst b/src/doc/en/faq/faq-usage.rst -index 2347a1190d..f5b0fe71a4 100644 ---- a/src/doc/en/faq/faq-usage.rst -+++ b/src/doc/en/faq/faq-usage.rst -@@ -338,7 +338,7 @@ ints. For example:: - sage: RealNumber = float; Integer = int - sage: from scipy import stats - sage: stats.ttest_ind(list([1,2,3,4,5]),list([2,3,4,5,.6])) -- Ttest_indResult(statistic=0.076752955645333687, pvalue=0.94070490247380478) -+ Ttest_indResult(statistic=0.0767529..., pvalue=0.940704...) - sage: stats.uniform(0,15).ppf([0.5,0.7]) - array([ 7.5, 10.5]) - -diff --git a/src/doc/en/thematic_tutorials/numerical_sage/cvxopt.rst b/src/doc/en/thematic_tutorials/numerical_sage/cvxopt.rst -index 314811c42b..e5f54ec4c2 100644 ---- a/src/doc/en/thematic_tutorials/numerical_sage/cvxopt.rst -+++ b/src/doc/en/thematic_tutorials/numerical_sage/cvxopt.rst -@@ -48,11 +48,13 @@ we could do the following. - sage: B = numpy.array([1.0]*5) - sage: B.shape=(5,1) - sage: print(B) -- [[ 1.] -- [ 1.] -- [ 1.] -- [ 1.] -- [ 1.]] -+ [[1.] -+ [1.] -+ [1.] -+ [1.] -+ [1.]] -+ -+ - sage: print(A) - [ 2.00e+00 3.00e+00 0 0 0 ] - [ 3.00e+00 0 4.00e+00 0 6.00e+00] -diff --git a/src/doc/en/thematic_tutorials/numerical_sage/numpy.rst b/src/doc/en/thematic_tutorials/numerical_sage/numpy.rst -index 5b89cd75ee..e50b2ea5d4 100644 ---- a/src/doc/en/thematic_tutorials/numerical_sage/numpy.rst -+++ b/src/doc/en/thematic_tutorials/numerical_sage/numpy.rst -@@ -84,7 +84,7 @@ well as take slices - sage: l[3] - 3.0 - sage: l[3:6] -- array([ 3., 4., 5.]) -+ array([3., 4., 5.]) - - You can do basic arithmetic operations - -@@ -147,11 +147,11 @@ also do matrix vector multiplication, and matrix addition - sage: n = numpy.matrix([[1,2],[3,4]],dtype=float) - sage: v = numpy.array([[1],[2]],dtype=float) - sage: n*v -- matrix([[ 5.], -- [ 11.]]) -+ matrix([[ 5.], -+ [11.]]) - sage: n+n -- matrix([[ 2., 4.], -- [ 6., 8.]]) -+ matrix([[2., 4.], -+ [6., 8.]]) - - If ``n`` was created with :meth:`numpy.array`, then to do matrix vector - multiplication, you would use ``numpy.dot(n,v)``. -@@ -170,11 +170,11 @@ to manipulate - 22., 23., 24.]) - sage: n.shape=(5,5) - sage: n -- array([[ 0., 1., 2., 3., 4.], -- [ 5., 6., 7., 8., 9.], -- [ 10., 11., 12., 13., 14.], -- [ 15., 16., 17., 18., 19.], -- [ 20., 21., 22., 23., 24.]]) -+ array([[ 0., 1., 2., 3., 4.], -+ [ 5., 6., 7., 8., 9.], -+ [10., 11., 12., 13., 14.], -+ [15., 16., 17., 18., 19.], -+ [20., 21., 22., 23., 24.]]) - - This changes the one-dimensional array into a `5\times 5` array. - -@@ -187,8 +187,8 @@ NumPy arrays can be sliced as well - sage: n=numpy.array(range(25),dtype=float) - sage: n.shape=(5,5) - sage: n[2:4,1:3] -- array([[ 11., 12.], -- [ 16., 17.]]) -+ array([[11., 12.], -+ [16., 17.]]) - - It is important to note that the sliced matrices are references to - the original -@@ -224,8 +224,8 @@ Some particularly useful commands are - - sage: x=numpy.arange(0,2,.1,dtype=float) - sage: x -- array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , -- 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]) -+ array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, -+ 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]) - - You can see that :meth:`numpy.arange` creates an array of floats increasing by 0.1 - from 0 to 2. There is a useful command :meth:`numpy.r_` that is best explained by example -@@ -240,10 +240,11 @@ from 0 to 2. There is a useful command :meth:`numpy.r_` that is best explained b - sage: Integer=int - sage: n=r_[0.0:5.0] - sage: n -- array([ 0., 1., 2., 3., 4.]) -+ array([0., 1., 2., 3., 4.]) - sage: n=r_[0.0:5.0, [0.0]*5] - sage: n -- array([ 0., 1., 2., 3., 4., 0., 0., 0., 0., 0.]) -+ array([0., 1., 2., 3., 4., 0., 0., 0., 0., 0.]) -+ - - :meth:`numpy.r_` provides a shorthand for constructing NumPy arrays efficiently. - Note in the above ``0.0:5.0`` was shorthand for ``0.0, 1.0, 2.0, 3.0, 4.0``. -@@ -255,7 +256,7 @@ intervals. We can do this as follows - :: - - sage: r_[0.0:5.0:11*j] -- array([ 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. ]) -+ array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. ]) - - The notation ``0.0:5.0:11*j`` expands to a list of 11 equally space - points between 0 and 5 including both endpoints. Note that ``j`` is the -@@ -287,23 +288,23 @@ an equally spaced grid with `\Delta x = \Delta y = .25` for - sage: y=numpy.r_[0.0:1.0:5*j] - sage: xx,yy= meshgrid(x,y) - sage: xx -- array([[ 0. , 0.25, 0.5 , 0.75, 1. ], -- [ 0. , 0.25, 0.5 , 0.75, 1. ], -- [ 0. , 0.25, 0.5 , 0.75, 1. ], -- [ 0. , 0.25, 0.5 , 0.75, 1. ], -- [ 0. , 0.25, 0.5 , 0.75, 1. ]]) -+ array([[0. , 0.25, 0.5 , 0.75, 1. ], -+ [0. , 0.25, 0.5 , 0.75, 1. ], -+ [0. , 0.25, 0.5 , 0.75, 1. ], -+ [0. , 0.25, 0.5 , 0.75, 1. ], -+ [0. , 0.25, 0.5 , 0.75, 1. ]]) - sage: yy -- array([[ 0. , 0. , 0. , 0. , 0. ], -- [ 0.25, 0.25, 0.25, 0.25, 0.25], -- [ 0.5 , 0.5 , 0.5 , 0.5 , 0.5 ], -- [ 0.75, 0.75, 0.75, 0.75, 0.75], -- [ 1. , 1. , 1. , 1. , 1. ]]) -+ array([[0. , 0. , 0. , 0. , 0. ], -+ [0.25, 0.25, 0.25, 0.25, 0.25], -+ [0.5 , 0.5 , 0.5 , 0.5 , 0.5 ], -+ [0.75, 0.75, 0.75, 0.75, 0.75], -+ [1. , 1. , 1. , 1. , 1. ]]) - sage: f(xx,yy) -- array([[ 0. , 0.0625, 0.25 , 0.5625, 1. ], -- [ 0.0625, 0.125 , 0.3125, 0.625 , 1.0625], -- [ 0.25 , 0.3125, 0.5 , 0.8125, 1.25 ], -- [ 0.5625, 0.625 , 0.8125, 1.125 , 1.5625], -- [ 1. , 1.0625, 1.25 , 1.5625, 2. ]]) -+ array([[0. , 0.0625, 0.25 , 0.5625, 1. ], -+ [0.0625, 0.125 , 0.3125, 0.625 , 1.0625], -+ [0.25 , 0.3125, 0.5 , 0.8125, 1.25 ], -+ [0.5625, 0.625 , 0.8125, 1.125 , 1.5625], -+ [1. , 1.0625, 1.25 , 1.5625, 2. ]]) - - You can see that :meth:`numpy.meshgrid` produces a pair of matrices, here denoted - `xx` and `yy`, such that `(xx[i,j],yy[i,j])` has coordinates -@@ -324,7 +325,7 @@ equation `Ax=b` do - sage: b=numpy.array(range(1,6)) - sage: x=linalg.solve(A,b) - sage: numpy.dot(A,x) -- array([ 1., 2., 3., 4., 5.]) -+ array([1., 2., 3., 4., 5.]) - - This creates a random 5x5 matrix ``A``, and solves `Ax=b` where - ``b=[0.0,1.0,2.0,3.0,4.0]``. There are many other routines in the :mod:`numpy.linalg` -diff --git a/src/sage/calculus/riemann.pyx b/src/sage/calculus/riemann.pyx -index 60f37f7557..4ac3dedf1d 100644 ---- a/src/sage/calculus/riemann.pyx -+++ b/src/sage/calculus/riemann.pyx -@@ -1191,30 +1191,30 @@ cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values, - sage: zval = numpy.array([[0, 1, 1000],[.2+.3j,1,-.3j],[0,0,0]],dtype = numpy.complex128) - sage: deriv = numpy.array([[.1]],dtype = numpy.float64) - sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False,0.001) -- array([[[ 1., 1., 1.], -- [ 1., 1., 1.], -- [ 1., 1., 1.]], -+ array([[[1., 1., 1.], -+ [1., 1., 1.], -+ [1., 1., 1.]], - -- [[ 1., 1., 1.], -- [ 0., 0., 0.], -- [ 1., 1., 1.]], -+ [[1., 1., 1.], -+ [0., 0., 0.], -+ [1., 1., 1.]], - -- [[ 1., 1., 1.], -- [ 1., 1., 1.], -- [ 1., 1., 1.]]]) -+ [[1., 1., 1.], -+ [1., 1., 1.], -+ [1., 1., 1.]]]) - - sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True,0.001) -- array([[[ 1. , 1. , 1. ], -- [ 1. , 0.05558355, 0.05558355], -- [ 0.17301243, 0. , 0. ]], -+ array([[[1. , 1. , 1. ], -+ [1. , 0.05558355, 0.05558355], -+ [0.17301243, 0. , 0. ]], - -- [[ 1. , 0.96804683, 0.48044583], -- [ 0. , 0. , 0. ], -- [ 0.77351965, 0.5470393 , 1. ]], -+ [[1. , 0.96804683, 0.48044583], -+ [0. , 0. , 0. ], -+ [0.77351965, 0.5470393 , 1. ]], - -- [[ 1. , 1. , 1. ], -- [ 1. , 1. , 1. ], -- [ 1. , 1. , 1. ]]]) -+ [[1. , 1. , 1. ], -+ [1. , 1. , 1. ], -+ [1. , 1. , 1. ]]]) - """ - cdef Py_ssize_t i, j, imax, jmax - cdef FLOAT_T x, y, mag, arg, width, target, precision, dmag, darg -@@ -1279,14 +1279,14 @@ cpdef complex_to_rgb(np.ndarray[COMPLEX_T, ndim = 2] z_values): - sage: from sage.calculus.riemann import complex_to_rgb - sage: import numpy - sage: complex_to_rgb(numpy.array([[0, 1, 1000]], dtype = numpy.complex128)) -- array([[[ 1. , 1. , 1. ], -- [ 1. , 0.05558355, 0.05558355], -- [ 0.17301243, 0. , 0. ]]]) -+ array([[[1. , 1. , 1. ], -+ [1. , 0.05558355, 0.05558355], -+ [0.17301243, 0. , 0. ]]]) - - sage: complex_to_rgb(numpy.array([[0, 1j, 1000j]], dtype = numpy.complex128)) -- array([[[ 1. , 1. , 1. ], -- [ 0.52779177, 1. , 0.05558355], -- [ 0.08650622, 0.17301243, 0. ]]]) -+ array([[[1. , 1. , 1. ], -+ [0.52779177, 1. , 0.05558355], -+ [0.08650622, 0.17301243, 0. ]]]) - - - TESTS:: -diff --git a/src/sage/combinat/fully_packed_loop.py b/src/sage/combinat/fully_packed_loop.py -index 0a9bd61267..d2193cc2d6 100644 ---- a/src/sage/combinat/fully_packed_loop.py -+++ b/src/sage/combinat/fully_packed_loop.py -@@ -72,11 +72,11 @@ def _make_color_list(n, colors=None, color_map=None, randomize=False): - sage: _make_color_list(5, ['blue', 'red']) - ['blue', 'red', 'blue', 'red', 'blue'] - sage: _make_color_list(5, color_map='summer') -- [(0.0, 0.5, 0.40000000000000002), -- (0.25098039215686274, 0.62549019607843137, 0.40000000000000002), -- (0.50196078431372548, 0.75098039215686274, 0.40000000000000002), -- (0.75294117647058822, 0.87647058823529411, 0.40000000000000002), -- (1.0, 1.0, 0.40000000000000002)] -+ [(0.0, 0.5, 0.4), -+ (0.25098039215686274, 0.6254901960784314, 0.4), -+ (0.5019607843137255, 0.7509803921568627, 0.4), -+ (0.7529411764705882, 0.8764705882352941, 0.4), -+ (1.0, 1.0, 0.4)] - sage: _make_color_list(8, ['blue', 'red'], randomize=True) - ['blue', 'blue', 'red', 'blue', 'red', 'red', 'red', 'blue'] - """ -diff --git a/src/sage/finance/time_series.pyx b/src/sage/finance/time_series.pyx -index 28779365df..3ab0282861 100644 ---- a/src/sage/finance/time_series.pyx -+++ b/src/sage/finance/time_series.pyx -@@ -111,8 +111,8 @@ cdef class TimeSeries: - - sage: import numpy - sage: v = numpy.array([[1,2], [3,4]], dtype=float); v -- array([[ 1., 2.], -- [ 3., 4.]]) -+ array([[1., 2.], -+ [3., 4.]]) - sage: finance.TimeSeries(v) - [1.0000, 2.0000, 3.0000, 4.0000] - sage: finance.TimeSeries(v[:,0]) -@@ -2100,14 +2100,14 @@ cdef class TimeSeries: - - sage: w[0] = 20 - sage: w -- array([ 20. , -3. , 4.5, -2. ]) -+ array([20. , -3. , 4.5, -2. ]) - sage: v - [20.0000, -3.0000, 4.5000, -2.0000] - - If you want a separate copy do not give the ``copy=False`` option. :: - - sage: z = v.numpy(); z -- array([ 20. , -3. , 4.5, -2. ]) -+ array([20. , -3. , 4.5, -2. ]) - sage: z[0] = -10 - sage: v - [20.0000, -3.0000, 4.5000, -2.0000] -diff --git a/src/sage/functions/hyperbolic.py b/src/sage/functions/hyperbolic.py -index aff552f450..7a6df931e7 100644 ---- a/src/sage/functions/hyperbolic.py -+++ b/src/sage/functions/hyperbolic.py -@@ -214,7 +214,7 @@ class Function_coth(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: coth(a) -- array([ 1.03731472, 1.00496982, 1.00067115]) -+ array([1.03731472, 1.00496982, 1.00067115]) - """ - return 1.0 / tanh(x) - -@@ -267,7 +267,7 @@ class Function_sech(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: sech(a) -- array([ 0.26580223, 0.09932793, 0.03661899]) -+ array([0.26580223, 0.09932793, 0.03661899]) - """ - return 1.0 / cosh(x) - -@@ -318,7 +318,7 @@ class Function_csch(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: csch(a) -- array([ 0.27572056, 0.09982157, 0.03664357]) -+ array([0.27572056, 0.09982157, 0.03664357]) - """ - return 1.0 / sinh(x) - -@@ -586,7 +586,7 @@ class Function_arccoth(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2,5) - sage: acoth(a) -- array([ 0.54930614, 0.34657359, 0.25541281]) -+ array([0.54930614, 0.34657359, 0.25541281]) - """ - return arctanh(1.0 / x) - -diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py -index ed6365bef4..99b8b04dad 100644 ---- a/src/sage/functions/orthogonal_polys.py -+++ b/src/sage/functions/orthogonal_polys.py -@@ -810,12 +810,12 @@ class Func_chebyshev_T(ChebyshevFunction): - sage: z2 = numpy.array([[1,2],[1,2]]) - sage: z3 = numpy.array([1,2,3.]) - sage: chebyshev_T(1,z) -- array([ 1., 2.]) -+ array([1., 2.]) - sage: chebyshev_T(1,z2) -- array([[ 1., 2.], -- [ 1., 2.]]) -+ array([[1., 2.], -+ [1., 2.]]) - sage: chebyshev_T(1,z3) -- array([ 1., 2., 3.]) -+ array([1., 2., 3.]) - sage: chebyshev_T(z,0.1) - array([ 0.1 , -0.98]) - """ -@@ -1095,12 +1095,12 @@ class Func_chebyshev_U(ChebyshevFunction): - sage: z2 = numpy.array([[1,2],[1,2]]) - sage: z3 = numpy.array([1,2,3.]) - sage: chebyshev_U(1,z) -- array([ 2., 4.]) -+ array([2., 4.]) - sage: chebyshev_U(1,z2) -- array([[ 2., 4.], -- [ 2., 4.]]) -+ array([[2., 4.], -+ [2., 4.]]) - sage: chebyshev_U(1,z3) -- array([ 2., 4., 6.]) -+ array([2., 4., 6.]) - sage: chebyshev_U(z,0.1) - array([ 0.2 , -0.96]) - """ -diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py -index 1883daa3e6..9885222817 100644 ---- a/src/sage/functions/other.py -+++ b/src/sage/functions/other.py -@@ -389,7 +389,7 @@ class Function_ceil(BuiltinFunction): - sage: import numpy - sage: a = numpy.linspace(0,2,6) - sage: ceil(a) -- array([ 0., 1., 1., 2., 2., 2.]) -+ array([0., 1., 1., 2., 2., 2.]) - - Test pickling:: - -@@ -553,7 +553,7 @@ class Function_floor(BuiltinFunction): - sage: import numpy - sage: a = numpy.linspace(0,2,6) - sage: floor(a) -- array([ 0., 0., 0., 1., 1., 2.]) -+ array([0., 0., 0., 1., 1., 2.]) - sage: floor(x)._sympy_() - floor(x) - -@@ -869,7 +869,7 @@ def sqrt(x, *args, **kwds): - sage: import numpy - sage: a = numpy.arange(2,5) - sage: sqrt(a) -- array([ 1.41421356, 1.73205081, 2. ]) -+ array([1.41421356, 1.73205081, 2. ]) - """ - if isinstance(x, float): - return math.sqrt(x) -diff --git a/src/sage/functions/spike_function.py b/src/sage/functions/spike_function.py -index 1e021de3fe..56635ca98f 100644 ---- a/src/sage/functions/spike_function.py -+++ b/src/sage/functions/spike_function.py -@@ -157,7 +157,7 @@ class SpikeFunction: - sage: S = spike_function([(-3,4),(-1,1),(2,3)]); S - A spike function with spikes at [-3.0, -1.0, 2.0] - sage: P = S.plot_fft_abs(8) -- sage: p = P[0]; p.ydata -+ sage: p = P[0]; p.ydata # abs tol 1e-8 - [5.0, 5.0, 3.367958691924177, 3.367958691924177, 4.123105625617661, 4.123105625617661, 4.759921664218055, 4.759921664218055] - """ - w = self.vector(samples = samples, xmin=xmin, xmax=xmax) -@@ -176,8 +176,8 @@ class SpikeFunction: - sage: S = spike_function([(-3,4),(-1,1),(2,3)]); S - A spike function with spikes at [-3.0, -1.0, 2.0] - sage: P = S.plot_fft_arg(8) -- sage: p = P[0]; p.ydata -- [0.0, 0.0, -0.211524990023434..., -0.211524990023434..., 0.244978663126864..., 0.244978663126864..., -0.149106180027477..., -0.149106180027477...] -+ sage: p = P[0]; p.ydata # abs tol 1e-8 -+ [0.0, 0.0, -0.211524990023434, -0.211524990023434, 0.244978663126864, 0.244978663126864, -0.149106180027477, -0.149106180027477] - """ - w = self.vector(samples = samples, xmin=xmin, xmax=xmax) - xmin, xmax = self._ranges(xmin, xmax) -diff --git a/src/sage/functions/trig.py b/src/sage/functions/trig.py -index 501e7ff6b6..5f760912f0 100644 ---- a/src/sage/functions/trig.py -+++ b/src/sage/functions/trig.py -@@ -724,7 +724,7 @@ class Function_arccot(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arccot(a) -- array([ 0.46364761, 0.32175055, 0.24497866]) -+ array([0.46364761, 0.32175055, 0.24497866]) - """ - return math.pi/2 - arctan(x) - -@@ -780,7 +780,7 @@ class Function_arccsc(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arccsc(a) -- array([ 0.52359878, 0.33983691, 0.25268026]) -+ array([0.52359878, 0.33983691, 0.25268026]) - """ - return arcsin(1.0/x) - -@@ -838,7 +838,7 @@ class Function_arcsec(GinacFunction): - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arcsec(a) -- array([ 1.04719755, 1.23095942, 1.31811607]) -+ array([1.04719755, 1.23095942, 1.31811607]) - """ - return arccos(1.0/x) - -@@ -913,13 +913,13 @@ class Function_arctan2(GinacFunction): - sage: a = numpy.linspace(1, 3, 3) - sage: b = numpy.linspace(3, 6, 3) - sage: atan2(a, b) -- array([ 0.32175055, 0.41822433, 0.46364761]) -+ array([0.32175055, 0.41822433, 0.46364761]) - - sage: atan2(1,a) -- array([ 0.78539816, 0.46364761, 0.32175055]) -+ array([0.78539816, 0.46364761, 0.32175055]) - - sage: atan2(a, 1) -- array([ 0.78539816, 1.10714872, 1.24904577]) -+ array([0.78539816, 1.10714872, 1.24904577]) - - TESTS:: - -diff --git a/src/sage/matrix/constructor.pyx b/src/sage/matrix/constructor.pyx -index 12136f1773..491bf22e62 100644 ---- a/src/sage/matrix/constructor.pyx -+++ b/src/sage/matrix/constructor.pyx -@@ -503,8 +503,8 @@ def matrix(*args, **kwds): - [7 8 9] - Full MatrixSpace of 3 by 3 dense matrices over Integer Ring - sage: n = matrix(QQ, 2, 2, [1, 1/2, 1/3, 1/4]).numpy(); n -- array([[ 1. , 0.5 ], -- [ 0.33333333, 0.25 ]]) -+ array([[1. , 0.5 ], -+ [0.33333333, 0.25 ]]) - sage: matrix(QQ, n) - [ 1 1/2] - [1/3 1/4] -diff --git a/src/sage/matrix/matrix_double_dense.pyx b/src/sage/matrix/matrix_double_dense.pyx -index 66e54a79a4..0498334f4b 100644 ---- a/src/sage/matrix/matrix_double_dense.pyx -+++ b/src/sage/matrix/matrix_double_dense.pyx -@@ -606,6 +606,9 @@ cdef class Matrix_double_dense(Matrix_dense): - [ 3.0 + 9.0*I 4.0 + 16.0*I 5.0 + 25.0*I] - [6.0 + 36.0*I 7.0 + 49.0*I 8.0 + 64.0*I] - sage: B.condition() -+ doctest:warning -+ ... -+ ComplexWarning: Casting complex values to real discards the imaginary part - 203.851798... - sage: B.condition(p='frob') - 203.851798... -@@ -654,9 +657,7 @@ cdef class Matrix_double_dense(Matrix_dense): - True - sage: B = A.change_ring(CDF) - sage: B.condition() -- Traceback (most recent call last): -- ... -- LinAlgError: Singular matrix -+ +Infinity - - Improper values of ``p`` are caught. :: - -@@ -2519,7 +2520,7 @@ cdef class Matrix_double_dense(Matrix_dense): - sage: P.is_unitary(algorithm='orthonormal') - Traceback (most recent call last): - ... -- ValueError: failed to create intent(cache|hide)|optional array-- must have defined dimensions but got (0,) -+ error: ((lwork==-1)||(lwork >= MAX(1,2*n))) failed for 3rd keyword lwork: zgees:lwork=0 - - TESTS:: - -@@ -3635,8 +3636,8 @@ cdef class Matrix_double_dense(Matrix_dense): - [0.0 1.0 2.0] - [3.0 4.0 5.0] - sage: m.numpy() -- array([[ 0., 1., 2.], -- [ 3., 4., 5.]]) -+ array([[0., 1., 2.], -+ [3., 4., 5.]]) - - Alternatively, numpy automatically calls this function (via - the magic :meth:`__array__` method) to convert Sage matrices -@@ -3647,16 +3648,16 @@ cdef class Matrix_double_dense(Matrix_dense): - [0.0 1.0 2.0] - [3.0 4.0 5.0] - sage: numpy.array(m) -- array([[ 0., 1., 2.], -- [ 3., 4., 5.]]) -+ array([[0., 1., 2.], -+ [3., 4., 5.]]) - sage: numpy.array(m).dtype - dtype('float64') - sage: m = matrix(CDF, 2, range(6)); m - [0.0 1.0 2.0] - [3.0 4.0 5.0] - sage: numpy.array(m) -- array([[ 0.+0.j, 1.+0.j, 2.+0.j], -- [ 3.+0.j, 4.+0.j, 5.+0.j]]) -+ array([[0.+0.j, 1.+0.j, 2.+0.j], -+ [3.+0.j, 4.+0.j, 5.+0.j]]) - sage: numpy.array(m).dtype - dtype('complex128') - -diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py -index ccbd208810..c3f9a65093 100644 ---- a/src/sage/matrix/special.py -+++ b/src/sage/matrix/special.py -@@ -706,7 +706,7 @@ def diagonal_matrix(arg0=None, arg1=None, arg2=None, sparse=True): - - sage: import numpy - sage: entries = numpy.array([1.2, 5.6]); entries -- array([ 1.2, 5.6]) -+ array([1.2, 5.6]) - sage: A = diagonal_matrix(3, entries); A - [1.2 0.0 0.0] - [0.0 5.6 0.0] -@@ -716,7 +716,7 @@ def diagonal_matrix(arg0=None, arg1=None, arg2=None, sparse=True): - - sage: j = numpy.complex(0,1) - sage: entries = numpy.array([2.0+j, 8.1, 3.4+2.6*j]); entries -- array([ 2.0+1.j , 8.1+0.j , 3.4+2.6j]) -+ array([2. +1.j , 8.1+0.j , 3.4+2.6j]) - sage: A = diagonal_matrix(entries); A - [2.0 + 1.0*I 0.0 0.0] - [ 0.0 8.1 0.0] -diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx -index 37d92c1282..955d083b34 100644 ---- a/src/sage/modules/free_module_element.pyx -+++ b/src/sage/modules/free_module_element.pyx -@@ -988,7 +988,7 @@ cdef class FreeModuleElement(Vector): # abstract base class - sage: v.numpy() - array([1, 2, 5/6], dtype=object) - sage: v.numpy(dtype=float) -- array([ 1. , 2. , 0.83333333]) -+ array([1. , 2. , 0.83333333]) - sage: v.numpy(dtype=int) - array([1, 2, 0]) - sage: import numpy -@@ -999,7 +999,7 @@ cdef class FreeModuleElement(Vector): # abstract base class - be more efficient but may have unintended consequences:: - - sage: v.numpy(dtype=None) -- array([ 1. , 2. , 0.83333333]) -+ array([1. , 2. , 0.83333333]) - - sage: w = vector(ZZ, [0, 1, 2^63 -1]); w - (0, 1, 9223372036854775807) -diff --git a/src/sage/modules/vector_double_dense.pyx b/src/sage/modules/vector_double_dense.pyx -index 39fc2970de..2badf98284 100644 ---- a/src/sage/modules/vector_double_dense.pyx -+++ b/src/sage/modules/vector_double_dense.pyx -@@ -807,13 +807,13 @@ cdef class Vector_double_dense(FreeModuleElement): - - sage: v = vector(CDF,4,range(4)) - sage: v.numpy() -- array([ 0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j]) -+ array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j]) - sage: v = vector(CDF,0) - sage: v.numpy() - array([], dtype=complex128) - sage: v = vector(RDF,4,range(4)) - sage: v.numpy() -- array([ 0., 1., 2., 3.]) -+ array([0., 1., 2., 3.]) - sage: v = vector(RDF,0) - sage: v.numpy() - array([], dtype=float64) -@@ -823,11 +823,11 @@ cdef class Vector_double_dense(FreeModuleElement): - sage: import numpy - sage: v = vector(CDF, 3, range(3)) - sage: v.numpy() -- array([ 0.+0.j, 1.+0.j, 2.+0.j]) -+ array([0.+0.j, 1.+0.j, 2.+0.j]) - sage: v.numpy(dtype=numpy.float64) -- array([ 0., 1., 2.]) -+ array([0., 1., 2.]) - sage: v.numpy(dtype=numpy.float32) -- array([ 0., 1., 2.], dtype=float32) -+ array([0., 1., 2.], dtype=float32) - """ - if dtype is None or dtype is self._vector_numpy.dtype: - from copy import copy -diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx -index ad9693da62..758fb709b7 100644 ---- a/src/sage/plot/complex_plot.pyx -+++ b/src/sage/plot/complex_plot.pyx -@@ -61,9 +61,9 @@ cdef inline double mag_to_lightness(double r): - - sage: from sage.plot.complex_plot import complex_to_rgb - sage: complex_to_rgb([[0, 1, 10]]) -- array([[[ 0. , 0. , 0. ], -- [ 0.77172568, 0. , 0. ], -- [ 1. , 0.22134776, 0.22134776]]]) -+ array([[[0. , 0. , 0. ], -+ [0.77172568, 0. , 0. ], -+ [1. , 0.22134776, 0.22134776]]]) - """ - return atan(log(sqrt(r)+1)) * (4/PI) - 1 - -@@ -82,13 +82,13 @@ def complex_to_rgb(z_values): - - sage: from sage.plot.complex_plot import complex_to_rgb - sage: complex_to_rgb([[0, 1, 1000]]) -- array([[[ 0. , 0. , 0. ], -- [ 0.77172568, 0. , 0. ], -- [ 1. , 0.64421177, 0.64421177]]]) -+ array([[[0. , 0. , 0. ], -+ [0.77172568, 0. , 0. ], -+ [1. , 0.64421177, 0.64421177]]]) - sage: complex_to_rgb([[0, 1j, 1000j]]) -- array([[[ 0. , 0. , 0. ], -- [ 0.38586284, 0.77172568, 0. ], -- [ 0.82210588, 1. , 0.64421177]]]) -+ array([[[0. , 0. , 0. ], -+ [0.38586284, 0.77172568, 0. ], -+ [0.82210588, 1. , 0.64421177]]]) - """ - import numpy - cdef unsigned int i, j, imax, jmax -diff --git a/src/sage/plot/histogram.py b/src/sage/plot/histogram.py -index 5d28473731..fc4b2046c0 100644 ---- a/src/sage/plot/histogram.py -+++ b/src/sage/plot/histogram.py -@@ -53,10 +53,17 @@ class Histogram(GraphicPrimitive): - """ - import numpy as np - self.datalist=np.asarray(datalist,dtype=float) -+ if 'normed' in options: -+ from sage.misc.superseded import deprecation -+ deprecation(25260, "the 'normed' option is deprecated. Use 'density' instead.") - if 'linestyle' in options: - from sage.plot.misc import get_matplotlib_linestyle - options['linestyle'] = get_matplotlib_linestyle( - options['linestyle'], return_type='long') -+ if options.get('range', None): -+ # numpy.histogram performs type checks on "range" so this must be -+ # actual floats -+ options['range'] = [float(x) for x in options['range']] - GraphicPrimitive.__init__(self, options) - - def get_minmax_data(self): -@@ -80,10 +87,14 @@ class Histogram(GraphicPrimitive): - {'xmax': 4.0, 'xmin': 0, 'ymax': 2, 'ymin': 0} - - TESTS:: -- - sage: h = histogram([10,3,5], normed=True)[0] -- sage: h.get_minmax_data() # rel tol 1e-15 -- {'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.4761904761904765, 'ymin': 0} -+ doctest:warning...: -+ DeprecationWarning: the 'normed' option is deprecated. Use 'density' instead. -+ See https://trac.sagemath.org/25260 for details. -+ sage: h.get_minmax_data() -+ doctest:warning ...: -+ VisibleDeprecationWarning: Passing `normed=True` on non-uniform bins has always been broken, and computes neither the probability density function nor the probability mass function. The result is only correct if the bins are uniform, when density=True will produce the same result anyway. The argument will be removed in a future version of numpy. -+ {'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.476190476190..., 'ymin': 0} - """ - import numpy - -@@ -152,7 +163,7 @@ class Histogram(GraphicPrimitive): - 'rwidth': 'The relative width of the bars as a fraction of the bin width', - 'cumulative': '(True or False) If True, then a histogram is computed in which each bin gives the counts in that bin plus all bins for smaller values. Negative values give a reversed direction of accumulation.', - 'range': 'A list [min, max] which define the range of the histogram. Values outside of this range are treated as outliers and omitted from counts.', -- 'normed': 'Deprecated alias for density', -+ 'normed': 'Deprecated. Use density instead.', - 'density': '(True or False) If True, the counts are normalized to form a probability density. (n/(len(x)*dbin)', - 'weights': 'A sequence of weights the same length as the data list. If supplied, then each value contributes its associated weight to the bin count.', - 'stacked': '(True or False) If True, multiple data are stacked on top of each other.', -@@ -199,7 +210,7 @@ class Histogram(GraphicPrimitive): - subplot.hist(self.datalist.transpose(), **options) - - --@options(aspect_ratio='automatic',align='mid', weights=None, range=None, bins=10, edgecolor='black') -+@options(aspect_ratio='automatic', align='mid', weights=None, range=None, bins=10, edgecolor='black') - def histogram(datalist, **options): - """ - Computes and draws the histogram for list(s) of numerical data. -@@ -231,8 +242,9 @@ def histogram(datalist, **options): - - ``linewidth`` -- (float) width of the lines defining the bars - - ``linestyle`` -- (default: 'solid') Style of the line. One of 'solid' - or '-', 'dashed' or '--', 'dotted' or ':', 'dashdot' or '-.' -- - ``density`` -- (boolean - default: False) If True, the counts are -- normalized to form a probability density. -+ - ``density`` -- (boolean - default: False) If True, the result is the -+ value of the probability density function at the bin, normalized such -+ that the integral over the range is 1. - - ``range`` -- A list [min, max] which define the range of the - histogram. Values outside of this range are treated as outliers and - omitted from counts -diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py -index 23f5e61446..3b1b51d7cf 100644 ---- a/src/sage/plot/line.py -+++ b/src/sage/plot/line.py -@@ -502,14 +502,12 @@ def line2d(points, **options): - from sage.plot.all import Graphics - from sage.plot.plot import xydata_from_point_list - from sage.rings.all import CC, CDF -+ points = list(points) # make sure points is a python list - if points in CC or points in CDF: - pass - else: -- try: -- if not points: -- return Graphics() -- except ValueError: # numpy raises a ValueError if not empty -- pass -+ if len(points) == 0: -+ return Graphics() - xdata, ydata = xydata_from_point_list(points) - g = Graphics() - g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) -diff --git a/src/sage/plot/plot_field.py b/src/sage/plot/plot_field.py -index 0025098a8d..23c80902f3 100644 ---- a/src/sage/plot/plot_field.py -+++ b/src/sage/plot/plot_field.py -@@ -49,9 +49,10 @@ class PlotField(GraphicPrimitive): - sage: r.xpos_array - [0.0, 0.0, 1.0, 1.0] - sage: r.yvec_array -- masked_array(data = [0.0 0.70710678118... 0.70710678118... 0.89442719...], -- mask = [False False False False], -- fill_value = 1e+20) -+ masked_array(data=[0.0, 0.70710678118..., 0.70710678118..., -+ 0.89442719...], -+ mask=[False, False, False, False], -+ fill_value=1e+20) - - TESTS: - -diff --git a/src/sage/plot/streamline_plot.py b/src/sage/plot/streamline_plot.py -index f3da57c370..3806f4b32f 100644 ---- a/src/sage/plot/streamline_plot.py -+++ b/src/sage/plot/streamline_plot.py -@@ -38,16 +38,14 @@ class StreamlinePlot(GraphicPrimitive): - sage: r.options()['plot_points'] - 2 - sage: r.xpos_array -- array([ 0., 1.]) -+ array([0., 1.]) - sage: r.yvec_array -- masked_array(data = -- [[1.0 1.0] -- [0.5403023058681398 0.5403023058681398]], -- mask = -- [[False False] -- [False False]], -- fill_value = 1e+20) -- -+ masked_array( -+ data=[[1.0, 1.0], -+ [0.5403023058681398, 0.5403023058681398]], -+ mask=[[False, False], -+ [False, False]], -+ fill_value=1e+20) - - TESTS: - -diff --git a/src/sage/probability/probability_distribution.pyx b/src/sage/probability/probability_distribution.pyx -index 1b119e323f..3290b00695 100644 ---- a/src/sage/probability/probability_distribution.pyx -+++ b/src/sage/probability/probability_distribution.pyx -@@ -130,7 +130,17 @@ cdef class ProbabilityDistribution: - 0.0, - 1.4650000000000003] - sage: b -- [0.0, 0.20000000000000001, 0.40000000000000002, 0.60000000000000009, 0.80000000000000004, 1.0, 1.2000000000000002, 1.4000000000000001, 1.6000000000000001, 1.8, 2.0] -+ [0.0, -+ 0.2, -+ 0.4, -+ 0.6000000000000001, -+ 0.8, -+ 1.0, -+ 1.2000000000000002, -+ 1.4000000000000001, -+ 1.6, -+ 1.8, -+ 2.0] - """ - import pylab - l = [float(self.get_random_element()) for _ in range(num_samples)] -diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx -index 12ca1b222b..9bad7dae0c 100644 ---- a/src/sage/rings/rational.pyx -+++ b/src/sage/rings/rational.pyx -@@ -1041,7 +1041,7 @@ cdef class Rational(sage.structure.element.FieldElement): - dtype('O') - - sage: numpy.array([1, 1/2, 3/4]) -- array([ 1. , 0.5 , 0.75]) -+ array([1. , 0.5 , 0.75]) - """ - if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: - if mpz_fits_slong_p(mpq_numref(self.value)): -diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx -index 9b90c8833e..1ce05b937d 100644 ---- a/src/sage/rings/real_mpfr.pyx -+++ b/src/sage/rings/real_mpfr.pyx -@@ -1439,7 +1439,7 @@ cdef class RealNumber(sage.structure.element.RingElement): - - sage: import numpy - sage: numpy.arange(10.0) -- array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) -+ array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype - dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype -diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py -index de31fe9883..7a33ea6f5b 100644 ---- a/src/sage/schemes/elliptic_curves/height.py -+++ b/src/sage/schemes/elliptic_curves/height.py -@@ -1627,18 +1627,18 @@ class EllipticCurveCanonicalHeight: - even:: - - sage: H.wp_on_grid(v,4) -- array([[ 25.43920182, 5.28760943, 5.28760943, 25.43920182], -- [ 6.05099485, 1.83757786, 1.83757786, 6.05099485], -- [ 6.05099485, 1.83757786, 1.83757786, 6.05099485], -- [ 25.43920182, 5.28760943, 5.28760943, 25.43920182]]) -+ array([[25.43920182, 5.28760943, 5.28760943, 25.43920182], -+ [ 6.05099485, 1.83757786, 1.83757786, 6.05099485], -+ [ 6.05099485, 1.83757786, 1.83757786, 6.05099485], -+ [25.43920182, 5.28760943, 5.28760943, 25.43920182]]) - - The array of values on the half-grid:: - - sage: H.wp_on_grid(v,4,True) -- array([[ 25.43920182, 5.28760943], -- [ 6.05099485, 1.83757786], -- [ 6.05099485, 1.83757786], -- [ 25.43920182, 5.28760943]]) -+ array([[25.43920182, 5.28760943], -+ [ 6.05099485, 1.83757786], -+ [ 6.05099485, 1.83757786], -+ [25.43920182, 5.28760943]]) - """ - tau = self.tau(v) - fk, err = self.fk_intervals(v, 15, CDF) -diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx -index 9da38002e8..d61e74bf82 100644 ---- a/src/sage/symbolic/ring.pyx -+++ b/src/sage/symbolic/ring.pyx -@@ -1136,7 +1136,7 @@ cdef class NumpyToSRMorphism(Morphism): - sage: cos(numpy.int('2')) - cos(2) - sage: numpy.cos(numpy.int('2')) -- -0.41614683654714241 -+ -0.4161468365471424 - """ - cdef _intermediate_ring - diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 5d729d9c5fdd..c166a17fafc7 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.4"; + version = "8.5.beta0"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0gips1hagiz9m7s21bg5as8hrrm2x5k47h1bsq0pc46iplfwmv2d"; + sha256 = "0kc8fqwz97dwyf4hxz5yr9sjwh5q0jr7a9g1yrdaz66m5805r859"; }; # Patches needed because of particularities of nix or the way this is packaged. @@ -76,9 +76,6 @@ stdenv.mkDerivation rec { stripLen = 1; }) - # https://trac.sagemath.org/ticket/25260 - ./patches/numpy-1.15.1.patch - # needed for ntl update # https://trac.sagemath.org/ticket/25532 (fetchpatch { From 8e7da1b8a44e39f45f46585e9497b1abb7a41fc4 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 5 Nov 2018 11:05:33 +0100 Subject: [PATCH 02/13] sage: 8.5.beta0 -> 8.5.beta1 --- .../science/math/sage/patches/r-rpy.patch | 763 ++++++++++++++++++ .../science/math/sage/sage-src.nix | 4 +- 2 files changed, 765 insertions(+), 2 deletions(-) create mode 100644 pkgs/applications/science/math/sage/patches/r-rpy.patch diff --git a/pkgs/applications/science/math/sage/patches/r-rpy.patch b/pkgs/applications/science/math/sage/patches/r-rpy.patch new file mode 100644 index 000000000000..ab407c8fd744 --- /dev/null +++ b/pkgs/applications/science/math/sage/patches/r-rpy.patch @@ -0,0 +1,763 @@ +diff --git a/src/sage/doctest/test.py b/src/sage/doctest/test.py +index 2f4f74cfc2..c6c1bf9194 100644 +--- a/src/sage/doctest/test.py ++++ b/src/sage/doctest/test.py +@@ -500,12 +500,13 @@ Test ``atexit`` support in the doctesting framework:: + ....: pass + + Test the ``--memlimit`` option and ``# optional - memlimit`` +-(but only on Linux):: ++(but only on Linux). If this test fails, the memory needed to ++run it may have increased. Try increasing the limit. :: + + sage: from platform import system + sage: ok = True + sage: if system() == "Linux": +- ....: P = subprocess.Popen(["sage", "-t", "--warn-long", "0", "--memlimit=2000", "memlimit.rst"], stdout=subprocess.PIPE, **kwds) ++ ....: P = subprocess.Popen(["sage", "-t", "--warn-long", "0", "--memlimit=2100", "memlimit.rst"], stdout=subprocess.PIPE, **kwds) + ....: out, err = P.communicate() + ....: ok = ("MemoryError: failed to allocate" in out) + sage: ok or out +diff --git a/src/sage/interfaces/expect.py b/src/sage/interfaces/expect.py +index 51a37496c2..ba982f25f7 100644 +--- a/src/sage/interfaces/expect.py ++++ b/src/sage/interfaces/expect.py +@@ -1122,10 +1122,15 @@ If this all works, you can then make calls like: + + EXAMPLES: + +- We test all of this using the R interface. First we put ++ We test all of this using the Singular interface. First we put + 10 + 15 in the input stream:: + +- sage: r._sendstr('abc <- 10 +15;\n') ++ sage: singular._sendstr('def abc = 10 + 15;\n') ++ ++ Then we tell singular to print 10, which is an arbitrary number ++ different from the expected result 35. ++ ++ sage: singular._sendstr('10;\n') + + Here an exception is raised because 25 hasn't appeared yet in the + output stream. The key thing is that this doesn't lock, but instead +@@ -1135,7 +1140,7 @@ If this all works, you can then make calls like: + + sage: t = walltime() + sage: try: +- ....: r._expect_expr('25', timeout=0.5) ++ ....: singular._expect_expr('25', timeout=0.5) + ....: except Exception: + ....: print('Did not get expression') + Did not get expression +@@ -1145,24 +1150,24 @@ If this all works, you can then make calls like: + sage: w = walltime(t); w > 0.4 and w < 10 + True + +- We tell R to print abc, which equals 25. ++ We tell Singular to print abc, which equals 25. + + :: + +- sage: r._sendstr('abc;\n') ++ sage: singular._sendstr('abc;\n') + + Now 25 is in the output stream, so we can wait for it. + + :: + +- sage: r._expect_expr('25') ++ sage: singular._expect_expr('25') + +- This gives us everything before the 25. ++ This gives us everything before the 25, including the 10 we printed earlier. + + :: + +- sage: r._expect.before.decode('ascii') +- u'...abc;\r\n[1] ' ++ sage: singular._expect.before.decode('ascii') ++ u'...10\r\n> ' + + We test interrupting ``_expect_expr`` using the GP interface, + see :trac:`6661`. Unfortunately, this test doesn't work reliably using +@@ -1203,14 +1208,7 @@ If this all works, you can then make calls like: + + - ``string`` -- a string + +- EXAMPLES: We illustrate this function using the R interface:: +- +- sage: r._synchronize() +- sage: r._sendstr('a <- 10;\n') +- sage: r.eval('a') +- '[1] 10' +- +- We illustrate using the singular interface:: ++ EXAMPLES: We illustrate this function using the Singular interface:: + + sage: singular._synchronize() + sage: singular._sendstr('int i = 5;') +@@ -1260,7 +1258,7 @@ If this all works, you can then make calls like: + + EXAMPLES: We observe nothing, just as it should be:: + +- sage: r._synchronize() ++ sage: singular._synchronize() + + TESTS: + +diff --git a/src/sage/interfaces/gp.py b/src/sage/interfaces/gp.py +index 86f401571a..f3c6120ddc 100644 +--- a/src/sage/interfaces/gp.py ++++ b/src/sage/interfaces/gp.py +@@ -254,6 +254,7 @@ class Gp(ExtraTabCompletion, Expect): + self._eval_line('default(help, "gphelp -detex");') + # logfile disabled since Expect already logs + self._eval_line('default(log,0);') ++ self._eval_line("default(nbthreads,1);") + # set random seed + self.set_seed(self._seed) + +diff --git a/src/sage/interfaces/r.py b/src/sage/interfaces/r.py +index 5c75459903..06974a2324 100644 +--- a/src/sage/interfaces/r.py ++++ b/src/sage/interfaces/r.py +@@ -268,17 +268,17 @@ from __future__ import print_function, absolute_import + from six.moves import range + import six + +-from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement ++from .interface import Interface, InterfaceElement, InterfaceFunction, InterfaceFunctionElement + from sage.env import DOT_SAGE + import re +-import sage.rings.integer + from sage.structure.element import parent + from sage.interfaces.tab_completion import ExtraTabCompletion + from sage.docs.instancedoc import instancedoc ++from rpy2 import robjects ++from rpy2.robjects import packages ++from rpy2.robjects.conversion import localconverter + + COMMANDS_CACHE = '%s/r_commandlist.sobj'%DOT_SAGE +-PROMPT = '__SAGE__R__PROMPT__> ' +-prompt_re = re.compile("^>", re.M) + + #there is a mirror network, but lets take #1 for now + RRepositoryURL = "http://cran.r-project.org/" +@@ -288,12 +288,156 @@ RFilteredPackages = ['.GlobalEnv'] + # but package:base should cover this. i think. + RBaseCommands = ['c', "NULL", "NA", "True", "False", "Inf", "NaN"] + +-class R(ExtraTabCompletion, Expect): ++def _setup_r_to_sage_converter(): ++ """ ++ Set up a the converter used to convert from rpy2's ++ representation of R objects to the one sage expects. ++ ++ EXAMPLES:: ++ ++ Test ++ ++ Simple numeric values are represented as vectors in R. So `1` would actually ++ be an array of length 1. We convert all vectors of length 1 to simple values, ++ whether or not they "originally" were simple values or not: ++ ++ sage: r([42]).sage() ++ 42 ++ ++ sage: r(42).sage() ++ 42 ++ ++ sage: r('c("foo")').sage() ++ 'foo' ++ ++ Arrays of length greater than one are treated normally: ++ ++ sage: r([42, 43]).sage() ++ [42, 43] ++ ++ We also convert all numeric values to integers if that is possible without ++ loss of precision: ++ ++ sage: type(r([1.0]).sage()) == int ++ True ++ ++ sage: r([1.0, 42.5]).sage() ++ [1, 42.5] ++ ++ Matrices are converted to sage matrices: ++ ++ sage: r('matrix(c(2,4,3,1,5,7), nrow=2, ncol=3)').sage() ++ [2 3 5] ++ [4 1 7] ++ ++ More complex r structures are represented by dictionaries: ++ ++ sage: r.summary(1).sage() ++ {'DATA': [1, 1, 1, 1, 1, 1], ++ '_Names': ['Min.', '1st Qu.', 'Median', 'Mean', '3rd Qu.', 'Max.'], ++ '_r_class': ['summaryDefault', 'table']} ++ ++ sage: r.options(width="60").sage() ++ {'DATA': {'width': 60}, '_Names': 'width'} ++ ++ The conversion can handle "not a number", infintiy, imaginary values and ++ missing values: ++ ++ sage: r(-17).sqrt().sage() ++ nan ++ sage: r('-17+0i').sqrt().sage() ++ 4.123105625617661j ++ sage: r('NA').sage() ++ NA ++ sage: inf = r('Inf'); inf.sage() ++ inf ++ ++ ++ Character Vectors are represented by regular python arrays: ++ ++ sage: labs = r.paste('c("X","Y")', '1:10', sep='""'); labs.sage() ++ ['X1', 'Y2', 'X3', 'Y4', 'X5', 'Y6', 'X7', 'Y8', 'X9', 'Y10'] ++ """ ++ from rpy2.rinterface import SexpVector, ListSexpVector, FloatSexpVector ++ from rpy2.robjects.conversion import Converter ++ ++ # convert rpy2's representation of r objects to the one sage expects (as defined by the old ++ # expect interface) ++ cv = Converter('r to sage converter') ++ ++ # fallback ++ cv.ri2py.register(object, lambda obj: obj) ++ ++ def float_to_int_if_possible(f): ++ # preserve the behaviour of the old r parser, e.g. return 1 instead of 1.0 ++ return int(f) if isinstance(f, int) or f.is_integer() else round(f, 16) # TODO investigate the rounding ++ cv.ri2py.register(float, float_to_int_if_possible) ++ ++ def list_to_singleton_if_possible(l): ++ if len(l) == 1: ++ return l[0] ++ else: ++ return l ++ ++ def _vector(vec): ++ attrs = vec.list_attrs() ++ # Recursive calls have to be made explicitly ++ # https://bitbucket.org/rpy2/rpy2/issues/363/custom-converters-are-not-applied ++ data = list_to_singleton_if_possible([ cv.ri2py(val) for val in vec ]) ++ rclass = list(vec.do_slot('class')) if 'class' in attrs else vec.rclass ++ ++ if 'names' in attrs: ++ # seperate names and values, call ri2py recursively to convert elements ++ names = list_to_singleton_if_possible(list(vec.do_slot('names'))) ++ return { ++ 'DATA': data, ++ '_Names': names, ++ '_r_class': rclass, ++ } ++ else: ++ # if no names are present, convert to a normal list or a single value ++ return data ++ cv.ri2py.register(SexpVector, _vector) ++ ++ def _matrix(mat): ++ if 'dim' in mat.list_attrs(): ++ try: ++ from sage.matrix.constructor import matrix ++ dimensions = mat.do_slot("dim") ++ # TODO: higher dimensions? happens often in statistics ++ if len(dimensions) != 2: ++ raise TypeError ++ (nrow, ncol) = dimensions ++ #since R does it the other way round, we assign ++ #transposed and then transpose the matrix :) ++ m = matrix(ncol, nrow, [cv.ri2py(i) for i in mat]) ++ return m.transpose() ++ except TypeError: ++ pass ++ else: ++ return _vector(mat) ++ cv.ri2py.register(FloatSexpVector, _matrix) ++ ++ def _list_vector(vec): ++ # we have a R list (vector of arbitrary elements) ++ attrs = vec.list_attrs() ++ names = vec.do_slot('names') ++ values = [ cv.ri2py(val) for val in vec ] ++ rclass = list(vec.do_slot('class')) if 'class' in attrs else vec.rclass ++ data = zip(names, values) ++ return { ++ 'DATA': dict(data), ++ '_Names': cv.ri2py(names), ++ # '_r_class': rclass, # FIXME why not? ++ }; ++ cv.ri2py.register(ListSexpVector, _list_vector) ++ ++ return cv ++ ++class R(ExtraTabCompletion, Interface): + def __init__(self, +- maxread=None, script_subdirectory=None, +- server_tmpdir = None, ++ maxread=None, + logfile=None, +- server=None, + init_list_length=1024, + seed=None): + """ +@@ -319,46 +463,19 @@ class R(ExtraTabCompletion, Expect): + sage: r == loads(dumps(r)) + True + """ +- Expect.__init__(self, + +- # The capitalized version of this is used for printing. +- name = 'r', ++ Interface.__init__( ++ self, ++ name = 'r', # The capitalized version of this is used for printing. ++ ) + +- # This is regexp of the input prompt. If you can change +- # it to be very obfuscated that would be better. Even +- # better is to use sequence numbers. +- # options(prompt=\" \") +- prompt = '> ', #default, later comes the change ++ # It would be better to make this an attribute of `R`, but that leads to problems since ++ # we override `__getattr__`. ++ global _r_to_sage_converter ++ _r_to_sage_converter = _setup_r_to_sage_converter() + +- # This is the command that starts up your program +- # See #25806 for the --no-readline switch which fixes hangs for some +- command = "R --no-readline --vanilla --quiet", +- +- server=server, +- server_tmpdir=server_tmpdir, +- +- script_subdirectory = script_subdirectory, +- +- # If this is true, then whenever the user presses Control-C to +- # interrupt a calculation, the whole interface is restarted. +- restart_on_ctrlc = False, +- +- # If true, print out a message when starting +- # up the command when you first send a command +- # to this interface. +- verbose_start = False, +- +- logfile=logfile, +- +- # If an input is longer than this number of characters, then +- # try to switch to outputting to a file. +- eval_using_file_cutoff=1024) +- +- self.__seq = 0 +- self.__var_store_len = 0 +- self.__init_list_length = init_list_length +- self._prompt_wait = [self._prompt] + self._seed = seed ++ self._start() + + def set_seed(self, seed=None): + """ +@@ -391,14 +508,10 @@ class R(ExtraTabCompletion, Expect): + sage: r = R() + sage: r._start() + """ +- Expect._start(self) +- + # width is line width, what's a good value? maximum is 10000! + # pager needed to replace help view from less to printout + # option device= is for plotting, is set to x11, NULL would be better? +- self._change_prompt(PROMPT) +- self.eval('options(prompt=\"%s\",continue=\"%s\", width=100,pager="cat",device="png")'%(PROMPT, PROMPT)) +- self.expect().expect(PROMPT) ++ self.eval('options(width=100,pager="cat",device="png")') + self.eval('options(repos="%s")'%RRepositoryURL) + self.eval('options(CRAN="%s")'%RRepositoryURL) + +@@ -669,22 +782,17 @@ class R(ExtraTabCompletion, Expect): + ... + ImportError: ... + """ +- ret = self.eval('require("%s")' % library_name) +- if six.PY2: +- try: +- ret = ret.decode('utf-8') +- except UnicodeDecodeError: +- ret = ret.decode('latin-1') +- # try hard to parse the message string in a locale-independent way +- if ' library(' in ret: # locale-independent key-word +- raise ImportError("%s"%ret) ++ if robjects.packages.isinstalled(library_name): ++ robjects.packages.importr(library_name) + else: +- try: +- # We need to rebuild keywords! +- del self.__tab_completion +- except AttributeError: +- pass +- self._tab_completion(verbose=False, use_disk_cache=False) ++ raise ImportError("R library {} not installed".format(library_name)) ++ ++ try: ++ # We need to rebuild keywords! ++ del self.__tab_completion ++ except AttributeError: ++ pass ++ self._tab_completion(verbose=False, use_disk_cache=False) + + require = library #overwrites require + +@@ -789,17 +897,24 @@ class R(ExtraTabCompletion, Expect): + EXAMPLES:: + + sage: r.help('c') +- c package:base R Documentation ++ title ++ ----- ++ ++ Combine Values into a Vector or List ++ ++ name ++ ---- ++ ++ c + ... +- +- .. note:: +- +- This is similar to typing r.command?. + """ +- s = self.eval('help("%s")'%command).strip() # ?cmd is only an unsafe shortcut ++ s = robjects.help.pages(command)[0].to_docstring() ++ ++ # TODO what is this for? + import sage.plot.plot + if sage.plot.plot.EMBEDDED_MODE: + s = s.replace('_\x08','') ++ + return HelpExpression(s) + + def _assign_symbol(self): +@@ -914,9 +1029,19 @@ class R(ExtraTabCompletion, Expect): + '[1] 5' + """ + cmd = '%s <- %s'%(var,value) +- out = self.eval(cmd) +- if out.find("error") != -1: +- raise TypeError("Error executing code in R\nCODE:\n\t%s\nR ERROR:\n\t%s"%(cmd, out)) ++ # FIXME this is how it behaved before since the output was only compared to 'error' ++ # while the actual error message started with an upper-case 'Error'. ++ # The doctests rely on this when doing `loads(dumps(r('"abc"')))` which will load ++ # simply `"abc"` which will then again be set as `sage0 <- abc` (notice the missing ++ # quotes). The test will pass anyway because the identifier is reused for some reason. ++ # That means `sage0` will already be "abc" from the first `r('"abc"')` call. ++ from rpy2.rinterface import RRuntimeWarning, RRuntimeError ++ import warnings ++ warnings.filterwarnings("ignore", category = RRuntimeWarning) ++ try: ++ out = self.eval(cmd) ++ except RRuntimeError: ++ pass + + def get(self, var): + """ +@@ -934,9 +1059,20 @@ class R(ExtraTabCompletion, Expect): + sage: r.get('a') + '[1] 2' + """ +- s = self.eval('%s'%var) +- #return self._remove_indices_re.sub("", s).strip() +- return s ++ # FIXME again, this is how it behaved before. The doctest `L.hom(r, base_morphism=phi)` ++ # in sage/rings/function_field/function_field.py relies on this. It somehow ends up ++ # requesting a non-existant r object resulting in ++ # `RRuntimeError: Error in (function (expr, envir = parent.frame(), enclos = if (is.list(envir) || : ++ # object 'sage2' not found` ++ # I haven't figured out how or why it does that. ++ from rpy2.rinterface import RRuntimeWarning, RRuntimeError ++ import warnings ++ warnings.filterwarnings("ignore", category = RRuntimeWarning) ++ try: ++ s = self.eval('%s'%var) ++ return s ++ except RRuntimeError: ++ return '' + + def na(self): + """ +@@ -966,7 +1102,12 @@ class R(ExtraTabCompletion, Expect): + + sage: dummy = r._tab_completion(use_disk_cache=False) #clean doctest + sage: r.completions('tes') +- ['testInheritedMethods', 'testPlatformEquivalence', 'testVirtual'] ++ ['testInheritedMethods', ++ 'testInstalledBasic', ++ 'testInstalledPackage', ++ 'testInstalledPackages', ++ 'testPlatformEquivalence', ++ 'testVirtual'] + """ + return [name for name in self._tab_completion() if name[:len(s)] == s] + +@@ -986,8 +1127,7 @@ class R(ExtraTabCompletion, Expect): + """ + v = RBaseCommands + +- ll = self.eval('dput(search())') # loaded libs +- ll = self.convert_r_list(ll) ++ ll = self('search()')._sage_() # loaded libs + + for lib in ll: + if lib in RFilteredPackages: +@@ -996,9 +1136,7 @@ class R(ExtraTabCompletion, Expect): + if lib.find("package:") != 0: + continue #only packages + +- raw = self.eval('dput(objects("%s"))'%lib) +- raw = self.convert_r_list(raw) +- raw = [x.replace(".","_") for x in raw] ++ raw = self('objects("%s")'%lib)._sage_() + + #TODO are there others? many of them are shortcuts or + #should be done on another level, like selections in lists +@@ -1123,24 +1261,6 @@ class R(ExtraTabCompletion, Expect): + RFunction(self, 'plot')(*args, **kwds) + return RFunction(self, 'dev.off')() + +- def _strip_prompt(self, code): +- """ +- Remove the standard R prompt from the beginning of lines in code. +- +- INPUT: +- +- - code -- a string +- +- OUTPUT: a string +- +- EXAMPLES:: +- +- sage: s = '> a <- 2\n> b <- 3' +- sage: r._strip_prompt(s) +- ' a <- 2\n b <- 3' +- """ +- return prompt_re.sub("", code) +- + def eval(self, code, globals=None, locals=None, synchronize=True, *args, **kwds): + """ + Evaluates a command inside the R interpreter and returns the output +@@ -1151,9 +1271,8 @@ class R(ExtraTabCompletion, Expect): + sage: r.eval('1+1') + '[1] 2' + """ +- # TODO split code at ";" outside of quotes and send them as individual +- # lines without ";". +- return Expect.eval(self, code, synchronize=synchronize, *args, **kwds) ++ return str(robjects.r(code)).rstrip() ++ + + def _r_to_sage_name(self, s): + """ +@@ -1255,16 +1374,8 @@ class R(ExtraTabCompletion, Expect): + self.execute('setwd(%r)' % dir) + + +-# patterns for _sage_() +-rel_re_param = re.compile(r'\s([\w\.]+)\s=') +-rel_re_range = re.compile(r'([\d]+):([\d]+)') +-rel_re_integer = re.compile(r'([^\d])([\d]+)L') +-rel_re_terms = re.compile(r'terms\s*=\s*(.*?),') +-rel_re_call = re.compile(r'call\s*=\s*(.*?)\),') +- +- + @instancedoc +-class RElement(ExtraTabCompletion, ExpectElement): ++class RElement(ExtraTabCompletion, InterfaceElement): + + def _tab_completion(self): + """ +@@ -1315,7 +1426,7 @@ class RElement(ExtraTabCompletion, ExpectElement): + sage: len(x) + 5 + """ +- return int(self.parent().eval('dput(length(%s))'%self.name())[:-1] ) ++ return self.parent()('length(%s)'%self.name())._sage_() + + def __getattr__(self, attrname): + """ +@@ -1777,95 +1888,9 @@ class RElement(ExtraTabCompletion, ExpectElement): + self._check_valid() + P = self.parent() + +- # This is the core of the trick: using dput +- # dput prints out the internal structure of R's data elements +- # options via .deparseOpts(control=...) +- # TODO: dput also works with a file, if things get huge! +- # [[However, using a file for output often isn't necessary +- # since pipe buffering works pretty well for output. +- # That said, benchmark this. -- William Stein]] +- exp = P.eval('dput(%s)'%self.name()) +- +- # Preprocess expression +- # example what this could be: +- # structure(list(statistic = structure(0.233549683248457, .Names = "t"), +- # parameter = structure(5.58461538461538, .Names = "df"), p.value = 0.823657802106985, +- # conf.int = structure(c(-2.41722062247400, 2.91722062247400 +- # ), conf.level = 0.95), estimate = structure(c(2.75, 2.5), .Names = c("mean of x", +- # "mean of y")), null.value = structure(0, .Names = "difference in means"), +- # alternative = "two.sided", method = "Welch Two Sample t-test", +- # data.name = "c(1, 2, 3, 5) and c(1, 2, 3, 4)"), .Names = c("statistic", +- # "parameter", "p.value", "conf.int", "estimate", "null.value", +- # "alternative", "method", "data.name"), class = "htest") +- +- # R's structure (from help): +- # structure(.Data, ...) +- # .Data: an object which will have various attributes attached to it. +- # ...: attributes, specified in 'tag=value' form, which will be +- # attached to data. +- #For historical reasons (these names are used when deparsing), +- # attributes '".Dim"', '".Dimnames"', '".Names"', '".Tsp"' and +- # '".Label"' are renamed to '"dim"', '"dimnames"', '"names"', +- # '"tsp"' and '"levels"'. +- +- +- +- # we want this in a single line +- exp.replace('\n','') +- exp = "".join(exp.split("\n")) +- +- # python compatible parameters +- exp = rel_re_param.sub(self._subs_dots, exp) +- +- # Rename class since it is a Python keyword +- exp = re.sub(' class = ', ' _r_class = ',exp) +- +- # Change 'structure' to '_r_structure' +- # TODO: check that we are outside of quotes "" +- exp = re.sub(r' structure\(', ' _r_structure(', exp) +- exp = re.sub(r'^structure\(', '_r_structure(', exp) # special case +- +- # Change 'list' to '_r_list' +- exp = re.sub(r' list\(', ' _r_list(', exp) +- exp = re.sub(r'\(list\(', '(_r_list(', exp) +- +- # Change 'a:b' to 'range(a,b+1)' +- exp = rel_re_range.sub(self._subs_range, exp) +- +- # Change 'dL' to 'Integer(d)' +- exp = rel_re_integer.sub(self._subs_integer, exp) +- +- # Wrap the right hand side of terms = ... in quotes since it +- # has a ~ in it. +- exp = rel_re_terms.sub(r'terms = "\1",', exp) +- +- +- # Change call = ..., to call = "...", +- exp = rel_re_call.sub(r'call = "\1",', exp) +- +- # seems to work for +- # rr = r.summary(r.princomp(r.matrix(r.c(1,2,3,4,3,4,1,2,2),4))) +- # rr._sage_() +- # but the call expression get's evaluated. why?!? TODO +- +- +- # translation: +- # c is an ordered list +- # list is a dictionary (where _Names give the entries names. +- # map entries in names to (value, name) in each entry? +- # structure is .. see above .. structure(DATA,**kw) +- # TODO: thinking of just replacing c( with ( to get a long tuple? +- +- +- exp = self._convert_nested_r_list(exp) +- +- # Set up the globals +- globs = {'NA':None, 'NULL':None, 'FALSE':False, 'TRUE':True, +- '_r_list':self._r_list, '_r_structure':self._r_structure, +- 'Integer':sage.rings.integer.Integer, +- 'character':str} +- +- return eval(exp, globs, globs) ++ with localconverter(_r_to_sage_converter) as cv: ++ parsed = robjects.r(self.name()) ++ return parsed + + + def _latex_(self): +@@ -1893,7 +1918,7 @@ class RElement(ExtraTabCompletion, ExpectElement): + + + @instancedoc +-class RFunctionElement(FunctionElement): ++class RFunctionElement(InterfaceFunctionElement): + def __reduce__(self): + """ + EXAMPLES:: +@@ -1917,9 +1942,16 @@ class RFunctionElement(FunctionElement): + sage: a = r([1,2,3]) + sage: length = a.length + sage: print(length.__doc__) +- length package:base R Documentation +- ... ++ title ++ ----- ++ ++ Length of an Object ++ ++ name ++ ---- + ++ length ++ ... + """ + M = self._obj.parent() + return M.help(self._name) +@@ -1951,7 +1983,7 @@ class RFunctionElement(FunctionElement): + + + @instancedoc +-class RFunction(ExpectFunction): ++class RFunction(InterfaceFunction): + def __init__(self, parent, name, r_name=None): + """ + A Function in the R interface. +@@ -2007,9 +2039,16 @@ class RFunction(ExpectFunction): + + sage: length = r.length + sage: print(length.__doc__) +- length package:base R Documentation +- ... ++ title ++ ----- ++ ++ Length of an Object + ++ name ++ ---- ++ ++ length ++ ... + """ + M = self._parent + return M.help(self._name) +diff --git a/src/sage/stats/r.py b/src/sage/stats/r.py +index cd2002559b..8a2f243901 100644 +--- a/src/sage/stats/r.py ++++ b/src/sage/stats/r.py +@@ -39,12 +39,12 @@ def ttest(x,y,conf_level = 0.95, **kw): + + Example:: + +- sage: a, b = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]); a +- 0.941026372027427 ++ sage: a, b = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]); a # abs tol 1e-12 ++ 0.9410263720274274 + """ + if len(x) != len(y): + raise AttributeError("vectors x and y must be of same length") + + test = myR.t_test(x,y,conf_level = conf_level, **kw)._sage_() +- t = test.get('DATA').get('p_value') ++ t = test.get('DATA').get('p.value') + return t, test diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index c166a17fafc7..8bbbebcca03d 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta0"; + version = "8.5.beta1"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0kc8fqwz97dwyf4hxz5yr9sjwh5q0jr7a9g1yrdaz66m5805r859"; + sha256 = "0pxalw7kw8zdnn51yp3s81c6r5m9a500f9yn14s2883jyag9yiz1"; }; # Patches needed because of particularities of nix or the way this is packaged. From 883aa992263ffcb99f73e6a36efbd28711d66416 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sat, 24 Nov 2018 22:59:51 +0100 Subject: [PATCH 03/13] sage: add short tests --- pkgs/applications/science/math/sage/sage-tests.nix | 12 +++++++++--- pkgs/applications/science/math/sage/sage.nix | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage-tests.nix b/pkgs/applications/science/math/sage/sage-tests.nix index feccf75a7acb..12433e12fe90 100644 --- a/pkgs/applications/science/math/sage/sage-tests.nix +++ b/pkgs/applications/science/math/sage/sage-tests.nix @@ -3,7 +3,12 @@ , sage-with-env , makeWrapper , files ? null # "null" means run all tests -, longTests ? true # run tests marked as "long time" +, longTests ? true # run tests marked as "long time" (roughly doubles runtime) +# Run as many tests as possible in approximately n seconds. This will give each +# file to test a "time budget" and stop tests if it is exceeded. 300 is the +# upstream default value. +# https://trac.sagemath.org/ticket/25270 for details. +, timeLimit ? null }: # for a quick test of some source files: @@ -14,6 +19,7 @@ let runAllTests = files == null; testArgs = if runAllTests then "--all" else testFileList; patienceSpecifier = if longTests then "--long" else ""; + timeSpecifier = if timeLimit == null then "" else "--short ${toString timeLimit}"; relpathToArg = relpath: lib.escapeShellArg "${src}/${relpath}"; # paths need to be absolute testFileList = lib.concatStringsSep " " (map relpathToArg files); in @@ -45,7 +51,7 @@ stdenv.mkDerivation rec { export HOME="$TMPDIR/sage-home" mkdir -p "$HOME" - # "--long" tests are in the order of 1h, without "--long" its 1/2h - "sage" -t --nthreads "$NIX_BUILD_CORES" --optional=sage ${patienceSpecifier} ${testArgs} + echo "Running sage tests with arguments ${timeSpecifier} ${patienceSpecifier} ${testArgs}" + "sage" -t --nthreads "$NIX_BUILD_CORES" --optional=sage ${timeSpecifier} ${patienceSpecifier} ${testArgs} ''; } diff --git a/pkgs/applications/science/math/sage/sage.nix b/pkgs/applications/science/math/sage/sage.nix index ac255643a348..541b9cb36dc2 100644 --- a/pkgs/applications/science/math/sage/sage.nix +++ b/pkgs/applications/science/math/sage/sage.nix @@ -54,6 +54,7 @@ stdenv.mkDerivation rec { passthru = { tests = sage-tests; + quicktest = sage-tests.override { longTests = false; timeLimit = 600; }; # as many tests as possible in ~10m doc = sagedoc; lib = sage-with-env.env.lib; kernelspec = jupyter-kernel-definition; From 3370247f7f49d16c63e5405ba589cf91ffd62340 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 25 Nov 2018 09:50:45 +0100 Subject: [PATCH 04/13] sage: 8.5.beta1 -> 8.5.beta2 --- pkgs/applications/science/math/sage/sage-src.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 8bbbebcca03d..208dcc43a7db 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta1"; + version = "8.5.beta2"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0pxalw7kw8zdnn51yp3s81c6r5m9a500f9yn14s2883jyag9yiz1"; + sha256 = "0m57lnaflymzdql3njaazbv178nyn4vc94az9dg6lc5ybrkvw808"; }; # Patches needed because of particularities of nix or the way this is packaged. From 2a87caa892bba6f388dbec71a45c9482433eb651 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 25 Nov 2018 10:41:36 +0100 Subject: [PATCH 05/13] sage: 8.5.beta2 -> 8.5.beta3 --- pkgs/applications/science/math/sage/sage-src.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 208dcc43a7db..a0c828289830 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta2"; + version = "8.5.beta3"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0m57lnaflymzdql3njaazbv178nyn4vc94az9dg6lc5ybrkvw808"; + sha256 = "1nhhx576188q87ma7yygp1mgqs2mcjk89cy4dqibzbv0vmhasz3c"; }; # Patches needed because of particularities of nix or the way this is packaged. From 90cebaf8280d819289438429a53214d1656d942d Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 25 Nov 2018 12:15:39 +0100 Subject: [PATCH 06/13] sage: 8.5.beta3 -> 8.5.beta4 --- .../sage/patches/no-invalid-gap-test.patch | 19 +++++++++++++++++++ .../science/math/sage/sage-src.nix | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch diff --git a/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch b/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch new file mode 100644 index 000000000000..546a78764897 --- /dev/null +++ b/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch @@ -0,0 +1,19 @@ +diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx +index bdde6aa60f..50459534f8 100644 +--- a/src/sage/libs/gap/util.pyx ++++ b/src/sage/libs/gap/util.pyx +@@ -165,14 +165,6 @@ def gap_root(): + sage: from sage.libs.gap.util import gap_root + sage: gap_root() # random output + '/home/vbraun/opt/sage-5.3.rc0/local/gap/latest' +- +- If GAP_ROOT_DIR is undefined or pointing to the wrong location, +- fall back code should be used to determine gapdir:: +- +- sage: import os +- sage: os.system("GAP_ROOT_DIR=/not_a_path sage -c \"sage.libs.gap.util.gap_root()\"") +- The gap-4.5.5.spkg (or later) seems to be not installed! +- ... + """ + import os.path + if os.path.exists(GAP_ROOT_DIR): diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index a0c828289830..dd96121925fe 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta3"; + version = "8.5.beta4"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "1nhhx576188q87ma7yygp1mgqs2mcjk89cy4dqibzbv0vmhasz3c"; + sha256 = "0x8zi5c1glw5h7231yxdyklmf1vgrvf0zvzwa4qwnm7x2nky62zf"; }; # Patches needed because of particularities of nix or the way this is packaged. @@ -46,6 +46,8 @@ stdenv.mkDerivation rec { # tests) are also run. That is necessary to test dochtml individually. See # https://trac.sagemath.org/ticket/26110 for an upstream discussion. ./patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch + + ./patches/no-invalid-gap-test.patch ]; # Patches needed because of package updates. We could just pin the versions of From 7ca2915a502c883eb68bd939251452b9057d3c9d Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Tue, 27 Nov 2018 18:26:16 +0100 Subject: [PATCH 07/13] sage: 8.5.beta4 -> 8.5.beta5 --- pkgs/applications/science/math/sage/default.nix | 14 +------------- pkgs/applications/science/math/sage/sage-env.nix | 1 + pkgs/applications/science/math/sage/sage-src.nix | 13 +++---------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix index 832b2f110565..dfdf210eec04 100644 --- a/pkgs/applications/science/math/sage/default.nix +++ b/pkgs/applications/science/math/sage/default.nix @@ -70,7 +70,7 @@ let sage-env = callPackage ./sage-env.nix { sagelib = python.pkgs.sagelib; inherit env-locations; - inherit python rWrapper ecl singular palp flint pynac pythonEnv; + inherit python ecl singular palp flint pynac pythonEnv; pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig }; @@ -124,18 +124,6 @@ let ignoreCollisions = true; } // { extraLibs = pythonRuntimeDeps; }; # make the libs accessible - # needs to be rWrapper, standard "R" doesn't include default packages - rWrapper = pkgs.rWrapper.override { - # https://trac.sagemath.org/ticket/25674 - R = pkgs.R.overrideAttrs (attrs: rec { - name = "R-3.4.4"; - src = fetchurl { - url = "http://cran.r-project.org/src/base/R-3/${name}.tar.gz"; - sha256 = "0dq3jsnwsb5j3fhl0wi3p5ycv8avf8s5j1y4ap3d2mkjmcppvsdk"; - }; - }); - }; - arb = pkgs.arb.override { inherit flint; }; singular = pkgs.singular.override { inherit flint; }; diff --git a/pkgs/applications/science/math/sage/sage-env.nix b/pkgs/applications/science/math/sage/sage-env.nix index 725ca0438670..7d4a66ea2b9c 100644 --- a/pkgs/applications/science/math/sage/sage-env.nix +++ b/pkgs/applications/science/math/sage/sage-env.nix @@ -76,6 +76,7 @@ let singular giac palp + # needs to be rWrapper since the default `R` doesn't include R's default libraries rWrapper gfan cddlib diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index dd96121925fe..81386533a39c 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta4"; + version = "8.5.beta5"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0x8zi5c1glw5h7231yxdyklmf1vgrvf0zvzwa4qwnm7x2nky62zf"; + sha256 = "1jnlk4y7njkg095kd3rhsi5929k6q90lzgyb7pshsjz251866nyv"; }; # Patches needed because of particularities of nix or the way this is packaged. @@ -70,6 +70,7 @@ stdenv.mkDerivation rec { ); in [ # New glpk version has new warnings, filter those out until upstream sage has found a solution + # Should be fixed with glpk > 4.65. # https://trac.sagemath.org/ticket/24824 ./patches/pari-stackwarn.patch # not actually necessary since the pari upgrade, but necessary for the glpk patch to apply (fetchpatch { @@ -78,14 +79,6 @@ stdenv.mkDerivation rec { stripLen = 1; }) - # needed for ntl update - # https://trac.sagemath.org/ticket/25532 - (fetchpatch { - name = "lcalc-c++11.patch"; - url = "https://git.archlinux.org/svntogit/community.git/plain/trunk/sagemath-lcalc-c++11.patch?h=packages/sagemath&id=0e31ae526ab7c6b5c0bfacb3f8b1c4fd490035aa"; - sha256 = "0p5wnvbx65i7cp0bjyaqgp4rly8xgnk12pqwaq3dqby0j2bk6ijb"; - }) - (fetchpatch { name = "cython-0.29.patch"; url = "https://git.sagemath.org/sage.git/patch/?h=f77de1d0e7f90ee12761140500cb8cbbb789ab20"; From 4900bbee179f393c447671424b5cab6e35c29bd3 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Wed, 28 Nov 2018 20:44:09 +0100 Subject: [PATCH 08/13] sage: preload openblasCompat --- .../science/math/sage/default.nix | 22 ++++--------------- .../science/math/sage/sage-env.nix | 11 ++++++++++ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix index dfdf210eec04..84cd5758acb2 100644 --- a/pkgs/applications/science/math/sage/default.nix +++ b/pkgs/applications/science/math/sage/default.nix @@ -32,8 +32,9 @@ let # `sagelib`, i.e. all of sage except some wrappers and runtime dependencies sagelib = self.callPackage ./sagelib.nix { - inherit flint ecl arb; - inherit sage-src pynac singular; + inherit ecl; + inherit sage-src; + pynac = pkgs.pynac; # *not* python.pkgs.pynac linbox = pkgs.linbox.override { withSage = true; }; }; }; @@ -59,7 +60,6 @@ let # the files its looking fore are located. Also see `sage-env`. env-locations = callPackage ./env-locations.nix { inherit pari_data ecl; - inherit singular; cysignals = python.pkgs.cysignals; three = nodePackages.three; mathjax = nodePackages.mathjax; @@ -70,7 +70,7 @@ let sage-env = callPackage ./sage-env.nix { sagelib = python.pkgs.sagelib; inherit env-locations; - inherit python ecl singular palp flint pynac pythonEnv; + inherit python ecl palp pythonEnv; pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig }; @@ -84,7 +84,6 @@ let sage-with-env = callPackage ./sage-with-env.nix { inherit pythonEnv; inherit sage-env; - inherit pynac singular; pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig three = nodePackages.three; }; @@ -124,19 +123,6 @@ let ignoreCollisions = true; } // { extraLibs = pythonRuntimeDeps; }; # make the libs accessible - arb = pkgs.arb.override { inherit flint; }; - - singular = pkgs.singular.override { inherit flint; }; - - # *not* to confuse with the python package "pynac" - pynac = pkgs.pynac.override { inherit singular flint; }; - - # With openblas (64 bit), the tests fail the same way as when sage is build with - # openblas instead of openblasCompat. Apparently other packages somehow use flints - # blas when it is available. Alternative would be to override flint to use - # openblasCompat. - flint = pkgs.flint.override { withBlas = false; }; - # Multiple palp dimensions need to be available and sage expects them all to be # in the same folder. palp = symlinkJoin { diff --git a/pkgs/applications/science/math/sage/sage-env.nix b/pkgs/applications/science/math/sage/sage-env.nix index 7d4a66ea2b9c..c7f0a19f1768 100644 --- a/pkgs/applications/science/math/sage/sage-env.nix +++ b/pkgs/applications/science/math/sage/sage-env.nix @@ -163,6 +163,17 @@ writeTextFile rec { # for find_library export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular]}:$DYLD_LIBRARY_PATH" + + # Make sure the correct openblas library is picked up. Without this, sage + # can either end up using flints openblas (which is not openblasCopmat, thus + # leading to the issues described in https://trac.sagemath.org/ticket/26000) + # or R's blas, leading to the issues described in + # https://bitbucket.org/rpy2/rpy2/issues/491. + # The first issue could alternatively be solved by overriding flint's + # openblas dependency and the second one is effectively solved by loading + # rpy2 lazily in sage. Preloading explicitly makes all the headaches go + # away much easier and more future proof though. + export LD_PRELOAD="${openblasCompat}/lib/libopenblas.so:$LD_PRELOAD" ''; } // { lib = sagelib; # equivalent of `passthru`, which `writeTextFile` doesn't support From 90bc5ce04ddc5dfda7d29486061ebf980424f161 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 10 Dec 2018 19:36:24 +0100 Subject: [PATCH 09/13] sage: 8.5.beta5 -> 8.5.beta6 --- .../math/sage/patches/dont-test-guess-gaproot.patch | 13 +++++++++++++ pkgs/applications/science/math/sage/sage-src.nix | 11 +++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 pkgs/applications/science/math/sage/patches/dont-test-guess-gaproot.patch diff --git a/pkgs/applications/science/math/sage/patches/dont-test-guess-gaproot.patch b/pkgs/applications/science/math/sage/patches/dont-test-guess-gaproot.patch new file mode 100644 index 000000000000..32b877428d51 --- /dev/null +++ b/pkgs/applications/science/math/sage/patches/dont-test-guess-gaproot.patch @@ -0,0 +1,13 @@ +diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx +index 5ff67107c1..1318df86fd 100644 +--- a/src/sage/libs/gap/util.pyx ++++ b/src/sage/libs/gap/util.pyx +@@ -165,7 +165,7 @@ def _guess_gap_root(): + EXAMPLES:: + + sage: from sage.libs.gap.util import _guess_gap_root +- sage: _guess_gap_root() ++ sage: _guess_gap_root() # not tested (not necessary on nixos) + The gap-4.5.5.spkg (or later) seems to be not installed! + ... + """ diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 81386533a39c..4685ee61957d 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta5"; + version = "8.5.beta6"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "1jnlk4y7njkg095kd3rhsi5929k6q90lzgyb7pshsjz251866nyv"; + sha256 = "0b3f7m1mxqh2sjb8q2bci7202gw8qi1kin13fzsmvfd3caxvxzcy"; }; # Patches needed because of particularities of nix or the way this is packaged. @@ -47,7 +47,7 @@ stdenv.mkDerivation rec { # https://trac.sagemath.org/ticket/26110 for an upstream discussion. ./patches/Only-test-py2-py3-optional-tests-when-all-of-sage-is.patch - ./patches/no-invalid-gap-test.patch + ./patches/dont-test-guess-gaproot.patch ]; # Patches needed because of package updates. We could just pin the versions of @@ -79,11 +79,6 @@ stdenv.mkDerivation rec { stripLen = 1; }) - (fetchpatch { - name = "cython-0.29.patch"; - url = "https://git.sagemath.org/sage.git/patch/?h=f77de1d0e7f90ee12761140500cb8cbbb789ab20"; - sha256 = "14wrpy8jgbnpza1j8a2nx8y2r946y82pll1fv3cn6gpfmm6640l3"; - }) # https://trac.sagemath.org/ticket/26360 (fetchpatch { name = "arb-2.15.1.patch"; From b09967d8128ef117a55fed27276dc8666f5fce50 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 16 Dec 2018 21:33:28 +0100 Subject: [PATCH 10/13] sage: 8.5.rc0 -> 8.5.rc1 --- pkgs/applications/science/math/sage/sage-src.nix | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 4685ee61957d..b8e8a39c84b4 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.beta6"; + version = "8.5.rc1"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0b3f7m1mxqh2sjb8q2bci7202gw8qi1kin13fzsmvfd3caxvxzcy"; + sha256 = "0pb0x5ay2xr5ywpnq0av7p6gf9mifg31yq645phyc8wc4vnhmz7z"; }; # Patches needed because of particularities of nix or the way this is packaged. @@ -79,13 +79,6 @@ stdenv.mkDerivation rec { stripLen = 1; }) - # https://trac.sagemath.org/ticket/26360 - (fetchpatch { - name = "arb-2.15.1.patch"; - url = "https://git.sagemath.org/sage.git/patch/?id=30cc778d46579bd0c7537ed33e8d7a4f40fd5c31"; - sha256 = "13vc2q799dh745sm59xjjabllfj0sfjzcacf8k59kwj04x755d30"; - }) - # https://trac.sagemath.org/ticket/26326 # needs to be split because there is a merge commit in between (fetchSageDiff { From 6f0f06ec89c5f6d55693092786c9f6c8db743910 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 23 Dec 2018 10:05:27 +0100 Subject: [PATCH 11/13] sage: 8.5.rc1 -> 8.5 --- pkgs/applications/science/math/sage/sage-src.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index b8e8a39c84b4..82a0a04bcb01 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -9,14 +9,14 @@ # all get the same sources with the same patches applied. stdenv.mkDerivation rec { - version = "8.5.rc1"; + version = "8.5"; name = "sage-src-${version}"; src = fetchFromGitHub { owner = "sagemath"; repo = "sage"; rev = version; - sha256 = "0pb0x5ay2xr5ywpnq0av7p6gf9mifg31yq645phyc8wc4vnhmz7z"; + sha256 = "08mb9626phsls2phdzqxsnp2df5pn5qr72m0mm4nncby26pwn19c"; }; # Patches needed because of particularities of nix or the way this is packaged. From 360eddd3a343ad5fdc310fb0cbf66e9d6aae31a7 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 23 Dec 2018 10:08:34 +0100 Subject: [PATCH 12/13] sage: remove outdated patch files --- .../sage/patches/no-invalid-gap-test.patch | 19 - .../science/math/sage/patches/r-rpy.patch | 763 ------------------ 2 files changed, 782 deletions(-) delete mode 100644 pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch delete mode 100644 pkgs/applications/science/math/sage/patches/r-rpy.patch diff --git a/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch b/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch deleted file mode 100644 index 546a78764897..000000000000 --- a/pkgs/applications/science/math/sage/patches/no-invalid-gap-test.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx -index bdde6aa60f..50459534f8 100644 ---- a/src/sage/libs/gap/util.pyx -+++ b/src/sage/libs/gap/util.pyx -@@ -165,14 +165,6 @@ def gap_root(): - sage: from sage.libs.gap.util import gap_root - sage: gap_root() # random output - '/home/vbraun/opt/sage-5.3.rc0/local/gap/latest' -- -- If GAP_ROOT_DIR is undefined or pointing to the wrong location, -- fall back code should be used to determine gapdir:: -- -- sage: import os -- sage: os.system("GAP_ROOT_DIR=/not_a_path sage -c \"sage.libs.gap.util.gap_root()\"") -- The gap-4.5.5.spkg (or later) seems to be not installed! -- ... - """ - import os.path - if os.path.exists(GAP_ROOT_DIR): diff --git a/pkgs/applications/science/math/sage/patches/r-rpy.patch b/pkgs/applications/science/math/sage/patches/r-rpy.patch deleted file mode 100644 index ab407c8fd744..000000000000 --- a/pkgs/applications/science/math/sage/patches/r-rpy.patch +++ /dev/null @@ -1,763 +0,0 @@ -diff --git a/src/sage/doctest/test.py b/src/sage/doctest/test.py -index 2f4f74cfc2..c6c1bf9194 100644 ---- a/src/sage/doctest/test.py -+++ b/src/sage/doctest/test.py -@@ -500,12 +500,13 @@ Test ``atexit`` support in the doctesting framework:: - ....: pass - - Test the ``--memlimit`` option and ``# optional - memlimit`` --(but only on Linux):: -+(but only on Linux). If this test fails, the memory needed to -+run it may have increased. Try increasing the limit. :: - - sage: from platform import system - sage: ok = True - sage: if system() == "Linux": -- ....: P = subprocess.Popen(["sage", "-t", "--warn-long", "0", "--memlimit=2000", "memlimit.rst"], stdout=subprocess.PIPE, **kwds) -+ ....: P = subprocess.Popen(["sage", "-t", "--warn-long", "0", "--memlimit=2100", "memlimit.rst"], stdout=subprocess.PIPE, **kwds) - ....: out, err = P.communicate() - ....: ok = ("MemoryError: failed to allocate" in out) - sage: ok or out -diff --git a/src/sage/interfaces/expect.py b/src/sage/interfaces/expect.py -index 51a37496c2..ba982f25f7 100644 ---- a/src/sage/interfaces/expect.py -+++ b/src/sage/interfaces/expect.py -@@ -1122,10 +1122,15 @@ If this all works, you can then make calls like: - - EXAMPLES: - -- We test all of this using the R interface. First we put -+ We test all of this using the Singular interface. First we put - 10 + 15 in the input stream:: - -- sage: r._sendstr('abc <- 10 +15;\n') -+ sage: singular._sendstr('def abc = 10 + 15;\n') -+ -+ Then we tell singular to print 10, which is an arbitrary number -+ different from the expected result 35. -+ -+ sage: singular._sendstr('10;\n') - - Here an exception is raised because 25 hasn't appeared yet in the - output stream. The key thing is that this doesn't lock, but instead -@@ -1135,7 +1140,7 @@ If this all works, you can then make calls like: - - sage: t = walltime() - sage: try: -- ....: r._expect_expr('25', timeout=0.5) -+ ....: singular._expect_expr('25', timeout=0.5) - ....: except Exception: - ....: print('Did not get expression') - Did not get expression -@@ -1145,24 +1150,24 @@ If this all works, you can then make calls like: - sage: w = walltime(t); w > 0.4 and w < 10 - True - -- We tell R to print abc, which equals 25. -+ We tell Singular to print abc, which equals 25. - - :: - -- sage: r._sendstr('abc;\n') -+ sage: singular._sendstr('abc;\n') - - Now 25 is in the output stream, so we can wait for it. - - :: - -- sage: r._expect_expr('25') -+ sage: singular._expect_expr('25') - -- This gives us everything before the 25. -+ This gives us everything before the 25, including the 10 we printed earlier. - - :: - -- sage: r._expect.before.decode('ascii') -- u'...abc;\r\n[1] ' -+ sage: singular._expect.before.decode('ascii') -+ u'...10\r\n> ' - - We test interrupting ``_expect_expr`` using the GP interface, - see :trac:`6661`. Unfortunately, this test doesn't work reliably using -@@ -1203,14 +1208,7 @@ If this all works, you can then make calls like: - - - ``string`` -- a string - -- EXAMPLES: We illustrate this function using the R interface:: -- -- sage: r._synchronize() -- sage: r._sendstr('a <- 10;\n') -- sage: r.eval('a') -- '[1] 10' -- -- We illustrate using the singular interface:: -+ EXAMPLES: We illustrate this function using the Singular interface:: - - sage: singular._synchronize() - sage: singular._sendstr('int i = 5;') -@@ -1260,7 +1258,7 @@ If this all works, you can then make calls like: - - EXAMPLES: We observe nothing, just as it should be:: - -- sage: r._synchronize() -+ sage: singular._synchronize() - - TESTS: - -diff --git a/src/sage/interfaces/gp.py b/src/sage/interfaces/gp.py -index 86f401571a..f3c6120ddc 100644 ---- a/src/sage/interfaces/gp.py -+++ b/src/sage/interfaces/gp.py -@@ -254,6 +254,7 @@ class Gp(ExtraTabCompletion, Expect): - self._eval_line('default(help, "gphelp -detex");') - # logfile disabled since Expect already logs - self._eval_line('default(log,0);') -+ self._eval_line("default(nbthreads,1);") - # set random seed - self.set_seed(self._seed) - -diff --git a/src/sage/interfaces/r.py b/src/sage/interfaces/r.py -index 5c75459903..06974a2324 100644 ---- a/src/sage/interfaces/r.py -+++ b/src/sage/interfaces/r.py -@@ -268,17 +268,17 @@ from __future__ import print_function, absolute_import - from six.moves import range - import six - --from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement -+from .interface import Interface, InterfaceElement, InterfaceFunction, InterfaceFunctionElement - from sage.env import DOT_SAGE - import re --import sage.rings.integer - from sage.structure.element import parent - from sage.interfaces.tab_completion import ExtraTabCompletion - from sage.docs.instancedoc import instancedoc -+from rpy2 import robjects -+from rpy2.robjects import packages -+from rpy2.robjects.conversion import localconverter - - COMMANDS_CACHE = '%s/r_commandlist.sobj'%DOT_SAGE --PROMPT = '__SAGE__R__PROMPT__> ' --prompt_re = re.compile("^>", re.M) - - #there is a mirror network, but lets take #1 for now - RRepositoryURL = "http://cran.r-project.org/" -@@ -288,12 +288,156 @@ RFilteredPackages = ['.GlobalEnv'] - # but package:base should cover this. i think. - RBaseCommands = ['c', "NULL", "NA", "True", "False", "Inf", "NaN"] - --class R(ExtraTabCompletion, Expect): -+def _setup_r_to_sage_converter(): -+ """ -+ Set up a the converter used to convert from rpy2's -+ representation of R objects to the one sage expects. -+ -+ EXAMPLES:: -+ -+ Test -+ -+ Simple numeric values are represented as vectors in R. So `1` would actually -+ be an array of length 1. We convert all vectors of length 1 to simple values, -+ whether or not they "originally" were simple values or not: -+ -+ sage: r([42]).sage() -+ 42 -+ -+ sage: r(42).sage() -+ 42 -+ -+ sage: r('c("foo")').sage() -+ 'foo' -+ -+ Arrays of length greater than one are treated normally: -+ -+ sage: r([42, 43]).sage() -+ [42, 43] -+ -+ We also convert all numeric values to integers if that is possible without -+ loss of precision: -+ -+ sage: type(r([1.0]).sage()) == int -+ True -+ -+ sage: r([1.0, 42.5]).sage() -+ [1, 42.5] -+ -+ Matrices are converted to sage matrices: -+ -+ sage: r('matrix(c(2,4,3,1,5,7), nrow=2, ncol=3)').sage() -+ [2 3 5] -+ [4 1 7] -+ -+ More complex r structures are represented by dictionaries: -+ -+ sage: r.summary(1).sage() -+ {'DATA': [1, 1, 1, 1, 1, 1], -+ '_Names': ['Min.', '1st Qu.', 'Median', 'Mean', '3rd Qu.', 'Max.'], -+ '_r_class': ['summaryDefault', 'table']} -+ -+ sage: r.options(width="60").sage() -+ {'DATA': {'width': 60}, '_Names': 'width'} -+ -+ The conversion can handle "not a number", infintiy, imaginary values and -+ missing values: -+ -+ sage: r(-17).sqrt().sage() -+ nan -+ sage: r('-17+0i').sqrt().sage() -+ 4.123105625617661j -+ sage: r('NA').sage() -+ NA -+ sage: inf = r('Inf'); inf.sage() -+ inf -+ -+ -+ Character Vectors are represented by regular python arrays: -+ -+ sage: labs = r.paste('c("X","Y")', '1:10', sep='""'); labs.sage() -+ ['X1', 'Y2', 'X3', 'Y4', 'X5', 'Y6', 'X7', 'Y8', 'X9', 'Y10'] -+ """ -+ from rpy2.rinterface import SexpVector, ListSexpVector, FloatSexpVector -+ from rpy2.robjects.conversion import Converter -+ -+ # convert rpy2's representation of r objects to the one sage expects (as defined by the old -+ # expect interface) -+ cv = Converter('r to sage converter') -+ -+ # fallback -+ cv.ri2py.register(object, lambda obj: obj) -+ -+ def float_to_int_if_possible(f): -+ # preserve the behaviour of the old r parser, e.g. return 1 instead of 1.0 -+ return int(f) if isinstance(f, int) or f.is_integer() else round(f, 16) # TODO investigate the rounding -+ cv.ri2py.register(float, float_to_int_if_possible) -+ -+ def list_to_singleton_if_possible(l): -+ if len(l) == 1: -+ return l[0] -+ else: -+ return l -+ -+ def _vector(vec): -+ attrs = vec.list_attrs() -+ # Recursive calls have to be made explicitly -+ # https://bitbucket.org/rpy2/rpy2/issues/363/custom-converters-are-not-applied -+ data = list_to_singleton_if_possible([ cv.ri2py(val) for val in vec ]) -+ rclass = list(vec.do_slot('class')) if 'class' in attrs else vec.rclass -+ -+ if 'names' in attrs: -+ # seperate names and values, call ri2py recursively to convert elements -+ names = list_to_singleton_if_possible(list(vec.do_slot('names'))) -+ return { -+ 'DATA': data, -+ '_Names': names, -+ '_r_class': rclass, -+ } -+ else: -+ # if no names are present, convert to a normal list or a single value -+ return data -+ cv.ri2py.register(SexpVector, _vector) -+ -+ def _matrix(mat): -+ if 'dim' in mat.list_attrs(): -+ try: -+ from sage.matrix.constructor import matrix -+ dimensions = mat.do_slot("dim") -+ # TODO: higher dimensions? happens often in statistics -+ if len(dimensions) != 2: -+ raise TypeError -+ (nrow, ncol) = dimensions -+ #since R does it the other way round, we assign -+ #transposed and then transpose the matrix :) -+ m = matrix(ncol, nrow, [cv.ri2py(i) for i in mat]) -+ return m.transpose() -+ except TypeError: -+ pass -+ else: -+ return _vector(mat) -+ cv.ri2py.register(FloatSexpVector, _matrix) -+ -+ def _list_vector(vec): -+ # we have a R list (vector of arbitrary elements) -+ attrs = vec.list_attrs() -+ names = vec.do_slot('names') -+ values = [ cv.ri2py(val) for val in vec ] -+ rclass = list(vec.do_slot('class')) if 'class' in attrs else vec.rclass -+ data = zip(names, values) -+ return { -+ 'DATA': dict(data), -+ '_Names': cv.ri2py(names), -+ # '_r_class': rclass, # FIXME why not? -+ }; -+ cv.ri2py.register(ListSexpVector, _list_vector) -+ -+ return cv -+ -+class R(ExtraTabCompletion, Interface): - def __init__(self, -- maxread=None, script_subdirectory=None, -- server_tmpdir = None, -+ maxread=None, - logfile=None, -- server=None, - init_list_length=1024, - seed=None): - """ -@@ -319,46 +463,19 @@ class R(ExtraTabCompletion, Expect): - sage: r == loads(dumps(r)) - True - """ -- Expect.__init__(self, - -- # The capitalized version of this is used for printing. -- name = 'r', -+ Interface.__init__( -+ self, -+ name = 'r', # The capitalized version of this is used for printing. -+ ) - -- # This is regexp of the input prompt. If you can change -- # it to be very obfuscated that would be better. Even -- # better is to use sequence numbers. -- # options(prompt=\" \") -- prompt = '> ', #default, later comes the change -+ # It would be better to make this an attribute of `R`, but that leads to problems since -+ # we override `__getattr__`. -+ global _r_to_sage_converter -+ _r_to_sage_converter = _setup_r_to_sage_converter() - -- # This is the command that starts up your program -- # See #25806 for the --no-readline switch which fixes hangs for some -- command = "R --no-readline --vanilla --quiet", -- -- server=server, -- server_tmpdir=server_tmpdir, -- -- script_subdirectory = script_subdirectory, -- -- # If this is true, then whenever the user presses Control-C to -- # interrupt a calculation, the whole interface is restarted. -- restart_on_ctrlc = False, -- -- # If true, print out a message when starting -- # up the command when you first send a command -- # to this interface. -- verbose_start = False, -- -- logfile=logfile, -- -- # If an input is longer than this number of characters, then -- # try to switch to outputting to a file. -- eval_using_file_cutoff=1024) -- -- self.__seq = 0 -- self.__var_store_len = 0 -- self.__init_list_length = init_list_length -- self._prompt_wait = [self._prompt] - self._seed = seed -+ self._start() - - def set_seed(self, seed=None): - """ -@@ -391,14 +508,10 @@ class R(ExtraTabCompletion, Expect): - sage: r = R() - sage: r._start() - """ -- Expect._start(self) -- - # width is line width, what's a good value? maximum is 10000! - # pager needed to replace help view from less to printout - # option device= is for plotting, is set to x11, NULL would be better? -- self._change_prompt(PROMPT) -- self.eval('options(prompt=\"%s\",continue=\"%s\", width=100,pager="cat",device="png")'%(PROMPT, PROMPT)) -- self.expect().expect(PROMPT) -+ self.eval('options(width=100,pager="cat",device="png")') - self.eval('options(repos="%s")'%RRepositoryURL) - self.eval('options(CRAN="%s")'%RRepositoryURL) - -@@ -669,22 +782,17 @@ class R(ExtraTabCompletion, Expect): - ... - ImportError: ... - """ -- ret = self.eval('require("%s")' % library_name) -- if six.PY2: -- try: -- ret = ret.decode('utf-8') -- except UnicodeDecodeError: -- ret = ret.decode('latin-1') -- # try hard to parse the message string in a locale-independent way -- if ' library(' in ret: # locale-independent key-word -- raise ImportError("%s"%ret) -+ if robjects.packages.isinstalled(library_name): -+ robjects.packages.importr(library_name) - else: -- try: -- # We need to rebuild keywords! -- del self.__tab_completion -- except AttributeError: -- pass -- self._tab_completion(verbose=False, use_disk_cache=False) -+ raise ImportError("R library {} not installed".format(library_name)) -+ -+ try: -+ # We need to rebuild keywords! -+ del self.__tab_completion -+ except AttributeError: -+ pass -+ self._tab_completion(verbose=False, use_disk_cache=False) - - require = library #overwrites require - -@@ -789,17 +897,24 @@ class R(ExtraTabCompletion, Expect): - EXAMPLES:: - - sage: r.help('c') -- c package:base R Documentation -+ title -+ ----- -+ -+ Combine Values into a Vector or List -+ -+ name -+ ---- -+ -+ c - ... -- -- .. note:: -- -- This is similar to typing r.command?. - """ -- s = self.eval('help("%s")'%command).strip() # ?cmd is only an unsafe shortcut -+ s = robjects.help.pages(command)[0].to_docstring() -+ -+ # TODO what is this for? - import sage.plot.plot - if sage.plot.plot.EMBEDDED_MODE: - s = s.replace('_\x08','') -+ - return HelpExpression(s) - - def _assign_symbol(self): -@@ -914,9 +1029,19 @@ class R(ExtraTabCompletion, Expect): - '[1] 5' - """ - cmd = '%s <- %s'%(var,value) -- out = self.eval(cmd) -- if out.find("error") != -1: -- raise TypeError("Error executing code in R\nCODE:\n\t%s\nR ERROR:\n\t%s"%(cmd, out)) -+ # FIXME this is how it behaved before since the output was only compared to 'error' -+ # while the actual error message started with an upper-case 'Error'. -+ # The doctests rely on this when doing `loads(dumps(r('"abc"')))` which will load -+ # simply `"abc"` which will then again be set as `sage0 <- abc` (notice the missing -+ # quotes). The test will pass anyway because the identifier is reused for some reason. -+ # That means `sage0` will already be "abc" from the first `r('"abc"')` call. -+ from rpy2.rinterface import RRuntimeWarning, RRuntimeError -+ import warnings -+ warnings.filterwarnings("ignore", category = RRuntimeWarning) -+ try: -+ out = self.eval(cmd) -+ except RRuntimeError: -+ pass - - def get(self, var): - """ -@@ -934,9 +1059,20 @@ class R(ExtraTabCompletion, Expect): - sage: r.get('a') - '[1] 2' - """ -- s = self.eval('%s'%var) -- #return self._remove_indices_re.sub("", s).strip() -- return s -+ # FIXME again, this is how it behaved before. The doctest `L.hom(r, base_morphism=phi)` -+ # in sage/rings/function_field/function_field.py relies on this. It somehow ends up -+ # requesting a non-existant r object resulting in -+ # `RRuntimeError: Error in (function (expr, envir = parent.frame(), enclos = if (is.list(envir) || : -+ # object 'sage2' not found` -+ # I haven't figured out how or why it does that. -+ from rpy2.rinterface import RRuntimeWarning, RRuntimeError -+ import warnings -+ warnings.filterwarnings("ignore", category = RRuntimeWarning) -+ try: -+ s = self.eval('%s'%var) -+ return s -+ except RRuntimeError: -+ return '' - - def na(self): - """ -@@ -966,7 +1102,12 @@ class R(ExtraTabCompletion, Expect): - - sage: dummy = r._tab_completion(use_disk_cache=False) #clean doctest - sage: r.completions('tes') -- ['testInheritedMethods', 'testPlatformEquivalence', 'testVirtual'] -+ ['testInheritedMethods', -+ 'testInstalledBasic', -+ 'testInstalledPackage', -+ 'testInstalledPackages', -+ 'testPlatformEquivalence', -+ 'testVirtual'] - """ - return [name for name in self._tab_completion() if name[:len(s)] == s] - -@@ -986,8 +1127,7 @@ class R(ExtraTabCompletion, Expect): - """ - v = RBaseCommands - -- ll = self.eval('dput(search())') # loaded libs -- ll = self.convert_r_list(ll) -+ ll = self('search()')._sage_() # loaded libs - - for lib in ll: - if lib in RFilteredPackages: -@@ -996,9 +1136,7 @@ class R(ExtraTabCompletion, Expect): - if lib.find("package:") != 0: - continue #only packages - -- raw = self.eval('dput(objects("%s"))'%lib) -- raw = self.convert_r_list(raw) -- raw = [x.replace(".","_") for x in raw] -+ raw = self('objects("%s")'%lib)._sage_() - - #TODO are there others? many of them are shortcuts or - #should be done on another level, like selections in lists -@@ -1123,24 +1261,6 @@ class R(ExtraTabCompletion, Expect): - RFunction(self, 'plot')(*args, **kwds) - return RFunction(self, 'dev.off')() - -- def _strip_prompt(self, code): -- """ -- Remove the standard R prompt from the beginning of lines in code. -- -- INPUT: -- -- - code -- a string -- -- OUTPUT: a string -- -- EXAMPLES:: -- -- sage: s = '> a <- 2\n> b <- 3' -- sage: r._strip_prompt(s) -- ' a <- 2\n b <- 3' -- """ -- return prompt_re.sub("", code) -- - def eval(self, code, globals=None, locals=None, synchronize=True, *args, **kwds): - """ - Evaluates a command inside the R interpreter and returns the output -@@ -1151,9 +1271,8 @@ class R(ExtraTabCompletion, Expect): - sage: r.eval('1+1') - '[1] 2' - """ -- # TODO split code at ";" outside of quotes and send them as individual -- # lines without ";". -- return Expect.eval(self, code, synchronize=synchronize, *args, **kwds) -+ return str(robjects.r(code)).rstrip() -+ - - def _r_to_sage_name(self, s): - """ -@@ -1255,16 +1374,8 @@ class R(ExtraTabCompletion, Expect): - self.execute('setwd(%r)' % dir) - - --# patterns for _sage_() --rel_re_param = re.compile(r'\s([\w\.]+)\s=') --rel_re_range = re.compile(r'([\d]+):([\d]+)') --rel_re_integer = re.compile(r'([^\d])([\d]+)L') --rel_re_terms = re.compile(r'terms\s*=\s*(.*?),') --rel_re_call = re.compile(r'call\s*=\s*(.*?)\),') -- -- - @instancedoc --class RElement(ExtraTabCompletion, ExpectElement): -+class RElement(ExtraTabCompletion, InterfaceElement): - - def _tab_completion(self): - """ -@@ -1315,7 +1426,7 @@ class RElement(ExtraTabCompletion, ExpectElement): - sage: len(x) - 5 - """ -- return int(self.parent().eval('dput(length(%s))'%self.name())[:-1] ) -+ return self.parent()('length(%s)'%self.name())._sage_() - - def __getattr__(self, attrname): - """ -@@ -1777,95 +1888,9 @@ class RElement(ExtraTabCompletion, ExpectElement): - self._check_valid() - P = self.parent() - -- # This is the core of the trick: using dput -- # dput prints out the internal structure of R's data elements -- # options via .deparseOpts(control=...) -- # TODO: dput also works with a file, if things get huge! -- # [[However, using a file for output often isn't necessary -- # since pipe buffering works pretty well for output. -- # That said, benchmark this. -- William Stein]] -- exp = P.eval('dput(%s)'%self.name()) -- -- # Preprocess expression -- # example what this could be: -- # structure(list(statistic = structure(0.233549683248457, .Names = "t"), -- # parameter = structure(5.58461538461538, .Names = "df"), p.value = 0.823657802106985, -- # conf.int = structure(c(-2.41722062247400, 2.91722062247400 -- # ), conf.level = 0.95), estimate = structure(c(2.75, 2.5), .Names = c("mean of x", -- # "mean of y")), null.value = structure(0, .Names = "difference in means"), -- # alternative = "two.sided", method = "Welch Two Sample t-test", -- # data.name = "c(1, 2, 3, 5) and c(1, 2, 3, 4)"), .Names = c("statistic", -- # "parameter", "p.value", "conf.int", "estimate", "null.value", -- # "alternative", "method", "data.name"), class = "htest") -- -- # R's structure (from help): -- # structure(.Data, ...) -- # .Data: an object which will have various attributes attached to it. -- # ...: attributes, specified in 'tag=value' form, which will be -- # attached to data. -- #For historical reasons (these names are used when deparsing), -- # attributes '".Dim"', '".Dimnames"', '".Names"', '".Tsp"' and -- # '".Label"' are renamed to '"dim"', '"dimnames"', '"names"', -- # '"tsp"' and '"levels"'. -- -- -- -- # we want this in a single line -- exp.replace('\n','') -- exp = "".join(exp.split("\n")) -- -- # python compatible parameters -- exp = rel_re_param.sub(self._subs_dots, exp) -- -- # Rename class since it is a Python keyword -- exp = re.sub(' class = ', ' _r_class = ',exp) -- -- # Change 'structure' to '_r_structure' -- # TODO: check that we are outside of quotes "" -- exp = re.sub(r' structure\(', ' _r_structure(', exp) -- exp = re.sub(r'^structure\(', '_r_structure(', exp) # special case -- -- # Change 'list' to '_r_list' -- exp = re.sub(r' list\(', ' _r_list(', exp) -- exp = re.sub(r'\(list\(', '(_r_list(', exp) -- -- # Change 'a:b' to 'range(a,b+1)' -- exp = rel_re_range.sub(self._subs_range, exp) -- -- # Change 'dL' to 'Integer(d)' -- exp = rel_re_integer.sub(self._subs_integer, exp) -- -- # Wrap the right hand side of terms = ... in quotes since it -- # has a ~ in it. -- exp = rel_re_terms.sub(r'terms = "\1",', exp) -- -- -- # Change call = ..., to call = "...", -- exp = rel_re_call.sub(r'call = "\1",', exp) -- -- # seems to work for -- # rr = r.summary(r.princomp(r.matrix(r.c(1,2,3,4,3,4,1,2,2),4))) -- # rr._sage_() -- # but the call expression get's evaluated. why?!? TODO -- -- -- # translation: -- # c is an ordered list -- # list is a dictionary (where _Names give the entries names. -- # map entries in names to (value, name) in each entry? -- # structure is .. see above .. structure(DATA,**kw) -- # TODO: thinking of just replacing c( with ( to get a long tuple? -- -- -- exp = self._convert_nested_r_list(exp) -- -- # Set up the globals -- globs = {'NA':None, 'NULL':None, 'FALSE':False, 'TRUE':True, -- '_r_list':self._r_list, '_r_structure':self._r_structure, -- 'Integer':sage.rings.integer.Integer, -- 'character':str} -- -- return eval(exp, globs, globs) -+ with localconverter(_r_to_sage_converter) as cv: -+ parsed = robjects.r(self.name()) -+ return parsed - - - def _latex_(self): -@@ -1893,7 +1918,7 @@ class RElement(ExtraTabCompletion, ExpectElement): - - - @instancedoc --class RFunctionElement(FunctionElement): -+class RFunctionElement(InterfaceFunctionElement): - def __reduce__(self): - """ - EXAMPLES:: -@@ -1917,9 +1942,16 @@ class RFunctionElement(FunctionElement): - sage: a = r([1,2,3]) - sage: length = a.length - sage: print(length.__doc__) -- length package:base R Documentation -- ... -+ title -+ ----- -+ -+ Length of an Object -+ -+ name -+ ---- - -+ length -+ ... - """ - M = self._obj.parent() - return M.help(self._name) -@@ -1951,7 +1983,7 @@ class RFunctionElement(FunctionElement): - - - @instancedoc --class RFunction(ExpectFunction): -+class RFunction(InterfaceFunction): - def __init__(self, parent, name, r_name=None): - """ - A Function in the R interface. -@@ -2007,9 +2039,16 @@ class RFunction(ExpectFunction): - - sage: length = r.length - sage: print(length.__doc__) -- length package:base R Documentation -- ... -+ title -+ ----- -+ -+ Length of an Object - -+ name -+ ---- -+ -+ length -+ ... - """ - M = self._parent - return M.help(self._name) -diff --git a/src/sage/stats/r.py b/src/sage/stats/r.py -index cd2002559b..8a2f243901 100644 ---- a/src/sage/stats/r.py -+++ b/src/sage/stats/r.py -@@ -39,12 +39,12 @@ def ttest(x,y,conf_level = 0.95, **kw): - - Example:: - -- sage: a, b = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]); a -- 0.941026372027427 -+ sage: a, b = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]); a # abs tol 1e-12 -+ 0.9410263720274274 - """ - if len(x) != len(y): - raise AttributeError("vectors x and y must be of same length") - - test = myR.t_test(x,y,conf_level = conf_level, **kw)._sage_() -- t = test.get('DATA').get('p_value') -+ t = test.get('DATA').get('p.value') - return t, test From 95909d4fb6abdfc491ccfe6d478d1af17cf315c7 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Fri, 28 Dec 2018 22:46:10 +0100 Subject: [PATCH 13/13] Revert "sage: preload openblasCompat" This reverts commit 4900bbee179f393c447671424b5cab6e35c29bd3. The issue that was supposed to fix is now fixed by lazy-loading rpy2 and makign sure scipy is loaded before that. That is not quite as nice, but preloading is now causing its own issues with openblas 0.3.4: https://github.com/xianyi/OpenBLAS/issues/1936 --- .../science/math/sage/default.nix | 22 +++++++++++++++---- .../science/math/sage/sage-env.nix | 11 ---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix index 84cd5758acb2..dfdf210eec04 100644 --- a/pkgs/applications/science/math/sage/default.nix +++ b/pkgs/applications/science/math/sage/default.nix @@ -32,9 +32,8 @@ let # `sagelib`, i.e. all of sage except some wrappers and runtime dependencies sagelib = self.callPackage ./sagelib.nix { - inherit ecl; - inherit sage-src; - pynac = pkgs.pynac; # *not* python.pkgs.pynac + inherit flint ecl arb; + inherit sage-src pynac singular; linbox = pkgs.linbox.override { withSage = true; }; }; }; @@ -60,6 +59,7 @@ let # the files its looking fore are located. Also see `sage-env`. env-locations = callPackage ./env-locations.nix { inherit pari_data ecl; + inherit singular; cysignals = python.pkgs.cysignals; three = nodePackages.three; mathjax = nodePackages.mathjax; @@ -70,7 +70,7 @@ let sage-env = callPackage ./sage-env.nix { sagelib = python.pkgs.sagelib; inherit env-locations; - inherit python ecl palp pythonEnv; + inherit python ecl singular palp flint pynac pythonEnv; pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig }; @@ -84,6 +84,7 @@ let sage-with-env = callPackage ./sage-with-env.nix { inherit pythonEnv; inherit sage-env; + inherit pynac singular; pkg-config = pkgs.pkgconfig; # not to confuse with pythonPackages.pkgconfig three = nodePackages.three; }; @@ -123,6 +124,19 @@ let ignoreCollisions = true; } // { extraLibs = pythonRuntimeDeps; }; # make the libs accessible + arb = pkgs.arb.override { inherit flint; }; + + singular = pkgs.singular.override { inherit flint; }; + + # *not* to confuse with the python package "pynac" + pynac = pkgs.pynac.override { inherit singular flint; }; + + # With openblas (64 bit), the tests fail the same way as when sage is build with + # openblas instead of openblasCompat. Apparently other packages somehow use flints + # blas when it is available. Alternative would be to override flint to use + # openblasCompat. + flint = pkgs.flint.override { withBlas = false; }; + # Multiple palp dimensions need to be available and sage expects them all to be # in the same folder. palp = symlinkJoin { diff --git a/pkgs/applications/science/math/sage/sage-env.nix b/pkgs/applications/science/math/sage/sage-env.nix index c7f0a19f1768..7d4a66ea2b9c 100644 --- a/pkgs/applications/science/math/sage/sage-env.nix +++ b/pkgs/applications/science/math/sage/sage-env.nix @@ -163,17 +163,6 @@ writeTextFile rec { # for find_library export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular]}:$DYLD_LIBRARY_PATH" - - # Make sure the correct openblas library is picked up. Without this, sage - # can either end up using flints openblas (which is not openblasCopmat, thus - # leading to the issues described in https://trac.sagemath.org/ticket/26000) - # or R's blas, leading to the issues described in - # https://bitbucket.org/rpy2/rpy2/issues/491. - # The first issue could alternatively be solved by overriding flint's - # openblas dependency and the second one is effectively solved by loading - # rpy2 lazily in sage. Preloading explicitly makes all the headaches go - # away much easier and more future proof though. - export LD_PRELOAD="${openblasCompat}/lib/libopenblas.so:$LD_PRELOAD" ''; } // { lib = sagelib; # equivalent of `passthru`, which `writeTextFile` doesn't support