knncolle_tatami
tatami wrappers for neighbor detection
Loading...
Searching...
No Matches
tatami bindings for knncolle

Unit tests Documentation Codecov

Overview

This library implements a wrapper class to use tatami::Matrix instances in the knncolle library. The goal is to support k-means clustering from alternative matrix representations (e.g., sparse, file-backed) without requiring realization into a knncolle::SimpleMatrix.

Quick start

Not much to say, really. Just replace the usual knncolle::SimpleMatrix with an instance of a knncolle_tatami::Matrix.

// Initialize this with an instance of a concrete tatami subclass.
std::shared_ptr<tatami::Matrix<double, int> > tmat;
knncolle_tatami::Matrix<int, double, double, int> wrapper(std::move(tmat), /* transposed = */ false);
auto index = builder.build_shared(wrapper);
auto res = knncolle::find_nearest_neighbors(*index, 5);
std::shared_ptr< Prebuilt< Index_, Data_, Distance_ > > build_shared(const Matrix_ &data) const
knncolle-compatible wrapper around a tatami matrix.
Definition knncolle_tatami.hpp:72
Use a tatami matrix with the knncolle library.
NeighborList< Index_, Distance_ > find_nearest_neighbors(const Prebuilt< Index_, Data_, Distance_ > &index, int k, int num_threads=1)

See the reference documentation for more details.

Building projects

CMake with FetchContent

If you're using CMake, you just need to add something like this to your CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(
knncolle_tatami
GIT_REPOSITORY https://github.com/knncolle/knncolle_tatami
GIT_TAG master # or any version of interest
)
FetchContent_MakeAvailable(knncolle_tatami)

Then you can link to knncolle_tatami to make the headers available during compilation:

# For executables:
target_link_libraries(myexe knncolle::knncolle_tatami)
# For libaries
target_link_libraries(mylib INTERFACE knncolle::knncolle_tatami)

By default, this will use FetchContent to fetch all external dependencies. Applications are advised to pin the versions of each dependency for stability - see extern/CMakeLists.txt for suggested versions. If you want to install them manually, use -DKNNCOLLE_TATAMI_FETCH_EXTERN=OFF.

CMake with find_package()

To install the library, clone an appropriate version of this repository and run:

mkdir build && cd build
cmake .. -DKNNCOLLE_TATAMI_TESTS=OFF
cmake --build . --target install

Then we can use find_package() as usual:

find_package(knncolle_knncolle_tatami CONFIG REQUIRED)
target_link_libraries(mylib INTERFACE knncolle::knncolle_tatami)

Again, this will automatically acquire all its dependencies, see recommendations above.

Manual

If you're not using CMake, the simple approach is to just copy the files in include/ - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I. This requires the external dependencies listed in extern/CMakeLists.txt.