Metadata-Version: 2.4
Name: tensorguard
Version: 1.0.2
Summary: TensorGuard helps to guard against bad Tensor Shapes
Home-page: https://github.com/Michedev/tensorguard
Author: mikedev
Author-email: mik3dev@gmail.com
License: Apache-2.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing_extensions>=3.7.4.3
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# TensorGuard
<img src="https://github.com/user-attachments/assets/dfddbe05-87e5-48df-8608-e25bf6087044" alt="tensorguard logo" width="300"> 

[![PyPI version fury.io](https://badge.fury.io/py/tensorguard.svg)](https://pypi.python.org/pypi/tensorguard/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/tensorguard.svg)](https://pypi.python.org/pypi/tensorguard/)
[![PyPI download month](https://img.shields.io/pypi/dm/tensorguard.svg)](https://pypi.python.org/pypi/tensorguard/)
[![GitHub followers](https://img.shields.io/github/followers/Michedev.svg?style=social&label=Follow&maxAge=2592000)](https://github.com/Michedev?tab=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

```python
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
