Metadata-Version: 2.4
Name: torchgear
Version: 0.1.0
Summary: Utility extensions for PyTorch
Author: Jiaqi Guo
License-Expression: MIT
Project-URL: Homepage, https://github.com/GjQAQ/torchgear
Project-URL: Repository, https://github.com/GjQAQ/torchgear
Project-URL: Issues, https://github.com/GjQAQ/torchgear/issues
Project-URL: Documentation, https://gjqaq.github.io/torchgear/
Keywords: pytorch,utilities,tensor
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0
Dynamic: license-file

# torchgear

Utility extensions for PyTorch: tensor math helpers, shape utilities, and `nn.Module` mixins for device/dtype consistency and parameter freezing.

## Requirements

- Python 3.12+
- PyTorch 2.0+

## Installation

```bash
pip install torchgear
```

Install from source:

```bash
git clone https://github.com/GjQAQ/torchgear.git
cd torchgear
pip install -e .
```

## Quick start

```python
import torch
import torchgear as tg
import torch.nn as nn

# Math helpers
z = torch.tensor([1 + 2j, 3 + 4j])
tg.abs2(z)

# Module base class
class MyModel(tg.TorchgearModule):
    def __init__(self):
        super().__init__()
        self.w = nn.Parameter(torch.randn(4))

    def forward(self, x):
        return x @ self.w

model = MyModel()
model.freeze()
```

## Documentation

Online documentation: https://gjqaq.github.io/torchgear/

API reference and guides are also in the `docs/` directory. Build locally with [uv](https://docs.astral.sh/uv/) (install uv first):

```bash
uv sync --group doc
cd docs && make html
```

Without uv, install `sphinx` and `furo`, then run `make html` in `docs/`.

## Development

Requires [uv](https://docs.astral.sh/uv/) (see link above to install):

```bash
uv sync --group test
pytest
```

Without uv, install `pytest` and run `pytest` from the project root.

## License

MIT License. See [LICENSE](LICENSE) for details.
