Skip to content
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

Test not failing consistently #1377

Closed
2 tasks
EmilyBourne opened this issue May 1, 2023 · 2 comments · Fixed by #1260
Closed
2 tasks

Test not failing consistently #1377

EmilyBourne opened this issue May 1, 2023 · 2 comments · Fixed by #1260
Assignees
Labels

Comments

@EmilyBourne
Copy link
Member

Describe the bug

We can see here that the test test_multi_return_array_scalar_op is (occasionally) failing when converting to Python. In the link this occurs on Python 3.7 however looking at the commit history we can see that this does not occur systematically. As described below, the bug is expected. It is therefore concerning that the test does not fail every time. We should find out why this is the case before fixing the bug

To Reproduce

Provide code to reproduce the behavior:

        @types('int8')
        @types('int16')
        @types('int32')
        @types('int64')
        @types('int')
        @types('float32')
        @types('float64')
        @types('float')
        @types('complex64')
        @types('complex128')
        def return_multi_array_scalar_op(a):
            from numpy import ones, int8, int16, int32, int64, float32, float64, complex64, complex128 #pylint: disable=unused-import
            x = ones(5, dtype=type(a))
            y = ones(5, dtype=type(a))
            return x * a, y * a

Error details

Provide the generated code:

from pyccel.decorators import types

@types('int8')
@types('int16')
@types('int32')
@types('int64')
@types('int')
@types('float32')
@types('float64')
@types('float')
@types('complex64')
@types('complex128')
def return_multi_array_scalar_op(a):
    from numpy import float64, int8, int64, int32, ones, float32, complex64, complex128, int16
    x = ones((5), dtype=int8)
    y = ones((5), dtype=int8)
    return x * a,y * a

We see that the dtype is now set to int8 instead of type(a). This is due to the poor handling of interfaces in the python translation as discussed in #802 and #1334. However the problem is avoidable here by propagating the PythonType instance to the printer instead of replacing it with the type in the semantic stage.

Expected behavior

Either the PythonType instance should be propagated to the printer instead of replacing it with the type in the semantic stage. Or if code duplication reduction is preferred then the test should be skipped with an appropriate reason.

Language

Python

Acceptance criteria

  • Find why the error was not reported consistently
  • Fix the bug
@EmilyBourne
Copy link
Member Author

It passes due to the multiplication x * a, y * a. x and y have the same type as the first type instruction (int8) so x * a promotes the result to the same type as a. This does not explain why the test sometimes fails with the wrong type.

The generated code is:

from pyccel.decorators import types

@types('int8')
@types('int16')
@types('int32')
@types('int64')
@types('int')
@types('float32')
@types('float64')
@types('float')
@types('complex64')
@types('complex128')
def return_multi_array_scalar_op(a : int):
    from numpy import ones, int32, int16, int8, float64, complex128, complex64, int64, float32
    x = ones((5), dtype=int8)
    y = ones((5), dtype=int8)
    return x * a,y * a

@EmilyBourne
Copy link
Member Author

@EmilyBourne EmilyBourne self-assigned this Aug 1, 2023
@EmilyBourne EmilyBourne linked a pull request Aug 1, 2023 that will close this issue
yguclu pushed a commit that referenced this issue Aug 15, 2023
Remove the duplicate `_print_NumpyArray` function from
PythonCodePrinter. The original `_print_NumpyArray` function is more
accurate as it specifies the `dtype` etc explicitly. Specifying the `dtype`
explicitly makes issue #1377 reproducible. To fix this problem support is
added for `a.dtype` expressions (Fixes #1421) using the similar function
[`np.result_type`](https://numpy.org/doc/stable/reference/generated/numpy.result_type.html).

The initialisation dtype is saved and used in the Python printer. This
is a work-around until #1334 is resolved well enough to define a clear
issue. Additionally a warning is raised if the Python code is not
consistent. Fixes #1377.

**Additional commits**
- Simplify bot linux/windows/macosx output to reduce duplication. Change
regex for C now that the test is no longer verbose.
- Stop generating `numpy.bool` in code as it has been deprecated by
NumPy. Instead use the default bool (with precision `-1`).
- Add support for NumPy's short type names.
- Reduce duplication in the Python printer.
- Remove outdated skips on tests.
- Stop array error tests failing in developer mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant