Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/jax.numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ Not every function in NumPy is implemented; contributions are welcome!
reshape
result_type
right_shift
rint
roll
rollaxis
roots
Expand Down
10 changes: 10 additions & 0 deletions jax/numpy/lax_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ def op(*args):
logical_xor = _logical_op(onp.logical_xor, lax.bitwise_xor)


@_wraps(onp.rint)
def rint(x):
dtype = _dtype(x)
if issubdtype(dtype, integer):
return lax.convert_element_type(x, float_)
if issubdtype(dtype, complexfloating):
return lax.complex(rint(lax.real(x)), rint(lax.imag(x)))
return _round_to_nearest_even(x)


@_wraps(onp.sign)
def sign(x):
dtype = _dtype(x)
Expand Down
2 changes: 2 additions & 0 deletions tests/lax_numpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def op_record(name, nargs, dtypes, shapes, rng_factory, diff_modes,
op_record("remainder", 2, default_dtypes, all_shapes, jtu.rand_nonzero, [],
tolerance={onp.float16: 1e-2}),
op_record("mod", 2, default_dtypes, all_shapes, jtu.rand_nonzero, []),
op_record("rint", 1, number_dtypes + uint_dtypes, all_shapes,
jtu.rand_some_inf_and_nan, []),
op_record("sign", 1, number_dtypes + uint_dtypes, all_shapes,
jtu.rand_some_inf_and_nan, []),
op_record('copysign', 2, default_dtypes, all_shapes, jtu.rand_some_inf_and_nan, [],
Expand Down