diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d914901..fcf3ef4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,23 +14,13 @@ jobs: with: submodules: "recursive" - - name: Make build directory - run: cmake -E make_directory ${{runner.workspace}}/build - - - name: Configure cmake - shell: bash - working-directory: ${{runner.workspace}}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Debug -DBUILD_DOCS=OFF -DBUILD_TESTING=ON -DBUILD_PYTHON=OFF - - - name: Build - shell: bash - working-directory: ${{runner.workspace}}/build - run: cmake --build . - - - name: Run tests - shell: bash - working-directory: ${{runner.workspace}}/build - run: ctest + - name: Build and run c++ tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_DOCS=OFF -DBUILD_PYTHON=OFF -DBUILD_TESTING=ON .. + cmake --build . + ctest python: name: "${{ matrix.os }} :: Python ${{ matrix.python-version }}" diff --git a/.readthedocs.yml b/.readthedocs.yml index 6da12dd..d462055 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,9 +1,9 @@ version: 2 build: - os: "ubuntu-20.04" + os: "ubuntu-22.04" tools: - python: "3.9" + python: "3.12" sphinx: builder: html diff --git a/CMakeLists.txt b/CMakeLists.txt index 75e22d1..1b84119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,14 @@ cmake_minimum_required(VERSION 3.15..3.26) # Set a name and a version number for your project: project( pybind11-numpy-example - VERSION 0.0.7 + VERSION 0.0.9 LANGUAGES CXX) # Initialize some default paths include(GNUInstallDirs) # Define the minimum C++ standard that is required -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -19,15 +19,15 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(BUILD_PYTHON "Enable building of Python bindings" ON) option(BUILD_DOCS "Enable building of documentation" ON) -# Build the library -add_subdirectory(src) +# Build the c++ library +add_subdirectory(lib) -# Build the tests +# Build the c++ tests include(CTest) if(BUILD_TESTING) add_subdirectory(ext/Catch2) include(./ext/Catch2/extras/Catch.cmake) - add_subdirectory(tests) + add_subdirectory(tests/cpp) endif() # Build the documentation @@ -37,26 +37,26 @@ endif() # Build the python bindings if(BUILD_PYTHON) - add_subdirectory(python) + add_subdirectory(src) endif() # Add an alias target for use if this project is included as a subproject in # another project -add_library(pybind11-numpy-example::pybind11-numpy-example ALIAS - pybind11-numpy-example) +add_library(pybind11_numpy_example::pybind11_numpy_example ALIAS + pybind11_numpy_example) # Install targets and configuration install( - TARGETS pybind11-numpy-example - EXPORT pybind11-numpy-example-config + TARGETS pybind11_numpy_example + EXPORT pybind11_numpy_example_config RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( - EXPORT pybind11-numpy-example-config - NAMESPACE pybind11-numpy-example:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pybind11-numpy-example) + EXPORT pybind11_numpy_example_config + NAMESPACE pybind11_numpy_example:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/pybind11_numpy_example) install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/README.md b/README.md index 5b91b1c..2e4be5c 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ a Numpy array is much faster and uses a lot less memory: # How -The pybind11 code is in [python/pybind11-numpy-example_python.cpp](https://github.com/ssciwr/pybind11-numpy-example/blob/main/python/pybind11-numpy-example_python.cpp). +The pybind11 code is in [src/pybind11_numpy_example_python.cpp](https://github.com/ssciwr/pybind11-numpy-example/blob/main/src/pybind11_numpy_example_python.cpp). -The python project is defined in [pyproject.toml](https://github.com/ssciwr/pybind11-numpy-example/blob/main/pyproject.toml) +The python package is defined in [pyproject.toml](https://github.com/ssciwr/pybind11-numpy-example/blob/main/pyproject.toml) and uses [scikit-build-core](https://github.com/scikit-build/scikit-build-core). Each tagged commit triggers a [GitHub action job](https://github.com/ssciwr/pybind11-numpy-example/actions/workflows/pypi.yml) diff --git a/doc/index.rst b/doc/index.rst index d38b142..40b4b15 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -42,7 +42,7 @@ How === The pybind11 code is in -`python/pybind11-numpy-example\_python.cpp `__. +`src/pybind11\_numpy\_example\_python.cpp `__. The python project is defined in `pyproject.toml `__ and uses `scikit-build-core `__. diff --git a/ext/Catch2 b/ext/Catch2 index 6e79e68..f981c9c 160000 --- a/ext/Catch2 +++ b/ext/Catch2 @@ -1 +1 @@ -Subproject commit 6e79e682b726f524310d55dec8ddac4e9c52fb5f +Subproject commit f981c9cbcac07a2690e5a86767eba490b5465463 diff --git a/include/pybind11-numpy-example/pybind11-numpy-example.hpp b/include/pybind11_numpy_example/pybind11_numpy_example.hpp similarity index 100% rename from include/pybind11-numpy-example/pybind11-numpy-example.hpp rename to include/pybind11_numpy_example/pybind11_numpy_example.hpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..ba11044 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(pybind11_numpy_example pybind11_numpy_example.cpp) +target_include_directories( + pybind11_numpy_example + PUBLIC $ + $) diff --git a/lib/pybind11_numpy_example.cpp b/lib/pybind11_numpy_example.cpp new file mode 100644 index 0000000..7aab0b8 --- /dev/null +++ b/lib/pybind11_numpy_example.cpp @@ -0,0 +1 @@ +#include "pybind11_numpy_example/pybind11_numpy_example.hpp" diff --git a/pyproject.toml b/pyproject.toml index c5f3247..95e0ba2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,9 @@ description = "An example of using numpy with pybind11" readme = "README.md" license = {text = "MIT"} authors=[{name="Liam Keegan", email="liam@keegan.ch"}] +maintainers=[{name="Liam Keegan", email="liam@keegan.ch"}] requires-python = ">=3.7" +keywords = ["pybind11", "cibuildwheel", "c++", "pypi", "numpy", "simple", "example"] classifiers=[ "Programming Language :: C++", "Programming Language :: Python :: 3 :: Only", @@ -29,6 +31,7 @@ classifiers=[ [project.urls] Github = "https://github.com/ssciwr/pybind11-numpy-example" +Documentation = "https://pybind11-numpy-example.readthedocs.io" [project.optional-dependencies] test = ["pytest", "numpy"] @@ -41,5 +44,5 @@ BUILD_DOCS = "OFF" [tool.cibuildwheel] test-extras = "test" -test-command = "python -m pytest {project}/python/tests -v" +test-command = "python -m pytest {project}/tests/python -v" test-skip = "pp* *-musllinux* *-manylinux_i686" diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt deleted file mode 100644 index a3c5ebc..0000000 --- a/python/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -find_package(pybind11 CONFIG REQUIRED) -pybind11_add_module(pybind11numpyexample_python - pybind11-numpy-example_python.cpp) -target_link_libraries(pybind11numpyexample_python PUBLIC pybind11-numpy-example) -set_target_properties(pybind11numpyexample_python - PROPERTIES OUTPUT_NAME pybind11numpyexample) -install(TARGETS pybind11numpyexample_python DESTINATION .) diff --git a/scripts/benchmarks.sh b/scripts/benchmarks.sh index 1337f97..22348a2 100755 --- a/scripts/benchmarks.sh +++ b/scripts/benchmarks.sh @@ -8,8 +8,9 @@ echo "#n time (seconds)" > time_list.txt cp time_list.txt time_array.txt cp time_list.txt time_array_nocopy.txt -for n in 1000 10000 100000 1000000 10000000 50000000 100000000 200000000 300000000 400000000 +for n in 1000 10000 100000 1000000 10000000 50000000 100000000 200000000 300000000 400000000 600000000 800000000 1000000000 1200000000 do + echo $n m_list=$(./memory.py $n 0) m_array=$(./memory.py $n 1) m_array_nocopy=$(./memory.py $n 2) @@ -24,9 +25,9 @@ do echo "${n} ${t_array}" >> time_array.txt echo "${n} ${t_array_nocopy}" >> time_array_nocopy.txt done - -for n in 1000000000 2000000000 3000000000 4000000000 +for n in 2000000000 3000000000 4000000000 6000000000 8000000000 10000000000 12000000000 do + echo $n m_array=$(./memory.py $n 1) echo "${n} ${m_array}" >> mem_array.txt m_array_nocopy=$(./memory.py $n 2) @@ -38,8 +39,9 @@ do echo "${n} ${t_array_nocopy}" >> time_array_nocopy.txt done -for n in 5000000000 6000000000 7000000000 8000000000 +for n in 14000000000 16000000000 18000000000 20000000000 24000000000 do + echo $n m_array_nocopy=$(./memory.py $n 2) echo "${n} ${m_array_nocopy}" >> mem_array_nocopy.txt diff --git a/scripts/mem_array.txt b/scripts/mem_array.txt index 2042bc9..84b288d 100644 --- a/scripts/mem_array.txt +++ b/scripts/mem_array.txt @@ -1,15 +1,22 @@ #n memory (kb) -1000 18896 -10000 18864 -100000 19560 -1000000 23260 -10000000 58380 -50000000 214536 -100000000 410024 -200000000 800452 -300000000 1191012 -400000000 1581412 -1000000000 3925392 -2000000000 7831684 -3000000000 11737892 -4000000000 15644044 +1000 20648 +10000 20664 +100000 20840 +1000000 24520 +10000000 59672 +50000000 215920 +100000000 411412 +200000000 801848 +300000000 1192548 +400000000 1583112 +600000000 2363992 +800000000 3145808 +1000000000 3926680 +1200000000 4708296 +2000000000 7832800 +3000000000 11739192 +4000000000 15645488 +6000000000 23458288 +8000000000 31270592 +10000000000 39083108 +12000000000 46895616 diff --git a/scripts/mem_array_nocopy.txt b/scripts/mem_array_nocopy.txt index 3380000..daf7a68 100644 --- a/scripts/mem_array_nocopy.txt +++ b/scripts/mem_array_nocopy.txt @@ -1,19 +1,27 @@ #n memory (kb) -1000 18808 -10000 18864 -100000 18936 -1000000 20912 -10000000 38284 -50000000 116396 -100000000 214164 -200000000 409508 -300000000 604768 -400000000 800084 -1000000000 1971984 -2000000000 3925016 -3000000000 5878236 -4000000000 7831396 -5000000000 9784604 -6000000000 11737484 -7000000000 13690668 -8000000000 15643960 +1000 20656 +10000 20668 +100000 20844 +1000000 22596 +10000000 39936 +50000000 118080 +100000000 215964 +200000000 411264 +300000000 606336 +400000000 801716 +600000000 1192512 +800000000 1583148 +1000000000 1973368 +1200000000 2364404 +2000000000 3926908 +3000000000 5880000 +4000000000 7832964 +6000000000 11739264 +8000000000 15645624 +10000000000 19551908 +12000000000 23457968 +14000000000 27364404 +16000000000 31270648 +18000000000 35176512 +20000000000 39083136 +24000000000 46895548 diff --git a/scripts/mem_list.txt b/scripts/mem_list.txt index 111cb6a..a5c4ec1 100644 --- a/scripts/mem_list.txt +++ b/scripts/mem_list.txt @@ -1,11 +1,15 @@ #n memory (kb) -1000 0 -10000 444 -100000 4164 -1000000 41356 -10000000 414140 -50000000 2069920 -100000000 4139380 -200000000 8278588 -300000000 12418828 -400000000 16557252 +1000 192 +10000 384 +100000 4224 +1000000 41088 +10000000 410304 +50000000 2050752 +100000000 4101504 +200000000 8203200 +300000000 12304704 +400000000 16405824 +600000000 24609216 +800000000 32811840 +1000000000 41014464 +1200000000 49218432 diff --git a/scripts/memory.png b/scripts/memory.png index 7ac77cb..3603730 100644 Binary files a/scripts/memory.png and b/scripts/memory.png differ diff --git a/scripts/memory.py b/scripts/memory.py index 5d88824..f73b2f5 100755 --- a/scripts/memory.py +++ b/scripts/memory.py @@ -2,7 +2,7 @@ # simple script to print approx memory usage -import pybind11numpyexample +import pybind11_numpy_example import resource import sys @@ -11,11 +11,11 @@ max_mem_before = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss if data_type == 0: - a = pybind11numpyexample.vector_as_list(n) + a = pybind11_numpy_example.vector_as_list(n) elif data_type == 1: - a = pybind11numpyexample.vector_as_array(n) + a = pybind11_numpy_example.vector_as_array(n) elif data_type == 2: - a = pybind11numpyexample.vector_as_array_nocopy(n) + a = pybind11_numpy_example.vector_as_array_nocopy(n) max_mem_after = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss diff --git a/scripts/time.png b/scripts/time.png index 89c65a1..0e12dcc 100644 Binary files a/scripts/time.png and b/scripts/time.png differ diff --git a/scripts/time.py b/scripts/time.py index e4c7497..0a7f277 100755 --- a/scripts/time.py +++ b/scripts/time.py @@ -2,7 +2,7 @@ # simple script to print approx time taken -import pybind11numpyexample +import pybind11_numpy_example import timeit import sys @@ -13,11 +13,11 @@ def doit(): if data_type == 0: - return pybind11numpyexample.vector_as_list(n) + return pybind11_numpy_example.vector_as_list(n) elif data_type == 1: - return pybind11numpyexample.vector_as_array(n) + return pybind11_numpy_example.vector_as_array(n) elif data_type == 2: - return pybind11numpyexample.vector_as_array_nocopy(n) + return pybind11_numpy_example.vector_as_array_nocopy(n) print(timeit.timeit(doit, number=iters) / iters) diff --git a/scripts/time_array.txt b/scripts/time_array.txt index de17e6c..6dfe24e 100644 --- a/scripts/time_array.txt +++ b/scripts/time_array.txt @@ -1,15 +1,22 @@ #n time (seconds) -1000 1.0294279672216436e-05 -10000 9.17243686327655e-05 -100000 0.0008979495345340525 -1000000 0.008858304726097478 -10000000 0.053286767499230336 -50000000 0.13255561800906435 -100000000 0.17452786200738046 -200000000 0.25977244100067765 -300000000 0.3446448600006988 -400000000 0.4255073300009826 -1000000000 0.9024126849981258 -2000000000 1.6776944080047542 -3000000000 2.439360503994976 -4000000000 3.1745616889966186 +1000 8.885241385522114e-06 +10000 8.064530965231068e-05 +100000 0.0007929159005605938 +1000000 0.009228698179041121 +10000000 0.05545463500311598 +50000000 0.16033962194342166 +100000000 0.23489250801503658 +200000000 0.387445722008124 +300000000 0.5446825119433925 +400000000 0.6931000800104812 +600000000 1.0074213709449396 +800000000 1.3038605999900028 +1000000000 1.6112821800634265 +1200000000 1.8958396930247545 +2000000000 3.080139480996877 +3000000000 4.569697203929536 +4000000000 6.015317940968089 +6000000000 8.836932464968413 +8000000000 11.728594742016867 +10000000000 14.558276921976358 +12000000000 17.50521888397634 diff --git a/scripts/time_array_nocopy.txt b/scripts/time_array_nocopy.txt index 213bec0..20b7c96 100644 --- a/scripts/time_array_nocopy.txt +++ b/scripts/time_array_nocopy.txt @@ -1,19 +1,27 @@ #n time (seconds) -1000 9.999668932844945e-06 -10000 9.167261039231114e-05 -100000 0.0008991213465261614 -1000000 0.008335511999162422 -10000000 0.050443788000848144 -50000000 0.12099327699979767 -100000000 0.15236243599792942 -200000000 0.21317349300079513 -300000000 0.27599514700705186 -400000000 0.33998234900354873 -1000000000 0.6818497240019497 -2000000000 1.2458708429912804 -3000000000 1.7789631179912249 -4000000000 2.310697248991346 -5000000000 2.809482886994374 -6000000000 3.338349138997728 -7000000000 3.847873509992496 -8000000000 4.3607585489953635 +1000 8.883211479922996e-06 +10000 7.990702798778003e-05 +100000 0.0007843043065012092 +1000000 0.007740272727625614 +10000000 0.050859106006100774 +50000000 0.1441949950531125 +100000000 0.239397105993703 +200000000 0.3419582910137251 +300000000 0.48297904699575156 +400000000 0.6020817440003157 +600000000 0.8661073229741305 +800000000 1.1198496220167726 +1000000000 1.3745229849591851 +1200000000 1.6183152759913355 +2000000000 2.622669712989591 +3000000000 3.8534785190131515 +4000000000 5.067567399004474 +6000000000 7.537025678087957 +8000000000 9.918707602075301 +10000000000 12.325743645080365 +12000000000 14.685017141047865 +14000000000 17.10181719996035 +16000000000 19.59815236995928 +18000000000 21.906724045053124 +20000000000 24.42910428403411 +24000000000 29.188139538047835 diff --git a/scripts/time_list.txt b/scripts/time_list.txt index dda04c7..2c1d011 100644 --- a/scripts/time_list.txt +++ b/scripts/time_list.txt @@ -1,11 +1,15 @@ #n time (seconds) -1000 1.6527705828344668e-05 -10000 0.00021758406994293084 -100000 0.0027138690693571353 -1000000 0.03301038918222978 -10000000 0.3295107399972039 -50000000 1.6292891499906546 -100000000 3.3216604850022122 -200000000 6.464595986995846 -300000000 9.88627804099815 -400000000 12.484707872994477 +1000 1.1281892404451172e-05 +10000 0.00012381860035491158 +100000 0.0021609368014822504 +1000000 0.028091967190531166 +10000000 0.3382009760243818 +50000000 1.6539601690601557 +100000000 3.3066364750266075 +200000000 6.4062930109212175 +300000000 9.456814253004268 +400000000 12.655741214985028 +600000000 18.71708781796042 +800000000 24.94151852594223 +1000000000 31.0570098310709 +1200000000 37.80632794194389 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a4856f..d9b6912 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ -add_library(pybind11-numpy-example pybind11-numpy-example.cpp) -target_include_directories( - pybind11-numpy-example - PUBLIC $ - $) +find_package(pybind11 CONFIG REQUIRED) +pybind11_add_module(_pybind11_numpy_example pybind11_numpy_example_python.cpp) +target_link_libraries(_pybind11_numpy_example PUBLIC pybind11_numpy_example) +install(TARGETS _pybind11_numpy_example DESTINATION pybind11_numpy_example) diff --git a/src/pybind11-numpy-example.cpp b/src/pybind11-numpy-example.cpp deleted file mode 100644 index b24c418..0000000 --- a/src/pybind11-numpy-example.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pybind11-numpy-example/pybind11-numpy-example.hpp" diff --git a/src/pybind11_numpy_example/__init__.py b/src/pybind11_numpy_example/__init__.py new file mode 100644 index 0000000..f22de2d --- /dev/null +++ b/src/pybind11_numpy_example/__init__.py @@ -0,0 +1,7 @@ +# here we import the contents of our compiled C++ module into this package: +from ._pybind11_numpy_example import * + + +# this allows us to also include pure python code in the same namespace: +def pure_python_list(size: int): + return list(range(size)) diff --git a/python/pybind11-numpy-example_python.cpp b/src/pybind11_numpy_example_python.cpp similarity index 95% rename from python/pybind11-numpy-example_python.cpp rename to src/pybind11_numpy_example_python.cpp index 504da91..27c4155 100644 --- a/python/pybind11-numpy-example_python.cpp +++ b/src/pybind11_numpy_example_python.cpp @@ -2,7 +2,7 @@ #include #include -#include "pybind11-numpy-example/pybind11-numpy-example.hpp" +#include "pybind11_numpy_example/pybind11_numpy_example.hpp" namespace py = pybind11; @@ -57,7 +57,7 @@ static py::array_t vector_as_array_nocopy(std::size_t size) { return as_pyarray(std::move(temp_vector)); } -PYBIND11_MODULE(pybind11numpyexample, m) { +PYBIND11_MODULE(_pybind11_numpy_example, m) { m.doc() = "Python Bindings for pybind11-numpy-example"; m.def("vector_as_list", &vector_as_list, "Returns a vector of 16-bit ints as a Python List"); diff --git a/tests/CMakeLists.txt b/tests/cpp/CMakeLists.txt similarity index 56% rename from tests/CMakeLists.txt rename to tests/cpp/CMakeLists.txt index eb5dc08..14600b3 100644 --- a/tests/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ -add_executable(tests pybind11-numpy-example_t.cpp) -target_link_libraries(tests PUBLIC pybind11-numpy-example +add_executable(tests pybind11_numpy_example_t.cpp) +target_link_libraries(tests PUBLIC pybind11_numpy_example Catch2::Catch2WithMain) # allow user to run tests with `make test` or `ctest` diff --git a/tests/pybind11-numpy-example_t.cpp b/tests/cpp/pybind11_numpy_example_t.cpp similarity index 86% rename from tests/pybind11-numpy-example_t.cpp rename to tests/cpp/pybind11_numpy_example_t.cpp index 899b42d..dd3744b 100644 --- a/tests/pybind11-numpy-example_t.cpp +++ b/tests/cpp/pybind11_numpy_example_t.cpp @@ -1,4 +1,4 @@ -#include "pybind11-numpy-example/pybind11-numpy-example.hpp" +#include "pybind11_numpy_example/pybind11_numpy_example.hpp" #include using namespace pybind11numpyexample; diff --git a/tests/tests.cpp b/tests/cpp/tests.cpp similarity index 100% rename from tests/tests.cpp rename to tests/cpp/tests.cpp diff --git a/python/tests/__init__.py b/tests/python/__init__.py similarity index 100% rename from python/tests/__init__.py rename to tests/python/__init__.py diff --git a/python/tests/test_python_bindings.py b/tests/python/test_pybind11_numpy_example.py similarity index 60% rename from python/tests/test_python_bindings.py rename to tests/python/test_pybind11_numpy_example.py index 0d08daa..d3b810b 100644 --- a/python/tests/test_python_bindings.py +++ b/tests/python/test_pybind11_numpy_example.py @@ -1,16 +1,19 @@ -import pybind11numpyexample +import pybind11_numpy_example as pne import numpy as np def test_pybind11_numpy_example(): - assert pybind11numpyexample.vector_as_list(0) == [] - assert pybind11numpyexample.vector_as_list(3) == [0, 1, 2] + assert pne.pure_python_list(0) == [] + assert pne.pure_python_list(3) == [0, 1, 2] - a0 = pybind11numpyexample.vector_as_array(0) + assert pne.vector_as_list(0) == [] + assert pne.vector_as_list(3) == [0, 1, 2] + + a0 = pne.vector_as_array(0) assert type(a0) == np.ndarray assert len(a0) == 0 assert a0.dtype == np.int16 - a3 = pybind11numpyexample.vector_as_array(3) + a3 = pne.vector_as_array(3) assert type(a3) == np.ndarray assert len(a3) == 3 assert a3.dtype == np.int16 @@ -18,11 +21,11 @@ def test_pybind11_numpy_example(): assert a3[1] == 1 assert a3[2] == 2 - a0 = pybind11numpyexample.vector_as_array_nocopy(0) + a0 = pne.vector_as_array_nocopy(0) assert type(a0) == np.ndarray assert len(a0) == 0 assert a0.dtype == np.int16 - a3 = pybind11numpyexample.vector_as_array_nocopy(3) + a3 = pne.vector_as_array_nocopy(3) assert type(a3) == np.ndarray assert len(a3) == 3 assert a3.dtype == np.int16