[pypy-commit] pypy numpy-refactor: ravel & flatten
fijal
noreply at buildbot.pypy.org
Wed Sep 5 22:08:52 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57162:95e1b5a22210
Date: 2012-09-05 22:08 +0200
http://bitbucket.org/pypy/pypy/changeset/95e1b5a22210/
Log: ravel & flatten
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
@@ -160,6 +160,25 @@
space.wrap(i)), "tolist"))
return space.newlist(l_w)
+ def descr_ravel(self, space, w_order=None):
+ if w_order is None or space.is_w(w_order, space.w_None):
+ order = 'C'
+ else:
+ order = space.str_w(w_order)
+ if order != 'C':
+ raise OperationError(space.w_NotImplementedError, space.wrap(
+ "order not implemented"))
+ return self.descr_reshape(space, [space.wrap(-1)])
+
+ def descr_flatten(self, space, w_order=None):
+ if self.is_scalar():
+ # scalars have no storage
+ return self.descr_reshape(space, [space.wrap(1)])
+ w_res = self.descr_ravel(space, w_order)
+ if w_res.implementation.storage == self.implementation.storage:
+ return w_res.descr_copy(space)
+ return w_res
+
# --------------------- operations ----------------------------
def _unaryop_impl(ufunc_name):
@@ -404,6 +423,8 @@
reshape = interp2app(W_NDimArray.descr_reshape),
T = GetSetProperty(W_NDimArray.descr_get_transpose),
tolist = interp2app(W_NDimArray.descr_tolist),
+ flatten = interp2app(W_NDimArray.descr_flatten),
+ ravel = interp2app(W_NDimArray.descr_ravel),
)
@unwrap_spec(ndmin=int, copy=bool, subok=bool)
More information about the pypy-commit
mailing list