-
Notifications
You must be signed in to change notification settings - Fork 171
Support array comparison #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support array comparison #2157
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from lpython import i32, Const | ||
from numpy import empty, int32 | ||
|
||
def main0(): | ||
n: Const[i32] = 1 | ||
x: i32[n, n] = empty([n, n], dtype=int32) | ||
y: i32[n, n] = empty([n, n], dtype=int32) | ||
|
||
x[0, 0] = -10 | ||
y[0, 0] = -10 | ||
|
||
print(x[0, 0], y[0, 0]) | ||
assert x == y | ||
|
||
y[0, 0] = 10 | ||
print(x[0, 0], y[0, 0]) | ||
assert x != y | ||
|
||
main0() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from lpython import (i8, i32, dataclass) | ||
from numpy import (empty, int8) | ||
|
||
@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() | ||
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]) | ||
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 r1.a == t1.a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-arrays_02-da94458", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/arrays_02.py", | ||
"infile_hash": "05e70a0056dc67dbf3a54ea66965db8746f9de012561ca95cb1fdb43", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-arrays_02-da94458.stderr", | ||
"stderr_hash": "dc0e5be7cd6de7395421aedf1ce11977206f3e35bb7cba271aed8992", | ||
"returncode": 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() | ||
--> tests/errors/arrays_02.py:28:8 | ||
| | ||
28 | assert r1.a == t1.a | ||
| ^^^^^^^^^^^^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here, we do not have access to the string Shall we do the following?
Or shall we keep the message as it is currently in the main branch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have access to AST and partial ASR, so we should be able to construct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this #2159, so that we don't forget. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this: