Skip to content

nanobind type caster between C++ Array/Vector and python cocotb.types.Array#288

Merged
ZiaCheemaGit merged 6 commits into
ktbarrett:devfrom
ZiaCheemaGit:array-type-caster
Jun 21, 2026
Merged

nanobind type caster between C++ Array/Vector and python cocotb.types.Array#288
ZiaCheemaGit merged 6 commits into
ktbarrett:devfrom
ZiaCheemaGit:array-type-caster

Conversation

@ZiaCheemaGit

Copy link
Copy Markdown
Collaborator

Fixes #267

@ZiaCheemaGit ZiaCheemaGit marked this pull request as draft June 17, 2026 08:59
@ZiaCheemaGit ZiaCheemaGit force-pushed the array-type-caster branch 2 times, most recently from 4aafedf to 7aafb25 Compare June 17, 2026 14:56
all test bindings .cpp files are separated per binding and
all python tests are now in `tests/nanobind/pytest`
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.97%. Comparing base (6a35641) to head (96f361a).
⚠️ Report is 5 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #288      +/-   ##
==========================================
- Coverage   92.76%   91.97%   -0.79%     
==========================================
  Files          23       23              
  Lines        1285     1309      +24     
  Branches      312      316       +4     
==========================================
+ Hits         1192     1204      +12     
- Misses         34       43       +9     
- Partials       59       62       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZiaCheemaGit ZiaCheemaGit marked this pull request as ready for review June 18, 2026 09:29
@ZiaCheemaGit ZiaCheemaGit requested a review from ktbarrett June 18, 2026 09:33
@ZiaCheemaGit

Copy link
Copy Markdown
Collaborator Author

Best reviewed commit by commit

@ktbarrett ktbarrett left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is also looking very good for a first pass.

Comment thread tests/nanobind/pytest/test_array_caster.py Outdated
Comment thread tests/nanobind/pytest/test_array_caster.py
Comment thread nanobind/include/type_cast_vector.hpp Outdated
Comment on lines +34 to +38
object py_range = src.attr("range");
int left = cast<int>(py_range.attr("left"));
int right = cast<int>(py_range.attr("right"));

coconext::types::Range c_range{left, right};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If we have successfully patched cocotb.types.Range with coconext's versions we should be able to just nb:cast<Range>(src.attr("range")) to get the range object.

Though I understand being defensive about it.

Comment thread nanobind/include/type_cast_vector.hpp Outdated
Comment thread nanobind/include/type_cast_vector.hpp Outdated
Comment thread nanobind/include/type_cast_array.hpp Outdated
Comment thread nanobind/include/type_cast_vector.hpp Outdated
Comment thread nanobind/include/type_cast_array.hpp Outdated
Comment thread nanobind/include/type_cast_array.hpp Outdated
ZiaCheemaGit added a commit to ZiaCheemaGit/coconext that referenced this pull request Jun 20, 2026
@ZiaCheemaGit ZiaCheemaGit requested a review from ktbarrett June 20, 2026 11:26

@ktbarrett ktbarrett left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also do the same changes for the Vector type.

The left and right are no longer limited to int, but to int64_t. It's best to just call out Array::index_t instead, just incase we change it again, like I did from int to int64_t.

I'm wondering if you can cut down on verbosity by using using namespace coconext::types in the caster method bodies?

Comment thread nanobind/include/type_cast_array.hpp Outdated
Comment thread nanobind/include/type_cast_array.hpp Outdated
Comment thread nanobind/include/type_cast_array.hpp Outdated
ZiaCheemaGit added a commit to ZiaCheemaGit/coconext that referenced this pull request Jun 20, 2026
@ZiaCheemaGit ZiaCheemaGit requested a review from ktbarrett June 20, 2026 14:44
Comment thread nanobind/include/type_cast_array.hpp Outdated
Comment thread nanobind/include/type_cast_vector.hpp Outdated
@ktbarrett

Copy link
Copy Markdown
Owner

Merge when you are ready.

@ZiaCheemaGit ZiaCheemaGit merged commit 24a9b48 into ktbarrett:dev Jun 21, 2026
15 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.

Add nanobind type caster between C++ Array/DynArray and Python cocotb.types.Array

2 participants