-
Notifications
You must be signed in to change notification settings - Fork 55
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 arctan2 #593
Feature arctan2 #593
Conversation
Codecov Report
@@ Coverage Diff @@
## master #593 +/- ##
=======================================
Coverage 96.48% 96.49%
=======================================
Files 75 75
Lines 15214 15249 +35
=======================================
+ Hits 14679 14714 +35
Misses 535 535
Continue to review full report at Codecov.
|
heat/core/trigonometrics.py
Outdated
>>> ht.arctan2(y, x) * 180 / ht.pi | ||
tensor([-135.0000, -45.0000, 45.0000, 135.0000], dtype=torch.float64) | ||
""" | ||
# Special Case: integer -> float because torch.atan2() does not work with integer types on version 1.5.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably issued as warning to the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. numpy allows integer types. I rewrote the comment a little bit.
heat/core/trigonometrics.py
Outdated
@@ -99,6 +102,44 @@ def arctan(x, out=None): | |||
return local_op(torch.atan, x, out) | |||
|
|||
|
|||
def arctan2(x1, x2, out=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Charlie updated our docstrings (to be found in branch 504). This function needs
a) a return type annotation
b) DNDarray
should be :class:DNDarray
Also out should be either removed if not used/applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope I found everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, have to be picky in the beginning about the new docstring formats... will add comments for now to every pull request to explain the style
heat/core/trigonometrics.py
Outdated
import torch | ||
from .constants import pi | ||
from .operations import __local_op as local_op | ||
from .operations import __binary_op as binary_op | ||
from . import dndarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be from .dndarray import DNDarray
, then DNDarray
can be annotated directly
heat/core/trigonometrics.py
Outdated
@@ -99,6 +105,32 @@ def arctan(x, out=None): | |||
return local_op(torch.atan, x, out) | |||
|
|||
|
|||
def arctan2(x1, x2) -> dndarray.DNDarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just -> DNDarray
heat/core/trigonometrics.py
Outdated
|
||
Parameters | ||
---------- | ||
x1 : :class:DNDarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, the :class:
is not needed, can be just DNDarray
heat/core/trigonometrics.py
Outdated
def arctan2(x1, x2) -> dndarray.DNDarray: | ||
""" | ||
Element-wise arc tangent of ``x1/x2`` choosing the quadrant correctly. | ||
Returns a new :class:``DNDarray`` with the signed angles in radians between vector (``x2``,``x1``) and vector (1,0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok, DNDarray
will now be displayed in markdown code-style. If you want to create a cross-reference link to the DNDarray class, you must use :class:~heat.core.dndarray.DNDarray
.... with the ~ in front the whole module path will not be displayed in the docs. However, since the returntype is already a link, I don't think this is necessary here, just a note for the future :)
heat/core/trigonometrics.py
Outdated
---------- | ||
x1 : :class:DNDarray | ||
y-coordinates | ||
x2 : :class:DNDarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, :class: not needed
heat/core/trigonometrics.py
Outdated
x1 : :class:DNDarray | ||
y-coordinates | ||
x2 : :class:DNDarray | ||
x-coordinates. If ``x1.shape != x2.shape``, they must be broadcastable to a common shape (which becomes the shape of the output). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Markdown code style, please refrain from using whitespaces around operators (it looks shitty in the docs due to the different font and size)
heat/core/trigonometrics.py
Outdated
x2 : :class:DNDarray | ||
x-coordinates. If ``x1.shape != x2.shape``, they must be broadcastable to a common shape (which becomes the shape of the output). | ||
|
||
Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this :)
Description
Issue/s resolved: #546
This PR adds a arctan2 function to HeAT
Changes proposed:
Type of change
New feature
Due Diligence
Does this change modify the behaviour of other functions? If so, which?
no