Skip to main content

A dedicated inverse-trigamma function implementation over positive reals

Project description

itrigamma

A self-contained implementation of the inverse-trigamma function, $\psi'^{-1}$, for inference on log-gamma random variables, etc.

Written in C with fast bindings for

  • Python (python/citrigamma.pyx)
  • R (r/RCall_itrigamma.c)

Python

Install

  • Through PyPI/pip: pip install itrigamma
  • or from source: python -m build; python -m pip install .

Test

Copy+paste into shell:

python <<'TEST_PY'
import time, numpy as np, math
from itrigamma import itrigamma

x = np.random.default_rng(0).random(10_000_000)

t = time.perf_counter()
y = itrigamma(x)
dt = time.perf_counter() - t

print(f'Approx. {(x.size/dt) / 1_000_000:.1f} million evals per sec.')

KNOWN = [
    (1.0e-8, 100000000.499999999167),
    (0.05, 20.49583523915460591),
    (0.10, 10.491681821078422372),
    (0.20, 5.4834517798530476662),
    (0.50, 2.4599529483523074137),
    (1.00, 1.4262551202150789904),
    (2.00, 0.87666407746426017692),
    (5.00, 0.49616873470410694489),
    (10.0, 0.33508104437803564513),
    (20.0, 0.23077632915242632912),
    (50.0, 0.14337981235286147770),
]

for i, (x0, y0) in enumerate(KNOWN):
    assert math.isclose(itrigamma(x0), y0, abs_tol=1e-12)
    print(f'  --> check {i}:\t{(x0,y0)}\tGOOD')

TEST_PY

Output (Exact results vary wrt machine precision.)

TEST_PY
Approx. 8.2 million evals per sec.
  --> check 0:	(1e-08, 100000000.5)	GOOD
  --> check 1:	(0.05, 20.495835239154605)	GOOD
  --> check 2:	(0.1, 10.491681821078423)	GOOD
  --> check 3:	(0.2, 5.4834517798530475)	GOOD
  --> check 4:	(0.5, 2.4599529483523073)	GOOD
  --> check 5:	(1.0, 1.426255120215079)	GOOD
  --> check 6:	(2.0, 0.8766640774642602)	GOOD
  --> check 7:	(5.0, 0.49616873470410694)	GOOD
  --> check 8:	(10.0, 0.33508104437803565)	GOOD
  --> check 9:	(20.0, 0.23077632915242632)	GOOD
  --> check 10:	(50.0, 0.14337981235286149)	GOOD

R

Install (R)

Clone the repository:

git clone https://github.com/nolan-h-hamilton/itrigamma.git
cd itrigamma

You can build with base R's r/utils/SHLIB utility as:

PKG_CPPFLAGS="-I$(pwd)/src" R CMD SHLIB r/RCall_itrigamma.c src/itrigamma.c -o r_itrigamma.so

This yields a shared library binary r_itrigamma.so. Load it within R using dyn.load("r_itrigamma.so").

Test (R)

Within R, you can then load the shared library and use base R's .Call for a simple wrapper,

dyn.load("r_itrigamma.so")

# Easiest: Write a simple wrapper around .Call, e.g.,
itrigamma = function(x) .Call("r_itrigamma", x)

# Test
x_ = seq(1.0e-8, 100, length.out = 50)

y = itrigamma(x_)

plot(x_,y, type='l')

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

itrigamma-0.1.0a2.tar.gz (86.5 kB view details)

Uploaded Source

Built Distributions

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

itrigamma-0.1.0a2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (144.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

itrigamma-0.1.0a2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (146.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

itrigamma-0.1.0a2-cp314-cp314-macosx_15_0_arm64.whl (32.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

itrigamma-0.1.0a2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (144.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

itrigamma-0.1.0a2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (147.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

itrigamma-0.1.0a2-cp313-cp313-macosx_15_0_arm64.whl (32.4 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

itrigamma-0.1.0a2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (151.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

itrigamma-0.1.0a2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (154.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

itrigamma-0.1.0a2-cp312-cp312-macosx_15_0_arm64.whl (33.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

itrigamma-0.1.0a2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (143.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

itrigamma-0.1.0a2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (144.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

itrigamma-0.1.0a2-cp311-cp311-macosx_15_0_arm64.whl (33.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file itrigamma-0.1.0a2.tar.gz.

File metadata

  • Download URL: itrigamma-0.1.0a2.tar.gz
  • Upload date:
  • Size: 86.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for itrigamma-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 815bf5ecdad80cc76ef49f63bd169594d1535a37c890cf18770f806019936346
MD5 3da2ca37dec8f67e40463a593758f9dd
BLAKE2b-256 91f9d134ed7a60cd6dae0cbb4c8630f2b7728c914402881e2f473f2b80d69600

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2.tar.gz:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9f1abf55651d9e2928e624fb93ec178bf3bb195fd357bac2097b0b664a52d6e3
MD5 e2719f6e42019ab9651ce5c06bcbc0ed
BLAKE2b-256 1adf77e06d3d53894ba3a757c0a7f42c897303d2518183fd539c07d6eda78a31

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b6f3d43e0ccb438819af921f82546c5399009085531fd63ccace2ce031723fd4
MD5 7202e402486e29a70af3d700c7aabdd9
BLAKE2b-256 8f206545221cf837b76267add10cb7ba24a08a322c716ab9c1c255b76871680a

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b955ff3c1466f69bd4ace2b847a9a82e83611afb3e591ae4f9dddc26867f8e8a
MD5 6842a141a96307abb4840d738b6cd18e
BLAKE2b-256 6868b6bcfb1e52d720c15b14f87ba573a2263959d2955d7a78eccf134d078732

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp314-cp314-macosx_15_0_arm64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 718cc21dc5ce82f0c088df6238ee6414749919c1796e12c9c841ee23e2922ea7
MD5 4e18557d227cf0dc18b6684a9d9273a3
BLAKE2b-256 78e9e0986be0f8e5d9f66c2d0da9df593998368741241713d4c1262b6b8245f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 330ee89cbc7dd812123fc39a3bc703578fe1bb1871a7db31087f503bc6fa3f9d
MD5 e08a3a2afc7591c13368ee4bd9bbc701
BLAKE2b-256 8d6a02d4fb149215fb5cef18c9bf5a0530bd19d468e4114bba6b407333e37319

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d75863ce39621900ad23b7d1a0b53f1a95eb070d5ddd3e93704d231fde245c5a
MD5 720d634bc97a515d6030e9c24ef064af
BLAKE2b-256 499567b3bb3a18ae303c33a17fca5f6b289fb31b6eaeef359c52806151004419

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bca00f00ef0005672081d8d6f8d811170b76c818abf2f29a9939ea3d03445c2f
MD5 0d6d91492e3de2af100fab545b269125
BLAKE2b-256 828e6a698fb9a0d81216659f7455c76e49e054b508587048ca9020870cee6b39

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 67adbdd9b2cbb9e65c561c605c30de5dc12e142e4c4f066ffa1e1e6da6a0f8a7
MD5 8fbf817465edf5cff77725ca2d324341
BLAKE2b-256 70f1508c01b85797d89617d7f772f34a10780fcb67159d7839495cc59424c9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f6c9bb925bc117e84da99930911460c49b60b2f2432e4eed83a75dc3128dd475
MD5 22edc2a6120a1f0bd58e373925736a2d
BLAKE2b-256 371e665d52d08194f1048574b043fe4672611ae42a0fecf4cd2dad7a982d2b39

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a4440a2099258d873bffc19e2f00ff7559f50d5f8c82d65d90941214a290130a
MD5 2a22811b7f9c23f9b4d6d343b529324a
BLAKE2b-256 719a7b572305db746f603a3a903ee878388d594907d4ad9b9fb15882f0320a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 8f58755b05547a58d6ebd19061fcc2628dcec132cd78304495f8abbf8d491069
MD5 d302a90b35dc09a3237295c1c53e4a35
BLAKE2b-256 e9d91602ba1c796344f0cb2f9c55bada83896705f2d71f7d5ebc704c150ed73e

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file itrigamma-0.1.0a2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for itrigamma-0.1.0a2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0604da808569f6e24d76c6ecdabea24adc2d0f2ccdba541a13174199247e6a1a
MD5 5029d16b69dc81ec2988444b5b9eceaf
BLAKE2b-256 849b6f105ec53a8849858c4a7cbafbb5695838ea0750b66063b874aa953bbfe1

See more details on using hashes here.

Provenance

The following attestation bundles were made for itrigamma-0.1.0a2-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: wheels.yml on nolan-h-hamilton/itrigamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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