ivy icon indicating copy to clipboard operation
ivy copied to clipboard

Developed the Complex function in tensor_functions

Open affan-sid opened this issue 2 years ago • 4 comments

affan-sid avatar Oct 21 '22 15:10 affan-sid

Thanks for the response. To implement the is_complex() function, can I use built in functions from the PyTorch Library?

On Fri, 21 Oct 2022 at 21:35, James Keane @.***> wrote:

@.**** requested changes on this pull request.

Hey, can you please reference which issue this tackles. You also would need to write a test for this function.

In ivy/functional/frontends/torch/tensor_functions.py https://github.com/unifyai/ivy/pull/5982#discussion_r1001985581:

@@ -14,8 +15,8 @@ def is_tensor(obj):

def is_storage(obj):

return ivy.is_storage(obj)

-# def is_complex(obj): -# return ivy.is_complex(obj) +def is_complex(obj):

  • return Tensor(ivy.is_complex(obj))
    

Ivy doesn't have is_complex in its api. You would need to make an implementation here using some of the Ivy Functions currently implemented

— Reply to this email directly, view it on GitHub https://github.com/unifyai/ivy/pull/5982#pullrequestreview-1151249348, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3XV6EXZPXXA2U5EIDZGJHTWELA3ZANCNFSM6AAAAAARLIEZXA . You are receiving this because you authored the thread.Message ID: @.***>

affan-sid avatar Oct 22 '22 05:10 affan-sid

No unfortunately, in order to wrap the function in Ivy code, we need to use functions that belong to Ivy. You can read up about Ivy frontends here :)

iamjameskeane avatar Oct 22 '22 09:10 iamjameskeane

Thanks again for the feedback. I have made the required changes, can you please check it now?

On Mon, 24 Oct 2022 at 23:58, James Keane @.***> wrote:

@.**** requested changes on this pull request.

Hey, some changes needed but its getting there!

In ivy/functional/frontends/torch/tensor_functions.py https://github.com/unifyai/ivy/pull/5982#discussion_r1003647393:

@@ -1,4 +1,5 @@

local

+from numpy import complex128, complex192, complex64

I don't think using numpy dtypes makes sense for a tensorflow frontend?

In ivy/functional/frontends/torch/tensor_functions.py https://github.com/unifyai/ivy/pull/5982#discussion_r1003648179:

@@ -14,8 +15,9 @@ def is_tensor(obj):

def is_storage(obj):

return ivy.is_storage(obj)

-# def is_complex(obj): -# return ivy.is_complex(obj) +def is_complex(obj):

  • if ivy.dtype(obj) == complex64 or ivy.dtype(obj) == complex128 or ivy.dtype(obj) == complex192:

I would actually cast to an Ivy.array here and then compare using Ivy dtypes. That would make the most sense, then return boolean value if it is complex or not :)

In ivy/functional/frontends/torch/tensor_functions.py https://github.com/unifyai/ivy/pull/5982#discussion_r1003649011:

@@ -43,4 +45,4 @@ def is_nonzero(input): 1, message="bool value of tensor with more than one or no values is ambiguous", )

  • return Tensor(ivy.nonzero(input)[0].size != 0)
  • return Tensor(ivy.nonzero(input)[0].size != 0)

Seems to be that you dont have a precommit hook installed, you can read up about that here https://lets-unify.ai/ivy/contributing/setting_up.html#pre-commit

In ivy_tests/test_ivy/test_frontends/test_torch/test_tensor_functions.py https://github.com/unifyai/ivy/pull/5982#discussion_r1003649822:

  • dtype_and_x,
  • as_variable,
  • num_positional_args,
  • native_array, +):
  • input_dtype, x = dtype_and_x
  • helpers.test_frontend_function(
  •    input_dtypes=input_dtype,
    
  •    as_variable_flags=as_variable,
    
  •    with_out=False,
    
  •    num_positional_args=num_positional_args,
    
  •    native_array_flags=native_array,
    
  •    frontend="torch",
    
  •    fn_tree="is_complex",
    
  •    obj=x[0],
    
  • )

Having three line breaks here would cause a lint error here

— Reply to this email directly, view it on GitHub https://github.com/unifyai/ivy/pull/5982#pullrequestreview-1153620950, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3XV6EQ2GH4I4327BOKZUODWE3L7DANCNFSM6AAAAAARLIEZXA . You are receiving this because you authored the thread.Message ID: @.***>

affan-sid avatar Oct 27 '22 15:10 affan-sid

Seems that tests didn't run, on your last commit. Once they are done running Ill drop a review :)

iamjameskeane avatar Oct 31 '22 17:10 iamjameskeane

This PR has been labelled as stale because it has been inactive for more than 7 days. If you would like to continue working on this PR, then please add another comment or this PR will be closed in 7 days.

ivy-seed avatar Dec 05 '22 06:12 ivy-seed

This PR has been closed because it has been marked as stale for more than 7 days with no activity.

ivy-seed avatar Dec 12 '22 06:12 ivy-seed