Skip to content

Add nanobind tutorial mirroring _tutoriels/pybind11 - #29

Merged
xadupre merged 6 commits into
mainfrom
copilot/create-project-nanobind
Apr 1, 2026
Merged

xadupre merged 6 commits into
mainfrom
copilot/create-project-nanobind

Conversation

Copilot AI commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Creates _tutoriels/nanobind as the nanobind equivalent of the existing _tutoriels/pybind11 project — same add_scaled (a + 2·b) and dot_product functions, both OpenMP-parallelised.

New files

  • dotnanobind.cpp — nanobind port of dot11.cpp:

    • Typed 1-D input arrays via nb::ndarray<double, nb::ndim<1>, nb::c_contig, nb::device::cpu>
    • Output array returned as nb::ndarray<nb::numpy, …> with memory owned by an nb::capsule (backed by std::make_unique<double[]>)
    • NB_MODULE instead of PYBIND11_MODULE
  • setup.py — setuptools build using nanobind's bundled sources:

    • Resolves include dir via nanobind.include_dir() and runtime via nanobind.source_dir()/nb_combined.cpp
    • Adds nanobind's bundled tsl/robin_map to include path (required by nb_combined.cpp)
    • -fvisibility=hidden added per nanobind recommendations
// input type alias
using Array1D = nb::ndarray<double, nb::ndim<1>, nb::c_contig, nb::device::cpu>;

// returning a numpy-owned array
double *raw = result.release();
nb::capsule owner(raw, [](void *p) noexcept { delete[] (double *)p; });
size_t shape[1] = {n};
return nb::ndarray<nb::numpy, double, nb::ndim<1>>(raw, 1, shape, owner);

Copilot AI changed the title [WIP] Create project similar to tutoriels pybind11 using nanobind Add nanobind tutorial mirroring _tutoriels/pybind11 Mar 31, 2026
Copilot AI requested a review from xadupre March 31, 2026 23:38
@xadupre
xadupre marked this pull request as ready for review April 1, 2026 07:22
@xadupre
xadupre merged commit e25dc3f into main Apr 1, 2026
16 of 21 checks passed
@xadupre
xadupre deleted the copilot/create-project-nanobind branch April 1, 2026 08:51
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.

creates a project with does the same things as _tutoriels/pybind11 but with nanobind, create in _tutoriels/nanobind

2 participants