[pypy-commit] pypy numpy-refactor: ones

fijal noreply at buildbot.pypy.org
Thu Aug 30 15:47:23 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r56940:55d7e959b3d5
Date: 2012-08-30 15:46 +0200
http://bitbucket.org/pypy/pypy/changeset/55d7e959b3d5/

Log:	ones

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -68,6 +68,9 @@
     def setitem(self, index, value):
         self.dtype.setitem(self, index, value)
 
+    def fill(self, box):
+        self.dtype.fill(self.storage, box, 0, self.size)
+
     # -------------------- applevel get/setitem -----------------------
 
     @jit.unroll_safe
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
@@ -69,6 +69,9 @@
     def is_scalar(self):
         return self.implementation.is_scalar()
 
+    def fill(self, box):
+        self.implementation.fill(box)
+
     def descr_get_size(self, space):
         return space.wrap(support.product(self.implementation.get_shape()))
 
@@ -182,8 +185,19 @@
         return scalar_w(space, dtype, space.wrap(0))
     return space.wrap(W_NDimArray(shape, dtype=dtype, order=order))
 
-def ones(space):
-    pass
+ at unwrap_spec(order=str)
+def ones(space, w_shape, w_dtype=None, order='C'):
+    dtype = space.interp_w(interp_dtype.W_Dtype,
+        space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)
+    )
+    shape = _find_shape(space, w_shape)
+    if not shape:
+        return scalar_w(space, dtype, space.wrap(0))
+    arr = W_NDimArray(shape, dtype=dtype, order=order)
+    one = dtype.box(1)
+    arr.fill(one)
+    return space.wrap(arr)
+
 
 def dot(space):
     pass


More information about the pypy-commit mailing list