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

Adds nin and nout properties to unary and binary element-wise classes #1478

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions dpctl/tensor/_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ def get_type_result_resolver_function(self):
"""
return self.result_type_resolver_fn_

@property
def nin(self):
"""
Returns the number of arguments treated as inputs.
"""
return 1

@property
def nout(self):
"""
Returns the number of arguments treated as outputs.
"""
return 1

@property
def types(self):
"""Returns information about types supported by
Expand Down Expand Up @@ -531,6 +545,20 @@ def get_type_promotion_path_acceptance_function(self):
"""
return self.acceptance_fn_

@property
def nin(self):
"""
Returns the number of arguments treated as inputs.
"""
return 2

@property
def nout(self):
"""
Returns the number of arguments treated as outputs.
"""
return 1

@property
def types(self):
"""Returns information about types supported by
Expand Down
24 changes: 24 additions & 0 deletions dpctl/tests/elementwise/test_elementwise_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,27 @@ def test_binary_class_str_repr():
kl_n = binary_fn.__name__
assert kl_n in s
assert kl_n in r


def test_unary_class_nin():
nin = unary_fn.nin
assert isinstance(nin, int)
assert nin == 1


def test_binary_class_nin():
nin = binary_fn.nin
assert isinstance(nin, int)
assert nin == 2


def test_unary_class_nout():
nout = unary_fn.nout
assert isinstance(nout, int)
assert nout == 1


def test_binary_class_nout():
nout = binary_fn.nout
assert isinstance(nout, int)
assert nout == 1