← 输入框|github.com|刷新
Skip to content

bugs with numpy.array #2089

Closed
Closed

Description

@rebcabin
  1. The error message mis-counts the number of arguments.
  2. The results do not match ordinary CPython.

MVE:

from lpython import (i8, i32, i64, f32, f64,
                     u8, u32,
                     TypeVar, Const,
                     dataclass)
from numpy import empty, sqrt, float32, float64, int8, array


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


def g() -> None:
    l2 : LPBHV_small = LPBHV_small(
        4,
        array([214, 157, 3, 146],dtype=int8))
        # [i8(214), i8(157), i8(3), i8(146)])


if __name__ == "__main__":
    print("Module HDC")
    print('')
    g()

runs:

(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s000)─┐
└─(14:19:03 on brian-lasr ✹)──> ~/CLionProjects/lpython/src/bin/lpython -I. issue2089.py                                                                  ──(Mon,Jul03)─┘
semantic error: array accepts only 1 argument for now, got 105553123855456 arguments instead.
  --> issue2089.py:17:9
   |
17 |         array([214, 157, 3, 146],dtype=int8))
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 


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).
(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s000)─┐
└─(14:19:11 on brian-lasr ✹)──> PYTHONPATH='../../src/runtime/lpython' python issue2089.py                                                            2 ↵ ──(Mon,Jul03)─┘
Module HDC

/Users/brian/CLionProjects/lpython/lasr/LP-pycharm/issue2089.py:17: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 214 to int8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)
will give the desired result (the cast overflows).
  array([214, 157, 3, 146],dtype=int8))
/Users/brian/CLionProjects/lpython/lasr/LP-pycharm/issue2089.py:17: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 157 to int8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)
will give the desired result (the cast overflows).
  array([214, 157, 3, 146],dtype=int8))
/Users/brian/CLionProjects/lpython/lasr/LP-pycharm/issue2089.py:17: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 146 to int8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)
will give the desired result (the cast overflows).
  array([214, 157, 3, 146],dtype=int8))

Activity

  1. added
    bug
    on Jul 3, 2023
  2. rebcabin commented on Jul 3, 2023

    @rebcabin
    ContributorAuthor

    A side comment: I do not see a way to write a literal array of i8. Will try some workarounds. I know I can set the elements individually.

  3. certik commented on Jul 3, 2023

    @certik
    Contributor

    The way to do it is array([214, 157, 3, 146],dtype=int8), which fails, so we need to fix it.

  4. rebcabin commented on Jul 3, 2023

    @rebcabin
    ContributorAuthor

    The following attempts do not work:

            i8[4](array([214, 157, 3, 146])))
            i8[:](array([214, 157, 3, 146])))
  5. self-assigned this
    on Jul 7, 2023
  6. certik commented on Aug 2, 2023

    @certik
    Contributor

    @czgdp1807 why don't you extend it to all the dtypes? It would be easy for you, since you did it for int8.

  7. czgdp1807 commented on Aug 2, 2023

    @czgdp1807
    Collaborator

    Sure. Let me fix lfortran/lfortran#2026 and then I will extend it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions