Differentiable PyTorch functions to calculate scientific notation.
Project description
torch-sci
Differentiable PyTorch functions to calculate scientific notation.
Installation
Bring your own PyTorch, then install this package:
pip install torch-sci
Usage
import torch
import torch_sci
x = torch.tensor(1234.0, requires_grad=True)
sig, exp = torch_sci.to_sci(x)
sig, exp
# => tensors: 1.234, 3.0
# some made up loss function, to test differentiability
loss = sig * exp
loss.backward()
assert x.grad != 0.0
torch_sci.from_sci(sig, exp)
# => tensor: 1234
# more test cases
torch_sci.to_sci(torch.tensor(-1234.0, requires_grad=True))
# => -1.234, 3
torch_sci.to_sci(torch.tensor(-0.1234, requires_grad=True))
# => -1.234, -1
torch_sci.to_sci(torch.tensor(0.0, requires_grad=True))
# => 0, -8 (common trick of + 1e-8 to avoid log 0)
torch_sci.to_sci(torch.tensor(0.1234, requires_grad=True))
# => 1.234, -1
torch_sci.to_sci(torch.tensor(1234.0, requires_grad=True))
# => 1.234, 3
Development
Setup
Install uv for dependency management if you haven't already. Then run:
# setup virtualenv
venv sync
Unit Tests
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torch_sci-1.0.0.tar.gz
(83.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_sci-1.0.0.tar.gz.
File metadata
- Download URL: torch_sci-1.0.0.tar.gz
- Upload date:
- Size: 83.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5aa493c89388088279566a4e0305d5b49cdedb5fac65416c34bbad40ecb7f56
|
|
| MD5 |
2fe065534a709123eb9f55b635139949
|
|
| BLAKE2b-256 |
b7d8508d249c3e46905eb3fd02d40f88e33c232d166df52b1be425fc0e4e2307
|
File details
Details for the file torch_sci-1.0.0-py3-none-any.whl.
File metadata
- Download URL: torch_sci-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7467ffbeb3aac6ec9d9c0003f73583d33808dff2c401d51429eaa7fe5e01425a
|
|
| MD5 |
3dcc07bf662c9fd82dc9fbdb391b8524
|
|
| BLAKE2b-256 |
6a91ca8aae8f57fc0c7e7690da2ebea1d34e13ee871df254d224839c973fe9a1
|