Skip to main content

TensorGuard

tensorguard logo

PyPI version fury.io PyPI pyversions PyPI download month GitHub followers


TensorGuard helps to guard against bad Tensor shapes in any tensor based library (e.g. Numpy, Pytorch, Tensorflow) using an intuitive symbolic-based syntax

Installation

pip install tensorguard

Basic Usage

import numpy as np  # could be tensorflow or torch as well
import tensorguard as tg

# tensorguard = tg.TensorGuard()  #could be done in a OOP fashion
img = np.ones([64, 32, 32, 3])
flat_img = np.ones([64, 1024])
labels = np.ones([64])

# check shape consistency
tg.guard(img, "B, H, W, C")
tg.guard(labels, "B, 1")  # raises error because of rank mismatch
tg.guard(flat_img, "B, H*W*C")  # raises error because 1024 != 32*32*3

# guard also returns the tensor, so it can be inlined
mean_img = tg.guard(np.mean(img, axis=0), "H, W, C")

# more readable reshapes
flat_img = tg.reshape(img, 'B, H*W*C')

# evaluate templates
assert tg.get_dims('H, W*C+1') == [32, 97]

Shape Template Syntax

The shape template mini-DSL supports many different ways of specifying shapes:

  • numbers: "64, 32, 32, 3"
  • named dimensions: "B, width, height2, channels"
  • wildcards: "B, *, *, *"
  • ellipsis: "B, ..., 3"
  • addition, subtraction, multiplication, division: "B*N, W/2, H*(C+1)"
  • dynamic dimensions: "?, H, W, C" (only matches [None, H, W, C])

Original Repo link: https://github.com/Qwlouse/shapeguard

Metadata

Release files for tensorguard 1.0.3

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

Source distribution (sdist)

Source distribution for tensorguard 1.0.3
File Size Uploaded
tensorguard-1.0.3.tar.gz 32.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tensorguard 1.0.3
File Interpreter ABI Platform
tensorguard-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 66.4 kB

Release files / tensorguard-1.0.3.tar.gz

Download URL tensorguard-1.0.3.tar.gz
Size 32.7 kB
Tags Source
SHA-256 checksum
How to use checksums
108d0ff457338c572d5e4f103fc1e2326d42135cdeb6382295434e29c0b97d6a
BLAKE2b-256 checksum
How to use checksums
455c1ee4b9128990dda58945b5ae9bbe32420ac230fcc6cc8476ff7926a05277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.

Transparency log

Release files / tensorguard-1.0.3-py3-none-any.whl

Download URL tensorguard-1.0.3-py3-none-any.whl
Size 33.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14847817d5913717ce65c85b71d9be53ef9837f285d014a9899d89f426460718
BLAKE2b-256 checksum
How to use checksums
f240170f67381ed7cf1047c4468474793a918b2e0a38ef5968eec77b5ce7aac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

2 release files

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