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

#10861 : Added modf in numpy frontend #11680

Merged
merged 10 commits into from
Apr 24, 2023

Conversation

RakshitKumar04
Copy link
Contributor

@RakshitKumar04 RakshitKumar04 commented Mar 3, 2023

Close #12086

@ivy-leaves ivy-leaves added the NumPy Frontend Developing the NumPy Frontend, checklist triggered by commenting add_frontend_checklist label Mar 3, 2023
@RakshitKumar04 RakshitKumar04 force-pushed the modf-ivy-patch2 branch 2 times, most recently from 9da2a6e to ca2fd08 Compare March 6, 2023 14:38
@RakshitKumar04
Copy link
Contributor Author

Hey, @kurshakuz can you please guide me and help in passing these checks

@RakshitKumar04
Copy link
Contributor Author

Hey, @kurshakuz I have updated the code, can please review my PR.

@RakshitKumar04 RakshitKumar04 mentioned this pull request Mar 9, 2023
@RakshitKumar04
Copy link
Contributor Author

Close #12086

@RakshitKumar04
Copy link
Contributor Author

Hey @kurshakuz, Please review the PR.

Copy link
Contributor

@kurshakuz kurshakuz left a comment

Choose a reason for hiding this comment

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

Hey! Sorry for a delayed response! I have just checked your implementation and it seems to fail local tests. Can you please resolve below errors, check them locally and let me know once you are done? Thanks!

======================================================================== FAILURES =========================================================================
_____________________________________________ test_numpy_modf[cpu-ivy.functional.backends.numpy-False-False] ______________________________________________

arguments = (), kwargs = {}

    @handle_frontend_test(
        fn_tree="numpy.modf",
>       dtypes_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float", "int"),
        ),
        where=np_frontend_helpers.where(),
    )
E   hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_dtypes=get_dtypes(kind='float', index='int'))` in @given

ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py:10: InvalidArgument
______________________________________________ test_numpy_modf[cpu-ivy.functional.backends.jax-False-False] _______________________________________________

arguments = (), kwargs = {}

    @handle_frontend_test(
        fn_tree="numpy.modf",
>       dtypes_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float", "int"),
        ),
        where=np_frontend_helpers.where(),
    )
E   hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_dtypes=get_dtypes(kind='float', index='int'))` in @given

ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py:10: InvalidArgument
___________________________________________ test_numpy_modf[cpu-ivy.functional.backends.tensorflow-False-False] ___________________________________________

arguments = (), kwargs = {}

    @handle_frontend_test(
        fn_tree="numpy.modf",
>       dtypes_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float", "int"),
        ),
        where=np_frontend_helpers.where(),
    )
E   hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_dtypes=get_dtypes(kind='float', index='int'))` in @given

ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py:10: InvalidArgument
_____________________________________________ test_numpy_modf[cpu-ivy.functional.backends.torch-False-False] ______________________________________________

arguments = (), kwargs = {}

    @handle_frontend_test(
        fn_tree="numpy.modf",
>       dtypes_and_x=helpers.dtype_and_values(
            available_dtypes=helpers.get_dtypes("float", "int"),
        ),
        where=np_frontend_helpers.where(),
    )
E   hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_dtypes=get_dtypes(kind='float', index='int'))` in @given

ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py:10: InvalidArgument
==================================================================== warnings summary =====================================================================
ivy/__init__.py:1164
  /workspaces/ivy/ivy/__init__.py:1164: UserWarning: jax module has been imported while ivy doesn't import it without setting a backend, ignore if that's intended
    warnings.warn(

ivy_tests/test_ivy/helpers/function_testing.py:69: 87 warnings
  /workspaces/ivy/ivy_tests/test_ivy/helpers/function_testing.py:69: DeprecationWarning: `np.bool8` is a deprecated alias for `np.bool_`.  (Deprecated NumPy 1.24)
    import ivy.compiler.compiler as ic

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================= short test summary info =================================================================
FAILED ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py::test_numpy_modf[cpu-ivy.functional.backends.numpy-False-False] - hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_...
FAILED ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py::test_numpy_modf[cpu-ivy.functional.backends.jax-False-False] - hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_...
FAILED ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py::test_numpy_modf[cpu-ivy.functional.backends.tensorflow-False-False] - hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_...
FAILED ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_trigonometric_functions.py::test_numpy_modf[cpu-ivy.functional.backends.torch-False-False] - hypothesis.errors.InvalidArgument: test_numpy_modf() got an unexpected keyword argument 'dtypes_and_x', from `dtypes_and_x=dtype_and_values(available_...
============================================================= 4 failed, 88 warnings in 1.78s ==============================================================

@to_ivy_arrays_and_back
@handle_numpy_casting
@from_zero_dim_arrays_to_scalar
def _modf(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please also clarify why do you need that underscore here? Thanks

Suggested change
def _modf(
def modf(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I referred to the ivy frontends docs which state that "In NumPy, add() is categorised under mathematical_functions with a sub-category of arithmetic_operations as shown in the numpy mathematical functions directory. It is important to note that add() is a universal function (ufunc) in NumPy, thus the function is actually an object with instance methods like .at and .reduce, etc. We deal with this in the NumPy frontend by including a ufunc class and initialising it in the init file" so thats why I used _modf.

https://lets-unify.ai/ivy/deep_dive/ivy_frontends.html

@RakshitKumar04
Copy link
Contributor Author

Hey, @kurshakuz I did some changes and tried to resolve the errors, can u please review it.

Copy link
Contributor

@kurshakuz kurshakuz left a comment

Choose a reason for hiding this comment

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

Hello @RakshitKumar04! I have tested your implementation and it is failing the tests. Please make sure it is correct and passes all of the tests, so that I can have a further look.

E               ivy.utils.exceptions.IvyException: Out argument must be an ivy.frontends.numpy.ndarray object

@RakshitKumar04 RakshitKumar04 force-pushed the modf-ivy-patch2 branch 2 times, most recently from a2c810c to 7d7a9d1 Compare March 25, 2023 16:31
@RakshitKumar04
Copy link
Contributor Author

RakshitKumar04 commented Mar 26, 2023

Hey, @kurshakuz I tried solving the error, please guide if it fails again

@RakshitKumar04
Copy link
Contributor Author

Hey, @kurshakuz please review my pr.

Copy link
Contributor

@kurshakuz kurshakuz left a comment

Choose a reason for hiding this comment

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

Please fix the following error and run the tests locally to see if your implementation works:

E               ivy.utils.exceptions.IvyException: Out argument must be an ivy.frontends.numpy.ndarray object

@RakshitKumar04
Copy link
Contributor Author

.

@RakshitKumar04 RakshitKumar04 force-pushed the modf-ivy-patch2 branch 3 times, most recently from 02b65e5 to 08a3011 Compare April 10, 2023 09:41
@RakshitKumar04
Copy link
Contributor Author

Hey, @kurshakuz can you please guide me on resolving these errors. I ran the modf function on my local machine. Out of 5, 1st test case got passed and the other 4 showed the error listed below.

  return self._data.__array_ufunc__(*args, **kwargs)

E AttributeError: 'ArrayImpl' object has no attribute 'array_ufunc'
E Falsifying example: test_numpy_modf(
E dtype_and_x=(['float32'], [array(-1., dtype=float32)]),
E fn_tree='ivy.functional.frontends.numpy.modf',
E test_flags=FrontendFunctionTestFlags(
E num_positional_args=1,
E with_out=False,
E inplace=False,
E as_variable=[False],
E native_arrays=[False],
E generate_frontend_arrays=False,
E ),
E on_device='cpu',
E frontend='numpy',
E )

self.__getattribute__(name)

E AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'array_ufunc'
E Falsifying example: test_numpy_modf(
E dtype_and_x=(['float32'], [array(-1., dtype=float32)]),
E fn_tree='ivy.functional.frontends.numpy.modf',
E test_flags=FrontendFunctionTestFlags(
E num_positional_args=1,
E with_out=False,
E inplace=False,
E as_variable=[False],
E native_arrays=[False],
E generate_frontend_arrays=False,
E ),
E on_device='cpu',
E frontend='numpy',
E )

  return self._data.__array_ufunc__(*args, **kwargs)

E AttributeError: 'Tensor' object has no attribute 'array_ufunc'
E Falsifying example: test_numpy_modf(
E dtype_and_x=(['float32'], [array(-1., dtype=float32)]),
E fn_tree='ivy.functional.frontends.numpy.modf',
E test_flags=FrontendFunctionTestFlags(
E num_positional_args=1,
E with_out=False,
E inplace=False,
E as_variable=[False],
E native_arrays=[False],
E generate_frontend_arrays=False,
E ),
E on_device='cpu',
E frontend='numpy',
E )

  return self._data.__array_ufunc__(*args, **kwargs)

E TypeError: 'NoneType' object is not callable
E Falsifying example: test_numpy_modf(
E dtype_and_x=(['float32'], [array(-1., dtype=float32)]),
E fn_tree='ivy.functional.frontends.numpy.modf',
E test_flags=FrontendFunctionTestFlags(
E num_positional_args=1,
E with_out=False,
E inplace=False,
E as_variable=[False],
E native_arrays=[False],
E generate_frontend_arrays=False,
E ),
E on_device='cpu',
E frontend='numpy',
E )

@kurshakuz
Copy link
Contributor

@RakshitKumar04 I have not seen this error previously as well. I would suggest to address that issue in one of the Discord channels, maybe some has experience of dealing with that error. Can you do that?

@RakshitKumar04
Copy link
Contributor Author

@kurshakuz Yes Sir, I will do that.

@RakshitKumar04 RakshitKumar04 force-pushed the modf-ivy-patch2 branch 6 times, most recently from d146279 to e4ed4f6 Compare April 22, 2023 15:46
@RakshitKumar04
Copy link
Contributor Author

RakshitKumar04 commented Apr 22, 2023

>       assert ret_dtype == ret_from_gt_dtype, (
            "the ground truth framework {} returned a {} datatype while "
            "the backend {} returned a {} datatype".format(
                ground_truth_backend,
                ret_from_gt_dtype,
                ivy.current_backend_str(),
                ret_dtype,
            )
        )
E       AssertionError: the ground truth framework numpy returned a float16 datatype while the backend numpy returned a uint8 datatype
E       Falsifying example: test_numpy_modf(
E           dtypes_values_casting=(['uint8'], [array(1, dtype=uint8)], 'no', None),
E           where=[array(False)],

Hey @kurshakuz how do I resolve this error?

@fnhirwa
Copy link
Contributor

fnhirwa commented Apr 24, 2023

Hey @RakshitKumar04 and @kurshakuz

It seems like is the casting issue that is on our testing side 😁
I am fixing that and I think we can merge this PR.

@fnhirwa fnhirwa merged commit 325b25b into ivy-llc:master Apr 24, 2023
@RakshitKumar04 RakshitKumar04 deleted the modf-ivy-patch2 branch June 20, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NumPy Frontend Developing the NumPy Frontend, checklist triggered by commenting add_frontend_checklist Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modf
5 participants