Skip to content

Commit

Permalink
Implement required batch shape methods for TFP compatible bijectors.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 382357500
  • Loading branch information
gpapamak authored and DistraxDev committed Jul 1, 2021
1 parent cf8cad7 commit ddaf358
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions distrax/_src/bijectors/tfp_compatible_bijector.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ def name(self) -> str:
"""The name of the wrapped bijector."""
return name_ or f"TFPCompatible{base_bijector.name}"

@property
def experimental_batch_shape(self) -> None:
return None
def experimental_batch_shape(self, x_event_ndims=None, y_event_ndims=None):
raise NotImplementedError()

def experimental_batch_shape_tensor(
self, x_event_ndims=None, y_event_ndims=None):
raise NotImplementedError()

def forward_dtype(self, _: jnp.dtype) -> None:
"""Returns None, making no promise regarding dtypes."""
Expand Down
4 changes: 2 additions & 2 deletions distrax/_src/distributions/multinomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from distrax._src.distributions import distribution
from distrax._src.utils import math
import jax
import jax.lax as lax
from jax import lax
import jax.numpy as jnp
from tensorflow_probability.substrates import jax as tfp

Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self,
else:
assert self._logits is not None
probs_batch_shape = self._logits.shape[:-1]
self._batch_shape = jax.lax.broadcast_shapes(
self._batch_shape = lax.broadcast_shapes(
probs_batch_shape, self._total_count.shape)

@property
Expand Down

0 comments on commit ddaf358

Please sign in to comment.