Skip to content

Commit

Permalink
Merge branch 'master' into bitwise_not
Browse files Browse the repository at this point in the history
  • Loading branch information
samthakur587 authored Jun 27, 2023
2 parents 16cf25f + 78b86ec commit 8894f8b
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ivy/functional/frontends/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def exp(x, name=None):
@to_ivy_arrays_and_back
def cumprod(x, dim=None, dtype=None, name=None):
return ivy.cumprod(x, axis=dim, dtype=dtype)


@with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle")
@to_ivy_arrays_and_back
Expand Down
16 changes: 16 additions & 0 deletions ivy/functional/frontends/paddle/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ def logical_xor(self, y, out=None, name=None):
)
def bitwise_not(self,out=None, name=None):
return paddle_frontend.bitwise_not(self, out=out)

@with_unsupported_dtypes(
{
"2.5.0 and below": (
"bool",
"uint8",
"int8",
"int16",
"complex64",
"complex128",
)
},
"paddle",
)
def greater_than(self, y, name=None):
return paddle_frontend.greater_than(self, y)

@with_supported_dtypes({"2.5.0 and below": ("float32", "float64")}, "paddle")
def rsqrt(self, name=None):
Expand Down
38 changes: 36 additions & 2 deletions ivy/functional/frontends/tensorflow/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ivy
from ivy.functional.frontends.tensorflow.func_wrapper import to_ivy_arrays_and_back
from ivy.func_wrapper import with_unsupported_dtypes

from ivy.functional.frontends.tensorflow import check_tensorflow_casting

def _reduce_strides_dilations(dim, stride, dilations):
if not isinstance(stride, int):
Expand Down Expand Up @@ -487,4 +487,38 @@ def pool(
# log_poisson_loss
@to_ivy_arrays_and_back
def log_poisson_loss(targets, log_input, compute_full_loss=False, name=None):
return ivy.log_poisson_loss(targets, log_input, compute_full_loss, name)
return ivy.log_poisson_loss(targets, log_input, compute_full_loss, name)


#weighted_moments
@to_ivy_arrays_and_back
def weighted_moments(x, axes, frequency_weights, keepdims=False, name=None):
fw_x_prod=frequency_weights * x
fw_x_prod=ivy.array(fw_x_prod)
weighted_input_sum = ivy.sum(fw_x_prod, axis=axes, keepdims=True).astype(fw_x_prod.dtype)

broadcasted_weights = frequency_weights + ivy.zeros_like(x)
broadcasted_weights=ivy.array(broadcasted_weights)
sum_of_weights = ivy.sum(broadcasted_weights, axis=axes, keepdims=True).astype(broadcasted_weights.dtype)

divisor = ivy.reciprocal(sum_of_weights)

weighted_input_sum, divisor = check_tensorflow_casting(weighted_input_sum, divisor)
weighted_mean = ivy.multiply(weighted_input_sum, divisor)

x, weighted_mean = check_tensorflow_casting(x, weighted_mean)
squared_difference = ivy.square(ivy.subtract(x, weighted_mean))
if isinstance(squared_difference, complex):
squared_difference = squared_difference.real - squared_difference.imag*1j

fw_sq_diff_prod=frequency_weights * squared_difference
fw_sq_diff_prod=ivy.array(fw_sq_diff_prod)
weighted_distsq = ivy.sum(fw_sq_diff_prod, axis=axes, keepdims=True).astype(fw_sq_diff_prod.dtype)

weighted_distsq, divisor=check_tensorflow_casting(weighted_distsq, divisor)
weighted_variance = ivy.multiply(weighted_distsq, divisor)

if not keepdims:
weighted_mean = ivy.squeeze(weighted_mean, axis=axes)
weighted_variance = ivy.squeeze(weighted_variance, axis=axes)
return weighted_mean, weighted_variance
4 changes: 4 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def addmm_(self, mat1, mat2, *, beta=1, alpha=1):
self.ivy_array = self.addmm(mat1, mat2, beta=beta, alpha=alpha).ivy_array
return self

@with_unsupported_dtypes({"2.0.1 and below": ("float16",)}, "torch")
def addmv(self, mat, vec, *, beta=1, alpha=1):
return torch_frontend.addmv(self, mat, vec, beta=beta, alpha=alpha)

@with_unsupported_dtypes({"2.0.1 and below": ("float16",)}, "torch")
def addbmm(self, batch1, batch2, *, beta=1, alpha=1):
return torch_frontend.addbmm(self, batch1, batch2, beta=beta, alpha=alpha)
Expand Down
30 changes: 21 additions & 9 deletions ivy/functional/ivy/experimental/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
to_native_arrays_and_back,
inputs_to_native_shapes,
handle_nestable,
handle_mixed_function,
handle_array_like_without_promotion,
handle_view,
inputs_to_ivy_arrays,
Expand All @@ -33,7 +32,6 @@

@handle_exceptions
@handle_nestable
@handle_mixed_function
@handle_array_like_without_promotion
@handle_view
@inputs_to_ivy_arrays
Expand Down Expand Up @@ -955,9 +953,7 @@ def _check_arguments(

@handle_exceptions
@handle_nestable
@handle_mixed_function
@handle_array_like_without_promotion
@handle_out_argument
@inputs_to_ivy_arrays
@handle_array_function
def pad(
Expand Down Expand Up @@ -1212,6 +1208,15 @@ def pad(
return padded


pad.mixed_backend_wrappers = {
"to_add": (
"inputs_to_native_arrays",
"outputs_to_ivy_arrays",
),
"to_skip": ("inputs_to_ivy_arrays",),
}


@handle_exceptions
@handle_nestable
@handle_array_like_without_promotion
Expand Down Expand Up @@ -1400,7 +1405,7 @@ def dstack(
[[2, 3]],
[[3, 4]]])
"""
return ivy.current_backend().dstack(arrays)
return ivy.current_backend().dstack(arrays, out=out)


@handle_nestable
Expand Down Expand Up @@ -1683,11 +1688,10 @@ def expand(
return ivy.current_backend(x).expand(x, shape, out=out, copy=None)


@handle_out_argument
@handle_mixed_function
@handle_nestable
@handle_exceptions
@handle_array_like_without_promotion
@inputs_to_ivy_arrays
def put_along_axis(
arr: Union[ivy.Array, ivy.NativeArray],
indices: Union[ivy.Array, ivy.NativeArray],
Expand Down Expand Up @@ -1777,7 +1781,6 @@ def _check_bounds(shape0, shape1, strides1, itemsize):


@handle_exceptions
@handle_mixed_function
@handle_nestable
@handle_array_like_without_promotion
@inputs_to_native_shapes
Expand Down Expand Up @@ -1840,6 +1843,15 @@ def as_strided(
)


as_strided.mixed_backend_wrappers = {
"to_add": (
"inputs_to_native_arrays",
"outputs_to_ivy_arrays",
),
"to_skip": ("inputs_to_ivy_arrays",),
}


@handle_exceptions
@handle_nestable
@handle_out_argument
Expand Down Expand Up @@ -1953,8 +1965,8 @@ def _interleave(a, b, axis):

@handle_exceptions
@handle_nestable
@handle_mixed_function
@inputs_to_ivy_arrays
@handle_array_function
def associative_scan(
x: Union[ivy.Array, ivy.NativeArray],
fn: Callable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def test_paddle_reciprocal(
x=x[0],
)


# cumprod
@handle_frontend_test(
fn_tree="paddle.tensor.math.cumprod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1446,3 +1446,38 @@ def test_paddle_instance_ceil(
frontend=frontend,
on_device=on_device,
)


# greater_than
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="paddle.to_tensor",
method_name="greater_than",
dtypes_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
num_arrays=2,
shared_dtype=True,
safety_factor_scale="log",
small_abs_safety_factor=32,
),
)
def test_paddle_greater_than(
dtypes_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
):
input_dtype, x = dtypes_and_x
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
init_all_as_kwargs_np={"data": x[0]},
method_input_dtypes=input_dtype,
method_all_as_kwargs_np={"y": x[1]},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@ def test_tensorflow_zero_fraction(
available_dtypes=helpers.get_dtypes("numeric"),
num_arrays=2,
shared_dtype=True,
large_abs_safety_factor=24,
small_abs_safety_factor=24,
safety_factor_scale="log",
),
test_with_out=st.just(False),
)
Expand All @@ -1457,6 +1460,8 @@ def test_tensorflow_truediv(
on_device=on_device,
x=x[0],
y=x[1],
rtol=1e-2,
atol=1e-2,
)


Expand Down
39 changes: 39 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,3 +1603,42 @@ def test_log_poisson_loss(
compute_full_loss=compute_full_loss,
atol=1e-2,
)


# weighted moments
@handle_frontend_test(
fn_tree="tensorflow.nn.weighted_moments",
dtype_and_x_and_axis=_statistical_dtype_values(function="mean"),
dtype_and_fw=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=1,
min_value=0.00001,
),
keepdims=st.booleans(),
test_with_out=st.just(False),
)
def test_tensorflow_weighted_moments(
*,
dtype_and_x_and_axis,
dtype_and_fw,
keepdims,
frontend,
test_flags,
fn_tree,
on_device,
):
input_dtype, x, axis = dtype_and_x_and_axis
fw_dtype, fw = dtype_and_fw
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-1,
atol=1e-1,
x=x[0],
axes=axis,
frequency_weights=fw[0],
keepdims=keepdims,
)
54 changes: 54 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ivy_tests.test_ivy.test_frontends.test_torch.test_blas_and_lapack_ops import (
_get_dtype_and_3dbatch_matrices,
_get_dtype_input_and_matrices,
_get_dtype_input_and_mat_vec,
)
from ivy.functional.frontends.torch import Tensor
from ivy_tests.test_ivy.helpers import handle_frontend_method
Expand Down Expand Up @@ -464,6 +465,59 @@ def test_torch_instance_addmm_(
)


# addmv
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="addmv",
dtype_and_matrices=_get_dtype_input_and_mat_vec(with_input=True),
beta=st.floats(
min_value=-5,
max_value=5,
allow_nan=False,
allow_subnormal=False,
allow_infinity=False,
),
alpha=st.floats(
min_value=-5,
max_value=5,
allow_nan=False,
allow_subnormal=False,
allow_infinity=False,
),
)
def test_torch_instance_addmv(
dtype_and_matrices,
beta,
alpha,
frontend,
frontend_method_data,
init_flags,
method_flags,
on_device,
):
input_dtype, x, mat, vec = dtype_and_matrices
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
init_all_as_kwargs_np={
"data": x,
},
method_input_dtypes=input_dtype,
method_all_as_kwargs_np={
"mat": mat,
"vec": vec,
"beta": beta,
"alpha": alpha,
},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
atol_=1e-02,
on_device=on_device,
)


# addbmm
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit 8894f8b

Please sign in to comment.