Blis BLAS-like Linear Algebra Library

1.3.3 · active · verified Sun Mar 29

Blis is a Python library that provides a high-performance, self-contained C-extension for BLAS-like dense linear algebra operations. Developed by Explosion (the creators of spaCy), it focuses on delivering fast matrix multiplication and other linear algebra routines without requiring external system dependencies. The library is actively maintained, with a current version of 1.3.3, and releases often include support for newer Python versions and updates to underlying dependencies like NumPy.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the high-level `einsum` function from `blis.py` for efficient matrix multiplication. It uses NumPy arrays as input and output, showcasing how Blis integrates with the NumPy ecosystem. The `einsum` function supports various tensor operations with specific restrictions that allow direct mapping to optimized Blis routines. Ensure NumPy is installed as a dependency.

import numpy as np
from blis.py import einsum

dim_a, dim_b, dim_c = 500, 128, 300

arr1 = np.random.rand(dim_a, dim_b).astype('float32')
arr2 = np.random.rand(dim_b, dim_c).astype('float32')
out = np.zeros((dim_a, dim_c), dtype='float32')

# Perform matrix multiplication using einsum
einsum('ab,bc->ac', arr1, arr2, out=out)

print(f"Output shape: {out.shape}")
# Example of returning a new array with transposed output
out_transposed = einsum('ab,bc->ca', arr1, arr2)
print(f"Transposed output shape: {out_transposed.shape}")

view raw JSON →