Skip to main content

Ultrametric matrix tools

This 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 matrix
  • Test ultramtic matrix property
  • Construct the ultrametric tree from the ultrametric matrix
  • Get properties of ultrametric tree
  • Fast multiplication of ultrametric matrix with vector

The implementation is written in Rust and can be cross-compiled to Python.

Table of Contents

Quickstart

Quickstart Rust

Add the following to the Cargo.toml file:

[dependencies]
# TODO: replace the * by the latest version.
ultrametric_matrix_tools = "*"

An example of the usage of is:

use ultrametric_matrix_tools::na::{DMatrix, DVector};
use ultrametric_matrix_tools::UltrametricTree;

fn main() {
    let matrix = 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,
        ],
    );
    let vector = DVector::from_vec(vec![4.0, 2.0, 7.0, 5.0]);

    let tree = UltrametricTree::from_matrix(&matrix);
    let product = tree * vector;
}

More examples can be found in ./examples/.

Quickstart Python

You can install the current release by running:

pip install ultrametric_matrix_tools

An example of the construction of the ultrametric tree and multiplication with it is:

from ultrametric_matrix_tools import UltrametricTree
import numpy as np

matrix = 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 examples can be found in ./examples/.

Build

Build Rust Library

The Rust library is build by running:

cargo build --release

The compiled Rust library is located in ./target/release/ and can be copied from there.

Build Python Module

The Python module is build from the Rust code using the PyO3. To build the Python module, you need to install Cargo and run:

cargo build --release

The 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 --release

Windows (requires mingw32-python and mingw64-python):

make python_package_windows

Currently, cross-compiling to macOS is not supported.

Examples

Rust Example

You can try out the Rust examples, you need to install 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 multiplication

Python Example

To run the Python examples, you need to install 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=multiplication

Alternatively, if you have the Python package already installed via pip, then you can run the examples directly:

python [example_name].py

License

This project is under the Apache-2.0 license.

Benchmarks

The benchmarks use criterion for cargo, which can be installed by running:

cargo install cargo-criterion

The benchmarks can be found in ./benches and are run by:

cargo criterion --bench [benchmark_name]

Metadata

Release files for ultrametric-matrix-tools 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ultrametric-matrix-tools 0.1.1
File Size Uploaded Provenance
ultrametric_matrix_tools-0.1.1.tar.gz 31.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ultrametric-matrix-tools 0.1.1
File Interpreter ABI Platform
ultrametric_matrix_tools-0.1.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl CPython 3.6 abi3 Linux glibc 2.5+ x86-64 Details

Total release size: 599.4 kB

Release files / ultrametric_matrix_tools-0.1.1.tar.gz

Download URL ultrametric_matrix_tools-0.1.1.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e1ac41b9a65f1423ee300becac15fc141372244c65fd03f5a0f40a6e9c509a57
BLAKE2b-256 checksum
How to use checksums
e0f3a2cea70cf9cf049d00bf0e229ad6ec42b990ced25cedb395c82e08597bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.2 importlib-metadata/4.6.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Release files / ultrametric_matrix_tools-0.1.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL ultrametric_matrix_tools-0.1.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 568.0 kB
Tags CPython 3.6 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
b3340288fc1f01eb450bb00e606e98455227421cfa6be813576d3977255e1064
BLAKE2b-256 checksum
How to use checksums
4f1e968962755293e556bb8fc70f106ecbc42cf583529df33df04f33e8cf1063
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.2 importlib-metadata/4.6.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Security for ultrametric-matrix-tools 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page