Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pybind11-numpy-example

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pybind11-numpy-example

An example of using numpy with pybind11

  • 1.0.1
  • PyPI
  • Socket score

Maintainers
2

pybind11-numpy-example

License: MIT PyPI Release Conda Release Python Versions GitHub Workflow Status Documentation Status

What

A simple example of how to use pybind11 with numpy and publish this as a library on PyPI and conda-forge.

This C++/Python library creates a std::vector of 16-bit ints, and provides a Python interface to the contents of this vector in a few different ways:

  • a Python List (copy the data)
  • a NumPy ndarray (copy the data).
  • a NumPy ndarray (move the data).

Why

Python Lists are great! However, when storing many small elements of the same type, a Numpy array is much faster and uses a lot less memory:

Memory used vs number of elements

Time used vs number of elements

How

The pybind11 code is in src/pybind11_numpy_example_python.cpp.

The python package is defined in pyproject.toml and uses scikit-build-core.

Each tagged commit triggers a GitHub action job which uses cibuildwheel to build and upload a new release including binary wheels for all platforms to PyPI.

The conda-forge package is generated from this recipe, and automatically updates when a new version is uploaded to PyPI.

The scripts used to generate the above plots are in scripts.

This repo was quickly set up using the SSC C++ Project Cookiecutter.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc