Skip to content

Commit

Permalink
Merge pull request #27 from normal-computing/linalg-typehints
Browse files Browse the repository at this point in the history
Add type hints to linalg matrix inputs
  • Loading branch information
denismelanson authored May 29, 2024
2 parents 7b88fb1 + 6b9ed8f commit cb85b64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "thermox"
version = "0.0.1"
description = "OU Processes and Linear Algebra with JAX"
description = "Exact OU processes with JAX"
readme = "README.md"
requires-python =">=3.9"
license = {text = "Apache-2.0"}
Expand Down
20 changes: 10 additions & 10 deletions thermox/linalg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import jax
import jax.numpy as jnp
from thermox.sampler import sample, sample_identity_diffusion
from jax.lax import fori_loop
from jax import Array
from jax import Array, random
from thermox.sampler import sample, sample_identity_diffusion
from thermox.utils import ProcessedDriftMatrix


def solve(
A,
A: Array | ProcessedDriftMatrix,
b,
num_samples: int = 10000,
dt: float = 1.0,
Expand Down Expand Up @@ -34,15 +34,15 @@ def solve(
Approximate solution, x, of the linear system.
"""
if key is None:
key = jax.random.PRNGKey(0)
key = random.PRNGKey(0)
ts = jnp.arange(burnin, burnin + num_samples) * dt
x0 = jnp.zeros_like(b)
samples = sample_identity_diffusion(key, ts, x0, A, jnp.linalg.solve(A, b))
return jnp.mean(samples, axis=0)


def inv(
A,
A: Array,
num_samples: int = 10000,
dt: float = 1.0,
burnin: int = 0,
Expand All @@ -65,7 +65,7 @@ def inv(
Approximate inverse of A.
"""
if key is None:
key = jax.random.PRNGKey(0)
key = random.PRNGKey(0)
ts = jnp.arange(burnin, burnin + num_samples) * dt
b = jnp.zeros(A.shape[0])
x0 = jnp.zeros_like(b)
Expand All @@ -74,7 +74,7 @@ def inv(


def expnegm(
A,
A: Array,
num_samples: int = 10000,
dt: float = 1.0,
burnin: int = 0,
Expand All @@ -100,7 +100,7 @@ def expnegm(
Approximate negative matrix exponential, exp(-A).
"""
if key is None:
key = jax.random.PRNGKey(0)
key = random.PRNGKey(0)

A_shifted = (A + alpha * jnp.eye(A.shape[0])) / dt
B = A_shifted + A_shifted.T
Expand All @@ -113,7 +113,7 @@ def expnegm(


def expm(
A,
A: Array,
num_samples: int = 10000,
dt: float = 1.0,
burnin: int = 0,
Expand Down

0 comments on commit cb85b64

Please sign in to comment.