Grasplogic Native

1.2.5 · active · verified Fri Apr 17

Graspologic-native is a Python native companion module providing high-performance C++ implementations for core algorithms used by the `graspologic` library, such as graph matching, partitioning, and clustering. It offers accelerated computation for graph-theoretic operations. The current version is 1.2.5, and its release cadence generally aligns with major updates to the `graspologic` library.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to directly use the `leiden` community detection algorithm from `graspologic_native.partition`. It creates a simple adjacency matrix and applies the algorithm to find community assignments for the nodes. Note that `graspologic-native` functions often expect NumPy arrays as input.

import numpy as np
from graspologic_native.partition import leiden

# Create a sample adjacency matrix (e.g., for a small graph)
# Must be a square NumPy array, typically int or float type.
adj_matrix = np.array([
    [0, 1, 1, 0, 0],
    [1, 0, 1, 0, 0],
    [1, 1, 0, 0, 0],
    [0, 0, 0, 0, 1],
    [0, 0, 0, 1, 0]
], dtype=np.int32)

# Call the leiden community detection algorithm
# Parameters: adjacency matrix, resolution, random_seed, n_iterations
# Returns: communities (numpy array of community assignments)
communities = leiden(adj_matrix, 1.0, 42, 10)

print(f"Adjacency Matrix:\n{adj_matrix}")
print(f"Detected Communities: {communities}")

# Expected output might be something like:
# Detected Communities: [0 0 0 1 1]

view raw JSON →