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

feat(numpy backend): removed manual dtype casting. #23681

Merged
merged 2 commits into from
Sep 18, 2023
Merged

feat(numpy backend): removed manual dtype casting. #23681

merged 2 commits into from
Sep 18, 2023

Conversation

Madjid-CH
Copy link
Contributor

PR Description

used script for dtypes checking:

import numpy as np

dtypes = [
    np.dtype("int8"),
    np.dtype("int16"),
    np.dtype("int32"),
    np.dtype("int64"),
    np.dtype("uint8"),
    np.dtype("uint16"),
    np.dtype("uint32"),
    np.dtype("uint64"),
    np.dtype("float16"),
    np.dtype("float32"),
    np.dtype("float64"),
    np.dtype("complex64"),
    np.dtype("complex128"),
    np.dtype("bool"),
]


def get_supported_and_unsupported_dtypes():
    supported_dtypes = set()
    unsupported_dtypes = set()

    for dtype in dtypes:
        try:
            x = np.array(
                [[1, 2], [2, 1]],
                dtype=dtype,
            )
            x1 = np.array([1, 1, 1], dtype=dtype)
            x2 = np.array([1, 2, 3], dtype=dtype)
            print(dtype,  cummax(x1))
            supported_dtypes.add(dtype)
        except Exception as e:
            print(e)
            unsupported_dtypes.add(dtype)

    return supported_dtypes, unsupported_dtypes


if __name__ == "__main__":
    supported_dtypes, unsupported_dtypes = get_supported_and_unsupported_dtypes()

    supported_dtypes = sorted(str(d) for d in supported_dtypes)
    unsupported_dtypes = sorted(str(d) for d in unsupported_dtypes)


    print("Supported Data Types:")
    m = f"""@with_supported_dtypes(
            {{"1.25.2 and below": {tuple(supported_dtypes)}}}, backend_version
        )"""
    print(m)

    print("\nUnsupported Data Types:")
    m = f"""@with_unsupported_dtypes(
            {{"1.25.2 and below": {tuple(unsupported_dtypes)}}}, backend_version
        )"""
    print(m)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Compliance Checks

Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.

Issue Reference

In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our contributing guide and our PR template.
This check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.

@@ -428,13 +428,6 @@ def cummax(
dtype: Optional[np.dtype] = None,
out: Optional[np.ndarray] = None,
) -> Tuple[np.ndarray, np.ndarray]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result of running the script on cummax:

int8 (array([1, 1, 1], dtype=int8), array([0, 1, 2], dtype=int64))
int16 (array([1, 1, 1], dtype=int16), array([0, 1, 2], dtype=int64))
int32 (array([1, 1, 1]), array([0, 1, 2], dtype=int64))
int64 (array([1, 1, 1], dtype=int64), array([0, 1, 2], dtype=int64))
uint8 (array([1, 1, 1], dtype=uint8), array([0, 1, 2], dtype=int64))
uint16 (array([1, 1, 1], dtype=uint16), array([0, 1, 2], dtype=int64))
uint32 (array([1, 1, 1], dtype=uint32), array([0, 1, 2], dtype=int64))
uint64 (array([1, 1, 1], dtype=uint64), array([0, 1, 2], dtype=int64))
float16 (array([1., 1., 1.], dtype=float16), array([0, 1, 2], dtype=int64))
float32 (array([1., 1., 1.], dtype=float32), array([0, 1, 2], dtype=int64))
float64 (array([1., 1., 1.]), array([0, 1, 2], dtype=int64))
complex64 (array([1.+0.j, 1.+0.j, 1.+0.j], dtype=complex64), array([0, 1, 2], dtype=int64))
complex128 (array([1.+0.j, 1.+0.j, 1.+0.j]), array([0, 1, 2], dtype=int64))
bool (array([ True,  True,  True]), array([0, 1, 2], dtype=int64))
Supported Data Types:
@with_supported_dtypes(
        {"1.25.2 and below": ('bool', 'complex128', 'complex64', 'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8')}, backend_version
    )
Unsupported Data Types:
@with_unsupported_dtypes(
        {"1.25.2 and below": ()}, backend_version
    )

@@ -527,10 +520,7 @@ def cummin(
out: Optional[np.ndarray] = None,
) -> np.ndarray:
if dtype is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for cummin

int8 [1 1 1]
int16 [1 1 1]
int32 [1 1 1]
int64 [1 1 1]
uint8 [1 1 1]
uint16 [1 1 1]
uint32 [1 1 1]
uint64 [1 1 1]
float16 [1. 1. 1.]
float32 [1. 1. 1.]
float64 [1. 1. 1.]
complex64 [1.+0.j 1.+0.j 1.+0.j]
complex128 [1.+0.j 1.+0.j 1.+0.j]
bool [ True  True  True]
Supported Data Types:
@with_supported_dtypes(
        {"1.25.2 and below": ('bool', 'complex128', 'complex64', 'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8')}, backend_version
    )
Unsupported Data Types:
@with_unsupported_dtypes(
        {"1.25.2 and below": ()}, backend_version
    )

@@ -171,7 +171,7 @@ def var(
# ------#


@with_unsupported_dtypes({"1.25.2 and below": "bfloat16"}, backend_version)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int8 [1 2 6]
int16 [1 2 6]
int32 [1 2 6]
int64 [1 2 6]
uint8 [1 2 6]
uint16 [1 2 6]
uint32 [1 2 6]
uint64 [1 2 6]
float16 [1. 2. 6.]
float32 [1. 2. 6.]
float64 [1. 2. 6.]
complex64 [1.+0.j 2.+0.j 6.+0.j]
complex128 [1.+0.j 2.+0.j 6.+0.j]
bool [ True  True  True]
Supported Data Types:
@with_supported_dtypes(
        {"1.25.2 and below": ('bool', 'complex128', 'complex64', 'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8')}, backend_version
    )
Unsupported Data Types:
@with_unsupported_dtypes(
        {"1.25.2 and below": ()}, backend_version
    )

@@ -218,10 +215,6 @@ def cumsum(
out: Optional[np.ndarray] = None,
) -> np.ndarray:
if dtype is None:
if x.dtype == "bool":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int8 [1 3 6]
int16 [1 3 6]
int32 [1 3 6]
int64 [1 3 6]
uint8 [1 3 6]
uint16 [1 3 6]
uint32 [1 3 6]
uint64 [1 3 6]
float16 [1. 3. 6.]
float32 [1. 3. 6.]
float64 [1. 3. 6.]
complex64 [1.+0.j 3.+0.j 6.+0.j]
complex128 [1.+0.j 3.+0.j 6.+0.j]
bool [ True  True  True]
Supported Data Types:
@with_supported_dtypes(
        {"1.25.2 and below": ('bool', 'complex128', 'complex64', 'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8')}, backend_version
    )
Unsupported Data Types:
@with_unsupported_dtypes(
        {"1.25.2 and below": ()}, backend_version
    )

@ivy-seed ivy-seed assigned D0m-inic and sherry30 and unassigned D0m-inic Sep 15, 2023
Copy link
Contributor

@vedpatwardhan vedpatwardhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Feel free to merge, thanks @Madjid-CH 😄
(I'm assuming you've already run the tests for the functions changed and the tests pass or fail, whichever was the state of those tests before the changes. And even if it fails, the logs of the failure are the same as those before making the changes.)

@Madjid-CH
Copy link
Contributor Author

lgtm! Feel free to merge, thanks @Madjid-CH 😄 (I'm assuming you've already run the tests for the functions changed and the tests pass or fail, whichever was the state of those tests before the changes. And even if it fails, the logs of the failure are the same as those before making the changes.)

yeah, the tests was failing because of a missing on_device attribute and now they are passing except for cummax, it test is still failing after modification.

@Madjid-CH Madjid-CH merged commit cfcfbea into ivy-llc:main Sep 18, 2023
9 of 19 checks passed
@Madjid-CH Madjid-CH deleted the manual-dtype-casting-removal-numpy branch September 18, 2023 08:58
iababio pushed a commit to iababio/ivy that referenced this pull request Sep 27, 2023
druvdub pushed a commit to druvdub/ivy that referenced this pull request Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants