Skip to content

Implementing repeat function #875

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

prady0t
Copy link
Contributor

@prady0t prady0t commented Jun 2, 2025

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • πŸͺ„ Feature
  • 🐞 Bug Fix
  • πŸ”§ Optimization
  • πŸ“š Documentation
  • πŸ§ͺ Test
  • πŸ› οΈ Other

Related issues

  • Related issue #
  • Closes #

Checklist

  • Code follows style guide
  • Tests added
  • Documented the changes

Part of the effort to adhere to array API standards. Similar to np.repeat but for sparse arrays.

prady0t added 2 commits June 2, 2025 17:03
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Jun 2, 2025

@hameerabbasi Will add tests after your reviews

Copy link
Collaborator

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

Adding tests might reveal some bugs here.

Co-authored-by: Hameer Abbasi <2190658+hameerabbasi@users.noreply.github.com>
Copy link

codspeed-hq bot commented Jun 2, 2025

CodSpeed Performance Report

Merging #875 will degrade performances by 30.62%

Comparing prady0t:array-api-tests-adherence (f2d67ce) with main (9988853)

Summary

⚑ 1 improvements
❌ 1 regressions
βœ… 338 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
⚑ test_gcxs_dot_ndarray[coo-m=200-n=200-p=200] 2.8 ms 2 ms +41.94%
❌ test_index_fancy[side=100-rank=1-format='coo'] 939.4 ¡s 1,354 ¡s -30.62%

prady0t added 2 commits June 3, 2025 02:19
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Jun 2, 2025

Yes, there were a few bugs, mostly with reshaping. I've removed them and added the tests. Hopefully, this is a correct implementation. The function still doesn't account for uneven repeats.

prady0t added 3 commits June 3, 2025 18:07
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
raise TypeError("`a` must be a SparseArray.")

if not isinstance(repeats, int):
raise Exception("`repeats` must be an integer, uneven repeats are not yet Implemented.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
raise Exception("`repeats` must be an integer, uneven repeats are not yet Implemented.")
raise ValueError("`repeats` must be an integer, uneven repeats are not supported.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it not possible to implement uneven repeats for sparse arrays? It's not possible via broadcasting, we might have to find a different way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's required by the Array API standard, I'd implement it as follows: Take the ceiling; use the current implementation then truncate to the desired length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the standard specifies this: https://data-apis.org/array-api/2024.12/API_specification/generated/array_api.repeat.html#repeat

Should I modify the behaviour in this PR or in future(keeping it as not implemented)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This PR is good as the change is related.

prady0t added 2 commits June 7, 2025 14:52
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
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.

2 participants