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

Feature/713 result type #761

Merged
merged 26 commits into from
May 28, 2021
Merged

Feature/713 result type #761

merged 26 commits into from
May 28, 2021

Conversation

mtar
Copy link
Collaborator

@mtar mtar commented Apr 20, 2021

Description

This PR provides an implementation of result_type. Additionally, some changes in __binary_op on the output are introduced.

Issue/s resolved: #713

Changes proposed:

  • add result_type()
  • __binary_op calls result_type() for type promotions
  • __binary_op uses scalars if an operand is a number
  • new entries type mappings

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Due Diligence

  • All split configurations tested
  • Multiple dtypes tested in relevant functions
  • Documentation updated (if needed)
  • Updated changelog.md under the title "Pending Additions"

Does this change modify the behaviour of other functions? If so, which?

yes, the result type of __binary_op follows result_type and scalars are returned when adding scalars and numbers.

@mtar mtar added the enhancement New feature or request label Apr 20, 2021
@codecov
Copy link

codecov bot commented Apr 20, 2021

Codecov Report

Merging #761 (3aa6a32) into master (e0a1821) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #761      +/-   ##
==========================================
- Coverage   95.35%   95.35%   -0.01%     
==========================================
  Files          64       64              
  Lines        8854     8891      +37     
==========================================
+ Hits         8443     8478      +35     
- Misses        411      413       +2     
Flag Coverage Δ
gpu 94.45% <100.00%> (+<0.01%) ⬆️
unit 90.90% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
heat/core/_operations.py 95.78% <100.00%> (-1.06%) ⬇️
heat/core/types.py 96.51% <100.00%> (+0.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0a1821...3aa6a32. Read the comment docs.

@mtar mtar marked this pull request as ready for review April 20, 2021 14:09
@mtar mtar marked this pull request as draft April 20, 2021 14:40
@mtar mtar marked this pull request as ready for review April 21, 2021 08:40
@mtar mtar requested a review from coquelin77 April 21, 2021 11:26
Copy link
Member

@coquelin77 coquelin77 left a comment

Choose a reason for hiding this comment

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

looks good. minor changes and questions

Comment on lines 900 to 907
except Exception:
try:
# type
if isinstance(arg, np.dtype):
arg = arg.char
type1 = canonical_heat_type(arg)
prec1 = 1
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

why such a broad exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

what is raised when this happens? TypeError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah - I first thought you meant the except block and not the caught exception 🤦

Comment on lines 918 to 937
else:
if prec1 == prec2:
return promote_types(type1, type2), prec1

for sclass in (bool, integer, float):
if issubdtype(type1, sclass) and issubdtype(type2, sclass):
if prec1 < prec2:
return type1, min(prec1, prec2)
if prec1 > prec2:
return type2, min(prec1, prec2)

tc1 = __type_codes[type1]
tc2 = __type_codes[type2]

if tc1 < tc2:
return type2, min(prec1, prec2)
if tc1 > tc2:
return type1, min(prec1, prec2)

raise RuntimeError("Something went wrong") # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

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

can drop these down some tabs, the if loops end with returns

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I flattened the else block.

@coquelin77
Copy link
Member

will merge once tests finish

@coquelin77 coquelin77 merged commit dcebadc into master May 28, 2021
@coquelin77 coquelin77 deleted the feature/713-result-type branch May 28, 2021 12:10
@ClaudiaComito ClaudiaComito linked an issue Jun 1, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request local operator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement result_type Implement result_type
2 participants