Skip to content

Commit 1f70cf3

Browse files
zhujun98wolfv
authored andcommitted
Document build, tests and fix CMakeLists.txt in benchmark. (xtensor-stack#216)
* Document build, tests and fix CMakeLists.txt in benchmark.
1 parent 719b9d1 commit 1f70cf3

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

benchmark/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
# The full license is in the file LICENSE, distributed with this software. #
77
############################################################################
88

9+
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
10+
project(xtensor-python-benchmark)
11+
12+
find_package(xtensor-python REQUIRED CONFIG)
13+
set(XTENSOR_PYTHON_INCLUDE_DIR ${xtensor-python_INCLUDE_DIRS})
14+
endif ()
15+
916
message(STATUS "Forcing tests build type to Release")
1017
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
1118

@@ -72,7 +79,7 @@ if (APPLE)
7279
elseif (MSVC)
7380
target_link_libraries(${XTENSOR_PYTHON_BENCHMARK_TARGET} ${PYTHON_LIBRARIES})
7481
else ()
75-
target_link_libraries(${XTENSOR_PYTHON_BENCHMARK_TARGET} "-shared")
82+
target_link_libraries(${XTENSOR_PYTHON_BENCHMARK_TARGET} PRIVATE xtensor-python)
7683
endif()
7784

7885
configure_file(benchmark_pyarray.py benchmark_pyarray.py COPYONLY)
@@ -81,5 +88,11 @@ configure_file(benchmark_pybind_array.py benchmark_pybind_array.py COPYONLY)
8188
configure_file(benchmark_pyvectorize.py benchmark_pyvectorize.py COPYONLY)
8289
configure_file(benchmark_pybind_vectorize.py benchmark_pybind_vectorize.py COPYONLY)
8390

84-
add_custom_target(xbenchmark DEPENDS ${XTENSOR_PYTHON_BENCHMARK_TARGET})
91+
add_custom_target(xbenchmark
92+
COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pyarray.py"
93+
COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pytensor.py"
94+
COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pybind_array.py"
95+
COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pyvectorize.py"
96+
COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pybind_vectorize.py"
97+
DEPENDS ${XTENSOR_PYTHON_BENCHMARK_TARGET})
8598

benchmark/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ PYBIND11_MODULE(benchmark_xtensor_python, m)
1717
if(_import_array() < 0)
1818
{
1919
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
20-
return nullptr;
2120
}
2221

2322
m.doc() = "Benchmark module for xtensor python bindings";

benchmark/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def build_extensions(self):
107107
description='An example project using xtensor-python',
108108
long_description='',
109109
ext_modules=ext_modules,
110-
install_requires=['pybind11==2.0.1'],
110+
install_requires=['pybind11>=2.2.1'],
111111
cmdclass={'build_ext': BuildExt},
112112
zip_safe=False,
113113
)

docs/source/dev_build_options.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
2+
3+
Distributed under the terms of the BSD 3-Clause License.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
8+
Build, test and benchmark
9+
=========================
10+
11+
``xtensor-python`` build supports the following options:
12+
13+
- ``BUILD_TESTS``: enables the ``xtest`` and ``xbenchmark`` targets (see below).
14+
- ``DOWNLOAD_GTEST``: downloads ``gtest`` and builds it locally instead of using a binary installation.
15+
- ``GTEST_SRC_DIR``: indicates where to find the ``gtest`` sources instead of downloading them.
16+
17+
All these options are disabled by default. Enabling ``DOWNLOAD_GTEST`` or
18+
setting ``GTEST_SRC_DIR`` enables ``BUILD_TESTS``.
19+
20+
If the ``BUILD_TESTS`` option is enabled, the following targets are available:
21+
22+
- xtest: builds an run the test suite.
23+
- xbenchmark: builds and runs the benchmarks.
24+
25+
For instance, building the test suite of ``xtensor-python`` and downloading ``gtest`` automatically:
26+
27+
.. code::
28+
29+
mkdir build
30+
cd build
31+
cmake -DDOWNLOAD_GTEST=ON ../
32+
make xtest
33+
34+
To run the benchmark:
35+
36+
.. code::
37+
38+
make xbenchmark
39+
40+
To test the Python bindings:
41+
42+
.. code::
43+
44+
cd ..
45+
pytest -s

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ This software is licensed under the BSD-3-Clause license. See the LICENSE file f
7373
.. toctree::
7474
:caption: DEVELOPER ZONE
7575

76+
dev_build_options
7677
compilers
7778
releasing
7879

0 commit comments

Comments
 (0)