Skip to main content

A library to simplify and automate einsum operations in a more intuitive way.

Project description

eincraft

eincraft is an experimental Python library designed to simplify and automate einsum operations in a more intuitive and user-friendly way. In its current alpha state, the library allows you to write einsum operations in a more straightforward and readable format, such as C.ik = A.ij * B.jk, rather than using the traditional einsum notation.

Installation

To install eincraft, you can use pip:

pip install .

If you want to enable support for the optional opt_einsum backend, install it with:

pip install .[opt_einsum]

Usage

Here's an example of how to use eincraft:

import numpy as np
import eincraft as ec

# Create tensor objects
A = ec.EinTen('A')
B = ec.EinTen('B')
C = ec.EinTen('C')
Z = ec.EinTen('Z')


# Write einsum operation
Z.kji = 2.0 * A.ij * B.jk * C.ijk + 4.0 * A.ij * 2.0 * B.id * C.idk
Z.ijk += 0.25 * A.ij * B.jk * C.kdd

# Define the numpy arrays
a = np.random.rand(3, 3)
b = np.random.rand(3, 3)
c = np.random.rand(3, 3, 3)

# Evaluate the einsum operations
z = Z.evaluate(A=a, B=b, C=c)

# Let's check the result
np.allclose(z, 2.0 * np.einsum('ij,jk,ijk->kji', a, b, c) + 4.0 * np.einsum('ij,id,idk->ijk', a, 2.0 * b, c) + 0.25 * np.einsum('ij,jk,kdd->ijk', a, b, c))

Running the tests

To run the tests, you can use the following command:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eincraft-0.2.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eincraft-0.2.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file eincraft-0.2.0.tar.gz.

File metadata

  • Download URL: eincraft-0.2.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for eincraft-0.2.0.tar.gz
Algorithm Hash digest
SHA256 99cd39377e9eb3e76b9f8f9d8a3b1bc17cf61768884c5d79d8795d73f559e4fb
MD5 51ae72439d2016c7a9b313aed8544ef9
BLAKE2b-256 bfb3e649029cbcd03794c186afadc96b892c7b1055af9e8e88430e5065e53115

See more details on using hashes here.

File details

Details for the file eincraft-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: eincraft-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for eincraft-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70768337d6fa5d0083b6b61cd095df2846bc62fb25651f839a9deb215a3f63d0
MD5 bcc1050a1288977fa62c46a2787b91e1
BLAKE2b-256 e4282e398345db6dd990b839febac64e11235f6de1f4f88c6823cfbc42e0f7b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page