Skip to main content

binary sparse and dense tensor partial-tracing

Project description

bisum --- PyTorch Sparse-Tensor Partial-Trace

CI

This program traces 2 sparse-tensor (torch.tensor objects) via 3 Tracing-Prescription:

  1. {einsum} string (like numpy, str, labelling each tensor axis)
  2. ncon (used in the tensor-network community, list of 1d int torch.tensor, labelling each tensor axis)
  3. adjacency-matrix (as in numpy.tensordot, (2,n) 2d int torch.tensor, with n being the number of indices idenified between the two tensors)

API

Let's begin by initializing the 2 tensors, we can initialize random-sparse-tensors

import torch
from bisum import bisum

shape_A = torch.tensor([8,7,7,4,11,6])
shape_B = torch.tensor([9,7,3,7,11,8])
A = torch.rand(shape_A)
B = torch.rand(shape_B)

Suppose we would like to compute the following partial-trace/tensor-contraction $C_{njwl} = A_{iksndj} B_{wklsdi}$:

C_einsum = bisum("iksndj, wklsdi -> njwl", A, B)
C_ncon   = bisum([[-1,-2,-3,4,-5,6],[1,-2,3,-3,-5,-1]], A, B)
C_adjmat = bisum(torch.tensor([[0,1,2,4],[5,1,3,4]]), A, B)

print(torch.allclose(C_einsum, C_ncon) and torch.allclose(C_ncon, C_adjmat))

while the pure tensor-product, $\otimes$ is:

import numpy as np

C_einsum = bisum("abcdef, ghijkl", A, B)
C_ncon   = bisum([], A, B)
C_adjmat = bisum(torch.tensor([]), A, B)

print(np.allclose(C_einsum, C_ncon) and np.allclose(C_ncon, C_adjmat))

Install

pip install bisum

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

bisum-0.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

bisum-0.2.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bisum-0.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.4

File hashes

Hashes for bisum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cc4b9f98a5d4382f5b60ca21873dac1ace1e31501825c758c3c0808035cfb32a
MD5 bf9ae22ccb09bd8b9a230e97ef5cbafd
BLAKE2b-256 e8cda986410fefc16a9b2cf8783ffc4dc61e48b6a00ef455e7215cdfb2b20b21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bisum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.4

File hashes

Hashes for bisum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad0228c54d87dd641a2bad5d218f6cd164310f29d521e9adaae8d57bcdaf1b29
MD5 151f77455b621acea7d34721b27f5694
BLAKE2b-256 aae28bae44bcbd015d82baaa15ced4f684110f69da8813a0468d5e3fc37c0e08

See more details on using hashes here.

Supported by

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