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

implement bincount function #18199

Closed
wants to merge 1,442 commits into from
Closed

Conversation

druvdub
Copy link
Contributor

@druvdub druvdub commented Jul 2, 2023

Close #18183

@druvdub
Copy link
Contributor Author

druvdub commented Jul 2, 2023

could someone clarify if the implementation is correct or not?
as I am a bit confused as there is sub-task to implement bincount in tensor.linalg as well and was wondering if this one should reference that one via paddle_frontend

@ivy-leaves ivy-leaves added the Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist label Jul 2, 2023
@druvdub druvdub marked this pull request as draft July 2, 2023 23:12
@ivy-leaves
Copy link

If you are working on an open task, please edit the PR description to link to the issue you've created.

For more information, please check ToDo List Issues Guide.

Thank you 🤗

@xoiga123
Copy link
Contributor

xoiga123 commented Jul 3, 2023

Hi @druvdub! Thank you for contributing to Ivy 🤗 The implementation looks okay to me at first glance, but could you link to the issue that you've created (if you've been following the Frontend API Guide) so that I know what you're working on precisely? Also, please comment

add_frontend_checklist

to create a checklist so that I know where you're stuck on. Thank ya ⭐

@druvdub
Copy link
Contributor Author

druvdub commented Jul 3, 2023

add_frontend_checklist

@druvdub
Copy link
Contributor Author

druvdub commented Jul 3, 2023

Hi @xoiga123 I have added the reference to the issue and the checklist comment.

@druvdub druvdub marked this pull request as ready for review July 3, 2023 23:00
@xoiga123
Copy link
Contributor

xoiga123 commented Jul 4, 2023

Hey thank you for linking to the issue, but please re-comment add_frontend_checklist as editing a comment doesn't work 😢

@druvdub
Copy link
Contributor Author

druvdub commented Jul 4, 2023

Frontend Task Checklist

IMPORTANT NOTICE 🚨:

The Ivy Docs represent the ground truth for the task descriptions and this checklist should only be used as a supplementary item to aid with the review process.

Please note that the contributor is not expected to understand everything in the checklist. It's mainly here for the reviewer to make sure everything has been done correctly 🙂

LEGEND 🗺:

  • ❌ : Check item is not completed.
  • ✅ : Check item is ready for review.
  • 🆘 : Stuck/Doubting implementation (PR author should add comments explaining why).
  • ⏩ : Check is not applicable to function (skip).
  • 🆗 : Check item is implemented and does not require any edits.

CHECKS 📑:

    • ❌: The function/method definition is not missing any of the original arguments.
    • ❌: In case the function/method to be implemented is an alias of an existing function/method:
        • ❌: It is being declared as such by setting fun1 = fun2, rather than being re-implemented from scratch.
        • ❌: The alias is added to the existing function/method's test in the aliases parameter of handle_frontend_test/handle_frontend_method.
    • ❌: The naming of the function/method and its arguments exactly matches the original.
    • ❌: No defined argument is being ignored in the function/method's implementation.
    • ❌: In special cases where an argument's implementation should be pending due to an incomplete superset of an ivy function:
        • ❌: A ToDo comment has been added prompting to pass the frontend argument to the ivy function whose behavior is to be extended.
    • ❌: In case a frontend function is being added:
        • ❌: It is a composition of ivy functions.
        • ❌: In case the needed composition is long (using numerous ivy functions), a Missing Function Suggestion issue has been opened to suggest a new ivy function should be added to shorten the frontend implementation.
        • ❌: @to_ivy_arrays_and_back has been added to the function.
    • ❌: In case a frontend method is being added:
        • ❌: It is composed of existing frontend functions or methods.
        • ❌: If a required frontend function has not yet been added, the method may be implemented as a composition of ivy functions, making sure that:
          • ❌: @to_ivy_arrays_and_back has been added to the method.
          • ❌: A ToDo comment has been made prompting to remove the decorator and update the implementation as soon as the missing function has been added.
    • ❌: The function/method's test has been added (except in the alias case mentioned in <2>):
        • ❌: All supported arguments are being generated in handle_frontend_test/handle_frontend_method and passed to test_frontend_function/test_frontend_method.
        • ❌: The argument generation covers all possible supported values. Array sizes, dimensions, and axes adhere to the full supported set of the original function/method.
        • ❌: The available_dtypes parameter passed to the helper generating the function/method's input array is set to helpers.get_dtypes("valid"). If there are unsupported dtypes that cause the test to fail, they should be handled by adding @with_supported_dtypes/@with_unsupported_dtype to the function/method.
    • ❌: The PR is not introducing any test failures.
        • ❌: The lint checks are passing.
        • ❌: The implemented test is passing for all backends.
    • ❌: The PR closes a Sub Task issue linked to one of the open frontend ToDo lists.
    • ❌: The function/method and its test have been added to the correct .py files corresponding to the addressed ToDo list.
    • ❌: The PR only contains changes relevant to the addressed subtask.

@druvdub
Copy link
Contributor Author

druvdub commented Jul 9, 2023

@xoiga123 hello, I made some changes to the test, but I still am not able to run it. Is it possible to test the function separately somewhere manually to test?

[UPDATE],
hi, I just realised, that bincount in the backend has

@with_unsupported_device_and_dtypes(
    {
        "2.5.0 and below": {
            "cpu": (
                "int8",
                "int16",
                "uint8",
                "float16",
                "float32",
                "float64",
                "complex64",
                "complex128",
                "bool",
            )
        }
    },```
    
should I update my function to be this? including the device as well?

@druvdub
Copy link
Contributor Author

druvdub commented Jul 14, 2023

@xoiga123 I have updated the method and the test now, should hopefully work correctly.

Copy link
Contributor

@xoiga123 xoiga123 left a comment

Choose a reason for hiding this comment

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

Sorry for the late review 😓

Comment on lines 2658 to 2659
min_value=1,
max_value=2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you limit it to only [1, 2]? From their example,

x = paddle.to_tensor([1, 2, 1, 4, 5])
result1 = paddle.bincount(x)
print(result1) # [0, 2, 1, 0, 1, 1]

Comment on lines 2662 to 2663
min_dim_size=1,
max_dim_size=2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the dimension only in [1, 2]? Same example as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, sorry was busy last week, I couldn't figure why the tests are not running so I tried duplicating the test from paddle.linalg.bincount

Comment on lines 2666 to 2673
def test_paddle_instance_bincount(
dtypes_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also test for all the arguments, i.e. weights and minlength

@ivy-seed
Copy link

ivy-seed commented Aug 6, 2023

This PR has been labelled as stale because it has been inactive for more than 7 days. If you would like to continue working on this PR, then please add another comment or this PR will be closed in 7 days.

@ivy-seed ivy-seed added the Stale label Aug 6, 2023
@druvdub
Copy link
Contributor Author

druvdub commented Aug 6, 2023

hi @xoiga123 sorry have been busy for a while so didn't do any changes till now but, I wrote the test with only two values since I was trying to follow the similar format to

@handle_frontend_test(
    fn_tree="paddle.bincount",
    dtype_and_x=helpers.dtype_and_values(
        available_dtypes=helpers.get_dtypes("integer"),
        min_value=1,
        max_value=2,
        shape=st.shared(
            helpers.get_shape(
                min_num_dims=1,
                max_num_dims=1,
            ),
            key="a_s_d",
        ),
    ),
    test_with_out=st.just(False),
)
def test_paddle_bincount(
    *,
    dtype_and_x,
    on_device,
    fn_tree,
    backend_fw,
    frontend,
    test_flags,
):
    input_dtype, x = dtype_and_x
    helpers.test_frontend_function(
        input_dtypes=input_dtype,
        frontend=frontend,
        test_flags=test_flags,
        backend_to_test=backend_fw,
        fn_tree=fn_tree,
        on_device=on_device,
        x=x[0],
        weights=None,
        minlength=0,
    )

to this test which is in linalg.py

@xoiga123
Copy link
Contributor

@druvdub that test seems to be misimplemented as well, it is also missing tests for weights and minlength and also too narrow parameter generation. It would be nice if you could fix this PR first, then maybe go on and fix test_paddle_bincount if you want to 😄

@ivy-seed ivy-seed assigned aparajith21 and unassigned xoiga123 Aug 11, 2023
@druvdub
Copy link
Contributor Author

druvdub commented Aug 13, 2023

will update and push soon

@aparajith21
Copy link
Contributor

will update and push soon

Hi, thanks for contributing, please let me know if this is still being worked on or in progress?

@druvdub
Copy link
Contributor Author

druvdub commented Sep 20, 2023

will update and push soon

Hi, thanks for contributing, please let me know if this is still being worked on or in progress?

Hi, yea really sorry haven't made any progress on this due to some work issues. Will get around this week and push the tests.

vedpatwardhan and others added 20 commits October 14, 2023 23:12
we were only testing with the `numpy` backend uptil now
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.

Conventional Commit PR Title

In order to be considered for merging, the pull request title must match the specification in conventional commits. You can edit the title in order for this check to pass.
Most often, our PR titles are something like one of these:

  • docs: correct typo in README
  • feat: implement dark mode"
  • fix: correct remove button behavior

Linting Errors

  • Found type "null", must be one of "feat","fix","docs","style","refactor","perf","test","build","ci","chore","revert"
  • No subject found

@github-actions
Copy link
Contributor

Thank you for this PR, here is the CI results:


This pull request does not result in any additional test failures. Congratulations!

@vandit98
Copy link
Contributor

hi @aparajith21
can i work on this issue.

@NripeshN NripeshN closed this Dec 23, 2023
@druvdub druvdub deleted the bincount-implementation branch February 10, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Paddle Frontend Developing the Paddle Frontend, checklist triggered by commenting add_frontend_checklist Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bincount