Skip to content

Commit

Permalink
Add logspace for jax frontend and its test (#11935)
Browse files Browse the repository at this point in the history
Co-authored-by: zaeemansari70 <[email protected]>
  • Loading branch information
xingyu-long and zaeemansari70 authored Mar 8, 2023
1 parent bfb44de commit d5a7eac
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ivy/functional/frontends/jax/numpy/creation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ivy
from ivy.func_wrapper import with_unsupported_dtypes
from ivy.functional.frontends.jax.devicearray import DeviceArray

from ivy.functional.frontends.jax.func_wrapper import (
Expand Down Expand Up @@ -119,3 +120,13 @@ def empty_like(a, dtype=None, shape=None):
@to_ivy_arrays_and_back
def full(shape, fill_value, dtype=None):
return ivy.full(shape, fill_value, dtype=dtype)


@handle_jax_dtype
@to_ivy_arrays_and_back
@with_unsupported_dtypes({"0.3.14 and below": ("float16", "bfloat16", )}, 'jax')
def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0):
if not endpoint:
interval = (stop - start) / num
stop -= interval
return ivy.logspace(start, stop, num, base=base, axis=axis, dtype=dtype)
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,53 @@ def test_jax_numpy_full(
fill_value=fill_value,
dtype=dtype,
)


@st.composite
def _get_dtype_and_range(draw):
dim = draw(helpers.ints(min_value=2, max_value=5))
dtype = draw(helpers.get_dtypes("float", index=1, full=False))
start = draw(
helpers.array_values(dtype=dtype[0], shape=(dim,), min_value=-50, max_value=0)
)
stop = draw(
helpers.array_values(dtype=dtype[0], shape=(dim,), min_value=1, max_value=50)
)
return dtype * 2, start, stop


# logspace
@handle_frontend_test(
fn_tree="jax.numpy.logspace",
dtype_start_stop=_get_dtype_and_range(),
num=helpers.ints(min_value=5, max_value=50),
base=helpers.ints(min_value=2, max_value=10),
axis=helpers.ints(min_value=-1, max_value=0),
test_with_out=st.just(False),
)
def test_jax_numpy_logspace(
dtype_start_stop,
num,
base,
axis,
frontend,
test_flags,
fn_tree,
on_device,
):
input_dtypes, start, stop = dtype_start_stop
helpers.test_frontend_function(
input_dtypes=input_dtypes,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-01,
start=start,
stop=stop,
num=num,
endpoint=True,
base=base,
dtype=input_dtypes[0],
axis=axis,
)

0 comments on commit d5a7eac

Please sign in to comment.