Commit 14e2dfe3 authored by Julien Jerphanion's avatar Julien Jerphanion

Add Makefile setup

parent 04f8be00
SHELL = /bin/bash
PROJECT = cython+
VENV_PATH=`conda info --base`/envs/${PROJECT}
PIP_EXECUTABLE=${VENV_PATH}/bin/pip
PYTHON_EXECUTABLE=${VENV_PATH}/bin/python
PYTEST_EXECUTABLE=${VENV_PATH}/bin/pytest
COMMIT=`git rev-parse --short HEAD`
# Used when not using the python runtime
INCLUDE_DIRS = -I/usr/include/python3.9
EXE = kdtree
CXX = g++
CPPFLAGS = -O2 -g -Wno-unused-result -Wsign-compare -pthread $(INCLUDE_DIRS) -fopenmp
LDFLAGS += -Wl,--unresolved-symbols=ignore-all
MACROS = -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
EXT_SUFFIX := $(shell python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
EXT_SUFFIX := $(shell python -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
EXT = $(EXE)$(EXT_SUFFIX)
# Build with Python runtime
all: clean $(EXT)
.DEFAULT_GOAL := all
$(EXT): setup.py
@echo "[Cython Compiling $^ -> $@]"
python3 setup.py build_ext --inplace
pip3 install -e . -v
## help: Display list of commands
.PHONY: help
help: Makefile
@sed -n 's|^##||p' $< | column -t -s ':' | sed -e 's|^| |'
## all: Run the main targets
.PHONY: all
all: install benchmark-sequential benchmark-parallel
# Build without Python runtime
## install: Install conda env.
.PHONY: install
install: clean
conda env create --force -f environment.yml
${PIP_EXECUTABLE} install -e . -v
# nopython: Build without the Python runtime
.PHONY: nopython
nopython: $(EXE)
%.cpp: %.pyx
@echo "[Cython Compiling $^ -> $@]"
python3 -c "from Cython.Compiler.Main import main; main(command_line=1)" $^ --cplus -3
${PYTEST_EXECUTABLE} -c "from Cython.Compiler.Main import main; main(command_line=1)" $^ --cplus -3
@rm -f $(subst .cpp,.h,$@)
%: %.cpp
@echo "[C++ Compiling $^ -> $@]"
$(LINK.cpp) $^ $(MACROS) -o $@
# Run without Python runtime
## runnopython: Run without Python runtime
.PHONY: runnopython
runnopython: $(EXE)
# Information of the runtime are currently redirected to stderr.
# This is just a simple way to mute them.
./$(EXE) 2>/dev/null
## clean: Remove generated files from Cython and C/C++ compilation
.PHONY: clean
clean:
-rm -f *.c *.cpp *.html
-rm -f *.h
......@@ -42,5 +65,22 @@ clean:
-rm -f -r build
-rm -f *.json
.PHONY: all run nopython runnopython clean
.PRECIOUS: %.cpp
## benchmark-sequential: Run benchmarks for sequential execution, 'NAME' variable can be provided
# Uses taskset to cap to a cpu solely
.PHONY: benchmark-sequential
benchmark-sequential:
@[ "${NAME}" ] || export NAME=${COMMIT}
taskset -c 0 ${PYTHON_EXECUTABLE} benchmarks/benchmark.py ${NAME}seq
## benchmark-parallel: Run benchmarks for parallel execution, 'NAME' variable can be provided
.PHONY: benchmark-parallel
benchmark-parallel:
@[ "${NAME}" ] || export NAME=${COMMIT}
${PYTHON_EXECUTABLE} benchmarks/benchmark.py ${NAME}par
## test: Launch all the test.
.PHONY: test
test:
${PYTEST_EXECUTABLE} tests
name: cython+
channels:
- conda-forge
dependencies:
- python=3.9
- compilers
- jupyter
- numpy
- matplotlib
- seaborn
- pandas
- pyaml
- pip
- threadpoolctl
- pytest
- scikit-learn
- memory_profiler
- pip:
# Install cython+ from upstream directly
- -e git+https://lab.nexedi.com/nexedi/cython.git@fd3a224472d75f7c6107828c1e4b9587f3990a46#egg=Cython
# The installation of the 'kdtree' module is made then
......@@ -10,6 +10,8 @@ extensions = [
language="c++",
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
include_dirs=[numpy.get_include()],
extra_compile_args=["-fopenmp"],
extra_link_args=["-fopenmp"],
sources=["kdtree.pyx"],
),
]
......
......@@ -19,6 +19,4 @@ def test_against_sklearn(n, d, k, leaf_size):
tree.query(query_points, closests)
skl_closests = skl_tree.query(query_points, k=k, return_distance=False).astype(np.int32)
# The back tracking part of the algorithm is not yet implemented
# hence, we test for a almost equality
np.testing.assert_equal(closests, skl_closests)
\ No newline at end of file
ipython==7.22.0
jupyter==1.0.0
line-profiler==3.1.0
matplotlib==3.4.1
numpy==1.20.2
pytest==6.2.3
pandas==1.2.4
PyYAML==5.4.1
memory_profiler==0.58.0
seaborn==0.11.1
-e git+https://lab.nexedi.com/nexedi/cython.git@fd3a224472d75f7c6107828c1e4b9587f3990a46#egg=Cython
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment