summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/_import_tools.py4
-rw-r--r--numpy/core/defmatrix.py2
-rw-r--r--numpy/core/ma.py2
-rw-r--r--numpy/dft/fftpack.py12
-rw-r--r--numpy/dual.py9
-rw-r--r--numpy/lib/function_base.py104
-rw-r--r--numpy/lib/mlab.py9
-rw-r--r--numpy/lib/polynomial.py2
-rw-r--r--numpy/random/mtrand/mtrand.c4
-rw-r--r--numpy/random/mtrand/mtrand.pyx4
10 files changed, 121 insertions, 31 deletions
diff --git a/numpy/_import_tools.py b/numpy/_import_tools.py
index 3139c1d63..6a08e00b0 100644
--- a/numpy/_import_tools.py
+++ b/numpy/_import_tools.py
@@ -264,12 +264,12 @@ class PackageLoader:
This function is intended to shorten the need to import many of numpy's
submodules constantly with statements such as
- import numpy.linalg, numpy.fft, numpy.etc...
+ import numpy.linalg, numpy.dft, numpy.etc...
Instead, you can say:
import numpy
- numpy.pkgload('linalg','fft',...)
+ numpy.pkgload('linalg','dft',...)
or
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py
index 547bfe493..a3f161384 100644
--- a/numpy/core/defmatrix.py
+++ b/numpy/core/defmatrix.py
@@ -199,7 +199,7 @@ class matrix(N.ndarray):
return self.transpose()
def getI(self):
- from numpy.linalg import inv
+ from numpy.dual import inv
return matrix(inv(self))
A = property(getA, None, doc="base array")
diff --git a/numpy/core/ma.py b/numpy/core/ma.py
index f32c21d48..ded2be698 100644
--- a/numpy/core/ma.py
+++ b/numpy/core/ma.py
@@ -822,7 +822,7 @@ array(data = %(data)s,
"""
# XXX: This changes bool conversion logic from MA.
- # XXX: In MA bool(a) == len(a) != 0, but in scipy
+ # XXX: In MA bool(a) == len(a) != 0, but in numpy
# XXX: scalars do not have len
m = self._mask
d = self._data
diff --git a/numpy/dft/fftpack.py b/numpy/dft/fftpack.py
index 2cd3d8f8a..c5bb085e2 100644
--- a/numpy/dft/fftpack.py
+++ b/numpy/dft/fftpack.py
@@ -19,12 +19,12 @@ inverse_fft2d(a, s=None, axes=(-2, -1))
real_fft2d(a, s=None, axes=(-2,-1))
inverse_real_fft2d(a, s=None, axes=(-2, -1))
"""
-__all__ = ['fft','inverse_fft', 'ifft', 'real_fft', 'refft', 'inverse_real_fft',
- 'irefft', 'hfft', 'ihfft', 'refftn', 'irefftn', 'refft2', 'irefft2',
- 'fft2', 'ifft2',
- 'hermite_fft','inverse_hermite_fft','fftnd','inverse_fftnd','fft2d',
- 'inverse_fft2d', 'real_fftnd', 'real_fft2d', 'inverse_real_fftnd',
- 'inverse_real_fft2d',]
+__all__ = ['fft','inverse_fft', 'ifft', 'real_fft', 'refft',
+ 'inverse_real_fft', 'irefft', 'hfft', 'ihfft', 'refftn',
+ 'irefftn', 'refft2', 'irefft2', 'fft2', 'ifft2',
+ 'hermite_fft','inverse_hermite_fft','fftnd','inverse_fftnd',
+ 'fft2d', 'inverse_fft2d', 'real_fftnd', 'real_fft2d',
+ 'inverse_real_fftnd', 'inverse_real_fft2d','fftn','ifftn']
from numpy.core import *
import fftpack_lite as fftpack
diff --git a/numpy/dual.py b/numpy/dual.py
index ad516e7a4..32baa020e 100644
--- a/numpy/dual.py
+++ b/numpy/dual.py
@@ -5,7 +5,7 @@
__all__ = ['fft','ifft','fftn','ifftn','fft2','ifft2',
'inv','svd','solve','det','eig','eigvals','lstsq',
- 'pinv','cholesky']
+ 'pinv','cholesky','i0']
try:
import scipy.linalg as linpkg
@@ -17,6 +17,10 @@ try:
except ImportError:
import numpy.dft as fftpkg
+try:
+ from scipy.special import i0
+except ImportError:
+ from numpy.lib import i0
fft = fftpkg.fft
ifft = fftpkg.ifft
@@ -35,6 +39,3 @@ lstsq = linpkg.lstsq
pinv = linpkg.pinv
cholesky = linpkg.cholesky
-del linpkg
-del fftpkg
-
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 71d46e843..d1166d2c7 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -7,16 +7,17 @@ l__all__ = ['logspace', 'linspace',
'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',
'histogram', 'bincount', 'digitize', 'cov', 'corrcoef', 'msort',
'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',
- 'kaiser', 'trapz'
+ 'kaiser', 'trapz', 'i0'
]
import types
import math
import numpy.core.numeric as _nx
-from numpy.core.numeric import ones, zeros, arange, concatenate, array, asarray, empty
+from numpy.core.numeric import ones, zeros, arange, concatenate, array, \
+ asarray, empty, empty_like
from numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar
-from numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \
- isnan, absolute, cos, less_equal, sqrt, sin, mod
+from numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, \
+ frompyfunc, isnan, absolute, cos, less_equal, sqrt, sin, mod, exp
from numpy.core.oldnumeric import ravel, nonzero, choose, \
sometrue, alltrue, reshape, any, all, typecodes, ArrayType, squeeze,\
sort
@@ -167,9 +168,6 @@ def asarray_chkfinite(a):
raise ValueError, "array must not contain infs or NaNs"
return a
-
-
-
def piecewise(x, condlist, funclist, *args, **kw):
"""Return a piecewise-defined function.
@@ -694,12 +692,102 @@ def hamming(M):
n = arange(0,M)
return 0.54-0.46*cos(2.0*pi*n/(M-1))
+## Code from cephes for i0
+
+_i0A = [
+-4.41534164647933937950E-18,
+ 3.33079451882223809783E-17,
+-2.43127984654795469359E-16,
+ 1.71539128555513303061E-15,
+-1.16853328779934516808E-14,
+ 7.67618549860493561688E-14,
+-4.85644678311192946090E-13,
+ 2.95505266312963983461E-12,
+-1.72682629144155570723E-11,
+ 9.67580903537323691224E-11,
+-5.18979560163526290666E-10,
+ 2.65982372468238665035E-9,
+-1.30002500998624804212E-8,
+ 6.04699502254191894932E-8,
+-2.67079385394061173391E-7,
+ 1.11738753912010371815E-6,
+-4.41673835845875056359E-6,
+ 1.64484480707288970893E-5,
+-5.75419501008210370398E-5,
+ 1.88502885095841655729E-4,
+-5.76375574538582365885E-4,
+ 1.63947561694133579842E-3,
+-4.32430999505057594430E-3,
+ 1.05464603945949983183E-2,
+-2.37374148058994688156E-2,
+ 4.93052842396707084878E-2,
+-9.49010970480476444210E-2,
+ 1.71620901522208775349E-1,
+-3.04682672343198398683E-1,
+ 6.76795274409476084995E-1]
+
+_i0B = [
+-7.23318048787475395456E-18,
+-4.83050448594418207126E-18,
+ 4.46562142029675999901E-17,
+ 3.46122286769746109310E-17,
+-2.82762398051658348494E-16,
+-3.42548561967721913462E-16,
+ 1.77256013305652638360E-15,
+ 3.81168066935262242075E-15,
+-9.55484669882830764870E-15,
+-4.15056934728722208663E-14,
+ 1.54008621752140982691E-14,
+ 3.85277838274214270114E-13,
+ 7.18012445138366623367E-13,
+-1.79417853150680611778E-12,
+-1.32158118404477131188E-11,
+-3.14991652796324136454E-11,
+ 1.18891471078464383424E-11,
+ 4.94060238822496958910E-10,
+ 3.39623202570838634515E-9,
+ 2.26666899049817806459E-8,
+ 2.04891858946906374183E-7,
+ 2.89137052083475648297E-6,
+ 6.88975834691682398426E-5,
+ 3.36911647825569408990E-3,
+ 8.04490411014108831608E-1]
+
+def _chbevl(x, vals):
+ b0 = vals[0]
+ b1 = 0.0
+
+ for i in xrange(1,len(vals)):
+ b2 = b1
+ b1 = b0
+ b0 = x*b1 - b2 + vals[i]
+
+ return 0.5*(b0 - b2)
+
+
+def _i0_1(x):
+ return exp(x) * _chbevl(x/2.0-2, _i0A)
+
+def _i0_2(x):
+ return exp(x) * _chbevl(32.0/x - 2.0, _i0B) / sqrt(x)
+
+def i0(x):
+ x = atleast_1d(x)
+ y = empty_like(x)
+ ind = (x<0)
+ x[ind] = -x[ind]
+ ind = (x<=8.0)
+ y[ind] = _i0_1(x[ind])
+ ind2 = ~ind
+ y[ind2] = _i0_2(x[ind2])
+ return y.squeeze()
+
def kaiser(M,beta):
"""kaiser(M, beta) returns a Kaiser window of length M with shape parameter
beta. It depends on numpy.special (in full numpy) for the modified bessel
function i0.
"""
- from numpy.special import i0
+ from numpy.dual import i0
n = arange(0,M)
alpha = (M-1)/2.0
return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)
diff --git a/numpy/lib/mlab.py b/numpy/lib/mlab.py
index 5a04fe589..cb634b826 100644
--- a/numpy/lib/mlab.py
+++ b/numpy/lib/mlab.py
@@ -5,10 +5,11 @@ from numpy.core.numeric import *
from twodim_base import eye, tri, diag, fliplr, flipud, rot90, tril, triu
from numpy.core.oldnumeric import amax as max
from numpy.core.oldnumeric import amin as min
-from function_base import msort, median, trapz, diff, cov, corrcoef, kaiser, blackman, \
- bartlett, hanning, hamming, sinc, angle
-from numpy.core.oldnumeric import cumsum, ptp, mean, std, prod, cumprod, squeeze
+from function_base import msort, median, trapz, diff, cov, corrcoef, \
+ kaiser, blackman, bartlett, hanning, hamming, sinc, angle
+from numpy.core.oldnumeric import cumsum, ptp, mean, std, prod, cumprod, \
+ squeeze
from polynomial import roots
from numpy.random import rand, randn
-from numpy.linalg import eig, svd
+from numpy.dual import eig, svd
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index 62d195c8a..83e919263 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -19,7 +19,7 @@ lstsq = None
def get_linalg_funcs():
"Look for linear algebra functions in numpy"
global eigvals, lstsq
- from numpy.linalg import eigvals, lstsq
+ from numpy.dual import eigvals, lstsq
return
def _eigvals(arg):
diff --git a/numpy/random/mtrand/mtrand.c b/numpy/random/mtrand/mtrand.c
index a6038c069..2ea2049b8 100644
--- a/numpy/random/mtrand/mtrand.c
+++ b/numpy/random/mtrand/mtrand.c
@@ -1,4 +1,4 @@
-/* Generated by Pyrex 0.9.3.1 on Wed Jan 4 20:21:15 2006 */
+/* Generated by Pyrex 0.9.3.1 on Thu Jan 5 00:40:10 2006 */
#include "Python.h"
#include "structmember.h"
@@ -3942,7 +3942,7 @@ static PyObject *__pyx_k115p;
static char (__pyx_k112[]) = "mean must be 1 dimensional";
static char (__pyx_k113[]) = "cov must be 2 dimensional and square";
static char (__pyx_k114[]) = "mean and cov must have same length";
-static char (__pyx_k115[]) = "numpy.linalg";
+static char (__pyx_k115[]) = "numpy.dual";
static PyObject *__pyx_f_6mtrand_11RandomState_multivariate_normal(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6mtrand_11RandomState_multivariate_normal[] = "Return an array containing multivariate normally distributed random numbers\n with specified mean and covariance.\n\n multivariate_normal(mean, cov) -> random values\n multivariate_normal(mean, cov, [m, n, ...]) -> random values\n\n mean must be a 1 dimensional array. cov must be a square two dimensional\n array with the same number of rows and columns as mean has elements.\n\n The first form returns a single 1-D array containing a multivariate\n normal.\n\n The second form returns an array of shape (m, n, ..., cov.shape[0]).\n In this case, output[i,j,...,:] is a 1-D array containing a multivariate\n normal.\n ";
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index 89256fcf6..4f8bd3057 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -832,8 +832,8 @@ cdef class RandomState:
# Then the matrix products of the rows of x and A has the desired
# covariance. Note that sqrt(s)*v where (u,s,v) is the singular value
# decomposition of cov is such an A.
-
- from numpy.linalg import svd
+
+ from numpy.dual import svd
# XXX: we really should be doing this by Cholesky decomposition
(u,s,v) = svd(cov)
x = _sp.matrixmultiply(x*_sp.sqrt(s),v)