Skip to content

Implement numpy.all #2136

Open
Open
@rebcabin

Description

@rebcabin

The following code passes CPython but not LPython:

from lpython import (i8, i32, i64, f32, f64,
                     dataclass
                     )
from numpy import (empty,
                   int8,
                   all,
                   )

r : i8 = i8(240)

@dataclass
class Foo:
    a : i8[4] = empty(4, dtype=int8)
    dim : i32 = 4

def trinary_majority(x : Foo, y : Foo, z : Foo) -> Foo:
    foo : Foo = Foo()

    # Issue 2132
    # assert foo.dim == x.dim == y.dim == z.dim

    assert foo.dim == x.dim
    assert x.dim == y.dim
    assert y.dim == z.dim

    i : i32
    for i in range(foo.dim):
        foo.a[i] = (x.a[i] & y.a[i]) | (y.a[i] & z.a[i]) | (z.a[i] & x.a[i])

    # Issue 2130
    # foo.a = x.a | y.a | z.a
    # foo.a = (x.a & y.a) | (y.a & z.a) | (z.a & x.a)
    return foo


t1 : Foo = Foo()
t1.a = empty(4, dtype=int8)

t2 : Foo = Foo()
t2.a = empty(4, dtype=int8)

t3 : Foo = Foo()
t3.a = empty(4, dtype=int8)

r1 : Foo = trinary_majority(t1, t2, t3)

assert all(r1.a == t1.a)

runs:

(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s012)─┐
└─(12:21:29 on brian-lasr ✹ ✭)──> PYTHONPATH='../../src/runtime/lpython' python issue2126.py                                                          1 ↵ ──(Sun,Jul09)─┘
(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s012)─┐
└─(12:28:00 on brian-lasr ✹ ✭)──> ~/CLionProjects/lpython/src/bin/lpython -I. issue2126.py                                                                ──(Sun,Jul09)─┘
semantic error: The symbol 'all' not found in the module 'numpy'
 --> issue2126.py:6:20
  |
6 |                    all,
  |                    ^^^ 


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that must be fixed).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions