numpy.greater_equal.outer uses stub from pypy's micronumpy and not numpy ufunc...

Create issue
Issue #48 resolved
M created an issue

EDIT: Simpler bug reproduction on the bottom of report. EDIT2: Found "real" problem, probably, see last comments.

Not works in: pypy 5.1.1 with numpy from https://bitbucket.org/pypy/numpy/ ( 2de5fffe8210079d591a132b6d9a82eb619d5967 )

Works in: normal numpy in python2 and python3

Error:

  File "lab4.py", line 12, in my_rq
    Q,R = numpy.linalg.qr(numpy.flipud(A).T)
  File "/usr/local/Cellar/pypy/5.1.1/libexec/site-packages/numpy/linalg/linalg.py", line 831, in qr
    return wrap(q), wrap(triu(r))
  File "/usr/local/Cellar/pypy/5.1.1/libexec/site-packages/numpy/lib/twodim_base.py", line 484, in triu
    mask = tri(*m.shape[-2:], k=k-1, dtype=bool)
  File "/usr/local/Cellar/pypy/5.1.1/libexec/site-packages/numpy/lib/twodim_base.py", line 415, in tri
    arange(-k, M-k, dtype=_min_int(-k, M - k)))
ValueError: outer product only supported for binary functions

Code:

def my_rq(A):
    Q,R = numpy.linalg.qr(numpy.flipud(A).T)
    R = numpy.flipud(R.T)
    Q = Q.T
    return R[:,::-1], Q[::-1,:]

This code generates RQ decomposition from numpy.linalg.qr decomposition.

A matrix:

[[ 0.45827554 -0.29474237 -0.01395746]
 [-0.05085589 -0.0545847  -0.54105993]
 [ 0.10900958  0.17834548 -0.04426782]]

This simple code works with normal python numpy, but not with pypy's numpy:

import numpy

a = numpy.arange(3)
b = numpy.arange(1,4)
print(a)
print(b)
print(numpy.greater_equal.outer(a,b))

Comments (15)

  1. M reporter

    numpy.flipud(A).T is the same in both versions, and equals:

    [[ 0.10900958 -0.05085589  0.45827554]
     [ 0.17834548 -0.0545847  -0.29474237]
     [-0.04426782 -0.54105993 -0.01395746]]
    

    So it has to be something wrong with numpy.linalg.qr, triu or tri.

  2. M reporter

    I've injected some prints into both numpies, and it seems r is the same in pypy version:

    [[-0.21365823 -0.04059207  0.00932179]
     [ 0.55272163  0.54466866  0.00130836]
     [-0.13719317  0.91389158  0.54497316]]
    

    Later I've injected into tri and this:

        print(N)
        print(-k)
        print(M-k)
        print(_min_int(0, N))
        print(_min_int(-k, M - k))
    

    gave the same output in both.

  3. M reporter
    print(arange(N, dtype=_min_int(0, N)),
                                arange(-k, M-k, dtype=_min_int(-k, M - k)))
    

    Injected into tri gives in both versions: [0 1 2] [1 2 3]

    so it must be a bug in greater_equal.outer

  4. M reporter

    It looks that numpy.ufunc outer is not defined in this numpy. And in pypy there is some stub ( why it's in pypy code and not here? ) that does only:

        def _outer(self, space, __args__):
            raise OperationError(space.w_ValueError, space.wrap(
                "outer product only supported for binary functions"))
    

    ( /module/micronumpy/ufuncs.py in pypy repo )

  5. M reporter

    There is outer() implemetation in core/src/umath/ufunc_object.c... Why then stub version from micronumpy is used and not this one?

  6. Log in to comment