file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
src/version.py
Python
#!/usr/bin/env python3 # With no command line flag, this prints the nanobind version. # With flags -w semver, this writes the new version to where it's needed. import os import re import sys # Parse the header file <nanobind/nanobind.h> and print the version. def get_version(root): major = '' minor = '' ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/common.py
Python
import platform import gc import pytest import threading is_pypy = platform.python_implementation() == 'PyPy' is_darwin = platform.system() == 'Darwin' def collect() -> None: if is_pypy: for _ in range(3): gc.collect() else: gc.collect() skip_on_pypy = pytest.mark.skipif( is_p...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/conftest.py
Python
def pytest_addoption(parser): parser.addoption('--enable-slow-tests', action='store_true', dest="enable-slow-tests", default=False, help="enable long-running tests")
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/inter_module.cpp
C++
#include "inter_module.h" Shared create_shared() { return { 123 }; } bool check_shared(const Shared &shared, int expected) { return shared.value == expected; } void increment_shared(Shared &shared) { ++shared.value; }
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/inter_module.h
C/C++ Header
#include <nanobind/nb_defs.h> #if defined(SHARED_BUILD) # define EXPORT_SHARED NB_EXPORT #else # define EXPORT_SHARED NB_IMPORT #endif struct EXPORT_SHARED Shared { int value; }; extern EXPORT_SHARED Shared create_shared(); extern EXPORT_SHARED bool check_shared(const Shared &shared, int expected); extern EXPO...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/object_py.h
C/C++ Header
#include <nanobind/nanobind.h> NAMESPACE_BEGIN(nanobind) NAMESPACE_BEGIN(detail) template <typename T> struct type_caster<ref<T>> { using Caster = make_caster<T>; static constexpr bool IsClass = true; NB_TYPE_CASTER(ref<T>, Caster::Name) bool from_python(handle src, uint8_t flags, ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/py_recursive_stub_test/__init__.py
Python
FOO = 123 from . import bar
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/py_recursive_stub_test/bar.py
Python
BAR=456
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/py_stub_test.py
Python
"""Example module docstring.""" import sys if sys.version_info < (3, 11, 0): # Work around limitations in typing.overload in Python<3.11 import typing_extensions as typing else: import typing # Ignore a type and a function from elsewhere. These shouldn't be included in # the stub by default from os import...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_accessor.cpp
C++
#include <nanobind/nanobind.h> namespace nb = nanobind; struct A { int value; }; NB_MODULE(test_accessor_ext, m) { nb::class_<A>(m, "A") .def(nb::init<>()) .def_rw("value", &A::value); m.def("test_str_attr_accessor_inplace_mutation", []() { nb::object a_ = nb::module_::import_("test_accessor...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_accessor.py
Python
import test_accessor_ext as t def test_01_str_attr_inplace_mutation(): """ Tests that a C++ expression like obj.attr("foo") += ... can actually modify the object in-place. """ a = t.test_str_attr_accessor_inplace_mutation() assert a.value == 1 def test_02_str_item_inplace_mutation(): ""...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_callbacks.cpp
C++
// This is an example of using nb::call_policy to support binding an // object that takes non-owning callbacks. Since the callbacks can't // directly keep a Python object alive (they're trivially copyable), we // maintain a sideband structure to manage the lifetimes. #include <algorithm> #include <unordered_set> #incl...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_callbacks.py
Python
import test_callbacks_ext as t import gc def test_callbacks(): pub1 = t.publisher() pub2 = t.publisher() record = [] def sub1(x): record.append(x + 10) def sub2(x): record.append(x + 20) pub1.subscribe(sub1) pub2.subscribe(sub2) for pub in (pub1, pub2): pub.s...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_chrono.cpp
C++
/* tests/test_chrono.cpp -- test conversions to/from std::chrono types Ported from pybind11/tests/test_chrono.cpp Copyright (c) 2016 Trent Houliston <trent@houliston.me> and Wenzel Jakob <wenzel.jakob@epfl.ch> All rights reserved. Use of this source code is governed by a BSD...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_chrono.py
Python
# Ported from pybind11/tests/test_chrono.py import test_chrono_ext as m import time import datetime import sys import pytest def test_chrono_system_clock(): # Get the time from both c++ and datetime date0 = datetime.datetime.today() date1 = m.test_chrono1() date2 = datetime.datetime.today() # ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_classes.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/trampoline.h> #include <nanobind/operators.h> #include <nanobind/stl/optional.h> #include <nanobind/stl/string.h> #include <nanobind/stl/pair.h> #include <nanobind/stl/shared_ptr.h> #include <nanobind/stl/tuple.h> #include <nanobind/stl/unique_ptr.h> #include <map> #inc...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_classes.h
C/C++ Header
#pragma once #include <memory> class NeverDestruct { public: static NeverDestruct& make(); NeverDestruct(const NeverDestruct&) = delete; NeverDestruct& operator=(const NeverDestruct&) = delete; int var() const; void set_var(int i); private: NeverDestruct(); // incomplete type error...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_classes.py
Python
import sys import test_classes_ext as t import pytest from common import skip_on_pypy, collect def optional(arg: str, /) -> str: if sys.version_info < (3, 10): return "typing.Optional[" + arg + "]" else: return arg + " | " + "None" @pytest.fixture def clean(): collect() t.reset() ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_classes_extra.cpp
C++
#include "test_classes.h" struct NeverDestruct::NDImpl{ int var = 0; }; NeverDestruct::NeverDestruct() { impl = std::make_unique<NeverDestruct::NDImpl>(); } int NeverDestruct::var() const { return impl->var; } void NeverDestruct::set_var(int i) { impl->var = i; } NeverDestruct& NeverDestruct::make(...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_eigen.cpp
C++
#include <nanobind/stl/complex.h> #include <nanobind/eigen/dense.h> #include <nanobind/eigen/sparse.h> #include <nanobind/trampoline.h> #include <iostream> namespace nb = nanobind; using namespace nb::literals; NB_MODULE(test_eigen_ext, m) { m.def("addV3i", [](const Eigen::Vector3i &a, con...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_eigen.py
Python
import pytest import gc import itertools import re import sys try: import numpy as np from numpy.testing import assert_array_equal import test_eigen_ext as t def needs_numpy_and_eigen(x): return x except: needs_numpy_and_eigen = pytest.mark.skip(reason="NumPy and Eigen are required") @nee...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_enum.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/operators.h> #include <nanobind/stl/string.h> namespace nb = nanobind; enum class Enum : uint32_t { A, B, C = (uint32_t) -1 }; enum class Flag : uint32_t { A = 1, B = 2, C = 4}; enum class UnsignedFlag : uint64_t { A = 1 << 0, B = 1 << 1, All = (uint6...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_enum.py
Python
import test_enum_ext as t import pytest def test01_unsigned_enum(): assert repr(t.Enum.A) == 'Enum.A' assert str(t.Enum.A) == 'Enum.A' assert repr(t.Enum.B) == 'Enum.B' assert str(t.Enum.B) == 'Enum.B' assert repr(t.Enum.C) == 'Enum.C' assert str(t.Enum.C) == 'Enum.C' assert t.Enum.A.name =...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_eval.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/eval.h> #include <nanobind/stl/pair.h> namespace nb = nanobind; NB_MODULE(test_eval_ext, m) { auto global = nb::dict(nb::module_::import_("__main__").attr("__dict__")); m.def("test_eval_statements", [global]() { auto local = nb::dict(); local[...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_eval.py
Python
import os import pytest import test_eval_ext as m def test_evals(capsys): assert m.test_eval_statements() captured = capsys.readouterr() assert captured.out == "Hello World!\n" assert m.test_eval() assert m.test_eval_single_statement() assert m.test_eval_failure() def test_eval_closure()...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_exception.cpp
C++
#include <nanobind/nanobind.h> namespace nb = nanobind; class MyError1 : public std::exception { public: virtual const char *what() const noexcept { return "MyError1"; } }; class MyError2 : public std::exception { public: virtual const char *what() const noexcept { return "MyError2"; } }; class MyError3 : p...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_exception.py
Python
import test_exception_ext as t import pytest def test01_base(): with pytest.raises(RuntimeError): assert t.raise_generic() def test02_bad_alloc(): with pytest.raises(MemoryError): assert t.raise_bad_alloc() def test03_runtime_error(): with pytest.raises(RuntimeError) as excinfo: a...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_functions.cpp
C++
#include <string.h> #include <nanobind/nanobind.h> #include <nanobind/stl/function.h> #include <nanobind/stl/pair.h> #include <nanobind/stl/string.h> #include <nanobind/stl/vector.h> namespace nb = nanobind; using namespace nb::literals; int call_guard_value = 0; struct my_call_guard { my_call_guard() { call_gu...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_functions.py
Python
import test_functions_ext as t import pytest import sys import re # Reference counting behavior changed on 3.14a7+ py_3_14a7_or_newer = sys.version_info >= (3, 14, 0, 'alpha', 7) def fail_fn(): # used in test_30 raise RuntimeError("Foo") def test01_capture(): # Functions with and without capture object of...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_holders.cpp
C++
#if defined(__GNUC__) // warning: '..' declared with greater visibility than the type of its field '..' # pragma GCC diagnostic ignored "-Wattributes" #endif #include <nanobind/stl/shared_ptr.h> #include <nanobind/stl/unique_ptr.h> #include <nanobind/stl/pair.h> #include <nanobind/stl/vector.h> namespace nb = nanobi...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_holders.py
Python
import sys import test_holders_ext as t import pytest from common import collect # Reference counting behavior changed on 3.14a7+ py_3_14a7_or_newer = sys.version_info >= (3, 14, 0, 'alpha', 7) @pytest.fixture def clean(): collect() t.reset() # ----------------------------------------------------------------...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_inter_module.py
Python
import test_inter_module_1_ext as t1 import test_inter_module_2_ext as t2 import test_classes_ext as t3 import pytest from common import xfail_on_pypy_darwin try: from concurrent import interpreters # Added in Python 3.14 def needs_interpreters(x): return x except: needs_interpreters = pytest.mark...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_inter_module_1.cpp
C++
#include <nanobind/nanobind.h> #include "inter_module.h" namespace nb = nanobind; NB_MODULE(test_inter_module_1_ext, m) { m.def("create_shared", &create_shared); }
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_inter_module_2.cpp
C++
#include <nanobind/nanobind.h> #include "inter_module.h" namespace nb = nanobind; NB_MODULE(test_inter_module_2_ext, m) { nb::class_<Shared>(m, "Shared"); m.def("check_shared", &check_shared); m.def("increment_shared", &increment_shared); }
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_intrusive.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/stl/pair.h> #include <nanobind/trampoline.h> #include <nanobind/intrusive/counter.h> #include <nanobind/intrusive/ref.h> namespace nb = nanobind; using namespace nb::literals; static int test_constructed = 0; static int test_destructed = 0; class Test : public nb::in...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_intrusive.py
Python
import test_intrusive_ext as t import pytest from common import collect @pytest.fixture def clean(): collect() t.reset() def test01_construct(clean): o = t.Test() assert o.value(0) == 123 assert t.get_value_1(o) == 124 assert t.get_value_2(o) == 125 assert t.get_value_3(o) == 126 del o...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_intrusive_impl.cpp
C++
#include <nanobind/intrusive/counter.inl>
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_issue.cpp
C++
#include <nanobind/stl/shared_ptr.h> #include <nanobind/stl/string.h> #include <nanobind/stl/vector.h> #include <unordered_map> namespace nb = nanobind; using namespace nb::literals; NB_MODULE(test_issue_ext, m) { // ------------------------------------ // issue #279: dynamic_attr broken // -------------...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_issue.py
Python
import test_issue_ext as m import pytest # Issue #279: dynamic_attr broken @pytest.mark.parametrize("variant", [1, 2]) def test01_issue_279(variant): def _get_parameter(self: m.Model, key: str): p = self._get_param(key) if p is not None: # cache it for fast access later setattr(self, k...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_jax.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/ndarray.h> namespace nb = nanobind; int destruct_count = 0; NB_MODULE(test_jax_ext, m) { m.def("destruct_count", []() { return destruct_count; }); m.def("ret_jax", []() { struct alignas(64) Buf { float f[8]; }; Buf *buf = n...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_jax.py
Python
import test_ndarray_ext as t import test_jax_ext as tj import pytest import warnings import importlib from common import collect try: import jax.numpy as jnp def needs_jax(x): return x except: needs_jax = pytest.mark.skip(reason="JAX is required") @needs_jax def test01_constrain_order(): with...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_make_iterator.cpp
C++
#include <nanobind/make_iterator.h> #include <nanobind/stl/unordered_map.h> #include <nanobind/stl/string.h> namespace nb = nanobind; NB_MODULE(test_make_iterator_ext, m) { struct StringMap { std::unordered_map<std::string, std::string> map; decltype(map.cbegin()) begin() const { return map.cbegin...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_make_iterator.py
Python
import test_make_iterator_ext as t from common import parallelize data = [ {}, { 'a' : 'b' }, { str(i) : chr(i) for i in range(1000) } ] def test01_key_iterator(): for d in data: m = t.StringMap(d) assert sorted(list(m)) == sorted(list(d)) def test02_value_iterator(): types = []...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_ndarray.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/ndarray.h> #include <nanobind/stl/pair.h> #include <algorithm> #include <complex> #include <vector> namespace nb = nanobind; using namespace nb::literals; int destruct_count = 0; static float f_global[] { 1, 2, 3, 4, 5, 6, 7, 8 }; static int i_global[] { 1, 2, 3, 4, ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_ndarray.py
Python
import test_ndarray_ext as t import pytest import warnings import importlib from common import collect, skip_on_pypy try: import numpy as np def needs_numpy(x): return x except: needs_numpy = pytest.mark.skip(reason="NumPy is required") try: import torch def needs_torch(x): return ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_specialization.py
Python
import sys import sysconfig import dis import pytest # Note: these tests verify that CPython's adaptive specializing interpreter can # optimize various expressions involving nanobind types. They are expected to # be somewhat fragile across Python versions as the bytecode and specialization # opcodes may change. # Ski...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl.cpp
C++
#include <nanobind/stl/tuple.h> #include <nanobind/stl/pair.h> #include <nanobind/stl/vector.h> #include <nanobind/stl/function.h> #include <nanobind/stl/list.h> #include <nanobind/stl/string.h> #include <nanobind/stl/string_view.h> #include <nanobind/stl/optional.h> #include <nanobind/stl/variant.h> #include <nanobind...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl.py
Python
import test_stl_ext as t import typing import pytest import sys from common import collect, skip_on_pypy def optional(arg: str, /) -> str: if sys.version_info < (3, 10): return "typing.Optional[" + arg + "]" else: return arg + " | " + "None" def union(*args: str) -> str: if sys.version_...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl_bind_map.cpp
C++
#include <map> #include <string> #include <unordered_map> #include <vector> #include <nanobind/stl/bind_map.h> #include <nanobind/stl/string.h> #include <nanobind/stl/vector.h> namespace nb = nanobind; // testing for insertion of non-copyable class class E_nc { public: explicit E_nc(int i) : value{i} {} E_nc...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl_bind_map.py
Python
import pytest import sys import platform import test_stl_bind_map_ext as t def test_map_string_double(capfd): mm = t.MapStringDouble() mm["a"] = 1 mm["b"] = 2.5 assert list(mm) == ["a", "b"] assert "b" in mm assert 123 not in mm assert mm["b"] == 2.5 assert "c" not in mm with py...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl_bind_vector.cpp
C++
#include <nanobind/stl/bind_vector.h> #include <nanobind/stl/shared_ptr.h> namespace nb = nanobind; NB_MODULE(test_stl_bind_vector_ext, m) { nb::bind_vector<std::vector<unsigned int>>(m, "VectorInt"); nb::bind_vector<std::vector<bool>>(m, "VectorBool"); // Ensure that a repeated binding call is ignored ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stl_bind_vector.py
Python
import pytest import platform import test_stl_bind_vector_ext as t def test01_vector_int(capfd): v_int = t.VectorInt([0, 0]) assert len(v_int) == 2 assert bool(v_int) is True # test construction from a generator v_int1 = t.VectorInt(x for x in range(5)) assert t.VectorInt(v_int1) == t.VectorI...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_stubs.py
Python
import os import pathlib import difflib import sys import platform import pytest is_unsupported = platform.python_implementation() == 'PyPy' or sys.version_info < (3, 10) skip_on_unsupported = pytest.mark.skipif( is_unsupported, reason="Stub generation is only tested on CPython >= 3.10.0") def remove_platform_dep...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_tensorflow.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/ndarray.h> namespace nb = nanobind; int destruct_count = 0; NB_MODULE(test_tensorflow_ext, m) { m.def("destruct_count", []() { return destruct_count; }); m.def("ret_tensorflow", []() { struct alignas(256) Buf { float f[8]; }; ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_tensorflow.py
Python
import test_ndarray_ext as t import test_tensorflow_ext as ttf import pytest import warnings import importlib from common import collect try: import tensorflow as tf import tensorflow.config def needs_tensorflow(x): return x except: needs_tensorflow = pytest.mark.skip(reason="TensorFlow is requ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_thread.cpp
C++
#include <nanobind/nanobind.h> #include <nanobind/stl/shared_ptr.h> #include <memory> #include <vector> namespace nb = nanobind; using namespace nb::literals; struct Counter { size_t value = 0; void inc() { value++; } void merge(Counter &o) { value += o.value; o.value = 0; } }; struc...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_thread.py
Python
import random import threading import test_thread_ext as t from test_thread_ext import Counter, GlobalData, ClassWithProperty, ClassWithClassProperty from common import parallelize def test01_object_creation(n_threads=8): # This test hammers 'inst_c2p' from multiple threads, and # checks that the locking of i...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_typing.cpp
C++
#include <nanobind/typing.h> #include <nanobind/operators.h> namespace nb = nanobind; using namespace nb::literals; class NestedClass {}; namespace nanobind { namespace detail { template <> struct type_caster<NestedClass> { NB_TYPE_CASTER(NestedClass, const_name("py_stub_test.AClass.NestedClass")) bool from...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
tests/test_typing.py
Python
import test_typing_ext as t import sys import pytest import platform def test01_parameterize_generic(): assert str(type(t.Wrapper[int]) == 't.Wrapper[int]') if platform.python_implementation() != 'PyPy': assert issubclass(t.WrapperFoo, t.Wrapper) assert t.WrapperFoo.__bases__ == (t.Wrapper,) ...
wjakob/nanobind
3,353
nanobind: tiny and efficient C++/Python bindings
C++
wjakob
Wenzel Jakob
EPFL
src/nanobind_example/__init__.py
Python
from .nanobind_example_ext import add, __doc__
wjakob/nanobind_example
119
A nanobind example project
CMake
wjakob
Wenzel Jakob
EPFL
src/nanobind_example_ext.cpp
C++
#include <nanobind/nanobind.h> namespace nb = nanobind; using namespace nb::literals; NB_MODULE(nanobind_example_ext, m) { m.doc() = "This is a \"hello world\" example with nanobind"; m.def("add", [](int a, int b) { return a + b; }, "a"_a, "b"_a); }
wjakob/nanobind_example
119
A nanobind example project
CMake
wjakob
Wenzel Jakob
EPFL
tests/test_basic.py
Python
import nanobind_example as m def test_add(): assert m.add(1, 2) == 3
wjakob/nanobind_example
119
A nanobind example project
CMake
wjakob
Wenzel Jakob
EPFL
parallel_stable_sort.h
C/C++ Header
/* Copyright (C) 2014 Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of con...
wjakob/pss
15
Parallel Stable Sort
C++
wjakob
Wenzel Jakob
EPFL
pss_common.h
C/C++ Header
/* Copyright (C) 2014 Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions a...
wjakob/pss
15
Parallel Stable Sort
C++
wjakob
Wenzel Jakob
EPFL
rigol/__init__.py
Python
""" Rigol instrument control and measurement tools. This package provides tools for controlling Rigol oscilloscopes and performing measurements. Submodules: rigol.bode - Bode plot measurement tool rigol.scope - Generic oscilloscope control interface rigol.util - Utility functions for analysis and visualiz...
wjakob/rigol
2
Bode plot utility for Rigol DHO900 series oscilloscopes
Python
wjakob
Wenzel Jakob
EPFL
rigol/bode.py
Python
""" BodePlot: Unified class for Bode plot measurements with Rigol DHO924S. Combines scope configuration, measurement sweeps, and data management. Supports flexible callbacks for progress reporting and live plotting. Usage: bode = BodePlot( input_ch=1, output_ch=2, afg_amplitude=10.0, ...
wjakob/rigol
2
Bode plot utility for Rigol DHO900 series oscilloscopes
Python
wjakob
Wenzel Jakob
EPFL
rigol/scope.py
Python
""" Generic scope abstraction for SCPI-controlled oscilloscopes. This module provides a property-based API for controlling oscilloscope parameters with batched command execution for efficiency. Properties are automatically generated from parameter tables for efficiency and maintainability. """ from enum import Enum ...
wjakob/rigol
2
Bode plot utility for Rigol DHO900 series oscilloscopes
Python
wjakob
Wenzel Jakob
EPFL
rigol/util.py
Python
""" Utility functions for Bode plot analysis and visualization. """ import re import sys from typing import Tuple, Optional, Dict, Callable import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatter # Precompiled regex for SI unit parsing # Matches: optional sign, number, optional...
wjakob/rigol
2
Bode plot utility for Rigol DHO900 series oscilloscopes
Python
wjakob
Wenzel Jakob
EPFL
test_scope.py
Python
""" Comprehensive test suite for Scope abstraction. Tests every exposed parameter with set + query round-trip verification. Requires a connected oscilloscope at 192.168.5.2. """ import pytest import numpy as np from rigol.scope import Scope @pytest.fixture(scope="module") def scope(): """Create scope instance f...
wjakob/rigol
2
Bode plot utility for Rigol DHO900 series oscilloscopes
Python
wjakob
Wenzel Jakob
EPFL
setup.py
Python
import sys, re, os try: from skbuild import setup import nanobind except ImportError: print("The preferred way to invoke 'setup.py' is via pip, as in 'pip " "install .'. If you wish to run the setup script directly, you must " "first install the build dependencies listed in pyproject.to...
wjakob/typing_repro
5
CMake
wjakob
Wenzel Jakob
EPFL
src/typing_repro/__init__.py
Python
from .typing_repro_ext import A
wjakob/typing_repro
5
CMake
wjakob
Wenzel Jakob
EPFL
src/typing_repro_ext.cpp
C++
#include <nanobind/nanobind.h> namespace nb = nanobind; using namespace nb::literals; NB_MODULE(typing_repro_ext, m) { struct A { }; nb::class_<A>(m, "A") .def(nb::init<>()) .def("add", [](A &, int a, int b) { return a + b; }, "a"_a, "b"_a); }
wjakob/typing_repro
5
CMake
wjakob
Wenzel Jakob
EPFL
tests/test_basic.py
Python
import typing_repro as m def test_add(): assert m.A().add(1, 2) == 3
wjakob/typing_repro
5
CMake
wjakob
Wenzel Jakob
EPFL
flight_server.py
Python
# Copied from https://github.com/apache/arrow/blob/master/python/examples/flight/server.py # + modified to use grpc+unix """An example Flight Python server.""" import argparse import ast import threading import time import pyarrow import pyarrow.flight class FlightServer(pyarrow.flight.FlightServerBase): def _...
wjones127/arrow-ipc-bench
16
Testing various methods of moving Arrow data between processes
Python
wjones127
Will Jones
lancedb
retrieve_arrow.py
Python
# In new Python from io import TextIOWrapper import pyarrow as pa import pyarrow.compute as pc import pyarrow.flight import pyarrow.plasma as plasma from multiprocessing import shared_memory from contextlib import contextmanager import time def retrieve_sharedmemory(name: str) -> pa.Table: table_shm = shared_memor...
wjones127/arrow-ipc-bench
16
Testing various methods of moving Arrow data between processes
Python
wjones127
Will Jones
lancedb
share_arrow.py
Python
from io import TextIOWrapper import time import pyarrow as pa import pyarrow.flight from multiprocessing import shared_memory import pyarrow.plasma as plasma from contextlib import contextmanager import numpy as np # TODO: show IPC file for comparison # TODO: show Ray actor for comparison def calculate_ipc_size(table...
wjones127/arrow-ipc-bench
16
Testing various methods of moving Arrow data between processes
Python
wjones127
Will Jones
lancedb
local_bench.sh
Shell
# Create a 1GB file cargo run --release file://$(pwd)/test.bin \ upload-data --size $((1024 * 1024 * 1024)) OUTPUT_FILE=results.ndjson rm $OUTPUT_FILE # Test parallel download to see what parallelism works best for i in {1,5,10,20}; do echo "Running test $i" cargo run --release file://$(pwd)/test.bin \ ...
wjones127/object-store-bench
0
Rust
wjones127
Will Jones
lancedb
src/columnar.rs
Rust
//! A simulated columnar format. Various pages are stored in a single file. //! //! We simulate this by considering an existing blob and a set of fixed-size pages //! and splitting up the file into those pages so we can read. //! //! For example, we might get a parameter `--page-sizes=1024,4096,16384` and //! so then w...
wjones127/object-store-bench
0
Rust
wjones127
Will Jones
lancedb
src/download.rs
Rust
//! Parallel download implementation use std::sync::Arc; use futures::{StreamExt, TryStreamExt}; use object_store::{path::Path, ObjectStore}; use tracing::instrument; use crate::inspect_location; /// Benchmarks the approach of downloading an object in parallel /// /// * `location`: where the test object should be m...
wjones127/object-store-bench
0
Rust
wjones127
Will Jones
lancedb
src/main.rs
Rust
use std::sync::Arc; use clap::{Parser, Subcommand}; use futures::TryStreamExt; use object_store::{parse_url, ObjectMeta}; use object_store::{path::Path, ObjectStore}; use rand::{thread_rng, Rng, RngCore}; use tokio::io::AsyncWriteExt; use tracing_chrome::{ChromeLayerBuilder, TraceStyle}; use tracing_subscriber::prelud...
wjones127/object-store-bench
0
Rust
wjones127
Will Jones
lancedb
01/aoc_01/src/main.rs
Rust
fn find_pairs_that_add_to_sum( target_sum: u64, numbers: &Vec<u64> ) -> Result<(u64, u64), &'static str> { for op1 in numbers { for op2 in numbers { if op1 + op2 == target_sum { return Ok((*op1, *op2)); } } } Err("failed to find a matching pair") } fn find_triplets_that_add_to_sum...
wjwwood/advent_of_code_2020
2
Advent of Code for 2020
Rust
wjwwood
William Woodall
02/aoc_02/src/main.rs
Rust
use std::fs; fn parse_password_db_string<'a>( passwords_db_string: &'a String ) -> Vec<(usize, usize, &'a str, &'a str)> { let lines = passwords_db_string.lines(); let mut passwords: Vec<(usize, usize, &str, &str)> = Vec::new(); for line in lines { let tokens: Vec<&str> = line.split_whitespace().collect();...
wjwwood/advent_of_code_2020
2
Advent of Code for 2020
Rust
wjwwood
William Woodall
cmake/serialConfig.cmake
CMake
get_filename_component(SERIAL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set(SERIAL_INCLUDE_DIRS "${SERIAL_CMAKE_DIR}/../../../include") find_library(SERIAL_LIBRARIES serial PATHS ${SERIAL_CMAKE_DIR}/../../../lib/serial)
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
examples/serial_example.cc
C++
/*** * This example expects the serial port has a loopback on it. * * Alternatively, you could use an Arduino: * * <pre> * void setup() { * Serial.begin(<insert your baudrate here>); * } * * void loop() { * if (Serial.available()) { * Serial.write(Serial.read()); * } * } * </pre> */ #...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
include/serial/impl/unix.h
C/C++ Header
/*! * \file serial/impl/unix.h * \author William Woodall <wjwwood@gmail.com> * \author John Harrison <ash@greaterthaninfinity.com> * \version 0.1 * * \section LICENSE * * The MIT License * * Copyright (c) 2012 William Woodall, John Harrison * * Permission is hereby granted, free of charge, to any person o...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
include/serial/impl/win.h
C/C++ Header
/*! * \file serial/impl/windows.h * \author William Woodall <wjwwood@gmail.com> * \author John Harrison <ash@greaterthaninfinity.com> * \version 0.1 * * \section LICENSE * * The MIT License * * Copyright (c) 2012 William Woodall, John Harrison * * Permission is hereby granted, free of charge, to any perso...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
include/serial/serial.h
C/C++ Header
/*! * \file serial/serial.h * \author William Woodall <wjwwood@gmail.com> * \author John Harrison <ash.gti@gmail.com> * \version 0.1 * * \section LICENSE * * The MIT License * * Copyright (c) 2012 William Woodall * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
include/serial/v8stdint.h
C/C++ Header
// This header is from the v8 google project: // http://code.google.com/p/v8/source/browse/trunk/include/v8stdint.h // Copyright 2012 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions ...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/impl/list_ports/list_ports_linux.cc
C++
#if defined(__linux__) /* * Copyright (c) 2014 Craig Lilley <cralilley@gmail.com> * This software is made available under the terms of the MIT licence. * A copy of the licence can be obtained from: * http://opensource.org/licenses/MIT */ #include <vector> #include <string> #include <sstream> #include <stdexcept>...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/impl/list_ports/list_ports_osx.cc
C++
#if defined(__APPLE__) #include <sys/param.h> #include <stdint.h> #include <CoreFoundation/CoreFoundation.h> #include <IOKit/IOKitLib.h> #include <IOKit/serial/IOSerialKeys.h> #include <IOKit/IOBSD.h> #include <iostream> #include <string> #include <vector> #include "serial/serial.h" using serial::PortInfo; using s...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/impl/list_ports/list_ports_win.cc
C++
#if defined(_WIN32) /* * Copyright (c) 2014 Craig Lilley <cralilley@gmail.com> * This software is made available under the terms of the MIT licence. * A copy of the licence can be obtained from: * http://opensource.org/licenses/MIT */ #include "serial/serial.h" #include <tchar.h> #include <windows.h> #include <s...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/impl/unix.cc
C++
/* Copyright 2012 William Woodall and John Harrison * * Additional Contributors: Christopher Baker @bakercp */ #if !defined(_WIN32) #include <stdio.h> #include <string.h> #include <sstream> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/signal.h> #include <errno.h> #include <paths.h> #...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/impl/win.cc
C++
#if defined(_WIN32) /* Copyright 2012 William Woodall and John Harrison */ #include <sstream> #include "serial/impl/win.h" using std::string; using std::wstring; using std::stringstream; using std::invalid_argument; using serial::Serial; using serial::Timeout; using serial::bytesize_t; using serial::parity_t; using...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
src/serial.cc
C++
/* Copyright 2012 William Woodall and John Harrison */ #include <algorithm> #if !defined(_WIN32) && !defined(__OpenBSD__) && !defined(__FreeBSD__) # include <alloca.h> #endif #if defined (__MINGW32__) # define alloca __builtin_alloca #endif #include "serial/serial.h" #ifdef _WIN32 #include "serial/impl/win.h" #else...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
tests/proof_of_concepts/mdc2250.cc
C++
#include ""
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
tests/proof_of_concepts/python_serial_test.py
Python
#!/usr/bin/env python import serial, sys if len(sys.argv) != 2: print "python: Usage_serial_test <port name like: /dev/ttyUSB0>" sys.exit(1) sio = serial.Serial(sys.argv[1], 115200) sio.timeout = 250 while True: sio.write("Testing.") print sio.read(8)
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
tests/proof_of_concepts/tokenizer.cc
C++
#include <iostream> #include <string> #include <vector> #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> void _delimeter_tokenizer (std::string &data, std::vector<std::string> &tokens, std::string delimeter) { boost::spl...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
tests/unit/unix_timer_tests.cc
C++
#include "gtest/gtest.h" #include "serial/impl/unix.h" #include <unistd.h> #include <stdlib.h> using serial::MillisecondTimer; namespace { /** * Do 100 trials of timing gaps between 0 and 19 milliseconds. * Expect accuracy within one millisecond. */ TEST(timer_tests, short_intervals) { for (int trial = 0; tria...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
tests/unix_serial_tests.cc
C++
/* To run these tests you need to change the define below to the serial port * with a loop back device attached. * * Alternatively you could use an Arduino: void setup() { Serial.begin(115200); } void loop() { while (Serial.available() > 0) { Serial.write(Serial.read()); } } */ #include <string> #inclu...
wjwwood/cxx_serial
7
Cross-platform, Serial Port library written in C++
C++
wjwwood
William Woodall
http_requester/src/http_requester.cpp
C++
// Copyright 2023 William Woodall // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to...
wjwwood/http_requester
4
ROS packages for making HTTP Requests via ROS
C++
wjwwood
William Woodall