Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Cos, Sin, Acos, Sigmoid to PyTorch Frontend #2471

Merged
merged 23 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
64d3fed
Added cos and sin Pointwise ops to PyTorch Frontend
pritam1322 Jul 30, 2022
f5d4280
Added acos to Pointwise Ops to Pytorch Frontend
pritam1322 Jul 30, 2022
5623ddf
Delete test_elementwise.py
pritam1322 Jul 30, 2022
b77cb90
Delete pytest_for_elementwise.xml
pritam1322 Aug 1, 2022
e154812
Delete pytest_for_functional_core.xml
pritam1322 Aug 1, 2022
bba58e6
Non-linear Activation Function #sigmoid
pritam1322 Aug 1, 2022
dc64266
Merge remote-tracking branch 'origin/master' into master
pritam1322 Aug 1, 2022
5bf454c
Revert "Delete test_elementwise.py"
pritam1322 Aug 2, 2022
d4429c1
Revert "Delete pytest_for_elementwise.xml"
pritam1322 Aug 2, 2022
2522763
Revert "Delete pytest_for_functional_core.xml"
pritam1322 Aug 2, 2022
eaaa937
Non-linear Activation Function #sigmoid
pritam1322 Aug 2, 2022
cbed1ee
Deleted files
pritam1322 Aug 2, 2022
b3f6a20
Merge branch 'master' into master
iamjameskeane Aug 3, 2022
f0a0c68
Updated
pritam1322 Aug 3, 2022
ff73e0e
Update test_pointwise_ops.py
pritam1322 Aug 3, 2022
21368b0
Update test_pointwise_ops.py
pritam1322 Aug 3, 2022
76d6efd
Update test_pointwise_ops.py
pritam1322 Aug 3, 2022
e4135e3
Update test_elementwise.py
pritam1322 Aug 3, 2022
c0c795c
Updated sigmoid in test_non_linear_activation_functions.py
pritam1322 Aug 3, 2022
761a427
Updated test_non_linear_activation_functions.py
pritam1322 Aug 4, 2022
cc8b020
Update pointwise_ops.py
iamjameskeane Aug 4, 2022
aa411fd
Update pointwise_ops.py
pritam1322 Aug 4, 2022
48e30a2
Update pointwise_ops.py
pritam1322 Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ivy/functional/frontends/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
from .indexing_slicing_joining_mutating_ops import *
from . import pointwise_ops
from .pointwise_ops import *
from . import non_linear_activation_functions
from .non_linear_activation_functions import *
from . import creation_ops
from .creation_ops import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# global
import ivy


def sigmoid(input, out=None):
return ivy.sigmoid(input, out=out)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add float 16 as unsupported data type here


sigmoid.unsupported_dtypes = ("float16",)
21 changes: 21 additions & 0 deletions ivy/functional/frontends/torch/pointwise_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,26 @@ def tan(input, *, out=None):
tan.unsupported_dtypes = ("float16",)


def cos(input, *, out=None):
return ivy.cos(input, out=out)


cos.unsupported_dtypes = ("float16",)


def sin(input, *, out=None):
return ivy.sin(input, out=out)


sin.unsupported_dtypes = ("float16",)


def acos(input, *, out=None):
return ivy.acos(input, out=out)


acos.unsupported_dtypes = ("float16",)


def abs(input, *, out=None):
return ivy.abs(input, out=out)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# global
import numpy as np
from hypothesis import given, strategies as st

# local
import ivy_tests.test_ivy.helpers as helpers
import ivy.functional.backends.numpy as ivy_np
import ivy.functional.backends.torch as ivy_torch


@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=tuple(
set(ivy_np.valid_float_dtypes).intersection(
set(ivy_torch.valid_float_dtypes)
)
)
),
as_variable=st.booleans(),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(fn_name="sigmoid"),
native_array=st.booleans(),
)
def test_torch_sigmoid(
dtype_and_x,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x

helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
fw=fw,
frontend="torch",
fn_name="sigmoid",
input=np.asarray(x, dtype=input_dtype),
out=None,
)
117 changes: 117 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,120 @@ def test_torch_abs(
input=np.asarray(x, dtype=input_dtype),
out=None,
)


# cos
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=tuple(
set(ivy_np.valid_float_dtypes).intersection(
set(ivy_torch.valid_float_dtypes)
)
)
),
as_variable=st.booleans(),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="functional.frontends.torch.cos"
),
native_array=st.booleans(),
)
def test_torch_cos(
dtype_and_x,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
fw=fw,
frontend="torch",
fn_name="cos",
input=np.asarray(x, dtype=input_dtype),
out=None,
)


# sin
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=tuple(
set(ivy_np.valid_float_dtypes).intersection(
set(ivy_torch.valid_float_dtypes)
)
)
),
as_variable=st.booleans(),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="functional.frontends.torch.sin"
),
native_array=st.booleans(),
)
def test_torch_sin(
dtype_and_x,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
fw=fw,
frontend="torch",
fn_name="sin",
input=np.asarray(x, dtype=input_dtype),
out=None,
)


# acos
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=tuple(
set(ivy_np.valid_float_dtypes).intersection(
set(ivy_torch.valid_float_dtypes)
)
)
),
as_variable=st.booleans(),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="functional.frontends.torch.acos"
),
native_array=st.booleans(),
)
def test_torch_acos(
dtype_and_x,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
fw=fw,
frontend="torch",
fn_name="acos",
input=np.asarray(x, dtype=input_dtype),
out=None,
)