[Numpy-svn] r2952 - in trunk/numpy: . core core/blasdot lib/tests oldnumeric
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri Aug 4 14:47:32 EDT 2006
Author: oliphant
Date: 2006-08-04 13:47:25 -0500 (Fri, 04 Aug 2006)
New Revision: 2952
Modified:
trunk/numpy/add_newdocs.py
trunk/numpy/core/blasdot/_dotblas.c
trunk/numpy/core/fromnumeric.py
trunk/numpy/core/numeric.py
trunk/numpy/lib/tests/test_function_base.py
trunk/numpy/oldnumeric/__init__.py
trunk/numpy/oldnumeric/compat.py
Log:
Convert so that axis arguments are consistent for methods and functions. Place functions for which this changes the Numeric default into oldnumeric.
Modified: trunk/numpy/add_newdocs.py
===================================================================
--- trunk/numpy/add_newdocs.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/add_newdocs.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -226,7 +226,7 @@
""")
add_newdoc('numpy.core.multiarray','concatenate',
-"""concatenate((a1, a2, ...), axis=None)
+"""concatenate((a1, a2, ...), axis=0)
Join arrays together.
Modified: trunk/numpy/core/blasdot/_dotblas.c
===================================================================
--- trunk/numpy/core/blasdot/_dotblas.c 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/core/blasdot/_dotblas.c 2006-08-04 18:47:25 UTC (rev 2952)
@@ -172,7 +172,7 @@
}
-static char doc_matrixproduct[] = "matrixproduct(a,b)\nReturns the dot product of a and b for arrays of floating point types.\nLike the generic numpy equivalent the product sum is over\nthe last dimension of a and the second-to-last dimension of b.\nNB: The first argument is not conjugated.";
+static char doc_matrixproduct[] = "dot(a,b)\nReturns the dot product of a and b for arrays of floating point types.\nLike the generic numpy equivalent the product sum is over\nthe last dimension of a and the second-to-last dimension of b.\nNB: The first argument is not conjugated.";
static PyObject *
dotblas_matrixproduct(PyObject *dummy, PyObject *args)
Modified: trunk/numpy/core/fromnumeric.py
===================================================================
--- trunk/numpy/core/fromnumeric.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/core/fromnumeric.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -1,8 +1,7 @@
# Module containing non-deprecated functions borrowed from Numeric.
-__all__ = ['asarray', 'array', 'concatenate',
- # functions that are now methods
- 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',
+# functions that are now methods
+__all__ = ['take', 'reshape', 'choose', 'repeat', 'put', 'putmask',
'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',
'searchsorted', 'alen',
'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',
@@ -44,7 +43,7 @@
result = wrap(result)
return result
-def take(a, indices, axis=0):
+def take(a, indices, axis=None):
try:
take = a.take
except AttributeError:
@@ -53,8 +52,8 @@
# not deprecated --- copy if necessary, view otherwise
def reshape(a, newshape, order='C'):
- """Change the shape of a to newshape. Return a new view object if possible
- otherwise return a copy.
+ """Change the shape of a to newshape.
+ Return a new view object if possible otherwise return a copy.
"""
try:
reshape = a.reshape
@@ -69,7 +68,7 @@
return _wrapit(a, 'choose', choices)
return choose(choices)
-def repeat(a, repeats, axis=0):
+def repeat(a, repeats, axis=None):
"""repeat elements of a repeats times along axis
repeats is a sequence of length a.shape[axis]
telling how many times to repeat each element.
@@ -222,7 +221,6 @@
"""
return asarray(a).trace(offset, axis1, axis2, dtype)
-# not deprecated --- always returns a 1-d array. Copy-if-necessary.
def ravel(m,order='C'):
"""ravel(m) returns a 1d array corresponding to all the elements of it's
argument. The new array is a view of m if possible, otherwise it is
@@ -279,7 +277,7 @@
return _wrapit(m, 'clip', m_min, m_max)
return clip(m_min, m_max)
-def sum(x, axis=0, dtype=None):
+def sum(x, axis=None, dtype=None):
"""Sum the array over the given axis. The optional dtype argument
is the data type for intermediate calculations.
@@ -308,7 +306,7 @@
return _wrapit(x, 'sum', axis, dtype)
return sum(axis, dtype)
-def product (x, axis=0, dtype=None):
+def product (x, axis=None, dtype=None):
"""Product of the array elements over the given axis."""
try:
prod = x.prod
@@ -316,7 +314,7 @@
return _wrapit(x, 'prod', axis, dtype)
return prod(axis, dtype)
-def sometrue (x, axis=0):
+def sometrue (x, axis=None):
"""Perform a logical_or over the given axis."""
try:
any = x.any
@@ -324,7 +322,7 @@
return _wrapit(x, 'any', axis)
return any(axis)
-def alltrue (x, axis=0):
+def alltrue (x, axis=None):
"""Perform a logical_and over the given axis."""
try:
all = x.all
@@ -350,7 +348,7 @@
return _wrapit(x, 'all', axis)
return all(axis)
-def cumsum (x, axis=0, dtype=None):
+def cumsum (x, axis=None, dtype=None):
"""Sum the array over the given axis."""
try:
cumsum = x.cumsum
@@ -358,7 +356,7 @@
return _wrapit(x, 'cumsum', axis, dtype)
return cumsum(axis, dtype)
-def cumproduct (x, axis=0, dtype=None):
+def cumproduct (x, axis=None, dtype=None):
"""Sum the array over the given axis."""
try:
cumprod = x.cumprod
@@ -366,7 +364,7 @@
return _wrapit(x, 'cumprod', axis, dtype)
return cumprod(axis, dtype)
-def ptp(a, axis=0):
+def ptp(a, axis=None):
"""Return maximum - minimum along the the given dimension
"""
try:
@@ -375,7 +373,7 @@
return _wrapit(a, 'ptp', axis)
return ptp(axis)
-def amax(a, axis=0):
+def amax(a, axis=None):
"""Return the maximum of 'a' along dimension axis.
"""
try:
@@ -384,7 +382,7 @@
return _wrapit(a, 'max', axis)
return max(axis)
-def amin(a, axis=0):
+def amin(a, axis=None):
"""Return the minimum of a along dimension axis.
"""
try:
@@ -402,7 +400,7 @@
except TypeError:
return len(array(a,ndmin=1))
-def prod(a, axis=0, dtype=None):
+def prod(a, axis=None, dtype=None):
"""Return the product of the elements along the given axis
"""
try:
@@ -411,7 +409,7 @@
return _wrapit(a, 'prod', axis, dtype)
return prod(axis, dtype)
-def cumprod(a, axis=0, dtype=None):
+def cumprod(a, axis=None, dtype=None):
"""Return the cumulative product of the elments along the given axis
"""
try:
@@ -463,8 +461,8 @@
around = round_
-def mean(a, axis=0, dtype=None):
- """mean(a, axis=0, dtype=None)
+def mean(a, axis=None, dtype=None):
+ """mean(a, axis=None, dtype=None)
Return the arithmetic mean.
The mean is the sum of the elements divided by the number of elements.
@@ -477,8 +475,8 @@
return _wrapit(a, 'mean', axis, dtype)
return mean(axis, dtype)
-def std(a, axis=0, dtype=None):
- """std(sample, axis=0, dtype=None)
+def std(a, axis=None, dtype=None):
+ """std(sample, axis=None, dtype=None)
Return the standard deviation, a measure of the spread of a distribution.
The standard deviation is the square root of the average of the squared
@@ -492,8 +490,8 @@
return _wrapit(a, 'std', axis, dtype)
return std(axis, dtype)
-def var(a, axis=0, dtype=None):
- """var(sample, axis=0, dtype=None)
+def var(a, axis=None, dtype=None):
+ """var(sample, axis=None, dtype=None)
Return the variance, a measure of the spread of a distribution.
The variance is the average of the squared deviations from the mean,
Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/core/numeric.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -323,7 +323,6 @@
set_string_function(array_str, 0)
set_string_function(array_repr, 1)
-
little_endian = (sys.byteorder == 'little')
def indices(dimensions, dtype=int):
@@ -337,7 +336,7 @@
return array(lst)
def fromfunction(function, dimensions, **kwargs):
- """fromfunction(function, dimensions) returns an array constructed by
+ """fromfunction(function, dimensions, dtype=int) returns an array constructed by
calling function on a tuple of number grids. The function should
accept as many arguments as there are dimensions which is a list of
numbers indicating the length of the desired output for each axis.
@@ -345,7 +344,8 @@
The function can also accept keyword arguments which will be
passed in as well.
"""
- args = indices(dimensions)
+ dtype = kwargs.get('dtype', int)
+ args = indices(dimensions,dtype=dtype)
return function(*args,**kwargs)
def isscalar(num):
Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/lib/tests/test_function_base.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -20,7 +20,7 @@
def check_nd(self):
y1 = [[0,0,0],[0,1,0],[1,1,0]]
assert(any(y1))
- assert_array_equal(sometrue(y1),[1,1,0])
+ assert_array_equal(sometrue(y1,axis=0),[1,1,0])
assert_array_equal(sometrue(y1,axis=1),[0,1,1])
class test_all(NumpyTestCase):
@@ -36,7 +36,7 @@
def check_nd(self):
y1 = [[0,0,1],[0,1,1],[1,1,1]]
assert(not all(y1))
- assert_array_equal(alltrue(y1),[0,0,1])
+ assert_array_equal(alltrue(y1,axis=0),[0,0,1])
assert_array_equal(alltrue(y1,axis=1),[0,0,1])
class test_average(NumpyTestCase):
Modified: trunk/numpy/oldnumeric/__init__.py
===================================================================
--- trunk/numpy/oldnumeric/__init__.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/oldnumeric/__init__.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -2,20 +2,32 @@
from numpy import *
from compat import *
from olddefaults import *
+from typeconv import *
+from functions import *
import numpy
import compat
import olddefaults
+import typeconv
+import functions
__version__ = numpy.__version__
__all__ = ['__version__']
__all__ += numpy.__all__
__all__ += compat.__all__
+__all__ += typeconv.__all__
for name in olddefaults.__all__:
if name not in __all__:
__all__.append(name)
+for name in functions.__all__:
+ if name not in __all__:
+ __all__.apend(name)
+
+del name
del numpy
del compat
del olddefaults
+del functions
+del typeconv
Modified: trunk/numpy/oldnumeric/compat.py
===================================================================
--- trunk/numpy/oldnumeric/compat.py 2006-08-03 23:37:00 UTC (rev 2951)
+++ trunk/numpy/oldnumeric/compat.py 2006-08-04 18:47:25 UTC (rev 2952)
@@ -7,7 +7,7 @@
'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger',
# UnsignedInt64 and Unsigned128 added below if possible
# same for Int64 and Int128, Float128, and Complex128
- 'Int8', 'Int16', 'Int32',
+ 'Int8', 'Int16', 'Int32',
'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',
'PyObject', 'Float32', 'Float64', 'Float16', 'Float8',
'Complex32', 'Complex64', 'Complex8', 'Complex16',
@@ -19,6 +19,7 @@
'dump', 'dumps'
]
+
import numpy.core.multiarray as mu
import numpy.core.umath as um
import numpy.core.numerictypes as nt
@@ -38,6 +39,7 @@
def sarray(a, dtype=None, copy=False):
return array(a, dtype, copy)
+
#Use this to add a new axis to an array
#compatibility only
NewAxis = None
More information about the Numpy-svn
mailing list