Package: ultrametric-matrix-tools
Ultrametric matrix toolsThis toolbox provides functions and data structures to construct and handle ultrametric matrices in Rust and Python. The aim of the project is to provide efficient tools for ultrametric matrices and ultrametric trees. Currently, the project has the following features.Features:Generate a random ultrametric matrixTest ultramtic matrix propertyConstruct the ultrametric tree from the ultrametric matrixGet properties of ultrametric treeFast multiplication of ultrametric matrix with vectorThe implementation is written in Rust and can be cross-compiled to Python.Table of ContentsQuickstartQuickstart RustQuickstart PythonBuildBuild Rust LibraryBuild Python ModuleExamplesRust ExamplePython ExampleLicenseBenchmarksQuickstartQuickstart RustAdd the following to theCargo.tomlfile:[dependencies]# TODO: replace the * by the latest version.ultrametric_matrix_tools="*"An example of the usage of is:useultrametric_matrix_tools::na::{DMatrix,DVector};useultrametric_matrix_tools::UltrametricTree;fnmain(){letmatrix=DMatrix::from_vec(4,4,vec![0.0,1.0,3.0,1.0,1.0,3.0,1.0,1.0,3.0,1.0,5.0,1.0,1.0,1.0,1.0,1.0,],);letvector=DVector::from_vec(vec![4.0,2.0,7.0,5.0]);lettree=UltrametricTree::from_matrix(&matrix);letproduct=tree*vector;}More examplescan be found in./examples/.Quickstart PythonYou can install the current release by running:pip install ultrametric_matrix_toolsAn example of the construction of the ultrametric tree and multiplication with it is:fromultrametric_matrix_toolsimportUltrametricTreeimportnumpyasnpmatrix=np.array([[0.0,1.0,3.0,1.0],[1.0,3.0,1.0,1.0],[3.0,1.0,5.0,1.0],[1.0,1.0,1.0,1.0]])vector=np.array([4.0,2.0,7.0,5.0])tree=UltrametricTree(matrix)product=tree.mult(vector)More examplescan be found in./examples/.BuildBuild Rust LibraryThe Rust library is build by running:cargo build --releaseThe compiled Rust library is located in./target/release/and can be copied from there.Build Python ModuleThe Python module is build from the Rust code using thePyO3. To build the Python module, you need toinstall Cargoand run:cargo build --releaseThe compiled Python module is located in./target/release/and can be copied from there.To export the Python wheels from a Linux host system run the following commands:Linux (requires docker):docker run --rm -v $(pwd):/io konstin2/maturin build --releaseWindows (requires mingw32-python and mingw64-python):make python_package_windowsCurrently, cross-compiling to macOS is not supported.ExamplesRust ExampleYou can try out the Rust examples, you need toinstall Cargo. You can try out the Python examples located in./examples/by running the following command:cargo run --release --example [example_name]E.g. to run the multiplication example run:cargo run --release --example multiplicationPython ExampleTo run the Python examples, you need toinstall Cargo. You can try out the Python examples located in./examples/by running the following command:make python_example name=[example_name]E.g. to run the multiplication example run:make python_example name=multiplicationAlternatively, if you have the Python package already installed via pip, then you can run the examples directly:python [example_name].pyLicenseThis project is under theApache-2.0 license.BenchmarksThe benchmarks usecriterionforcargo, which can be installed by running:cargo install cargo-criterionThe benchmarks can be found in./benchesand are run by:cargo criterion --bench [benchmark_name]