You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-21Lines changed: 16 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -106,22 +106,21 @@ The idea is that downstream packages will link against the **knncolle** C++ inte
106
106
This allows downstream packages to (i) save time by avoiding the need to re-compile all algorithms and (ii) support more algorithms in **knncolle** extensions.
107
107
To do so:
108
108
109
-
1. Add `assorthead.includes()` to the compiler's include path for your package.
109
+
1. Add `knncolle.includes()` and `assorthead.includes()` to the compiler's include path for the package.
110
110
This can be done through `include_dirs=` of the `Extension()` definition in `setup.py`
111
-
or by adding a `target_include_directories()` in CMake, depending on your build system.
111
+
or by adding a `target_include_directories()` in CMake, depending on the build system.
112
112
2. Call `knncolle.build_index()` to construct a `GenericIndex` instance.
113
113
This exposes a shared pointer to the C++-allocated index via its `ptr` property.
114
-
3. Pass `ptr` to **pybind11**-wrapped C++ code as a [shared pointer to a `knncolle::Prebuilt`](lib/src/def.h),
114
+
3. Pass `ptr` to C++ code as a `uintptr_t` referencing a `knncolle::Prebuilt`.
115
115
which can be interrogated as described in the [**knncolle** documentation](https://github.com/knncolle/knncolle).
116
116
117
117
So, for example, the C++ code in our downstream package might look like this:
See also the definitions in [`lib/src/def.h`](lib/src/def.h) for the types of the pointers to be used in the C++ code.
174
+
Check out [the included header](src/knncolle/include/knncolle_py.h) for more definitions.
180
175
181
176
## Extending to more algorithms
182
177
183
178
### Via `define_builder()`
184
179
185
180
The best way to extend **knncolle** is to do so in C++.
186
-
This involves writing subclasses of the `Builder`, `Prebuilt` and `Searcher`interfaces in the [**knncolle**](https://github.com/knncolle/knncolle) library.
181
+
This involves writing subclasses of the interfaces in the [**knncolle**](https://github.com/knncolle/knncolle) library.
187
182
Once this is done, it is a simple matter of writing the following Python bindings:
188
183
189
184
- Implement a `SomeNewParameters` class that inherits from `Parameters`.
190
185
- Implement a `SomeNewIndex` class that inherits from `GenericIndex`.
191
186
This should accept a single `ptr` in its constructor and have a `ptr` property that returns the same value.
192
187
- Register a `define_builder()` method that dispatches on `SomeNewParameters`.
193
-
This should call into C++ and return a tuple containing a **pybind11**-wrapped [`BuilderPointer`](lib/src/def.h) and the `SomeNewIndex` constructor.
188
+
This should call into C++ and return a tuple containing a `Builder` object and the `SomeNewIndex` constructor.
194
189
195
190
No new methods are required for `find_knn()`, `build_index()`, etc. as the default method will work automatically if a `define_builder()` method is available.
196
-
This approach also allows the new method to be used in C++ code of downstream packages that accept a [`PrebuiltPointer`](lib/src/def.h) instance.
191
+
This approach also allows the new method to be used in C++ code of downstream packages.
0 commit comments