Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/unifyai/ivy into more_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai-Suraj-27 committed Sep 7, 2023
2 parents cb88238 + 80e8bdd commit 2eaff07
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 74 deletions.
20 changes: 10 additions & 10 deletions ivy/functional/backends/jax/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from ivy import as_native_dtype
from ivy.functional.backends.jax import JaxArray
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_infer_dtype,
asarray_handle_nestable,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_infer_dtype,
_asarray_handle_nestable,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
)


Expand Down Expand Up @@ -49,11 +49,11 @@ def arange(
return res


@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@asarray_infer_dtype
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
@_asarray_infer_dtype
def asarray(
obj: Union[
JaxArray,
Expand Down
16 changes: 8 additions & 8 deletions ivy/functional/backends/mxnet/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import ivy
from ivy.utils.exceptions import IvyNotImplementedException
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_handle_nestable,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_handle_nestable,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
)


Expand All @@ -30,10 +30,10 @@ def arange(
raise IvyNotImplementedException()


@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
def asarray(
obj: Union[
(
Expand Down
20 changes: 10 additions & 10 deletions ivy/functional/backends/numpy/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import ivy
from ivy.functional.backends.numpy.device import _to_device
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_infer_dtype,
asarray_handle_nestable,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_infer_dtype,
_asarray_handle_nestable,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
)
from .data_type import as_native_dtype

Expand Down Expand Up @@ -44,11 +44,11 @@ def arange(
return res


@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@asarray_infer_dtype
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
@_asarray_infer_dtype
def asarray(
obj: Union[
np.ndarray, bool, int, float, tuple, NestedSequence, SupportsBufferProtocol
Expand Down
20 changes: 10 additions & 10 deletions ivy/functional/backends/paddle/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
with_unsupported_device_and_dtypes,
)
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_handle_nestable,
asarray_infer_dtype,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_handle_nestable,
_asarray_infer_dtype,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
_remove_np_bfloat16,
)
from . import backend_version
Expand Down Expand Up @@ -64,11 +64,11 @@ def arange(
return paddle.arange(start, stop, step).cast(dtype)


@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@asarray_infer_dtype
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
@_asarray_infer_dtype
def asarray(
obj: Union[
paddle.Tensor,
Expand Down
20 changes: 10 additions & 10 deletions ivy/functional/backends/tensorflow/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import ivy
from ivy.func_wrapper import with_unsupported_dtypes
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_infer_dtype,
asarray_handle_nestable,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_infer_dtype,
_asarray_handle_nestable,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
)
from . import backend_version

Expand Down Expand Up @@ -65,11 +65,11 @@ def arange(
return tf.range(start, stop, delta=step, dtype=dtype)


@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@asarray_infer_dtype
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
@_asarray_infer_dtype
def asarray(
obj: Union[
tf.Tensor,
Expand Down
20 changes: 10 additions & 10 deletions ivy/functional/backends/torch/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
with_unsupported_device_and_dtypes,
)
from ivy.functional.ivy.creation import (
asarray_to_native_arrays_and_back,
asarray_infer_device,
asarray_infer_dtype,
asarray_handle_nestable,
_asarray_to_native_arrays_and_back,
_asarray_infer_device,
_asarray_infer_dtype,
_asarray_handle_nestable,
NestedSequence,
SupportsBufferProtocol,
asarray_inputs_to_native_shapes,
_asarray_inputs_to_native_shapes,
_remove_np_bfloat16,
)
from . import backend_version
Expand Down Expand Up @@ -96,11 +96,11 @@ def _stack_tensors(x, dtype):


@with_unsupported_dtypes({"2.0.1 and below": ("bfloat16",)}, backend_version)
@asarray_to_native_arrays_and_back
@asarray_infer_device
@asarray_handle_nestable
@asarray_inputs_to_native_shapes
@asarray_infer_dtype
@_asarray_to_native_arrays_and_back
@_asarray_infer_device
@_asarray_handle_nestable
@_asarray_inputs_to_native_shapes
@_asarray_infer_dtype
def asarray(
obj: Union[
torch.Tensor,
Expand Down
32 changes: 16 additions & 16 deletions ivy/functional/ivy/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
# --------#


def asarray_handle_nestable(fn: Callable) -> Callable:
def _asarray_handle_nestable(fn: Callable) -> Callable:
fn_name = fn.__name__

@functools.wraps(fn)
def _asarray_handle_nestable(*args, **kwargs):
def _asarray_handle_nestable_wrapper(*args, **kwargs):
"""
Call `fn` with the *nestable* property of the function correctly handled. This
means mapping the function to the container leaves if any containers are passed
Expand Down Expand Up @@ -71,8 +71,8 @@ def _asarray_handle_nestable(*args, **kwargs):
# the passed arguments, returning an ivy or a native array.
return fn(*args, **kwargs)

_asarray_handle_nestable.handle_nestable = True
return _asarray_handle_nestable
_asarray_handle_nestable_wrapper.handle_nestable = True
return _asarray_handle_nestable_wrapper


def _ivy_to_native(x):
Expand Down Expand Up @@ -126,9 +126,9 @@ def _remove_np_bfloat16(obj):
return obj


def asarray_to_native_arrays_and_back(fn: Callable) -> Callable:
def _asarray_to_native_arrays_and_back(fn: Callable) -> Callable:
@functools.wraps(fn)
def _asarray_to_native_arrays_and_back(*args, dtype=None, **kwargs):
def _asarray_to_native_arrays_and_back_wrapper(*args, dtype=None, **kwargs):
"""
Wrap `fn` so that input arrays are all converted to `ivy.NativeArray` instances
and return arrays are all converted to `ivy.Array` instances.
Expand All @@ -147,12 +147,12 @@ def _asarray_to_native_arrays_and_back(*args, dtype=None, **kwargs):
dtype = ivy.default_dtype(dtype=dtype, as_native=True)
return to_ivy(fn(*new_args, dtype=dtype, **kwargs))

return _asarray_to_native_arrays_and_back
return _asarray_to_native_arrays_and_back_wrapper


def asarray_infer_dtype(fn: Callable) -> Callable:
def _asarray_infer_dtype(fn: Callable) -> Callable:
@functools.wraps(fn)
def _asarray_infer_dtype(*args, dtype=None, **kwargs):
def _asarray_infer_dtype_wrapper(*args, dtype=None, **kwargs):
"""
Determine the correct `dtype`, and then calls the function with the `dtype`
passed explicitly. This wrapper is specifically for the backend implementations
Expand Down Expand Up @@ -204,13 +204,13 @@ def _infer_dtype(obj):
# call the function with dtype provided explicitly
return fn(*args, dtype=dtype, **kwargs)

_asarray_infer_dtype.infer_dtype = True
return _asarray_infer_dtype
_asarray_infer_dtype_wrapper.infer_dtype = True
return _asarray_infer_dtype_wrapper


def asarray_infer_device(fn: Callable) -> Callable:
def _asarray_infer_device(fn: Callable) -> Callable:
@functools.wraps(fn)
def _asarray_infer_device(*args, device=None, **kwargs):
def _asarray_infer_device_wrapper(*args, device=None, **kwargs):
"""
Determine the correct `device`, and then calls the function with the `device`
passed explicitly. This wrapper is specifically for the backend implementations
Expand Down Expand Up @@ -243,11 +243,11 @@ def _asarray_infer_device(*args, device=None, **kwargs):
# call the function with device provided explicitly
return fn(*args, device=device, **kwargs)

_asarray_infer_device.infer_device = True
return _asarray_infer_device
_asarray_infer_device_wrapper.infer_device = True
return _asarray_infer_device_wrapper


def asarray_inputs_to_native_shapes(fn: Callable) -> Callable:
def _asarray_inputs_to_native_shapes(fn: Callable) -> Callable:
@functools.wraps(fn)
def _inputs_to_native_shapes(*args, **kwargs):
new_arg = _shape_to_native(args[0])
Expand Down

0 comments on commit 2eaff07

Please sign in to comment.