Skip to content

Commit 663e29f

Browse files
committed
Fix weak typing
1 parent 451ee7d commit 663e29f

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

oryx/policy/actor_critic/mlp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def __init__(
5353
):
5454
if isinstance(env.action_space, Discrete):
5555
act_size = int(env.action_space.n)
56-
self.log_std = jnp.array([])
56+
self.log_std = jnp.array([], dtype=float)
5757
elif isinstance(env.action_space, Box):
5858
if env.action_space.shape:
5959
act_size = int(jnp.prod(jnp.asarray(env.action_space.shape)))
60-
self.log_std = jnp.full((act_size,), log_std_init)
60+
self.log_std = jnp.full((act_size,), log_std_init, dtype=float)
6161
else:
6262
act_size = "scalar"
63-
self.log_std = jnp.array(log_std_init)
63+
self.log_std = jnp.array(log_std_init, dtype=float)
6464
else:
6565
raise NotImplementedError(
6666
f"Action space {type(env.action_space)} not supported."

oryx/space/base_space.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class Discrete(AbstractSpace[Int[Array, ""]]):
6969
def __init__(self, n: Int[ArrayLike, ""], start: Int[ArrayLike, ""] = 0):
7070
assert n > 0, "n must be positive" # pyright: ignore
7171

72-
self._n = jnp.asarray(n)
73-
self.start = jnp.asarray(start)
72+
self._n = jnp.array(n, dtype=float)
73+
self.start = jnp.array(start, dtype=float)
7474

7575
@property
7676
def n(self) -> Int[Array, ""]:
@@ -133,8 +133,8 @@ def __init__(
133133
high: Float[ArrayLike, " ..."],
134134
shape: tuple[int, ...] | None = None,
135135
):
136-
low = jnp.asarray(low)
137-
high = jnp.asarray(high)
136+
low = jnp.asarray(low, dtype=float)
137+
high = jnp.asarray(high, dtype=float)
138138
if shape is None:
139139
low, high = jnp.broadcast_arrays(low, high)
140140
shape = low.shape
@@ -361,8 +361,8 @@ def __init__(self, ns: tuple[int, ...], starts: tuple[int, ...] = (0,)):
361361
assert len(ns) == len(starts), "ns and starts must have the same length"
362362
assert all(n > 0 for n in ns), "all n must be positive"
363363

364-
self.ns = jnp.asarray(ns)
365-
self.starts = jnp.asarray(starts)
364+
self.ns = jnp.array(ns, dtype=float)
365+
self.starts = jnp.array(starts, dtype=float)
366366

367367
@property
368368
def shape(self) -> tuple[int, ...]:

0 commit comments

Comments
 (0)