Skip to content

Commit

Permalink
refactor: directly use nplike.asarray
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jan 20, 2023
1 parent b3e541b commit f52401e
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/awkward/_nplikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,12 @@ def raw(self, array: ArrayLike, nplike: NumpyLike) -> ArrayLike:
if isinstance(nplike, Numpy):
return array
elif isinstance(nplike, Cupy):
cupy = Cupy.instance()
return cupy.asarray(array, dtype=array.dtype, order="C")
return nplike.asarray(array, order="C")
elif isinstance(nplike, ak._typetracer.TypeTracer):
return ak._typetracer.TypeTracerArray(dtype=array.dtype, shape=array.shape)
return nplike.asarray(array)
elif isinstance(nplike, Jax):
jax = Jax.instance()
return jax.asarray(array, dtype=array.dtype)
return jax.asarray(array)
else:
raise ak._errors.wrap_error(
TypeError(
Expand Down Expand Up @@ -596,13 +595,11 @@ def raw(self, array: ArrayLike, nplike: NumpyLike) -> ArrayLike:
if isinstance(nplike, Cupy):
return array
elif isinstance(nplike, Numpy):
numpy = Numpy.instance()
return numpy.asarray(array.get(), dtype=array.dtype, order="C")
return nplike.asarray(array.get(), dtype=array.dtype, order="C")
elif isinstance(nplike, ak._typetracer.TypeTracer):
return ak._typetracer.TypeTracerArray(dtype=array.dtype, shape=array.shape)
return nplike.asarray(array, dtype=array.dtype)
elif isinstance(nplike, Jax):
jax = Jax.instance()
return jax.asarray(array.get(), dtype=array.dtype)
return nplike.asarray(array.get(), dtype=array.dtype)
else:
raise ak._errors.wrap_error(
TypeError(
Expand Down Expand Up @@ -763,13 +760,11 @@ def raw(self, array: ArrayLike, nplike: NumpyLike) -> ArrayLike:
if isinstance(nplike, Jax):
return array
elif isinstance(nplike, ak._nplikes.Cupy):
cupy = ak._nplikes.Cupy.instance()
return cupy.asarray(array)
return nplike.asarray(array)
elif isinstance(nplike, ak._nplikes.Numpy):
numpy = ak._nplikes.Numpy.instance()
return numpy.asarray(array)
return nplike.asarray(array)
elif isinstance(nplike, ak._typetracer.TypeTracer):
return ak._typetracer.TypeTracerArray(dtype=array.dtype, shape=array.shape)
return nplike.asarray(array, dtype=array.dtype)
else:
raise ak._errors.wrap_error(
TypeError(
Expand Down

0 comments on commit f52401e

Please sign in to comment.