powerit
C++ implementation for power iterations
|
Not much to say here, this repository just contains a header-only C++ library to perform power iterations. It's a quick-and-dirty method of getting the first eigenvector from a diagonalizable matrix - most typically from a covariance matrix, to get the first principal component. Well, maybe it's not so quick, but it doesn't add any dependencies and it'll get the job done. And sometimes that's enough.
This is a header-only library, so usage is pretty simple:
Users can tune the number of iterations, tolerance, and number of threads via the Options
argument. Check out the API reference for more information.
FetchContent
If you're using CMake, you just need to add something like this to your CMakeLists.txt
:
Then you can link to powerit to make the headers available during compilation:
find_package()
To install the library, clone the desired version of this repository and run:
Then, we can use find_package()
as usual:
By default, this will use FetchContent
to fetch all external dependencies (listed in extern/CMakeLists.txt
). If you want to install them manually, use -DPOWERIT_FETCH_EXTERN=OFF
.
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
, which also need to be made available during compilation.