Skip to content

Commit

Permalink
fix: Updated type annotations to use Optional when default paramete…
Browse files Browse the repository at this point in the history
…r is `None`. (#27255)
  • Loading branch information
Sai-Suraj-27 authored Nov 14, 2023
1 parent d1d471d commit cb8d76f
Show file tree
Hide file tree
Showing 37 changed files with 126 additions and 118 deletions.
2 changes: 1 addition & 1 deletion ivy/data_classes/array/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def to_native(

def args_to_native(
*args: Iterable[Any],
include_derived: Dict[str, bool] = None,
include_derived: Optional[Dict[str, bool]] = None,
cont_inplace: bool = False,
to_ignore: Optional[Union[type, Tuple[type]]] = None,
**kwargs: Dict[str, Any],
Expand Down
8 changes: 4 additions & 4 deletions ivy/data_classes/array/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def reduce_window(
def fft2(
self: ivy.Array,
*,
s: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
dim: Sequence[int] = (-2, -1),
norm: str = "backward",
out: Optional[ivy.Array] = None,
Expand Down Expand Up @@ -1144,8 +1144,8 @@ def rfft(

def rfftn(
self: ivy.Array,
s: Sequence[int] = None,
axes: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
axes: Optional[Sequence[int]] = None,
*,
norm: str = "backward",
out: Optional[ivy.Array] = None,
Expand Down Expand Up @@ -1291,7 +1291,7 @@ def max_unpool1d(
kernel_size: Union[Tuple[int], int],
/,
*,
strides: Union[int, Tuple[int]] = None,
strides: Optional[Union[int, Tuple[int]]] = None,
padding: Union[int, Tuple[int]] = 0,
data_format: Optional[str] = "NCW",
) -> ivy.Array:
Expand Down
2 changes: 1 addition & 1 deletion ivy/data_classes/array/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def rot90(
self: ivy.Array,
/,
*,
copy: bool = None,
copy: Optional[bool] = None,
k: int = 1,
axes: Tuple[int, int] = (0, 1),
out: Optional[ivy.Array] = None,
Expand Down
4 changes: 2 additions & 2 deletions ivy/data_classes/container/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ def static_max_unpool1d(
kernel_size: Union[Tuple[int], int],
/,
*,
strides: Union[int, Tuple[int]] = None,
strides: Optional[Union[int, Tuple[int]]] = None,
padding: Union[int, Tuple[int]] = 0,
data_format: Union[str, ivy.Container] = "NCW",
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
Expand Down Expand Up @@ -2817,7 +2817,7 @@ def max_unpool1d(
kernel_size: Union[Tuple[int], int],
/,
*,
strides: Union[int, Tuple[int]] = None,
strides: Optional[Union[int, Tuple[int]]] = None,
padding: Union[int, Tuple[int]] = 0,
data_format: Optional[str] = "NCW",
) -> ivy.Container:
Expand Down
6 changes: 3 additions & 3 deletions ivy/functional/backends/jax/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def reduce_window(
def fft2(
x: JaxArray,
*,
s: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
dim: Sequence[int] = (-2, -1),
norm: str = "backward",
out: Optional[JaxArray] = None,
Expand Down Expand Up @@ -873,8 +873,8 @@ def rfft(
@with_unsupported_dtypes({"0.4.20 and below": ("float16", "complex")}, backend_version)
def rfftn(
x: JaxArray,
s: Sequence[int] = None,
axes: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
axes: Optional[Sequence[int]] = None,
*,
norm: str = "backward",
out: Optional[JaxArray] = None,
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/jax/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_item(
/,
query: Union[JaxArray, Tuple],
*,
copy: bool = None,
copy: Optional[bool] = None,
) -> JaxArray:
if ivy.is_array(query) and ivy.is_bool_dtype(query):
if not len(query.shape):
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/mxnet/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def repeat(
/,
repeats: Union[(int, List[int])],
*,
axis: int = None,
axis: Optional[int] = None,
out: Optional[Union[(None, mx.ndarray.NDArray)]] = None,
) -> Union[(None, mx.ndarray.NDArray)]:
raise IvyNotImplementedException()
Expand Down
28 changes: 14 additions & 14 deletions ivy/functional/backends/numpy/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def arange(
step: float = 1,
*,
dtype: Optional[np.dtype] = None,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
if dtype:
Expand All @@ -56,7 +56,7 @@ def asarray(
*,
copy: Optional[bool] = None,
dtype: Optional[np.dtype] = None,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
ret = np.asarray(obj, dtype=dtype)
Expand All @@ -67,7 +67,7 @@ def empty(
shape: Union[ivy.NativeShape, Sequence[int]],
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.empty(shape, dtype)
Expand All @@ -78,7 +78,7 @@ def empty_like(
/,
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.empty_like(x, dtype=dtype)
Expand All @@ -92,7 +92,7 @@ def eye(
k: int = 0,
batch_shape: Optional[Union[int, Sequence[int]]] = None,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
if n_cols is None:
Expand Down Expand Up @@ -132,7 +132,7 @@ def full(
fill_value: Union[int, float, bool],
*,
dtype: Optional[Union[ivy.Dtype, np.dtype]] = None,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
dtype = ivy.default_dtype(dtype=dtype, item=fill_value, as_native=True)
Expand All @@ -145,7 +145,7 @@ def full_like(
fill_value: Number,
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.full_like(x, fill_value, dtype=dtype)
Expand All @@ -160,7 +160,7 @@ def linspace(
axis: Optional[int] = None,
endpoint: bool = True,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
if axis is None:
Expand Down Expand Up @@ -189,7 +189,7 @@ def ones(
shape: Union[ivy.NativeShape, Sequence[int]],
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.ones(shape, dtype)
Expand All @@ -200,7 +200,7 @@ def ones_like(
/,
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.ones_like(x, dtype=dtype)
Expand All @@ -222,7 +222,7 @@ def zeros(
shape: Union[ivy.NativeShape, Sequence[int]],
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.zeros(shape, dtype)
Expand All @@ -233,7 +233,7 @@ def zeros_like(
/,
*,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
return np.zeros_like(x, dtype=dtype)
Expand Down Expand Up @@ -266,7 +266,7 @@ def one_hot(
off_value: Optional[Number] = None,
axis: Optional[int] = None,
dtype: Optional[np.dtype] = None,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
on_none = on_value is None
Expand Down Expand Up @@ -310,6 +310,6 @@ def triu_indices(
k: int = 0,
/,
*,
device: str = None,
device: Optional[str] = None,
) -> Tuple[np.ndarray]:
return tuple(np.asarray(np.triu_indices(n=n_rows, k=k, m=n_cols)))
2 changes: 1 addition & 1 deletion ivy/functional/backends/numpy/experimental/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def tril_indices(
k: int = 0,
/,
*,
device: str = None,
device: Optional[str] = None,
) -> Tuple[np.ndarray, ...]:
return tuple(np.asarray(np.tril_indices(n=n_rows, k=k, m=n_cols)))

Expand Down
6 changes: 3 additions & 3 deletions ivy/functional/backends/numpy/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def ifft(
def fft2(
x: np.ndarray,
*,
s: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
dim: Sequence[int] = (-2, -1),
norm: str = "backward",
out: Optional[np.ndarray] = None,
Expand Down Expand Up @@ -1041,8 +1041,8 @@ def rfft(

def rfftn(
x: np.ndarray,
s: Sequence[int] = None,
axes: Sequence[int] = None,
s: Optional[Sequence[int]] = None,
axes: Optional[Sequence[int]] = None,
*,
norm: str = "backward",
out: Optional[np.ndarray] = None,
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/numpy/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_item(
/,
query: Union[np.ndarray, Tuple],
*,
copy: bool = None,
copy: Optional[bool] = None,
) -> np.ndarray:
return x.__getitem__(query)

Expand Down
8 changes: 4 additions & 4 deletions ivy/functional/backends/numpy/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def random_uniform(
high: Union[float, np.ndarray] = 1.0,
shape: Optional[Union[ivy.NativeShape, Sequence[int], np.ndarray]] = None,
dtype: np.dtype,
device: str = None,
device: Optional[str] = None,
out: Optional[np.ndarray] = None,
seed: Optional[int] = None,
) -> np.ndarray:
Expand All @@ -39,7 +39,7 @@ def random_normal(
mean: Union[float, np.ndarray] = 0.0,
std: Union[float, np.ndarray] = 1.0,
shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,
device: str = None,
device: Optional[str] = None,
dtype: np.dtype,
seed: Optional[int] = None,
out: Optional[np.ndarray] = None,
Expand All @@ -60,7 +60,7 @@ def multinomial(
batch_size: int = 1,
probs: Optional[np.ndarray] = None,
replace: bool = True,
device: str = None,
device: Optional[str] = None,
seed: Optional[int] = None,
out: Optional[np.ndarray] = None,
) -> np.ndarray:
Expand Down Expand Up @@ -95,7 +95,7 @@ def randint(
/,
*,
shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,
device: str = None,
device: Optional[str] = None,
dtype: Optional[Union[np.dtype, ivy.Dtype]] = None,
seed: Optional[int] = None,
out: Optional[np.ndarray] = None,
Expand Down
4 changes: 2 additions & 2 deletions ivy/functional/backends/paddle/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def fft(
/,
*,
norm: Optional[str] = "backward",
n: Union[int, Tuple[int]] = None,
n: Optional[Union[int, Tuple[int]]] = None,
out: Optional[paddle.Tensor] = None,
) -> paddle.Tensor:
if not isinstance(dim, int):
Expand Down Expand Up @@ -414,7 +414,7 @@ def ifft(
dim: int,
*,
norm: Optional[str] = "backward",
n: Union[int, Tuple[int]] = None,
n: Optional[Union[int, Tuple[int]]] = None,
out: Optional[paddle.Tensor] = None,
) -> paddle.Tensor:
raise IvyNotImplementedException()
Expand Down
11 changes: 8 additions & 3 deletions ivy/functional/backends/paddle/experimental/norms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def batch_norm(

@with_supported_dtypes({"2.5.2 and below": ("float32", "float64")}, backend_version)
def l1_normalize(
x: paddle.Tensor, /, *, axis: int = None, out: paddle.Tensor = None
x: paddle.Tensor, /, *, axis: Optional[int] = None, out: paddle.Tensor = None
) -> paddle.Tensor:
if not isinstance(x, paddle.Tensor):
x = paddle.to_tensor(x)
Expand All @@ -131,7 +131,7 @@ def l1_normalize(


def l2_normalize(
x: paddle.Tensor, /, *, axis: int = None, out: paddle.Tensor = None
x: paddle.Tensor, /, *, axis: Optional[int] = None, out: paddle.Tensor = None
) -> paddle.Tensor:
raise IvyNotImplementedException()

Expand Down Expand Up @@ -164,6 +164,11 @@ def instance_norm(


def lp_normalize(
x: paddle.Tensor, /, *, p: float = 2, axis: int = None, out: paddle.Tensor = None
x: paddle.Tensor,
/,
*,
p: float = 2,
axis: Optional[int] = None,
out: paddle.Tensor = None,
) -> paddle.Tensor:
raise IvyNotImplementedException()
2 changes: 1 addition & 1 deletion ivy/functional/backends/paddle/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_item(
/,
query: Union[paddle.Tensor, Tuple],
*,
copy: bool = None,
copy: Optional[bool] = None,
) -> paddle.Tensor:
if copy:
x = paddle.clone(x)
Expand Down
4 changes: 2 additions & 2 deletions ivy/functional/backends/paddle/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def cross(
axisa: int = -1,
axisb: int = -1,
axisc: int = -1,
axis: int = None,
axis: Optional[int] = None,
out: Optional[paddle.Tensor] = None,
) -> paddle.Tensor:
def _cross(x1, x2, axisa, axisb, axisc, axis):
Expand Down Expand Up @@ -433,7 +433,7 @@ def tensorsolve(
x2: paddle.Tensor,
/,
*,
axes: Union[int, Tuple[List[int], List[int]]] = None,
axes: Optional[Union[int, Tuple[List[int], List[int]]]] = None,
out: Optional[paddle.Tensor] = None,
) -> paddle.Tensor:
# Implemented as a composite function in ivy.functional.ivy.linear_algebra
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/paddle/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def repeat(
/,
repeats: Union[int, Iterable[int]],
*,
axis: int = None,
axis: Optional[int] = None,
out: Optional[paddle.Tensor] = None,
) -> paddle.Tensor:
# handle the case when repeats contains 0 as paddle doesn't support it
Expand Down
Loading

0 comments on commit cb8d76f

Please sign in to comment.