From 6fd2b38134fe40c521c2e15fe9e55a3ba6b4aaf8 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Thu, 13 Sep 2018 17:15:07 +0800 Subject: [PATCH 01/13] adding Pipfile --- Pipfile | 17 +++++++ Pipfile.lock | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 3 ++ 3 files changed, 149 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..1c8837e --- /dev/null +++ b/Pipfile @@ -0,0 +1,17 @@ +[pipenv] +allow_prereleases = false + +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +pybind11 = "*" + +[dev-packages] +pylama = "*" +pytest = "*" + +[requires] +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..e011db8 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,129 @@ +{ + "_meta": { + "hash": { + "sha256": "e73f0859adb689f83b51e2797725616c5732b7408be15fb441437974d56aaaee" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "pybind11": { + "hashes": [ + "sha256:642abbbd2948ed5af28e69adfae1535347c7aa9eb0cdab130e20e1f198f8e1cf", + "sha256:bd68159013d20c79bf79893b174a6ee7f74af740bf60ae731565f5d8d4094403" + ], + "index": "pypi", + "version": "==2.2.4" + } + }, + "develop": { + "atomicwrites": { + "hashes": [ + "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", + "sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee" + ], + "markers": "python_version != '3.0.*' and python_version >= '2.7' and python_version != '3.3.*' and python_version != '3.2.*' and python_version != '3.1.*'", + "version": "==1.2.1" + }, + "attrs": { + "hashes": [ + "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", + "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" + ], + "version": "==18.2.0" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "more-itertools": { + "hashes": [ + "sha256:c187a73da93e7a8acc0001572aebc7e3c69daf7bf6881a2cea10650bd4420092", + "sha256:c476b5d3a34e12d40130bc2f935028b5f636df8f372dc2c1c01dc19681b2039e", + "sha256:fcbfeaea0be121980e15bc97b3817b5202ca73d0eae185b4550cbfce2a3ebb3d" + ], + "version": "==4.3.0" + }, + "pluggy": { + "hashes": [ + "sha256:6e3836e39f4d36ae72840833db137f7b7d35105079aee6ec4a62d9f80d594dd1", + "sha256:95eb8364a4708392bae89035f45341871286a333f749c3141c20573d2b3876e1" + ], + "markers": "python_version != '3.0.*' and python_version != '3.2.*' and python_version != '3.3.*' and python_version >= '2.7' and python_version != '3.1.*'", + "version": "==0.7.1" + }, + "py": { + "hashes": [ + "sha256:06a30435d058473046be836d3fc4f27167fd84c45b99704f2fb5509ef61f9af1", + "sha256:50402e9d1c9005d759426988a492e0edaadb7f4e68bcddfea586bc7432d009c6" + ], + "markers": "python_version != '3.0.*' and python_version >= '2.7' and python_version != '3.3.*' and python_version != '3.2.*' and python_version != '3.1.*'", + "version": "==1.6.0" + }, + "pycodestyle": { + "hashes": [ + "sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83", + "sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a" + ], + "version": "==2.4.0" + }, + "pydocstyle": { + "hashes": [ + "sha256:08a870edc94508264ed90510db466c6357c7192e0e866561d740624a8fc7d90c", + "sha256:4d5bcde961107873bae621f3d580c3e35a426d3687ffc6f8fb356f6628da5a97", + "sha256:af9fcccb303899b83bec82dc9a1d56c60fc369973223a5e80c3dfa9bdf984405" + ], + "version": "==2.1.1" + }, + "pyflakes": { + "hashes": [ + "sha256:9a7662ec724d0120012f6e29d6248ae3727d821bba522a0e6b356eff19126a49", + "sha256:f661252913bc1dbe7fcfcbf0af0db3f42ab65aabd1a6ca68fe5d466bace94dae" + ], + "markers": "python_version != '3.3.*' and python_version != '3.1.*' and python_version >= '2.7' and python_version != '3.0.*' and python_version != '3.2.*'", + "version": "==2.0.0" + }, + "pylama": { + "hashes": [ + "sha256:390c1dab1daebdf3d6acc923e551b035c3faa77d8b96b98530c230493f9ec712", + "sha256:a3670459e7855529e2ccd3959e0bdebd694ac62bcdc7c58a877f3456c0a2058b" + ], + "index": "pypi", + "version": "==7.4.3" + }, + "pytest": { + "hashes": [ + "sha256:453cbbbe5ce6db38717d282b758b917de84802af4288910c12442984bde7b823", + "sha256:a8a07f84e680482eb51e244370aaf2caa6301ef265f37c2bdefb3dd3b663f99d" + ], + "index": "pypi", + "version": "==3.8.0" + }, + "six": { + "hashes": [ + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + ], + "version": "==1.11.0" + }, + "snowballstemmer": { + "hashes": [ + "sha256:919f26a68b2c17a7634da993d91339e288964f93c274f1343e3bbbe2096e1128", + "sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89" + ], + "version": "==1.2.1" + } + } +} diff --git a/README.md b/README.md index dbad46e..b230d00 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ python_example An example project built with [pybind11](https://github.com/pybind/pybind11). +DC: I am extending this with additional examples to explore specific data types +that I need to manage in another project. + Installation ------------ From 1208ea6f7bc92bf77b8fa2c69660e73c9e60bd5e Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Thu, 13 Sep 2018 17:24:00 +0800 Subject: [PATCH 02/13] adding Makefile and adjusting build flags --- .gitignore | 1 + Makefile | 32 ++++++++++++++++++++++++++++++++ setup.py | 20 +++++++++++++++++--- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 839282b..85a71c0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ MANIFEST _build _generate build +dist/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ac91213 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +SHELL=/bin/sh + +.SILENT: +.IGNORE: + +.PHONY: help +help: + echo + echo 'Utility Makefile + echo '================ + echo + echo 'Targets supported are:' + echo + echo ' * clean: remove all build artefacts' + echo ' * build: builds the Python package' + echo ' * deps: Installs Python build dependencies into a Pipenv environment' + +.PHONY: build +build: + pipenv run python setup.py bdist bdist_wheel + rm -rf tmp/ + +.PHONY: dev +dev: + pipenv install --dev + +.PHONY: clean +clean: + echo Cleaning ... + rm -rf build/ + rm -rf tmp/ + echo ... done diff --git a/setup.py b/setup.py index a0db45c..1cfeb41 100644 --- a/setup.py +++ b/setup.py @@ -24,8 +24,9 @@ def __str__(self): ext_modules = [ Extension( 'python_example', - ['src/main.cpp'], + ['./src/main.cpp'], include_dirs=[ + './src', # Path to pybind11 headers get_pybind_include(), get_pybind_include(user=True) @@ -68,8 +69,21 @@ def cpp_flag(compiler): class BuildExt(build_ext): """A custom build extension for adding compiler-specific options.""" c_opts = { - 'msvc': ['/EHsc'], - 'unix': [], + 'msvc': [ + '/EHsc', + '/W3', + '/GL', + '/Od', + '/Oi', + '/Gy', + '/Zi', + '-DWINDOWS', + ], + 'unix': [ + '-O3', + '-DNDEBUG', + '-DUNIX', + ], } if sys.platform == 'darwin': From 3d04d1c22a1cac1fadb1a0cf3014b39e9fab2fcb Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Thu, 13 Sep 2018 17:24:40 +0800 Subject: [PATCH 03/13] retabbed setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1cfeb41..0ad27b2 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def __str__(self): 'python_example', ['./src/main.cpp'], include_dirs=[ - './src', + './src', # Path to pybind11 headers get_pybind_include(), get_pybind_include(user=True) From 15a35fbd8b5495f7bd5580ef31c2952e09de8a13 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Thu, 13 Sep 2018 17:29:03 +0800 Subject: [PATCH 04/13] converting tests to pytest --- .gitignore | 2 ++ Pipfile | 1 + Pipfile.lock | 6 +++++- README.md | 4 ++-- tests/test.py | 5 ----- tests/test_python_example.py | 10 ++++++++++ 6 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 tests/test.py create mode 100644 tests/test_python_example.py diff --git a/.gitignore b/.gitignore index 85a71c0..09e0bdb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ _build _generate build dist/ +.pytest_cache/ +tmp/ diff --git a/Pipfile b/Pipfile index 1c8837e..cf52335 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ name = "pypi" [packages] pybind11 = "*" +"e1839a8" = {path = ".", editable = true} [dev-packages] pylama = "*" diff --git a/Pipfile.lock b/Pipfile.lock index e011db8..7e1e691 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e73f0859adb689f83b51e2797725616c5732b7408be15fb441437974d56aaaee" + "sha256": "0a00c4f9533fa565d5c973655ab32d3e714a326c8cccf270ebe7e485b18af59d" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,10 @@ ] }, "default": { + "e1839a8": { + "editable": true, + "path": "." + }, "pybind11": { "hashes": [ "sha256:642abbbd2948ed5af28e69adfae1535347c7aa9eb0cdab130e20e1f198f8e1cf", diff --git a/README.md b/README.md index b230d00..de0d8d9 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ python_example An example project built with [pybind11](https://github.com/pybind/pybind11). -DC: I am extending this with additional examples to explore specific data types -that I need to manage in another project. +This fork has been extended with additional examples to explore specific data types +that are needed in another project. Installation ------------ diff --git a/tests/test.py b/tests/test.py deleted file mode 100644 index f877b62..0000000 --- a/tests/test.py +++ /dev/null @@ -1,5 +0,0 @@ -import python_example as m - -assert m.__version__ == '0.0.1' -assert m.add(1, 2) == 3 -assert m.subtract(1, 2) == -1 diff --git a/tests/test_python_example.py b/tests/test_python_example.py new file mode 100644 index 0000000..01dd79f --- /dev/null +++ b/tests/test_python_example.py @@ -0,0 +1,10 @@ +import python_example as m + +def test_version(): + assert m.__version__ == '0.0.1' + +def test_add_1_2(): + assert m.add(1, 2) == 3 + +def test_subtract_1_2(): + assert m.subtract(1, 2) == -1 From 883e3f76b698977bfa9f24226037b42baa57b8e2 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 10:26:35 +0800 Subject: [PATCH 05/13] adjusting make targets --- Makefile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ac91213..defe0f4 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,10 @@ SHELL=/bin/sh .SILENT: .IGNORE: +.PHONY: dev +dev: build + pipenv install -e . + .PHONY: help help: echo @@ -13,20 +17,22 @@ help: echo echo ' * clean: remove all build artefacts' echo ' * build: builds the Python package' - echo ' * deps: Installs Python build dependencies into a Pipenv environment' + echo ' * install: builds and installs into pipenv environment' + echo ' * test: runs unit tests' + echo ' * help: display help message' .PHONY: build build: pipenv run python setup.py bdist bdist_wheel rm -rf tmp/ -.PHONY: dev -dev: - pipenv install --dev - .PHONY: clean clean: echo Cleaning ... rm -rf build/ rm -rf tmp/ echo ... done + +.PHONY: test +test: + pytest ./tests From 77193e092761463a6efce8fa76a815e3b483ce29 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 10:47:30 +0800 Subject: [PATCH 06/13] minor changes --- .vscode/settings.json | 9 ++++ Makefile | 3 ++ Pipfile | 1 + Pipfile.lock | 95 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f47aced --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "python.pythonPath": "/home/daniel/.virtualenvs/python_example-XRpznMVn/bin/python", + "python.unitTest.pyTestArgs": [ + "tests" + ], + "python.unitTest.unittestEnabled": false, + "python.unitTest.nosetestsEnabled": false, + "python.unitTest.pyTestEnabled": true +} \ No newline at end of file diff --git a/Makefile b/Makefile index defe0f4..9548186 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ SHELL=/bin/sh .SILENT: .IGNORE: +.PHONY: all +all: clean dev test + .PHONY: dev dev: build pipenv install -e . diff --git a/Pipfile b/Pipfile index cf52335..3b285ff 100644 --- a/Pipfile +++ b/Pipfile @@ -13,6 +13,7 @@ pybind11 = "*" [dev-packages] pylama = "*" pytest = "*" +pylint = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index 7e1e691..62e3991 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "0a00c4f9533fa565d5c973655ab32d3e714a326c8cccf270ebe7e485b18af59d" + "sha256": "a22b40cb5d89b9f9553c10d1f13ea9d57cbbef82424bd9027985d4fca98c8ab0" }, "pipfile-spec": 6, "requires": { @@ -30,6 +30,13 @@ } }, "develop": { + "astroid": { + "hashes": [ + "sha256:292fa429e69d60e4161e7612cb7cc8fa3609e2e309f80c224d93a76d5e7b58be", + "sha256:c7013d119ec95eb626f7a2011f0b63d0c9a095df9ad06d8507b37084eada1a8d" + ], + "version": "==2.0.4" + }, "atomicwrites": { "hashes": [ "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", @@ -45,6 +52,49 @@ ], "version": "==18.2.0" }, + "isort": { + "hashes": [ + "sha256:1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af", + "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8", + "sha256:ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497" + ], + "markers": "python_version != '3.0.*' and python_version != '3.1.*' and python_version != '3.3.*' and python_version != '3.2.*' and python_version >= '2.7'", + "version": "==4.3.4" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33", + "sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39", + "sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019", + "sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088", + "sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b", + "sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e", + "sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6", + "sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b", + "sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5", + "sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff", + "sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd", + "sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7", + "sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff", + "sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d", + "sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2", + "sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35", + "sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4", + "sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514", + "sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252", + "sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109", + "sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f", + "sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c", + "sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92", + "sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577", + "sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d", + "sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d", + "sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f", + "sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a", + "sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b" + ], + "version": "==1.3.1" + }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", @@ -107,6 +157,14 @@ "index": "pypi", "version": "==7.4.3" }, + "pylint": { + "hashes": [ + "sha256:1d6d3622c94b4887115fe5204982eee66fdd8a951cf98635ee5caee6ec98c3ec", + "sha256:31142f764d2a7cd41df5196f9933b12b7ee55e73ef12204b648ad7e556c119fb" + ], + "index": "pypi", + "version": "==2.1.1" + }, "pytest": { "hashes": [ "sha256:453cbbbe5ce6db38717d282b758b917de84802af4288910c12442984bde7b823", @@ -128,6 +186,41 @@ "sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89" ], "version": "==1.2.1" + }, + "typed-ast": { + "hashes": [ + "sha256:0948004fa228ae071054f5208840a1e88747a357ec1101c17217bfe99b299d58", + "sha256:10703d3cec8dcd9eef5a630a04056bbc898abc19bac5691612acba7d1325b66d", + "sha256:1f6c4bd0bdc0f14246fd41262df7dfc018d65bb05f6e16390b7ea26ca454a291", + "sha256:25d8feefe27eb0303b73545416b13d108c6067b846b543738a25ff304824ed9a", + "sha256:29464a177d56e4e055b5f7b629935af7f49c196be47528cc94e0a7bf83fbc2b9", + "sha256:2e214b72168ea0275efd6c884b114ab42e316de3ffa125b267e732ed2abda892", + "sha256:3e0d5e48e3a23e9a4d1a9f698e32a542a4a288c871d33ed8df1b092a40f3a0f9", + "sha256:519425deca5c2b2bdac49f77b2c5625781abbaf9a809d727d3a5596b30bb4ded", + "sha256:57fe287f0cdd9ceaf69e7b71a2e94a24b5d268b35df251a88fef5cc241bf73aa", + "sha256:668d0cec391d9aed1c6a388b0d5b97cd22e6073eaa5fbaa6d2946603b4871efe", + "sha256:68ba70684990f59497680ff90d18e756a47bf4863c604098f10de9716b2c0bdd", + "sha256:6de012d2b166fe7a4cdf505eee3aaa12192f7ba365beeefaca4ec10e31241a85", + "sha256:79b91ebe5a28d349b6d0d323023350133e927b4de5b651a8aa2db69c761420c6", + "sha256:8550177fa5d4c1f09b5e5f524411c44633c80ec69b24e0e98906dd761941ca46", + "sha256:898f818399cafcdb93cbbe15fc83a33d05f18e29fb498ddc09b0214cdfc7cd51", + "sha256:94b091dc0f19291adcb279a108f5d38de2430411068b219f41b343c03b28fb1f", + "sha256:a26863198902cda15ab4503991e8cf1ca874219e0118cbf07c126bce7c4db129", + "sha256:a8034021801bc0440f2e027c354b4eafd95891b573e12ff0418dec385c76785c", + "sha256:bc978ac17468fe868ee589c795d06777f75496b1ed576d308002c8a5756fb9ea", + "sha256:c05b41bc1deade9f90ddc5d988fe506208019ebba9f2578c622516fd201f5863", + "sha256:c9b060bd1e5a26ab6e8267fd46fc9e02b54eb15fffb16d112d4c7b1c12987559", + "sha256:edb04bdd45bfd76c8292c4d9654568efaedf76fe78eb246dde69bdb13b2dad87", + "sha256:f19f2a4f547505fe9072e15f6f4ae714af51b5a681a97f187971f50c283193b6" + ], + "markers": "python_version < '3.7' and implementation_name == 'cpython'", + "version": "==1.1.0" + }, + "wrapt": { + "hashes": [ + "sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6" + ], + "version": "==1.10.11" } } } From 0edbda95f4ee42c812bb5cf7940c1a549d3b2eff Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 15:18:35 +0800 Subject: [PATCH 07/13] setting up vscode --- .vscode/settings.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f47aced..1482b25 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,8 @@ ], "python.unitTest.unittestEnabled": false, "python.unitTest.nosetestsEnabled": false, - "python.unitTest.pyTestEnabled": true + "python.unitTest.pyTestEnabled": true, + "python.formatting.provider": "black", + "python.linting.pylamaEnabled": true, + "python.linting.pylintEnabled": false } \ No newline at end of file From a68803ab3e92341e485a1b44ba746d3f98c1eb3b Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 15:27:35 +0800 Subject: [PATCH 08/13] adding python include path to C++ intellisense --- .vscode/c_cpp_properties.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..f12856f --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "~/.virtualenvs/python_example-XRpznMVn/include/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64" + } + ], + "version": 4 +} \ No newline at end of file From 5ec050fe8cf82a707493c36999e8f4d8a600457c Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 16:22:20 +0800 Subject: [PATCH 09/13] tests for ndarray input and exceptions --- .vscode/settings.json | 15 +++- Pipfile | 2 +- Pipfile.lock | 129 ++++++++++------------------------- setup.py | 2 - src/main.cpp | 47 ++++++++++++- tests/test_python_example.py | 22 +++++- 6 files changed, 115 insertions(+), 102 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1482b25..2d76132 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,18 @@ "python.unitTest.pyTestEnabled": true, "python.formatting.provider": "black", "python.linting.pylamaEnabled": true, - "python.linting.pylintEnabled": false + "python.linting.pylintEnabled": false, + "files.associations": { + ".flaskenv": "dotenv", + "array": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "initializer_list": "cpp", + "string_view": "cpp", + "valarray": "cpp" + } } \ No newline at end of file diff --git a/Pipfile b/Pipfile index 3b285ff..e7eabf7 100644 --- a/Pipfile +++ b/Pipfile @@ -13,7 +13,7 @@ pybind11 = "*" [dev-packages] pylama = "*" pytest = "*" -pylint = "*" +numpy = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index 62e3991..7ef90bd 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "a22b40cb5d89b9f9553c10d1f13ea9d57cbbef82424bd9027985d4fca98c8ab0" + "sha256": "e241b6d03fa64340227a3f40663a85865b61e16e6f3ba1fa3f3d38b9ef468e55" }, "pipfile-spec": 6, "requires": { @@ -30,13 +30,6 @@ } }, "develop": { - "astroid": { - "hashes": [ - "sha256:292fa429e69d60e4161e7612cb7cc8fa3609e2e309f80c224d93a76d5e7b58be", - "sha256:c7013d119ec95eb626f7a2011f0b63d0c9a095df9ad06d8507b37084eada1a8d" - ], - "version": "==2.0.4" - }, "atomicwrites": { "hashes": [ "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", @@ -52,49 +45,6 @@ ], "version": "==18.2.0" }, - "isort": { - "hashes": [ - "sha256:1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af", - "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8", - "sha256:ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497" - ], - "markers": "python_version != '3.0.*' and python_version != '3.1.*' and python_version != '3.3.*' and python_version != '3.2.*' and python_version >= '2.7'", - "version": "==4.3.4" - }, - "lazy-object-proxy": { - "hashes": [ - "sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33", - "sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39", - "sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019", - "sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088", - "sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b", - "sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e", - "sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6", - "sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b", - "sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5", - "sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff", - "sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd", - "sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7", - "sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff", - "sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d", - "sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2", - "sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35", - "sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4", - "sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514", - "sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252", - "sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109", - "sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f", - "sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c", - "sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92", - "sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577", - "sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d", - "sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d", - "sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f", - "sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a", - "sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b" - ], - "version": "==1.3.1" - }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", @@ -110,6 +60,40 @@ ], "version": "==4.3.0" }, + "numpy": { + "hashes": [ + "sha256:1c362ad12dd09a43b348bb28dd2295dd9cdf77f41f0f45965e04ba97f525b864", + "sha256:2156a06bd407918df4ac0122df6497a9c137432118f585e5b17d543e593d1587", + "sha256:24e4149c38489b51fc774b1e1faa9103e82f73344d7a00ba66f6845ab4769f3f", + "sha256:340ec1697d9bb3a9c464028af7a54245298502e91178bddb4c37626d36e197b7", + "sha256:35db8d419345caa4eeaa65cd63f34a15208acd87530a30f0bc25fc84f55c8c80", + "sha256:361370e9b7f5e44c41eee29f2bb5cb3b755abb4b038bce6d6cbe08db7ff9cb74", + "sha256:36e8dcd1813ca92ce7e4299120cee6c03adad33d89b54862c1b1a100443ac399", + "sha256:378378973546ecc1dfaf9e24c160d683dd04df871ecd2dcc86ce658ca20f92c0", + "sha256:419e6faee16097124ee627ed31572c7e80a1070efa25260b78097cca240e219a", + "sha256:4287104c24e6a09b9b418761a1e7b1bbde65105f110690ca46a23600a3c606b8", + "sha256:549f3e9778b148a47f4fb4682955ed88057eb627c9fe5467f33507c536deda9d", + "sha256:5e359e9c531075220785603e5966eef20ccae9b3b6b8a06fdfb66c084361ce92", + "sha256:5ee7f3dbbdba0da75dec7e94bd7a2b10fe57a83e1b38e678200a6ad8e7b14fdc", + "sha256:62d55e96ec7b117d3d5e618c15efcf769e70a6effaee5842857b64fb4883887a", + "sha256:719b6789acb2bc86ea9b33a701d7c43dc2fc56d95107fd3c5b0a8230164d4dfb", + "sha256:7a70f2b60d48828cba94a54a8776b61a9c2657a803d47f5785f8062e3a9c7c55", + "sha256:7b9e37f194f8bcdca8e9e6af92e2cbad79e360542effc2dd6b98d63955d8d8a3", + "sha256:83b8fc18261b70f45bece2d392537c93dc81eb6c539a16c9ac994c47fc79f09a", + "sha256:9473ad28375710ab18378e72b59422399b27e957e9339c413bf00793b4b12df0", + "sha256:95b085b253080e5d09f7826f5e27dce067bae813a132023a77b739614a29de6e", + "sha256:98b86c62c08c2e5dc98a9c856d4a95329d11b1c6058cb9b5191d5ea6891acd09", + "sha256:a3bd01d6d3ed3d7c06d7f9979ba5d68281f15383fafd53b81aa44b9191047cf8", + "sha256:c81a6afc1d2531a9ada50b58f8c36197f8418ef3d0611d4c1d7af93fdcda764f", + "sha256:ce75ed495a746e3e78cfa22a77096b3bff2eda995616cb7a542047f233091268", + "sha256:dae8618c0bcbfcf6cf91350f8abcdd84158323711566a8c5892b5c7f832af76f", + "sha256:df0b02c6705c5d1c25cc35c7b5d6b6f9b3b30833f9d178843397ae55ecc2eebb", + "sha256:e3660744cda0d94b90141cdd0db9308b958a372cfeee8d7188fdf5ad9108ea82", + "sha256:f2362d0ca3e16c37782c1054d7972b8ad2729169567e3f0f4e5dd3cdf85f188e" + ], + "index": "pypi", + "version": "==1.15.1" + }, "pluggy": { "hashes": [ "sha256:6e3836e39f4d36ae72840833db137f7b7d35105079aee6ec4a62d9f80d594dd1", @@ -157,14 +141,6 @@ "index": "pypi", "version": "==7.4.3" }, - "pylint": { - "hashes": [ - "sha256:1d6d3622c94b4887115fe5204982eee66fdd8a951cf98635ee5caee6ec98c3ec", - "sha256:31142f764d2a7cd41df5196f9933b12b7ee55e73ef12204b648ad7e556c119fb" - ], - "index": "pypi", - "version": "==2.1.1" - }, "pytest": { "hashes": [ "sha256:453cbbbe5ce6db38717d282b758b917de84802af4288910c12442984bde7b823", @@ -186,41 +162,6 @@ "sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89" ], "version": "==1.2.1" - }, - "typed-ast": { - "hashes": [ - "sha256:0948004fa228ae071054f5208840a1e88747a357ec1101c17217bfe99b299d58", - "sha256:10703d3cec8dcd9eef5a630a04056bbc898abc19bac5691612acba7d1325b66d", - "sha256:1f6c4bd0bdc0f14246fd41262df7dfc018d65bb05f6e16390b7ea26ca454a291", - "sha256:25d8feefe27eb0303b73545416b13d108c6067b846b543738a25ff304824ed9a", - "sha256:29464a177d56e4e055b5f7b629935af7f49c196be47528cc94e0a7bf83fbc2b9", - "sha256:2e214b72168ea0275efd6c884b114ab42e316de3ffa125b267e732ed2abda892", - "sha256:3e0d5e48e3a23e9a4d1a9f698e32a542a4a288c871d33ed8df1b092a40f3a0f9", - "sha256:519425deca5c2b2bdac49f77b2c5625781abbaf9a809d727d3a5596b30bb4ded", - "sha256:57fe287f0cdd9ceaf69e7b71a2e94a24b5d268b35df251a88fef5cc241bf73aa", - "sha256:668d0cec391d9aed1c6a388b0d5b97cd22e6073eaa5fbaa6d2946603b4871efe", - "sha256:68ba70684990f59497680ff90d18e756a47bf4863c604098f10de9716b2c0bdd", - "sha256:6de012d2b166fe7a4cdf505eee3aaa12192f7ba365beeefaca4ec10e31241a85", - "sha256:79b91ebe5a28d349b6d0d323023350133e927b4de5b651a8aa2db69c761420c6", - "sha256:8550177fa5d4c1f09b5e5f524411c44633c80ec69b24e0e98906dd761941ca46", - "sha256:898f818399cafcdb93cbbe15fc83a33d05f18e29fb498ddc09b0214cdfc7cd51", - "sha256:94b091dc0f19291adcb279a108f5d38de2430411068b219f41b343c03b28fb1f", - "sha256:a26863198902cda15ab4503991e8cf1ca874219e0118cbf07c126bce7c4db129", - "sha256:a8034021801bc0440f2e027c354b4eafd95891b573e12ff0418dec385c76785c", - "sha256:bc978ac17468fe868ee589c795d06777f75496b1ed576d308002c8a5756fb9ea", - "sha256:c05b41bc1deade9f90ddc5d988fe506208019ebba9f2578c622516fd201f5863", - "sha256:c9b060bd1e5a26ab6e8267fd46fc9e02b54eb15fffb16d112d4c7b1c12987559", - "sha256:edb04bdd45bfd76c8292c4d9654568efaedf76fe78eb246dde69bdb13b2dad87", - "sha256:f19f2a4f547505fe9072e15f6f4ae714af51b5a681a97f187971f50c283193b6" - ], - "markers": "python_version < '3.7' and implementation_name == 'cpython'", - "version": "==1.1.0" - }, - "wrapt": { - "hashes": [ - "sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6" - ], - "version": "==1.10.11" } } } diff --git a/setup.py b/setup.py index 0ad27b2..56263dc 100644 --- a/setup.py +++ b/setup.py @@ -80,8 +80,6 @@ class BuildExt(build_ext): '-DWINDOWS', ], 'unix': [ - '-O3', - '-DNDEBUG', '-DUNIX', ], } diff --git a/src/main.cpp b/src/main.cpp index 94d89a6..554aba6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,43 @@ +#include +#include +#include +#include #include +#include -int add(int i, int j) { +namespace py = pybind11; + +void runtime_error() +{ + throw std::runtime_error("C++ failure"); +} + +void range_error() +{ + throw std::range_error("C++ range error"); +} + +int add(int i, int j) +{ return i + j; } -namespace py = pybind11; +double ndarray_sum(py::array_t ndarray) +{ + // double ndarray_sum(std::vector &ndarray) { + // return std::accumulate(ndarray.begin(), ndarray.end(), 0.0); + auto buf1 = ndarray.request(); + double sum = 0; + int n = buf1.size; + for (int i = 0; i < n; i++) + { + sum += ((double *)buf1.ptr)[i]; + } + return sum; +} -PYBIND11_MODULE(python_example, m) { +PYBIND11_MODULE(python_example, m) +{ m.doc() = R"pbdoc( Pybind11 example plugin ----------------------- @@ -32,6 +63,16 @@ PYBIND11_MODULE(python_example, m) { Some other explanation about the subtract function. )pbdoc"); + m.def("ndarray_sum", &ndarray_sum, R"pbdoc( + Return the sum of a numpy ndarray. + + Tests functions that accept a numpy array and + autoconvert to std::vector. + )pbdoc"); + + m.def("runtime_error", &runtime_error); + m.def("range_error", &range_error); + #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; #else diff --git a/tests/test_python_example.py b/tests/test_python_example.py index 01dd79f..97b3097 100644 --- a/tests/test_python_example.py +++ b/tests/test_python_example.py @@ -1,10 +1,30 @@ +import numpy as np import python_example as m +import pytest + def test_version(): - assert m.__version__ == '0.0.1' + assert m.__version__ == "0.0.1" + def test_add_1_2(): assert m.add(1, 2) == 3 + def test_subtract_1_2(): assert m.subtract(1, 2) == -1 + + +def test_ndarray_args(): + data = np.array([range(10)]) + assert m.ndarray_sum(data) == sum(range(10)) + + +def test_runtime_error(): + with pytest.raises(RuntimeError): + m.runtime_error() + + +def test_range_error(): + with pytest.raises(ValueError): + m.range_error() From 7625503c358f46783c2b30e08bea188deeab713d Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 16:45:56 +0800 Subject: [PATCH 10/13] added tests for numpy array returned from std::vector --- .vscode/settings.json | 3 ++- src/main.cpp | 7 +++++++ tests/test_python_example.py | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2d76132..697354f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,6 +20,7 @@ "vector": "cpp", "initializer_list": "cpp", "string_view": "cpp", - "valarray": "cpp" + "valarray": "cpp", + "stdexcept": "cpp" } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 554aba6..78e58a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,12 @@ double ndarray_sum(py::array_t ndarray) return sum; } +py::array_t get_ndarray(int n, double value) +{ + auto result = std::vector(n, value); + return py::array(result.size(), result.data()); +} + PYBIND11_MODULE(python_example, m) { m.doc() = R"pbdoc( @@ -72,6 +78,7 @@ PYBIND11_MODULE(python_example, m) m.def("runtime_error", &runtime_error); m.def("range_error", &range_error); + m.def("get_ndarray", &get_ndarray); #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; diff --git a/tests/test_python_example.py b/tests/test_python_example.py index 97b3097..c1654d4 100644 --- a/tests/test_python_example.py +++ b/tests/test_python_example.py @@ -28,3 +28,10 @@ def test_runtime_error(): def test_range_error(): with pytest.raises(ValueError): m.range_error() + + +def test_return_ndarray(): + a = m.get_ndarray(10, 5.0) + assert isinstance(a, np.ndarray) + np.testing.assert_allclose(a, 5.0) + assert len(a) == 10 From fcbaf0ff0f316704f31afd4b736896f9b332bc2d Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Fri, 14 Sep 2018 17:10:49 +0800 Subject: [PATCH 11/13] added test for returning a struct of std::vector as a python class of numpy arrays --- .vscode/settings.json | 8 +++++++- src/main.cpp | 24 ++++++++++++++++++++++++ tests/test_python_example.py | 11 +++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 697354f..d9980ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,12 @@ "initializer_list": "cpp", "string_view": "cpp", "valarray": "cpp", - "stdexcept": "cpp" + "stdexcept": "cpp", + "optional": "cpp", + "istream": "cpp", + "ostream": "cpp", + "system_error": "cpp", + "type_traits": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 78e58a6..7d2e66a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,24 @@ py::array_t get_ndarray(int n, double value) return py::array(result.size(), result.data()); } +struct VectorResults +{ + const py::array_t temperature; + const py::array_t humidity; +}; + +VectorResults get_vector_results(int len, double temp_value, double hum_value) +{ + auto tmp = std::vector(len, temp_value); + auto hum = std::vector(len, hum_value); + VectorResults results = { + py::array(tmp.size(), tmp.data()), // temperature + py::array(hum.size(), hum.data()), // humidity + }; + + return results; +} + PYBIND11_MODULE(python_example, m) { m.doc() = R"pbdoc( @@ -80,6 +98,12 @@ PYBIND11_MODULE(python_example, m) m.def("range_error", &range_error); m.def("get_ndarray", &get_ndarray); + py::class_(m, "VectorResults") + .def_readonly("temperature", &VectorResults::temperature) + .def_readonly("humidity", &VectorResults::humidity); + + m.def("get_vector_results", &get_vector_results); + #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; #else diff --git a/tests/test_python_example.py b/tests/test_python_example.py index c1654d4..7420f01 100644 --- a/tests/test_python_example.py +++ b/tests/test_python_example.py @@ -35,3 +35,14 @@ def test_return_ndarray(): assert isinstance(a, np.ndarray) np.testing.assert_allclose(a, 5.0) assert len(a) == 10 + + +def test_get_class_with_vector_results(): + n = 10 + t = 4.3 + h = 88.3 + results = m.get_vector_results(n, t, h) + assert len(results.temperature) == n + np.testing.assert_allclose(results.temperature, t) + assert len(results.humidity) == n + np.testing.assert_allclose(results.humidity, h) From b739c5ccec3d9c6600f8878c8c05fabd58e957a7 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Mon, 17 Sep 2018 12:08:34 +0800 Subject: [PATCH 12/13] updated to ctor syntax --- .vscode/settings.json | 3 ++- src/main.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d9980ba..9cc0c90 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -27,6 +27,7 @@ "ostream": "cpp", "system_error": "cpp", "type_traits": "cpp", - "variant": "cpp" + "variant": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7d2e66a..2d4105b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,11 @@ py::array_t get_ndarray(int n, double value) struct VectorResults { + VectorResults(const std::vector& temperature, + const std::vector& humidity) + : temperature(py::array(temperature.size(), temperature.data())), + humidity(py::array(humidity.size(), humidity.data())){}; + const py::array_t temperature; const py::array_t humidity; }; @@ -52,12 +57,7 @@ VectorResults get_vector_results(int len, double temp_value, double hum_value) { auto tmp = std::vector(len, temp_value); auto hum = std::vector(len, hum_value); - VectorResults results = { - py::array(tmp.size(), tmp.data()), // temperature - py::array(hum.size(), hum.data()), // humidity - }; - - return results; + return VectorResults(tmp, hum); } PYBIND11_MODULE(python_example, m) From 0f522326ca178ed0a2b818f74923e3f018c7b4fe Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Mon, 17 Sep 2018 12:34:41 +0800 Subject: [PATCH 13/13] adding pylama config --- pylama.ini | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 pylama.ini diff --git a/pylama.ini b/pylama.ini new file mode 100644 index 0000000..12ded65 --- /dev/null +++ b/pylama.ini @@ -0,0 +1,6 @@ +[pylama] +linters=pycodestyle,pyflakes +format=pylint + +[pylama:pycodestyle] +max_line_length=120 \ No newline at end of file