Skip to main content

Differentiable PyTorch functions to calculate scientific notation.

Project description

torch-sci

Test

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_sci-1.0.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

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

Hashes for torch_sci-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b5aa493c89388088279566a4e0305d5b49cdedb5fac65416c34bbad40ecb7f56
MD5 2fe065534a709123eb9f55b635139949
BLAKE2b-256 b7d8508d249c3e46905eb3fd02d40f88e33c232d166df52b1be425fc0e4e2307

See more details on using hashes here.

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

Hashes for torch_sci-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7467ffbeb3aac6ec9d9c0003f73583d33808dff2c401d51429eaa7fe5e01425a
MD5 3dcc07bf662c9fd82dc9fbdb391b8524
BLAKE2b-256 6a91ca8aae8f57fc0c7e7690da2ebea1d34e13ee871df254d224839c973fe9a1

See more details on using hashes here.

Supported by

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