Skip to content

Commit

Permalink
Merge pull request #40 from tataratat/release/v0.1.0
Browse files Browse the repository at this point in the history
Release/v0.1.0
j042 authored Jul 26, 2024
2 parents 7c778dc + 4469b73 commit a68d66a
Showing 13 changed files with 2,289 additions and 2,439 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
python-version: "3.10"

- name: build napf linux
run: pip install -e.
run: pip install .

- name: test
run: python3 tests/test_init_and_query.py
67 changes: 30 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -6,26 +6,33 @@ on:
pull_request:

jobs:
macos_wheel:
runs-on: macos-latest
strategy:
matrix:
arch: [x86_64, arm64]
cw_build: ["pp*", "cp*"]
exclude:
- arch: arm64
cw_build: "pp*"
macos_wheel_m:
runs-on: macos-14

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.cw_build }}
CIBW_TEST_SKIP: "*-macosx_x86_64"
CIBW_ARCHS: "arm64"

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

macos_wheel_intel:
runs-on: macos-13

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: build wheels
uses: pypa/cibuildwheel@v2.19
env:
CIBW_ARCHS: "x86_64"

- uses: actions/upload-artifact@v3
with:
@@ -34,22 +41,16 @@ jobs:

linux_wheel:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [x86_64]
cw_build: ["cp*manylinux*", "pp*manylinux*", "*musllinux*"]


steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.cw_build }}
CIBW_SKIP: "pp39-many*"
CIBW_ARCHS: x86_64
CIBW_BUILD: "cp*manylinux*"

- uses: actions/upload-artifact@v3
with:
@@ -60,14 +61,7 @@ jobs:
strategy:
matrix:
arch: [aarch64, ppc64le]
cw_build: ["cp36*many*", "cp37*many*", "cp38*many*", "cp39*many*", "cp310*many*", "cp311*many*", "cp312*many*", "pp37*many*", "pp38*many*", "pp39*many*"]
exclude:
- arch: ppc64le
cw_build: "pp37*many*"
- arch: ppc64le
cw_build: "pp38*many*"
- arch: ppc64le
cw_build: "pp39*many*"
cw_build: ["cp37*many*", "cp38*many*", "cp39*many*", "cp310*many*", "cp311*many*", "cp312*many*"]

steps:
- uses: actions/checkout@v3
@@ -81,11 +75,11 @@ jobs:
platforms: arm64, ppc64le

- name: build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.cw_build }}
CIBW_TEST_SKIP: "*-*linux_{aarch64,ppc64le,s390x}"
CIBW_TEST_SKIP: "*-*linux_{aarch64,ppc64le}"

- uses: actions/upload-artifact@v3
with:
@@ -104,9 +98,10 @@ jobs:
with:
submodules: recursive
- name: build wheels
uses: pypa/cibuildwheel@v2.18
uses: pypa/cibuildwheel@v2.19
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_SKIP: "pp*"


- uses: actions/upload-artifact@v3
@@ -129,10 +124,8 @@ jobs:
path: ./dist/*

upload_pypi:
needs: [macos_wheel, linux_wheel, windows_wheel, source_dist]
needs: [macos_wheel_m, macos_wheel_intel, linux_wheel, windows_wheel, source_dist]
runs-on: ubuntu-latest
permissions:
id-token: write
# try to publish only if this is a push to stable branch
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
@@ -143,4 +136,4 @@ jobs:

- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
skip_existing: true
38 changes: 18 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -6,11 +6,9 @@

# use default options for ci
ci:
autoupdate_schedule: "monthly"
autoupdate_schedule: "weekly"
submodules: false

exclude: "third_party/nanoflann.hpp"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
@@ -28,31 +26,31 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: "v3.15.2"
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/PyCQA/isort
rev: "5.13.2"
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: "24.4.2"
hooks:
- id: black
args: [--line-length=79]
additional_dependencies: [tomli]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
hooks:
- id: flake8
args: [--extend-ignore=E203]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.4
rev: v18.1.8
hooks:
- id: clang-format
types_or: [c++]

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: "v0.6.13"
hooks:
- id: cmake-format

- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
hooks:
- id: blackdoc
additional_dependencies: [tomli]
82 changes: 30 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
cmake_minimum_required(VERSION 3.12)
project(napf VERSION 0.0.0 LANGUAGES CXX)
project(
napf
VERSION 0.1.0
LANGUAGES CXX)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

endif()

# options
option(BUILD_EXAMPLES "build examples" ON)
option(BUILD_FORTRAN_MODULE "build fortran module" ON)
option(SPLINEPY_EXT "add splinepy extension" ON)
option(NAPF_BUILD_PYTHON "build python module" ON)

# config
set(exe_dest "bin")
@@ -29,68 +31,44 @@ add_library(napf INTERFACE)
add_library(napf::napf ALIAS napf)

# basic path
target_include_directories(napf
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${incl_dest}>)
target_include_directories(
napf INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${incl_dest}>)

# try to use installed nanoflann.
# else, include the one in the third_party
# try to use installed nanoflann. else, include the one in the third_party
find_package(nanoflann QUIET)
if(nanoflann_FOUND AND nanoflann_VERSION VERSION_GREATER_EQUAL "1.5.0")
message("nanoflann found - napf will link to nanoflann found in system.")
target_link_libraries(napf INTERFACE nanoflann::nanoflann)
else()
set(CXX_HEADERS ${CXX_HEADERS} third_party/nanoflann.hpp)
target_include_directories(napf
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party>)
target_include_directories(
napf INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party>)
endif()
target_compile_features(napf INTERFACE cxx_std_11)

if(BUILD_FORTRAN_MODULE)
message("*** building additional fortran module ***")
message("*** ------ NOT IMPLEMENTED ----------- ***")
endif(BUILD_FORTRAN_MODULE)

if(BUILD_EXAMPLES)
message("*** building examples ***")
message("*** ------ NOT IMPLEMENTED ----------- ***")
endif(BUILD_EXAMPLES)

if(SPLINEPY_EXT)
target_compile_definitions(napf INTERFACE -DSPLINEPYEXT)
endif(SPLINEPY_EXT)
if(NAPF_BUILD_PYTHON)
add_subdirectory(src/python)
endif()

# configure config files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"cmake/config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${cfg_dest}"
)
write_basic_package_version_file("${version_config}"
COMPATIBILITY SameMajorVersion)
configure_package_config_file("cmake/config.cmake.in" "${project_config}"
INSTALL_DESTINATION "${cfg_dest}")

install(
TARGETS napf
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${lib_dest}
ARCHIVE DESTINATION ${lib_dest}
INCLUDES DESTINATION "${incl_dest}"
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${cfg_dest}"
)
TARGETS napf
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${lib_dest}
ARCHIVE DESTINATION ${lib_dest}
INCLUDES
DESTINATION "${incl_dest}")
install(FILES "${project_config}" "${version_config}" DESTINATION "${cfg_dest}")

install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${cfg_dest}"
)
install(
FILES ${CXX_HEADERS}
DESTINATION ${incl_dest}
)
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${cfg_dest}")
install(FILES ${CXX_HEADERS} DESTINATION ${incl_dest})
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# napf
<p align="center"><img src="https://github.com/tataratat/napf/raw/main/docs/source/_static/napf.png" width="50%" title="nurbs"></p>

**napf - [nanoflann](https://github.com/jlblancoc/nanoflann) wrappers for python and maybe fortran**

[![main](https://github.com/tataratat/napf/actions/workflows/main.yml/badge.svg)](https://github.com/tataratat/napf/actions/workflows/main.yml)
[![PyPI version](https://badge.fury.io/py/napf.svg)](https://badge.fury.io/py/napf)

[nanoflann](https://github.com/jlblancoc/nanoflann) wrappers for python and maybe fortran.

## python
As `nanoflann` offers template classes, separate classes are implemented in `napf` for each ___{datatype, distance metric}___. All the search functions are equipped with multi-thread execution. Uses [numpy.ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) for data input and output.
2 changes: 1 addition & 1 deletion napf/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.0.8"
version = "0.1.0"
6 changes: 3 additions & 3 deletions napf/base.py
Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ def knn_search(self, queries, kneighbors, nthread=None):
Parameters
-----------
queires: (m, d) np.ndarray
queries: (m, d) np.ndarray
Data type will be casted to the same type as `tree_data`.
kneighbors: int
nthread: int
@@ -405,7 +405,7 @@ def radii_search(self, queries, radii, return_sorted, nthread=None):
# input size check
if len(queries) != len(radii):
raise ValueError(
f"Input size mismatch between queires ({len(queries)}) "
f"Input size mismatch between queries ({len(queries)}) "
f" and radii ({len(radii)})."
"They should be the same."
)
@@ -447,7 +447,7 @@ def unique_data_and_inverse(
Same as kdt.tree_data[unique_ids].
unique_ids: np.ndarray
Indices of unique entries from tree data.
First occurance is considered unique.
First occurrence is considered unique.
inverse_ids: np.ndarray
Indices to reconstruct original tree_data with
unique_data. kdt.tree_data == unique_data[inverse_ids]
47 changes: 41 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"pybind11",
"scikit-build-core",
"pybind11>=2.12",
]
build-backend = "scikit_build_core.build"

build-backend = "setuptools.build_meta"
[project]
name = "napf"
authors = [
{name="Jaewook Lee", email="jaewooklee042@gmail.com"}
]
license = {file = "LICENSE"}
description = "nanoflann python bindings for kdtree with multithreaded queries"
urls = {Homepage = "https://github.com/tataratat/napf"}
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Natural Language :: English",
"Topic :: Scientific/Engineering",
]
dependencies = ["numpy"]
dynamic = ["version"]
requires-python = ">=3.7"

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "napf/_version.py"

[tool.cibuildwheel]
test-command = "python {project}/tests/test_init_and_query.py"


[project.readme]
file = "README.md"
content-type = "text/markdown"

[tool.cibuildwheel.macos]
archs = ["x86_64", "arm64"]
test-skip = ["*x86_64"]
skip = "pp*"

[tool.cibuildwheel.linux]
skip = "pp*"

[tool.cibuildwheel.windows]
skip = "pp*"

[tool.black]
line-length = 79
exclude = "third_party"

[tool.blackdoc]
line-length = 75
70 changes: 0 additions & 70 deletions setup.py

This file was deleted.

21 changes: 21 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(NAPF_SOURCES
classes/radius_search_result_vectors.cpp classes/int_trees.cpp
classes/long_trees.cpp classes/float_trees.cpp classes/double_trees.cpp
napf.cpp)

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

python_add_library(_napf MODULE ${NAPF_SOURCES})
target_link_libraries(_napf PRIVATE pybind11::headers napf)
target_compile_definitions(_napf PRIVATE $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(_napf PRIVATE $<$<NOT:$<CONFIG:Debug>>:-O3>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSCV")
target_compile_options(_napf PRIVATE $<$<NOT:$<CONFIG:Debug>>:/O2>)
endif()

install(
TARGETS _napf
DESTINATION napf
COMPONENT PythonModule)
2 changes: 1 addition & 1 deletion tests/test_init_and_query.py
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ def test_func(dim, data_t, metric):
assert ids.shape[1] == nn
assert np.isclose(dists.sum(), 0)

# with five, only first two queires are zero and last three are
# with five, only first two queries are zero and last three are
# dummy values
nn = 5
ids, dists = kdt.rknn_search(random_data, 1e-10, 5)
2 changes: 1 addition & 1 deletion third_party/nanoflann
4,383 changes: 2,138 additions & 2,245 deletions third_party/nanoflann.hpp

Large diffs are not rendered by default.

0 comments on commit a68d66a

Please sign in to comment.