[pypy-commit] pypy default: Move fromnumeric into core/ subdirectory to follow numpy's layout

2012-01-17 Thread mikefc
Author: mikefc
Branch: 
Changeset: r51428:e4314d54ea7f
Date: 2012-01-18 09:10 +1000
http://bitbucket.org/pypy/pypy/changeset/e4314d54ea7f/

Log:Move fromnumeric into core/ subdirectory to follow numpy's layout

diff --git a/lib_pypy/numpypy/__init__.py b/lib_pypy/numpypy/__init__.py
--- a/lib_pypy/numpypy/__init__.py
+++ b/lib_pypy/numpypy/__init__.py
@@ -1,2 +1,2 @@
 from _numpypy import *
-from .fromnumeric import *
+from .core import *
diff --git a/lib_pypy/numpypy/core/__init__.py 
b/lib_pypy/numpypy/core/__init__.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -0,0 +1,1 @@
+from .fromnumeric import *
diff --git a/lib_pypy/numpypy/fromnumeric.py 
b/lib_pypy/numpypy/core/fromnumeric.py
rename from lib_pypy/numpypy/fromnumeric.py
rename to lib_pypy/numpypy/core/fromnumeric.py
___
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add numpypy.transpose() function to call the array method

2012-01-17 Thread mikefc
Author: mikefc
Branch: 
Changeset: r51429:bc30fb8eed3e
Date: 2012-01-18 09:29 +1000
http://bitbucket.org/pypy/pypy/changeset/bc30fb8eed3e/

Log:Add numpypy.transpose() function to call the array method

diff --git a/lib_pypy/numpypy/core/fromnumeric.py 
b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -451,8 +451,11 @@
 (2, 1, 3)
 
 """
-raise NotImplemented('Waiting on interp level method')
-
+if axes is not None:
+raise NotImplementedError('No "axes" arg yet.')
+if not hasattr(a, 'T'):
+a = numpypy.array(a)
+return a.T
 
 def sort(a, axis=-1, kind='quicksort', order=None):
 """
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py 
b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -125,3 +125,13 @@
 assert reshape(a, (1, -1)).shape == (1, 105)
 assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
 assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
+
+def test_transpose(self):   
+from numpypy import arange, array, transpose, ones
+x = arange(4).reshape((2,2))
+assert (transpose(x) == array([[0, 2],[1, 3]])).all()
+# Once axes argument is implemented, add more tests
+raises(NotImplementedError, "transpose(x, axes=(1, 0, 2))")
+# x = ones((1, 2, 3))
+# assert transpose(x, (1, 0, 2)).shape == (2, 1, 3)
+
___
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Use the proper exception for NotImplementedError

2012-01-17 Thread mikefc
Author: mikefc
Branch: 
Changeset: r51430:07bd76d923fd
Date: 2012-01-18 09:32 +1000
http://bitbucket.org/pypy/pypy/changeset/07bd76d923fd/

Log:Use the proper exception for NotImplementedError

diff --git a/lib_pypy/numpypy/core/fromnumeric.py 
b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -85,7 +85,7 @@
 array([4, 3, 6])
 
 """
-raise NotImplemented('Waiting on interp level method')
+raise NotImplementedError('Waiting on interp level method')
 
 
 # not deprecated --- copy if necessary, view otherwise
@@ -273,7 +273,7 @@
 [-1, -2, -3, -4, -5]]])
 
 """
-raise NotImplemented('Waiting on interp level method')
+raise NotImplementedError('Waiting on interp level method')
 
 
 def repeat(a, repeats, axis=None):
@@ -315,7 +315,7 @@
[3, 4]])
 
 """
-raise NotImplemented('Waiting on interp level method')
+raise NotImplementedError('Waiting on interp level method')
 
 
 def put(a, ind, v, mode='raise'):
@@ -366,7 +366,7 @@
 array([ 0,  1,  2,  3, -5])
 
 """
-raise NotImplemented('Waiting on interp level method')
+raise NotImplementedError('Waiting on interp level method')
 
 
 def swapaxes(a, axis1, axis2):
@@ -410,7 +410,7 @@
 [3, 7]]])
 
 """
-raise NotImplemented('Waiting on interp level method')
+raise NotImplementedError('Waiting on interp level method')
 
 
 def transpose(a, axes=None):
@@ -556,7 +556,7 @@
   dtype=[('name', '|S10'), ('height', 'http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: small changes

2012-04-12 Thread mikefc
Author: Michael Cheng 
Branch: extradoc
Changeset: r4189:ea0070e7a081
Date: 2012-04-12 22:13 +1000
http://bitbucket.org/pypy/extradoc/changeset/ea0070e7a081/

Log:small changes

diff --git a/blog/draft/numpy-status-update-3.rst 
b/blog/draft/numpy-status-update-3.rst
--- a/blog/draft/numpy-status-update-3.rst
+++ b/blog/draft/numpy-status-update-3.rst
@@ -6,15 +6,15 @@
 A lot of things happened in March, like `pycon`_. I was also busy doing other
 things (pictured), so apologies for the late numpy status update.
 
-However, a lot of things have happened and numpy continues to be on of the
-main points of entry for hacking on PyPy. Apologies to all the people who's
+However, a lot of things have happened and numpy continues to be one of the
+main points of entry for hacking on PyPy. Apologies to all the people whose
 patches I don't review in timely manner, but seriously, you do **a lot** of
 work.
 
 The list of things is definitely not exhaustive, and I might be forgetting
 important contributions. In a loose order:
 
-* Matti Picus made ``out`` parameter working for a lot (but not all)
+* Matti Picus made ``out`` parameter work for a lot of (but not all)
   functions.
 
 * We merged record dtypes support. The only missing dtypes left are complex
___
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: more ToDos mentioned at end

2012-04-12 Thread mikefc
Author: Michael Cheng 
Branch: extradoc
Changeset: r4190:bfc2761330f2
Date: 2012-04-12 22:35 +1000
http://bitbucket.org/pypy/extradoc/changeset/bfc2761330f2/

Log:more ToDos mentioned at end

diff --git a/blog/draft/numpy-status-update-3.rst 
b/blog/draft/numpy-status-update-3.rst
--- a/blog/draft/numpy-status-update-3.rst
+++ b/blog/draft/numpy-status-update-3.rst
@@ -11,7 +11,7 @@
 patches I don't review in timely manner, but seriously, you do **a lot** of
 work.
 
-The list of things is definitely not exhaustive, and I might be forgetting
+This list of changes is definitely not exhaustive, and I might be forgetting
 important contributions. In a loose order:
 
 * Matti Picus made ``out`` parameter work for a lot of (but not all)
@@ -19,7 +19,7 @@
 
 * We merged record dtypes support. The only missing dtypes left are complex
   (important), datetime (less important) and object (which will probably
-  never be implemented).
+  never be implemented because XXX).
 
 * Taavi Burns and others implemented lots of details, including lots of ufuncs.
   On the completely unscientific measure of "implemented functions" on
@@ -37,7 +37,15 @@
 
   +
 
-Next step would be to just continue implementing missing features. Future
-is hard to predict, but we're not far off!
+Next step would be to just continue implementing missing features such as
+
+* specialised arrays i.e. masked arrays and matrixes
+
+* core modules such as ``fft``, ``linalg``, ``random``.  
+
+* numpy's testing framework
+
+The future is hard to predict, but we're not far off!
 
 .. _`pycon`: http://us.pycon.org
+.. _`numpypy status page`: http://buildbot.pypy.org/numpy-status/latest.html
___
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: swapaxes for numpypy

2012-04-14 Thread mikefc
Author: Michael Cheng 
Branch: 
Changeset: r54360:886d352cf776
Date: 2012-04-14 20:04 +1000
http://bitbucket.org/pypy/pypy/changeset/886d352cf776/

Log:swapaxes for numpypy

diff --git a/lib_pypy/numpypy/core/fromnumeric.py 
b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -411,7 +411,8 @@
 [3, 7]]])
 
 """
-raise NotImplementedError('Waiting on interp level method')
+swapaxes = a.swapaxes
+return swapaxes(axis1, axis2)
 
 
 def transpose(a, axes=None):
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -513,7 +513,30 @@
 arr = concrete.copy(space)
 arr.setshape(space, new_shape)
 return arr
-
+   
+@unwrap_spec(axis1=int, axis2=int)
+def descr_swapaxes(self, space, axis1, axis2):
+"""a.swapaxes(axis1, axis2)
+
+Return a view of the array with `axis1` and `axis2` interchanged.
+
+Refer to `numpy.swapaxes` for full documentation.
+
+See Also
+
+numpy.swapaxes : equivalent function
+"""
+concrete = self.get_concrete()
+shape = concrete.shape[:]
+strides = concrete.strides[:]
+backstrides = concrete.backstrides[:]
+shape[axis1], shape[axis2] = shape[axis2], shape[axis1]   
+strides[axis1], strides[axis2] = strides[axis2], strides[axis1]
+backstrides[axis1], backstrides[axis2] = backstrides[axis2], 
backstrides[axis1] 
+arr = W_NDimSlice(concrete.start, strides, 
+   backstrides, shape, concrete)
+return space.wrap(arr)   
+  
 def descr_tolist(self, space):
 if len(self.shape) == 0:
 assert isinstance(self, Scalar)
@@ -1412,6 +1435,7 @@
 copy = interp2app(BaseArray.descr_copy),
 flatten = interp2app(BaseArray.descr_flatten),
 reshape = interp2app(BaseArray.descr_reshape),
+swapaxes = interp2app(BaseArray.descr_swapaxes),
 tolist = interp2app(BaseArray.descr_tolist),
 take = interp2app(BaseArray.descr_take),
 compress = interp2app(BaseArray.descr_compress),
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1410,6 +1410,35 @@
 assert (array([1, 2]).repeat(2) == array([1, 1, 2, 2])).all()
 
 
+def test_swapaxes(self):
+from _numpypy import array
+# testcases from numpy docstring
+x = array([[1, 2, 3]])
+assert (x.swapaxes(0, 1) == array([[1], [2], [3]])).all() 
+x = array([[[0,1],[2,3]],[[4,5],[6,7]]]) # shape = (2, 2, 2)
+assert (x.swapaxes(0, 2) == array([[[0, 4], [2, 6]], 
+   [[1, 5], [3, 7]]])).all() 
+assert (x.swapaxes(0, 1) == array([[[0, 1], [4, 5]], 
+   [[2, 3], [6, 7]]])).all()
+assert (x.swapaxes(1, 2) == array([[[0, 2], [1, 3]], 
+   [[4, 6],[5, 7]]])).all()
+
+# more complex shape i.e. (2, 2, 3)
+x = array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) 
+assert (x.swapaxes(0, 1) == array([[[1, 2, 3], [7, 8, 9]], 
+   [[4, 5, 6], [10, 11, 12]]])).all() 
+assert (x.swapaxes(0, 2) == array([[[1, 7], [4, 10]], [[2, 8], [5, 
11]], 
+   [[3, 9], [6, 12]]])).all() 
+assert (x.swapaxes(1, 2) == array([[[1, 4], [2, 5], [3, 6]], 
+   [[7, 10], [8, 11],[9, 12]]])).all() 
+
+# test slice
+assert (x[0:1,0:2].swapaxes(0,2) == array([[[1], [4]], [[2], [5]], 
+   [[3], [6]]])).all()
+# test virtual
+assert ((x + x).swapaxes(0,1) == array([[[ 2,  4,  6], [14, 16, 18]], 
+ [[ 8, 10, 12], [20, 22, 24]]])).all()
+
 class AppTestMultiDim(BaseNumpyAppTest):
 def test_init(self):
 import _numpypy
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py 
b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -136,4 +136,11 @@
 raises(NotImplementedError, "transpose(x, axes=(1, 0, 2))")
 # x = ones((1, 2, 3))
 # assert transpose(x, (1, 0, 2)).shape == (2, 1, 3)
-
+
+def test_fromnumeric(self):
+from numpypy import array, swapaxes
+x = array([[1,2,3]])
+assert (swapaxes(x,0,1) == ar

[pypy-commit] pypy default: fix printing of complexfloats

2012-12-28 Thread mikefc
Author: Michael Cheng 
Branch: 
Changeset: r59614:99904a8649b1
Date: 2012-12-29 12:23 +1000
http://bitbucket.org/pypy/pypy/changeset/99904a8649b1/

Log:fix printing of complexfloats

diff --git a/lib_pypy/numpypy/core/arrayprint.py 
b/lib_pypy/numpypy/core/arrayprint.py
--- a/lib_pypy/numpypy/core/arrayprint.py
+++ b/lib_pypy/numpypy/core/arrayprint.py
@@ -248,9 +248,9 @@
   'int' : IntegerFormat(data),
   'float' : FloatFormat(data, precision, suppress_small),
   'longfloat' : LongFloatFormat(precision),
-  #'complexfloat' : ComplexFormat(data, precision,
-  #   suppress_small),
-  #'longcomplexfloat' : LongComplexFormat(precision),
+  'complexfloat' : ComplexFormat(data, precision,
+ suppress_small),
+  'longcomplexfloat' : LongComplexFormat(precision),
   'datetime' : DatetimeFormat(data),
   'timedelta' : TimedeltaFormat(data),
   'numpystr' : repr_format,
___
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit