-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Added function eigvals #8945
Added function eigvals #8945
Conversation
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.
Hey! Thank you for your contribution! I have left a couple of comments here to understand the context better. For now implementation is looking good to me, but I will run tests later. Can you please for now answer to my comments and fix the lint errrors? Thanks!
@@ -102,4 +102,9 @@ def matrix_exp( | |||
|
|||
|
|||
def eig(x: JaxArray, /) -> Tuple[JaxArray]: | |||
return jnp.linalg.eig(x) | |||
w, v = jnp.linalg.eig(x) | |||
return w, v |
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.
You don't need to change other functions in this PR
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.
Sure, it was throwing merge conflicts that's why I changed it. I will undo the changes. Thanks for reviewing.
@@ -108,3 +108,10 @@ def eig(x: np.ndarray, /) -> Tuple[np.ndarray]: | |||
|
|||
|
|||
eig.support_native_out = False | |||
|
|||
|
|||
def eivalsg(x: np.ndarray, /) -> np.ndarray: |
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.
Can you please let me know what is eivalsg
function here? What is the difference from eivals
?
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.
It is a typo. Thanks for pointing out. Will fix it.
ret = torch.linalg.eig(x.to(torch.complex128)) | ||
else: | ||
ret = torch.linalg.eig(x) | ||
return tuple(ret) |
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.
Was the original function implementation throwing errors before your fix? Maybe we can split this PR into two. In the first you implement eigvals and in the other one you fix eig implementation?
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.
Maybe this was old implementation, that is why I did so. I will try to undo the changes and check once, how it goes. Thanks
Hey @kurshakuz, I have resolved the lint errors arising due to my changes. >>> x = ivy.array([[1,2], [3,4]])
>>> c = ivy.Container({'x':{'xx':x}})
>>> c.eig() The o/p is
eigvals is also facing the same issue. |
@hyadav2k hey! I have also checked this code snippet and it fails due to the same error. I see that your PR does not depend on Can you then show me the output of the |
Sure, I have reported it in discord.
Sure, I ran
@kurshakuz, kindly review the latest commit. Thanks. |
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.
Hey! I have tested your implementation locally and it passing the test. The only thing I think you would need to change is return the tf.Tensor as the only input type to the eig
method and remove it from the eigvals
as it is stated in the TF documentation. Otherwise LGTM
@@ -59,9 +59,18 @@ def matrix_exp( | |||
|
|||
|
|||
def eig( | |||
x: Union[tf.Tensor], | |||
x: Union[tf.Tensor, tf.Variable], |
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 don't think you need to change this line, as eig
only expects Tensor as input as stated here: https://www.tensorflow.org/api_docs/python/tf/linalg/eig
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.
Thanks for reviewing, I made the necessary changes.
|
||
|
||
def eigvals( | ||
x: Union[tf.Tensor, tf.Variable], |
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.
Similarly here: https://www.tensorflow.org/api_docs/python/tf/linalg/eigvals
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.
LGTM! Thank you for your contribution! 🙂
Close #8806