Skip to content

Commit

Permalink
Renaming datautils to arrayutils (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon authored Jun 5, 2024
1 parent 394a03d commit f0a35ee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions model/docs/extending_pyrenew.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ InfFeedbackSample = namedtuple(
)
```

The next step is to create the actual class. The bulk of its implementation lies in the function `pyrenew.latent.compute_infections_from_rt_with_feedback()`. We will also use the `pyrenew.datautils.pad_x_to_match_y()` function to ensure the passed vectors match their lengths. The following code-chunk shows most of the implementation of the `InfectionsWithFeedback` class:
The next step is to create the actual class. The bulk of its implementation lies in the function `pyrenew.latent.compute_infections_from_rt_with_feedback()`. We will also use the `pyrenew.arrayutils.pad_x_to_match_y()` function to ensure the passed vectors match their lengths. The following code-chunk shows most of the implementation of the `InfectionsWithFeedback` class:

```{python}
#| label: new-model-def
#| code-line-numbers: true
# Creating the class
from pyrenew.metaclass import RandomVariable
from pyrenew.latent import compute_infections_from_rt_with_feedback
from pyrenew import datautils as du
from pyrenew import arrayutils as au
from jax.typing import ArrayLike
import jax.numpy as jnp
Expand Down Expand Up @@ -181,7 +181,7 @@ class InfFeedback(RandomVariable):
inf_feedback_strength, *_ = self.infection_feedback_strength.sample(
**kwargs,
)
inf_feedback_strength = du.pad_x_to_match_y(
inf_feedback_strength = au.pad_x_to_match_y(
x=inf_feedback_strength, y=Rt, fill_value=inf_feedback_strength[0]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Utility functions for data processing.
Utility functions for processing arrays.
"""

import jax.numpy as jnp
Expand Down
4 changes: 2 additions & 2 deletions model/src/pyrenew/latent/infectionswithfeedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import jax.numpy as jnp
import numpyro as npro
import pyrenew.datautils as du
import pyrenew.arrayutils as au
import pyrenew.latent.infection_functions as inf
from numpy.typing import ArrayLike
from pyrenew.metaclass import RandomVariable, _assert_sample_and_rtype
Expand Down Expand Up @@ -160,7 +160,7 @@ def sample(

# Making sure inf_feedback_strength spans the Rt length
if inf_feedback_strength.size == 1:
inf_feedback_strength = du.pad_x_to_match_y(
inf_feedback_strength = au.pad_x_to_match_y(
x=inf_feedback_strength,
y=Rt,
fill_value=inf_feedback_strength[0],
Expand Down
4 changes: 2 additions & 2 deletions model/src/pyrenew/model/rtinfectionsrenewalmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import NamedTuple

import jax.numpy as jnp
import pyrenew.datautils as du
import pyrenew.arrayutils as au
from numpy.typing import ArrayLike
from pyrenew.deterministic import NullObservation
from pyrenew.metaclass import Model, RandomVariable, _assert_sample_and_rtype
Expand Down Expand Up @@ -291,7 +291,7 @@ def sample(
# is merged.
# SEE ALSO:
# https://github.com/CDCgov/multisignal-epi-inference/pull/123#discussion_r1612337288
i0 = du.pad_x_to_match_y(x=i0, y=gen_int, fill_value=0.0)
i0 = au.pad_x_to_match_y(x=i0, y=gen_int, fill_value=0.0)

# Sampling from the latent process
latent, *_ = self.sample_infections_latent(
Expand Down
16 changes: 8 additions & 8 deletions model/src/test/test_datautils.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"""
Tests for the datautils module.
Tests for the arrayutils module.
"""

import jax.numpy as jnp
import pyrenew.datautils as du
import pyrenew.arrayutils as au
import pytest


def test_datautils_pad_to_match():
def test_arrayutils_pad_to_match():
"""
Verifies extension when required and error when `fix_y` is True.
"""

x = jnp.array([1, 2, 3])
y = jnp.array([1, 2])

x_pad, y_pad = du.pad_to_match(x, y)
x_pad, y_pad = au.pad_to_match(x, y)

assert x_pad.size == y_pad.size
assert x_pad.size == 3

x = jnp.array([1, 2])
y = jnp.array([1, 2, 3])

x_pad, y_pad = du.pad_to_match(x, y)
x_pad, y_pad = au.pad_to_match(x, y)

assert x_pad.size == y_pad.size
assert x_pad.size == 3
Expand All @@ -33,17 +33,17 @@ def test_datautils_pad_to_match():

# Verify that the function raises an error when `fix_y` is True
with pytest.raises(ValueError):
x_pad, y_pad = du.pad_to_match(x, y, fix_y=True)
x_pad, y_pad = au.pad_to_match(x, y, fix_y=True)


def test_datautils_pad_x_to_match_y():
def test_arrayutils_pad_x_to_match_y():
"""
Verifies extension when required
"""

x = jnp.array([1, 2])
y = jnp.array([1, 2, 3])

x_pad = du.pad_x_to_match_y(x, y)
x_pad = au.pad_x_to_match_y(x, y)

assert x_pad.size == 3

0 comments on commit f0a35ee

Please sign in to comment.