usearch 0.2.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.clang-tidy +60 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +90 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +5 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.yml +64 -0
  5. package/.github/workflows/release.yml +47 -20
  6. package/.github/workflows/update_version.sh +1 -0
  7. package/.vscode/launch.json +22 -0
  8. package/.vscode/settings.json +9 -1
  9. package/.vscode/tasks.json +4 -4
  10. package/CITATION.cff +11 -0
  11. package/CMakeLists.txt +108 -95
  12. package/CODE_OF_CONDUCT.md +128 -0
  13. package/CONTRIBUTING.md +12 -0
  14. package/Cargo.toml +1 -1
  15. package/Dockerfile +14 -0
  16. package/README.md +21 -12
  17. package/VERSION +1 -1
  18. package/binding.gyp +13 -9
  19. package/build.rs +2 -1
  20. package/cmake/config.cmake.in +15 -0
  21. package/cmake/pkg-config.pc.in +4 -0
  22. package/cmake/usearchConfigVersion.cmake.in +20 -0
  23. package/conanfile.py +1 -1
  24. package/docs/{Benchmarking.md → benchmarks.md} +11 -2
  25. package/docs/benchmarks.rst +5 -0
  26. package/docs/{Compilation.md → compilation.md} +54 -27
  27. package/docs/compilation.rst +5 -0
  28. package/docs/conf.dox +2668 -0
  29. package/docs/index.rst +7 -0
  30. package/include/usearch/usearch.hpp +833 -439
  31. package/java/cloud/unum/usearch/cloud_unum_usearch_Index.cpp +17 -16
  32. package/javascript/lib.cpp +94 -20
  33. package/javascript/test.js +1 -1
  34. package/objc/USearchObjective.mm +47 -30
  35. package/objc/include/USearchObjective.h +18 -26
  36. package/package.json +1 -1
  37. package/pyproject.toml +3 -2
  38. package/python/lib.cpp +216 -130
  39. package/python/{bench.py → scripts/bench.py} +6 -1
  40. package/python/scripts/bench_params.py +112 -0
  41. package/python/{test.py → scripts/test.py} +32 -13
  42. package/python/usearch/client.py +100 -14
  43. package/python/usearch/server.py +104 -23
  44. package/rust/lib.cpp +20 -15
  45. package/rust/lib.hpp +5 -5
  46. package/rust/lib.rs +3 -3
  47. package/setup.py +7 -0
  48. package/src/CMakeLists.txt +107 -0
  49. package/src/bench.cpp +54 -19
  50. package/src/{advanced.hpp → punned.hpp} +235 -203
  51. package/src/test.cpp +62 -0
  52. package/swift/Index+Sugar.swift +1 -0
  53. package/swift/Test.swift +2 -1
  54. package/wolfram/lib.cpp +14 -14
package/.clang-tidy ADDED
@@ -0,0 +1,60 @@
1
+ Checks: '*,
2
+ -altera-id-dependent-backward-branch,
3
+ -altera-struct-pack-align,
4
+ -altera-unroll-loops,
5
+ -android-cloexec-fopen,
6
+ -bugprone-easily-swappable-parameters,
7
+ -cert-err58-cpp,
8
+ -concurrency-mt-unsafe,
9
+ -cppcoreguidelines-avoid-const-or-ref-data-members,
10
+ -cppcoreguidelines-avoid-do-while,
11
+ -cppcoreguidelines-avoid-goto,
12
+ -cppcoreguidelines-avoid-magic-numbers,
13
+ -cppcoreguidelines-avoid-non-const-global-variables,
14
+ -cppcoreguidelines-macro-usage,
15
+ -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
16
+ -cppcoreguidelines-pro-bounds-constant-array-index,
17
+ -cppcoreguidelines-pro-bounds-pointer-arithmetic,
18
+ -cppcoreguidelines-pro-type-reinterpret-cast,
19
+ -cppcoreguidelines-pro-type-union-access,
20
+ -cppcoreguidelines-rvalue-reference-param-not-moved,
21
+ -cppcoreguidelines-virtual-class-destructor,
22
+ -fuchsia-default-arguments-calls,
23
+ -fuchsia-default-arguments-declarations,
24
+ -fuchsia-overloaded-operator,
25
+ -google-explicit-constructor,
26
+ -google-readability-function-size,
27
+ -google-runtime-int,
28
+ -google-runtime-references,
29
+ -hicpp-avoid-goto,
30
+ -hicpp-explicit-conversions,
31
+ -hicpp-function-size,
32
+ -hicpp-no-array-decay,
33
+ -hicpp-no-assembler,
34
+ -hicpp-signed-bitwise,
35
+ -hicpp-uppercase-literal-suffix,
36
+ -llvm-header-guard,
37
+ -llvm-include-order,
38
+ -llvmlibc-*,
39
+ -misc-use-anonymous-namespace,
40
+ -misc-confusable-identifiers,
41
+ -misc-no-recursion,
42
+ -misc-non-private-member-variables-in-classes,
43
+ -modernize-concat-nested-namespaces,
44
+ -modernize-type-traits,
45
+ -modernize-use-nodiscard,
46
+ -modernize-use-trailing-return-type,
47
+ -readability-function-cognitive-complexity,
48
+ -readability-function-size,
49
+ -readability-identifier-length,
50
+ -readability-magic-numbers,
51
+ -readability-redundant-access-specifiers,
52
+ -readability-simplify-boolean-expr,
53
+ -readability-uppercase-literal-suffix'
54
+
55
+ CheckOptions:
56
+ - key: hicpp-special-member-functions.AllowSoleDefaultDtor
57
+ value: 1
58
+
59
+ WarningsAsErrors: '*'
60
+ HeaderFilterRegex: '.*hpp$'
@@ -0,0 +1,90 @@
1
+ name: Report a bug
2
+ description: Something doesn't work as expected?
3
+ title: "Bug: "
4
+ labels: ["bug", "invalid"]
5
+ assignees:
6
+ - octocat
7
+ body:
8
+ - type: markdown
9
+ attributes:
10
+ value: |
11
+ Thanks for taking the time to fill out this bug report!
12
+ If you have a small question, it may be faster to ask the maintainers on [Discord](https://discord.gg/4mxGrenbNt).
13
+ - type: textarea
14
+ id: what
15
+ attributes:
16
+ label: Describe the bug
17
+ placeholder: A short description of what the bug is.
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: steps
22
+ attributes:
23
+ label: Steps to reproduce
24
+ placeholder: Detail the steps taken to reproduce the behavior.
25
+ validations:
26
+ required: true
27
+ - type: textarea
28
+ id: expected
29
+ attributes:
30
+ label: Expected behavior
31
+ placeholder: A clear and concise description of what you expected to happen.
32
+ validations:
33
+ required: true
34
+ - type: input
35
+ id: version
36
+ attributes:
37
+ label: USearch version
38
+ placeholder: v0.4.X
39
+ validations:
40
+ required: true
41
+ - type: input
42
+ id: os
43
+ attributes:
44
+ label: Operating System
45
+ placeholder: Ubuntu 22.04
46
+ validations:
47
+ required: true
48
+ - type: dropdown
49
+ id: hardware
50
+ attributes:
51
+ label: Hardware architecture
52
+ options:
53
+ - x86
54
+ - Arm
55
+ validations:
56
+ required: true
57
+ - type: dropdown
58
+ id: frontend
59
+ attributes:
60
+ label: Which interface are you using?
61
+ options:
62
+ - C++ implementation
63
+ - Python bindings
64
+ - Other bindings
65
+ validations:
66
+ required: true
67
+ - type: input
68
+ id: contact
69
+ attributes:
70
+ label: Contact Details
71
+ description: How can we get in touch with you if we need more info?
72
+ placeholder: email@example.com
73
+ validations:
74
+ required: false
75
+ - type: checkboxes
76
+ id: duplicate
77
+ attributes:
78
+ label: Is there an existing issue for this?
79
+ description: Please search [our issues](https://github.com/unum-cloud/usearch/issues) to see if this bug already exists.
80
+ options:
81
+ - label: I have searched the existing issues
82
+ required: true
83
+ - type: checkboxes
84
+ id: terms
85
+ attributes:
86
+ label: Code of Conduct
87
+ description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/unum-cloud/usearch/blob/main/CODE_OF_CONDUCT.md)
88
+ options:
89
+ - label: I agree to follow this project's Code of Conduct
90
+ required: true
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: 💬 Ask on Discord
4
+ url: https://discord.gg/A6wxt6dS9j
5
+ about: Real-time communication with maintainers, contributors, and broader community
@@ -0,0 +1,64 @@
1
+ name: Request a feature
2
+ description: Something we haven't implemented yet?
3
+ title: "Feature: "
4
+ labels: ["enhancement"]
5
+ assignees:
6
+ - octocat
7
+ body:
8
+ - type: markdown
9
+ attributes:
10
+ value: |
11
+ Thanks for taking the time to fill out this feature request!
12
+ We have already scheduled a few features for our [next milestone](https://github.com/unum-cloud/usearch/milestones).
13
+ Still, if it is something we have yet to think about, we will happily extend our [roadmap](https://github.com/orgs/unum-cloud/projects/2).
14
+ It is also worth noting that choosing between speed and functionality, we generally prefer the former.
15
+ So in some cases, it makes more sense to build something on top of USearch rather than patch it 🤗
16
+ - type: textarea
17
+ id: what
18
+ attributes:
19
+ label: Describe what you are looking for
20
+ placeholder: A short description of what the feature would look like, ideally with code examples.
21
+ validations:
22
+ required: true
23
+ - type: checkboxes
24
+ id: check
25
+ attributes:
26
+ label: Can you contribute to the implementation?
27
+ options:
28
+ - label: I can contribute
29
+ - type: dropdown
30
+ id: interface
31
+ attributes:
32
+ label: Is your feature request specific to a certain interface?
33
+ options:
34
+ - It applies to everything
35
+ - C++ implementation
36
+ - Python bindings
37
+ - Other bindings
38
+ - Other
39
+ validations:
40
+ required: true
41
+ - type: input
42
+ id: contact
43
+ attributes:
44
+ label: Contact Details
45
+ description: How can we get in touch with you if we need more info?
46
+ placeholder: email@example.com
47
+ validations:
48
+ required: false
49
+ - type: checkboxes
50
+ id: duplicate
51
+ attributes:
52
+ label: Is there an existing issue for this?
53
+ description: Please search [our issues](https://github.com/unum-cloud/usearch/issues) to see if this bug already exists.
54
+ options:
55
+ - label: I have searched the existing issues
56
+ required: true
57
+ - type: checkboxes
58
+ id: terms
59
+ attributes:
60
+ label: Code of Conduct
61
+ description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/unum-cloud/usearch/blob/main/CODE_OF_CONDUCT.md)
62
+ options:
63
+ - label: I agree to follow this project's Code of Conduct
64
+ required: true
@@ -54,12 +54,7 @@ jobs:
54
54
  - name: Install CIBuildWheel
55
55
  run: python -m pip install cibuildwheel
56
56
 
57
- - name: Build wheels for Windows
58
- if: matrix.os == 'windows-2022'
59
- run: python -m cibuildwheel
60
-
61
- - name: Build wheels for POSIX
62
- if: matrix.os != 'windows-2022'
57
+ - name: Build wheels
63
58
  run: python -m cibuildwheel
64
59
 
65
60
  - uses: actions/upload-artifact@v3
@@ -86,9 +81,9 @@ jobs:
86
81
  - name: Publish to PyPi
87
82
  uses: pypa/gh-action-pypi-publish@release/v1
88
83
  with:
89
- packages_dir: ./dist/artifact
84
+ packages-dir: ./dist/artifact
90
85
  verbose: true
91
- print_hash: true
86
+ print-hash: true
92
87
 
93
88
  publish_javascript:
94
89
  name: Publish JavaScript
@@ -143,7 +138,7 @@ jobs:
143
138
  java-version: '11'
144
139
  distribution: 'adopt'
145
140
  - name: Setup Gradle
146
- uses: gradle/gradle-build-action@v2
141
+ uses: gradle/gradle-build-action@v2.4.2
147
142
  - name: Execute Gradle build
148
143
  run: gradle clean build
149
144
  - name: Publish package
@@ -165,20 +160,18 @@ jobs:
165
160
  - name: Run tests
166
161
  run: swift test
167
162
 
168
- deploy_docs:
169
- name: Deploy Docs
170
- environment:
171
- name: github-pages
172
- url: ${{ steps.deployment.outputs.page_url }}
163
+ build_docs:
164
+ name: Build Docs
173
165
  runs-on: ubuntu-22.04
174
- needs: publish_python
166
+ if: ${{ always() }}
167
+ needs: [publish_python, publish_javascript, publish_rust, publish_java, publish_swift]
168
+ permissions:
169
+ contents: write
175
170
  steps:
176
171
  - name: Checkout
177
172
  uses: actions/checkout@v3
178
173
  with:
179
174
  ref: 'main'
180
- - name: Setup GitHub Pages
181
- uses: actions/configure-pages@v2
182
175
  - name: Install dependencies
183
176
  run: sudo apt update && sudo apt install -y doxygen graphviz dia git && pip install sphinx breathe furo m2r2 sphinxcontrib-googleanalytics==0.2.dev20220708 sphinxcontrib-jquery
184
177
  - name: Install USearch from PyPi
@@ -187,11 +180,45 @@ jobs:
187
180
  run: cd docs && make html
188
181
  - name: Copy assets
189
182
  run: cp -r assets build/docs/html/
183
+ - name: Compress assets
184
+ run: tar -czvf docs.tar.gz build/docs/html/
185
+ - name: Upload docs to release
186
+ uses: xresloader/upload-to-github-release@v1
187
+ env:
188
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
189
+ with:
190
+ file: docs.tar.gz
191
+ asset_name: docs.tar.gz
192
+
193
+ deploy_docs_pages:
194
+ name: Deploy GitHub Pages
195
+ environment:
196
+ name: github-pages
197
+ url: ${{ steps.deployment.outputs.page_url }}
198
+ runs-on: ubuntu-22.04
199
+ needs: build_docs
200
+ if: ${{ github.event.build_docs.conclusion == 'success' }}
201
+ steps:
202
+ - uses: robinraju/release-downloader@v1.8
203
+ with:
204
+ latest: true
205
+ fileName: docs.tar.gz
206
+ - name: Setup GitHub Pages
207
+ uses: actions/configure-pages@v2
190
208
  - name: Upload artifacts
191
209
  uses: actions/upload-pages-artifact@v1
192
- with:
193
- # Upload entire repository
194
- path: "./build/docs/html/"
195
210
  - name: Deploy to GitHub Pages
196
211
  id: deployment
197
212
  uses: actions/deploy-pages@v1
213
+
214
+ deploy_docs_vercel:
215
+ name: Deploy Vercel
216
+ runs-on: ubuntu-22.04
217
+ needs: build_docs
218
+ if: ${{ github.event.build_docs.conclusion == 'success' }}
219
+ steps:
220
+ - name: Notify Vercel
221
+ uses: fjogeleit/http-request-action@v1
222
+ with:
223
+ url: ${{ secrets.DOCS_VERCEL }}
224
+ method: 'POST'
@@ -2,5 +2,6 @@
2
2
 
3
3
  echo $1 > VERSION &&
4
4
  sed -i "s/\"version\": \".*\"/\"version\": \"$1\"/" package.json &&
5
+ sed -i "s/^version: .*/version: $1/" CITATION.cff &&
5
6
  sed -i "s/version = \".*\"/version = \"$1\"/" Cargo.toml &&
6
7
  sed -i "s/version = '.*'/version = '$1'/" conanfile.py
@@ -4,6 +4,28 @@
4
4
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
+ {
8
+ "name": "Unit Test C++",
9
+ "type": "cppdbg",
10
+ "request": "launch",
11
+ "program": "${workspaceFolder}/build_debug/test",
12
+ "cwd": "${workspaceFolder}",
13
+ "environment": [
14
+ {
15
+ "name": "ASAN_OPTIONS",
16
+ "value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
17
+ }
18
+ ],
19
+ "stopAtEntry": false,
20
+ "linux": {
21
+ "preLaunchTask": "Linux Build C++ Bench Debug",
22
+ "MIMode": "gdb"
23
+ },
24
+ "osx": {
25
+ "preLaunchTask": "MacOS Build C++ Bench Debug",
26
+ "MIMode": "lldb"
27
+ }
28
+ },
7
29
  {
8
30
  "name": "Debug C++ Bench on Wiki 1M @Cos",
9
31
  "type": "cppdbg",
@@ -98,11 +98,15 @@
98
98
  "filesystem": "cpp",
99
99
  "__availability": "cpp",
100
100
  "version": "cpp",
101
- "future": "cpp"
101
+ "future": "cpp",
102
+ "__verbose_abort": "cpp"
102
103
  },
103
104
  "cSpell.words": [
104
105
  "astype",
106
+ "Availible",
105
107
  "BLAS",
108
+ "cflags",
109
+ "citerator",
106
110
  "downcasted",
107
111
  "Downcasting",
108
112
  "dtype",
@@ -110,11 +114,15 @@
110
114
  "FAISS",
111
115
  "hashable",
112
116
  "HNSW",
117
+ "hnswlib",
113
118
  "jaccard",
114
119
  "longlong",
115
120
  "memmap",
121
+ "Napi",
122
+ "ndarray",
116
123
  "ndim",
117
124
  "Numba",
125
+ "OPENMP",
118
126
  "preprocess",
119
127
  "Quickstart",
120
128
  "simsimd",
@@ -3,7 +3,7 @@
3
3
  "tasks": [
4
4
  {
5
5
  "label": "Linux Build C++ Bench Debug",
6
- "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make bench -C ./build_debug",
6
+ "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make -C ./build_debug",
7
7
  "args": [],
8
8
  "type": "shell",
9
9
  "problemMatcher": [
@@ -12,7 +12,7 @@
12
12
  },
13
13
  {
14
14
  "label": "Linux Build C++ Bench Release",
15
- "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make bench -C ./build_release",
15
+ "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make -C ./build_release",
16
16
  "args": [],
17
17
  "type": "shell",
18
18
  "problemMatcher": [
@@ -21,13 +21,13 @@
21
21
  },
22
22
  {
23
23
  "label": "MacOS Build C++ Bench Debug",
24
- "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make bench -C ./build_debug",
24
+ "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make -C ./build_debug",
25
25
  "args": [],
26
26
  "type": "shell",
27
27
  },
28
28
  {
29
29
  "label": "MacOS Build C++ Bench Release",
30
- "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make bench -C ./build_release",
30
+ "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make -C ./build_release",
31
31
  "args": [],
32
32
  "type": "shell"
33
33
  }
package/CITATION.cff ADDED
@@ -0,0 +1,11 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ authors:
4
+ - family-names: "Vardanian"
5
+ given-names: "Ashot"
6
+ orcid: "https://orcid.org/0000-0002-4882-1815"
7
+ title: "USearch"
8
+ version: 0.3.0
9
+ doi: 10.5281/zenodo.7949416
10
+ date-released: 2022-06-12
11
+ url: "https://github.com/unum-cloud/usearch"
package/CMakeLists.txt CHANGED
@@ -1,107 +1,120 @@
1
- cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
2
- project(usearch LANGUAGES CXX)
3
-
4
- set(CMAKE_CXX_STANDARD 11)
5
- set(CMAKE_CXX_STANDARD_REQUIRED YES)
6
- set(CMAKE_CXX_EXTENSIONS NO)
7
-
8
- option(USEARCH_USE_JEMALLOC "Use JeMalloc for Faster Memory Allocations" OFF)
9
- option(USEARCH_USE_OPENMP "Use OpenMP for a thread pool" OFF)
10
- option(USEARCH_USE_SIMD "Use SIMD hardware acceleration" OFF)
11
-
12
- option(USEARCH_BUILD_BENCHMARK "Compile a native benchmark in C++" ON)
13
- option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF)
14
-
15
- # Make "Release" by default
16
- if(NOT CMAKE_BUILD_TYPE)
17
- set(CMAKE_BUILD_TYPE Release)
1
+ # This CMake file is heavily inspired by following `usearch` CMake:
2
+ # https://github.com/nlohmann/json/blob/develop/CMakeLists.txt
3
+ cmake_minimum_required(VERSION 3.1)
4
+ project(usearch VERSION 0.6.0 LANGUAGES CXX)
5
+
6
+ # Determine if USearch is built as a subproject (using `add_subdirectory`) or if it is the main project
7
+ set(USEARCH_IS_MAIN_PROJECT OFF)
8
+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
9
+ set(USEARCH_IS_MAIN_PROJECT ON)
18
10
  endif()
19
11
 
20
- # List of all possible compiler IDs:
21
- # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
22
- if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
23
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
24
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wno-conversion -Wno-unknown-pragmas")
25
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
26
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=1")
27
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
28
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
29
-
30
- elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
31
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wfatal-errors")
32
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
33
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
34
-
35
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "NVIDIA" OR CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
36
- set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr --extended-lambda")
37
- set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_86,code=sm_86")
38
- set_property(SOURCE src/bench.cpp PROPERTY LANGUAGE CUDA)
39
- set_target_properties(bench PROPERTIES POSITION_INDEPENDENT_CODE ON)
40
- set_target_properties(bench PROPERTIES CUDA_ARCHITECTURES "86")
41
-
42
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
43
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
44
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1")
12
+ # Options
13
+ option(USEARCH_INSTALL "Install CMake targets" OFF)
14
+ option(USEARCH_BUILD_TEST "Compile a native unit test in C++" ${USEARCH_IS_MAIN_PROJECT})
15
+ option(USEARCH_BUILD_BENCHMARK "Compile a native benchmark in C++" ${USEARCH_IS_MAIN_PROJECT})
16
+ option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF)
45
17
 
46
- elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
47
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DEBUG")
48
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
49
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /DEBUG")
18
+ # Includes
19
+ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
20
+ include(ExternalProject)
21
+
22
+ # Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory
23
+ if (POLICY CMP0077)
24
+ cmake_policy(SET CMP0077 NEW)
25
+ endif ()
26
+
27
+ # Configuration
28
+ include(GNUInstallDirs)
29
+ set(USEARCH_TARGET_NAME ${PROJECT_NAME})
30
+ set(USEARCH_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
31
+ set(USEARCH_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
32
+ set(USEARCH_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
33
+ set(USEARCH_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
34
+ set(USEARCH_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
35
+ set(USEARCH_CMAKE_VERSION_CONFIG_FILE "${USEARCH_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
36
+ set(USEARCH_CMAKE_PROJECT_CONFIG_FILE "${USEARCH_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
37
+ set(USEARCH_CMAKE_PROJECT_TARGETS_FILE "${USEARCH_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
38
+ set(USEARCH_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
39
+
40
+
41
+ # Define our header-only library
42
+ add_library(${USEARCH_TARGET_NAME} INTERFACE)
43
+ add_library(${PROJECT_NAME}::${USEARCH_TARGET_NAME} ALIAS ${USEARCH_TARGET_NAME})
44
+ set(USEARCH_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
45
+ if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
46
+ target_compile_features(${USEARCH_TARGET_NAME} INTERFACE cxx_range_for)
50
47
  else()
51
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
52
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
53
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -pg -g")
48
+ target_compile_features(${USEARCH_TARGET_NAME} INTERFACE cxx_std_11)
54
49
  endif()
55
50
 
56
- if(APPLE)
57
- set(CMAKE_THREAD_LIBS_INIT "-lpthread")
58
- set(CMAKE_HAVE_THREADS_LIBRARY 1)
59
- set(CMAKE_USE_WIN32_THREADS_INIT 0)
60
- set(CMAKE_USE_PTHREADS_INIT 1)
61
- set(THREADS_PREFER_PTHREAD_FLAG ON)
51
+ target_compile_definitions(
52
+ ${USEARCH_TARGET_NAME}
53
+ INTERFACE
54
+ $<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:USEARCH_USE_OPENMP=0>
55
+ )
56
+ target_include_directories(
57
+ ${USEARCH_TARGET_NAME}
58
+ ${USEARCH_SYSTEM_INCLUDE} INTERFACE
59
+ $<BUILD_INTERFACE:${USEARCH_INCLUDE_BUILD_DIR}>
60
+ $<INSTALL_INTERFACE:include>
61
+ )
62
+
63
+ # Install a pkg-config file, so other tools can find this
64
+ configure_file(
65
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
66
+ "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
67
+ )
68
+
69
+ # Install a custom package version config file instead of
70
+ # write_basic_package_version_file to ensure that it's architecture-independent
71
+ # https://github.com/nlohmann/json/issues/1697
72
+ include(CMakePackageConfigHelpers)
73
+ configure_file(
74
+ "cmake/usearchConfigVersion.cmake.in"
75
+ ${USEARCH_CMAKE_VERSION_CONFIG_FILE}
76
+ @ONLY
77
+ )
78
+ configure_file(
79
+ ${USEARCH_CMAKE_CONFIG_TEMPLATE}
80
+ ${USEARCH_CMAKE_PROJECT_CONFIG_FILE}
81
+ @ONLY
82
+ )
83
+
84
+ if(USEARCH_INSTALL)
85
+ install(
86
+ DIRECTORY ${USEARCH_INCLUDE_BUILD_DIR}
87
+ DESTINATION ${USEARCH_INCLUDE_INSTALL_DIR}
88
+ )
89
+ install(
90
+ FILES ${USEARCH_CMAKE_PROJECT_CONFIG_FILE} ${USEARCH_CMAKE_VERSION_CONFIG_FILE}
91
+ DESTINATION ${USEARCH_CONFIG_INSTALL_DIR}
92
+ )
93
+ export(
94
+ TARGETS ${USEARCH_TARGET_NAME}
95
+ NAMESPACE ${PROJECT_NAME}::
96
+ FILE ${USEARCH_CMAKE_PROJECT_TARGETS_FILE}
97
+ )
98
+ install(
99
+ TARGETS ${USEARCH_TARGET_NAME}
100
+ EXPORT ${USEARCH_TARGETS_EXPORT_NAME}
101
+ INCLUDES DESTINATION ${USEARCH_INCLUDE_INSTALL_DIR}
102
+ )
103
+ install(
104
+ EXPORT ${USEARCH_TARGETS_EXPORT_NAME}
105
+ NAMESPACE ${PROJECT_NAME}::
106
+ DESTINATION ${USEARCH_CONFIG_INSTALL_DIR}
107
+ )
108
+ install(
109
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
110
+ DESTINATION ${USEARCH_PKGCONFIG_INSTALL_DIR}
111
+ )
62
112
  endif()
63
113
 
64
- find_package(Threads REQUIRED)
65
-
66
- if(${USEARCH_USE_OPENMP})
67
- find_package(OpenMP REQUIRED)
68
- include_directories(${OPENMP_INCLUDE_DIRS})
69
- endif()
70
-
71
- if(${USEARCH_USE_JEMALLOC})
72
- include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/jemalloc.cmake")
73
- endif()
74
-
75
- include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/clipp.cmake")
76
-
77
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
78
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/fp16/include")
79
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/simsimd/include")
80
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
81
-
82
- # Define our header-only library.
83
- add_library(usearch INTERFACE)
84
- target_sources(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/usearch/usearch.hpp")
85
- target_include_directories(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
86
-
87
- # Define the targets
88
- if(${USEARCH_BUILD_BENCHMARK})
89
- add_executable(bench src/bench.cpp)
90
- target_link_libraries(bench PRIVATE Threads::Threads)
91
-
92
- if(${USEARCH_USE_SIMD})
93
- target_compile_definitions(bench PRIVATE USEARCH_USE_SIMD=1)
94
- endif()
95
-
96
- if(${USEARCH_USE_OPENMP})
97
- target_link_libraries(bench PRIVATE ${OPENMP_LIBRARIES})
98
- endif()
99
-
100
- if(${USEARCH_USE_JEMALLOC})
101
- target_link_libraries(bench PRIVATE ${JEMALLOC_LIBRARIES})
102
- endif()
114
+ if(${USEARCH_BUILD_TEST} OR ${USEARCH_BUILD_BENCHMARK})
115
+ add_subdirectory(src)
103
116
  endif()
104
117
 
105
118
  if(${USEARCH_BUILD_WOLFRAM})
106
119
  add_subdirectory(wolfram)
107
- endif()
120
+ endif()