Skip to content

refactor(pybind): use as_span for joint constitution bindings#405

Merged
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:refactor/pybind-joint-as-span
Mar 25, 2026
Merged

refactor(pybind): use as_span for joint constitution bindings#405
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:refactor/pybind-joint-as-span

Conversation

@Ligo04
Copy link
Copy Markdown
Contributor

@Ligo04 Ligo04 commented Mar 25, 2026

Summary

  • Replace manual py::list iteration with py::array_t<T> and as_span<T>() / as_span_of<T>() for numeric parameters (IndexT, Float, Vector3) across all joint constitution pybind bindings
  • Affected files: fixed joint, prismatic joint, revolute joint, spherical joint, prismatic/revolute joint limits, driving prismatic/revolute joints, and external articulation constraint
  • Eliminates ~140 lines of boilerplate py::cast loops, improving type safety and consistency with NumPy-native Python API

Replace manual py::list iteration with py::array_t and as_span/as_span_of
for numeric parameters (IndexT, Float, Vector3) across all joint
constitution pybind bindings, reducing boilerplate and improving type safety.

Made-with: Cursor
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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!

This pull request significantly refactors the Pybind11 bindings for various joint constitution mechanisms. The core objective is to modernize the handling of numeric array parameters passed from Python to C++ by leveraging py::array_t and as_span utilities. This change streamlines the interface, making it more robust and performant by directly interfacing with NumPy arrays, thereby improving the overall developer experience and code maintainability.

Highlights

  • Pybind11 Bindings Refactoring: Replaced manual py::list iteration with py::array_t<T> and as_span<T>() or as_span_of<T>() for numeric parameters (IndexT, Float, Vector3) across all joint constitution Pybind11 bindings.
  • Improved Type Safety and Consistency: The change enhances type safety and aligns the Python API more closely with NumPy-native array handling, reducing the potential for type-related errors.
  • Code Reduction: Eliminated approximately 140 lines of boilerplate py::cast loops, leading to cleaner and more concise code.
  • Affected Components: This refactoring impacts fixed, prismatic, revolute, and spherical joints, as well as prismatic/revolute joint limits, driving prismatic/revolute joints, and external articulation constraints.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors Pybind11 bindings across several joint-related files. It updates function signatures to accept py::array_t instead of py::list for various parameters, replacing manual iteration and casting with more efficient as_span utility calls. This change streamlines the C++ code and likely improves performance by leveraging NumPy arrays directly. The reviewer suggests consistently using curly braces for all loop bodies to enhance code clarity and prevent potential issues.

Address PR review feedback: use braces for all loop bodies
for consistency and to prevent future modification bugs.

Made-with: Cursor
@MuGdxy MuGdxy merged commit c4a739f into spiriMirror:main Mar 25, 2026
14 checks passed
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