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

Added function eigvals #8945

Merged
merged 10 commits into from
Jan 2, 2023
Merged

Added function eigvals #8945

merged 10 commits into from
Jan 2, 2023

Conversation

hyadav2k
Copy link
Contributor

Close #8806

@ivy-leaves ivy-leaves added Array API Conform to the Array API Standard, created by The Consortium for Python Data API Standards Ivy API Experimental Run CI for testing API experimental/New feature or request Ivy Functional API labels Dec 20, 2022
Copy link
Contributor

@kurshakuz kurshakuz left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@hyadav2k
Copy link
Contributor Author

Hey @kurshakuz, I have resolved the lint errors arising due to my changes.
There is one issue I am facing, the eig for container is not working in my local even though the master is up to date with origin.

        >>> x = ivy.array([[1,2], [3,4]])
        >>> c = ivy.Container({'x':{'xx':x}})
        >>> c.eig()

The o/p is

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.3\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Users\harsh\ivy\ivy\container\linear_algebra.py", line 643, in eig
    return self.static_eig(
           ^^^^^^^^^^^^^^^^
TypeError: ContainerWithLinearAlgebraExperimental.static_eig() got an unexpected keyword argument 'out'

eigvals is also facing the same issue.
Kindly look into it. Thanks.

@kurshakuz
Copy link
Contributor

@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 eig() method, so I will for now suggest to focus on implementing the eigvals(). The only thing I would ask you is to report this issue in the discord if you can.

Can you then show me the output of the test_eigvals test? If it passes all of them, then it is good to go!

@hyadav2k
Copy link
Contributor Author

hyadav2k commented Jan 2, 2023

The only thing I would ask you is to report this issue in the discord if you can.

Sure, I have reported it in discord.

Can you then show me the output of the test_eigvals test? If it passes all of them, then it is good to go!

Sure, I ran pytest test_linalg.py::test_eigvals. It passed all the tests.

========================================================================================== test session starts ==========================================================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0
rootdir: /workspaces/ivy
plugins: metadata-2.0.4, typeguard-2.13.3, json-report-1.5.0, hypothesis-6.55.0
collected 4 items                                                                                                                                                                                       

test_linalg.py ....                                                                                                                                                                               [100%]

=========================================================================================== warnings summary ============================================================================================
../../../../../../../usr/local/lib/python3.8/dist-packages/flatbuffers/compat.py:19
  /usr/local/lib/python3.8/dist-packages/flatbuffers/compat.py:19: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================ 4 passed, 1 warning in 74.76s (0:01:14) ================================================================================

@kurshakuz, kindly review the latest commit. Thanks.

Copy link
Contributor

@kurshakuz kurshakuz left a 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],
Copy link
Contributor

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

Copy link
Contributor Author

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],
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@kurshakuz kurshakuz left a 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! 🙂

@kurshakuz kurshakuz merged commit ca18133 into ivy-llc:master Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Array API Conform to the Array API Standard, created by The Consortium for Python Data API Standards Ivy API Experimental Run CI for testing API experimental/New feature or request Ivy Functional API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eigvals
3 participants