Skip to content

Commit

Permalink
lint fixes as the lint bot is not commiting these days (#12578)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhirwa authored Mar 17, 2023
1 parent 93707bd commit 7dfbcb8
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 205 deletions.
7 changes: 3 additions & 4 deletions ivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,9 @@ class Node(str):
from ivy.utils.inspection import fn_array_spec, add_array_specs

try:
from . compiler.compiler import transpile , compile , unify

except:
compile,transpile,unify = None, None ,None
from .compiler.compiler import transpile, compile, unify
except: # noqa: E722
compile, transpile, unify = None, None, None

add_array_specs()

Expand Down
55 changes: 28 additions & 27 deletions ivy/array/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,33 +574,34 @@ def outer(
) -> ivy.Array:

"""
Computes the outer product between two arrays.
Parameters
----------
self : ivy.Array
The first input array.
x2 : ivy.Array or ivy.NativeArray
The second input array.
out : ivy.Array, optional
Output array. If provided, it must have the same shape as the expected output.
Returns
-------
ivy.Array
The outer product of the two arrays.
Examples
--------
>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5])
>>> z = x.outer(y)
>>> print(z)
ivy.array([[ 4, 5],
[ 8, 10],
[12, 15]])
"""
Computes the outer product between two arrays.
Parameters
----------
self : ivy.Array
The first input array.
x2 : ivy.Array or ivy.NativeArray
The second input array.
out : ivy.Array, optional
Output array. If provided, it must have the same
shape as the expected output.
Returns
-------
ivy.Array
The outer product of the two arrays.
Examples
--------
>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5])
>>> z = x.outer(y)
>>> print(z)
ivy.array([[ 4, 5],
[ 8, 10],
[12, 15]])
"""
return ivy.outer(self._data, x2, out=out)

def pinv(
Expand Down
139 changes: 74 additions & 65 deletions ivy/container/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,56 +1764,59 @@ def static_outer(
out: Optional[ivy.Container] = None,
) -> ivy.Container:
"""
ivy.Container static method variant of ivy.outer. This method simply wraps the
function, and so the docstring for ivy.outer also applies to this method with
minimal changes.
Computes the outer product of two arrays, x1 and x2, by computing the tensor
product along the last dimension of both arrays.
Parameters
----------
x1
first input array having shape (..., N1)
x2
second input array having shape (..., N2)
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains, otherwise key_chains will be
skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
out
optional output container, for writing the result to. The container must have
shape (..., N1, N2). The first x1.ndim-1 dimensions must have the same size as
those of the input array x1 and the first x2.ndim-1 dimensions must have the same
size as those of the input array x2.
Returns
-------
ret
an ivy container whose shape is (..., N1, N2). The first x1.ndim-1 dimensions
have the same size as those of the input array x1 and the first x2.ndim-1
dimensions have the same size as those of the input array x2.
Example
-------
>>> x1 =ivy.Container( a=ivy.array([[1, 2, 3], [4, 5, 6]]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3]))
>>> y = ivy.Container.static_outer(x1, x2)
>>> print(y)
ivy.array([[[ 1., 2., 3.],
[ 2., 4., 6.],
[ 3., 6., 9.]],
[[ 4., 8., 12.],
[ 5., 10., 15.],
[ 6., 12., 18.]]])
"""
ivy.Container static method variant of ivy.outer.
This method simply wraps the function, and so
the docstring for ivy.outer also applies to this method with
minimal changes.
Computes the outer product of two arrays, x1 and x2,
by computing the tensor product along the last dimension of both arrays.
Parameters
----------
x1
first input array having shape (..., N1)
x2
second input array having shape (..., N2)
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains,
otherwise key_chains will be skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
out
optional output container, for writing the result to.
The container must have shape (..., N1, N2). The first x1.ndim-1
dimensions must have the same size as those of the input array x1
and the first x2.ndim-1 dimensions must have the same
size as those of the input array x2.
Returns
-------
ret
an ivy container whose shape is (..., N1, N2).
The first x1.ndim-1 dimensions have the same size as those
of the input array x1 and the first x2.ndim-1
dimensions have the same size as those of the input array x2.
Example
-------
>>> x1 =ivy.Container( a=ivy.array([[1, 2, 3], [4, 5, 6]]))
>>> x2 = ivy.Container(a=ivy.array([1, 2, 3]))
>>> y = ivy.Container.static_outer(x1, x2)
>>> print(y)
ivy.array([[[ 1., 2., 3.],
[ 2., 4., 6.],
[ 3., 6., 9.]],
[[ 4., 8., 12.],
[ 5., 10., 15.],
[ 6., 12., 18.]]])
"""
return ContainerBase.cont_multi_map_in_function(
"outer",
x1,
Expand All @@ -1838,36 +1841,42 @@ def outer(
) -> ivy.Container:
"""
This is the instance method implementation of the static method static_outer
of the ivy.Container class.
It calculates the outer product of two input arrays or containers along the last dimension
and returns the resulting container.
of the ivy.Container class.
It calculates the outer product of two input arrays or
containers along the last dimension and returns the resulting container.
The input arrays should be either ivy.Container, ivy.Array, or ivy.NativeArray.
The output container shape is the concatenation of the shapes of the input container
s along the last dimension.
The output container shape is the concatenation of
the shapes of the input containers along the last dimension.
Parameters
----------
self : ivy.Container
Input container of shape (...,B) where the last dimension represents B elements.
Input container of shape (...,B) where the last dimension
represents B elements.
x2 : Union[ivy.Container, ivy.Array, ivy.NativeArray]
Second input array or container of shape (..., N) where the last dimension represents N elements.
Second input array or container of shape (..., N)
where the last dimension represents N elements.
key_chains : Optional[Union[List[str], Dict[str, str]]]
The key-chains to apply or not apply the method to. Default is None.
The key-chains to apply or not apply the method to. Default is None.
to_apply : bool
If True, the method will be applied to key_chains, otherwise key_chains will be skipped.
Default is True.
If True, the method will be applied to key_chains,
otherwise key_chains will be skipped.Default is True.
prune_unapplied : bool
Whether to prune key_chains for which the function was not applied. Default is False.
Whether to prune key_chains for which the function was not applied.
Default is False.
map_sequences : bool
Whether to also map the method to sequences (lists, tuples). Default is False.
Whether to also map the method to sequences (lists, tuples).
Default is False.
out : Optional[ivy.Container]
Optional output container to write the result to. If not provided, a new container will be created.
Optional output container to write the result to.
If not provided, a new container will be created.
Returns
-------
ivy.Container
A new container of shape (..., M, N) representing the outer product of the input arrays
or containers along the last dimension.
A new container of shape (..., M, N) representing
the outer product of the input arrays or containers
along the last dimension.
Examples
--------
>>> x = ivy.array([[1., 2.],[3., 4.]])
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/jax/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def ifft(


@handle_mixed_function(
lambda *args, mode="linear", scale_factor=None, recompute_scale_factor=None, align_corners=None, **kwargs: (
lambda *args, mode="linear", scale_factor=None, recompute_scale_factor=None, align_corners=None, **kwargs: ( # noqa: E501
not align_corners
and mode
not in [
Expand Down
1 change: 1 addition & 0 deletions ivy/functional/backends/numpy/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def matrix_transpose(
np.conjugate(x)
return np.swapaxes(x, -1, -2)


@with_unsupported_dtypes({"1.23.0 and below": ("float16",)}, backend_version)
def outer(
x1: np.ndarray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def around(a, decimals=0, out=None):
a = ivy.divide(a, factor)
return a


@to_ivy_arrays_and_back
def frexp(x, /):
return ivy.frexp(x)
4 changes: 3 additions & 1 deletion ivy/functional/frontends/jax/numpy/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,7 @@ def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=Non
std_a = ivy.std(a, axis=axis, correction=ddof, keepdims=keepdims, out=out)
if ivy.is_array(where):
where = ivy.array(where, dtype=ivy.bool)
std_a = ivy.where(where, std_a, ivy.default(out, ivy.zeros_like(std_a)), out=out)
std_a = ivy.where(
where, std_a, ivy.default(out, ivy.zeros_like(std_a)), out=out
)
return ivy.astype(std_a, ivy.as_ivy_dtype(dtype), copy=False)
4 changes: 2 additions & 2 deletions ivy/functional/frontends/tensorflow/general_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def num_to_bit_list(number):
)
ivy.assertions.check_true(
sum(ellipsis_mask) <= 1,
message="Only one non-zero bit is allowed in ellipsis_mask."
message="Only one non-zero bit is allowed in ellipsis_mask.",
)
begin, end = map(lambda x: ivy.array(x) if isinstance(x, int) else x, [begin, end])

Expand Down Expand Up @@ -307,7 +307,7 @@ def num_to_bit_list(number):
@to_ivy_arrays_and_back
def slice(input_, begin, size, name=None):
n_slices = 1 if isinstance(begin, int) else len(begin)
return strided_slice(input_, begin, begin + size, strides=[1]*n_slices)
return strided_slice(input_, begin, begin + size, strides=[1] * n_slices)


@to_ivy_arrays_and_back
Expand Down
1 change: 0 additions & 1 deletion ivy/functional/frontends/torch/blas_and_lapack_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,3 @@ def trapezoid(y, x=None, *, dx=None, dim=-1):
if x is not None:
y, x = torch_frontend.promote_types_of_torch_inputs(y, x)
return ivy.trapz(y, x=x, dx=dx, axis=dim)

3 changes: 0 additions & 3 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ivy.func_wrapper import with_supported_dtypes



class Tensor:
def __init__(self, array, device=None, _init_overload=False):

Expand Down Expand Up @@ -858,5 +857,3 @@ def __invert__(self):
# Method aliases
absolute, absolute_ = abs, abs_
ndimension = dim


4 changes: 3 additions & 1 deletion ivy/functional/ivy/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,9 @@ def mitchellcubic_kernel(s, b=1 / 3, c=1 / 3):
scale_factor = None
elif scale_factor is not None:
scale_factor = (
[scale_factor] * dims if isinstance(scale_factor, (int, float)) else scale_factor
[scale_factor] * dims
if isinstance(scale_factor, (int, float))
else scale_factor
)
scale_factor = (
[scale_factor[0]] * dims
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,3 @@ def test_jax_numpy_sort_complex(
a=x[0],
test_values=False,
)

Original file line number Diff line number Diff line change
Expand Up @@ -1046,13 +1046,17 @@ def _strided_slice_helper(draw):
) # maximum one ellipse
)
begin, end, strides = [], [], []
n_omit = draw(st.integers(min_value=0, max_value=ndims-1))
sub_shape = shape[:len(shape)-n_omit]
n_omit = draw(st.integers(min_value=0, max_value=ndims - 1))
sub_shape = shape[: len(shape) - n_omit]
for i in sub_shape:
begin += [draw(st.integers(min_value=0, max_value=i - 1))]
end += [draw(
st.integers(min_value=0, max_value=i - 1).filter(lambda x: x != begin[-1])
)]
end += [
draw(
st.integers(min_value=0, max_value=i - 1).filter(
lambda x: x != begin[-1]
)
)
]
if begin[-1] < end[-1]:
strides += [draw(st.integers(min_value=1, max_value=i))]
else:
Expand Down Expand Up @@ -1093,8 +1097,10 @@ def test_tensorflow_strided_slice(
shrink_axis_mask=masks[4],
)
except Exception as e:
if hasattr(e, "message") and \
"only stride 1 allowed on non-range indexing" in e.message:
if (
hasattr(e, "message")
and "only stride 1 allowed on non-range indexing" in e.message
):
assume(False)
raise e

Expand Down Expand Up @@ -1126,8 +1132,10 @@ def test_tensorflow_slice(
size=end - begin,
)
except Exception as e:
if hasattr(e, "message") and \
"only stride 1 allowed on non-range indexing" in e.message:
if (
hasattr(e, "message")
and "only stride 1 allowed on non-range indexing" in e.message
):
assume(False)
raise e

Expand Down Expand Up @@ -1543,7 +1551,7 @@ def test_tensorflow_split(
valid_axis=True,
force_int_axis=True,
),
repeats=helpers.ints(min_value=1, max_value=5)
repeats=helpers.ints(min_value=1, max_value=5),
)
def test_tensorflow_repeat(
*,
Expand All @@ -1564,7 +1572,7 @@ def test_tensorflow_repeat(
on_device=on_device,
input=x[0],
repeats=repeats,
axis=axis
axis=axis,
)


Expand Down
Loading

0 comments on commit 7dfbcb8

Please sign in to comment.