Add block_marginal_sqrt_cov and jit support#177
Merged
SamDuffield merged 3 commits intomainfrom Feb 7, 2026
Merged
Conversation
They don't work with `jit` see https://docs.jax.dev/en/latest/debugging/checkify_guide.html
Collaborator
|
This is not necessary, the shape of This test for the old code (with assertions) runs fine (we should probably add this) import chex
import jax
import jax.numpy as jnp
import pytest
from absl.testing import parameterized
from jax import random
from cuthbertlib.linalg.marginal_sqrt_cov import marginal_sqrt_cov
@pytest.fixture(scope="module", autouse=True)
def config():
jax.config.update("jax_enable_x64", True)
yield
jax.config.update("jax_enable_x64", False)
class TestMarginalSqrtCov(chex.TestCase):
@chex.variants(with_jit=True, without_jit=True)
@parameterized.product(
seed=[0, 42, 99],
block=[
(6, 0, 3), # top-left block
(6, 3, 6), # bottom-right block
(8, 2, 5), # middle block
(10, 1, 9), # large block
],
)
def test_marginal_sqrt_cov(self, seed, block):
n, start, end = block
key = random.key(seed)
# Random lower-triangular joint square root
L = jnp.tril(random.normal(key, (n, n)))
# Extract marginal square root
B = self.variant(
marginal_sqrt_cov,
static_argnames=("start", "end"),
)(L, start, end)
# Expected marginal covariance block
Sigma = L @ L.T
Sigma_block = Sigma[start:end, start:end]
# Check B is lower triangular
assert jnp.allclose(B, jnp.tril(B))
# Check B B^T reproduces marginal covariance
assert jnp.allclose(B @ B.T, Sigma_block) |
Contributor
Author
|
I've pulled changes made in #178 and addressed here the comments. Let's just use this PR for fixing |
Sahel13
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
They don't work with
jitsee https://docs.jax.dev/en/latest/debugging/checkify_guide.html