[Algs] move sort_by_keys to new primitives folder#1159
[Algs] move sort_by_keys to new primitives folder#1159tdavidcl merged 8 commits intoShamrock-code:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @tdavidcl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've undertaken a significant refactoring effort to improve the modularity and organization of the shamalgs library. Specifically, the sort_by_key functionality has been extracted from the general algorithm module and relocated to a new primitives module. This change better reflects its foundational nature as a core primitive operation. The public interface for sort_by_key now also includes an explicit check for power-of-two lengths, enhancing its robustness. This move ensures a clearer separation of concerns within the library and simplifies future maintenance and development.
Highlights
- Function Relocation: The
sort_by_keyfunction, previously located inshamalgs::algorithm, has been refactored and moved to a newshamalgs::primitivesnamespace. This improves code organization by placing fundamental sorting operations in a more appropriate, lower-level module. - API Refinement and Input Validation: A new internal function,
sort_by_key_pow2_len, has been introduced withinshamalgs::primitives. The publicsort_by_keynow acts as a wrapper, performing a check to ensure the input length is a power of two before delegating tosort_by_key_pow2_len. This adds robustness by enforcing a common requirement for bitonic sort implementations. - Namespace Updates Across the Codebase: All existing call sites and test cases that previously used
shamalgs::algorithm::sort_by_keyhave been updated to correctly reference the function in its newshamalgs::primitivesnamespace.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request correctly refactors the sort_by_key functionality into a new primitives folder and namespace. The changes are consistent across the codebase, including updates to CMake files, headers, implementation files, and tests. I've identified a few minor areas for improvement: the documentation for the sort_by_key function should be updated to reflect the power-of-two length requirement, and a magic number used as a threshold should be an integer literal for better clarity and type safety. Overall, this is a solid refactoring.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the sort_by_key functionality by moving it into a new primitives directory. The changes are well-structured, separating the interface from the implementation. I've identified a critical issue in the new sort_by_keys.cpp file related to incorrect namespace resolution that will cause compilation errors. Additionally, I've pointed out some areas for improvement in the documentation within sort_by_keys.hpp to remove contradictions and inaccuracies, and suggested refactoring a magic number to improve code clarity and maintainability.
| * @param buf_values Buffer containing the values to reorder | ||
| * @param len Length of both buffers (must be a power of 2) | ||
| * | ||
| * @throws std::invalid_argument if len is not a power of 2 |
There was a problem hiding this comment.
The @throws tag here is misleading. This function sort_by_key_pow2_len does not perform the power-of-two check itself; the check is done in the calling function sort_by_key. Therefore, this function doesn't throw std::invalid_argument. This also applies to the USM version of this function on line 79. Please remove this @throws tag to accurately reflect the function's behavior. The precondition that len must be a power of 2 is already documented in the @param tag.
Workflow reportworkflow report corresponding to commit f7aa7d0 Pre-commit check reportPre-commit check: ✅ Test pipeline can run. Clang-tidy diff reportNo relevant changes found. You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review. Doxygen diff with
|
No description provided.