ivy icon indicating copy to clipboard operation
ivy copied to clipboard

added frontend jax numpy namespace function sum

Open Nunyapa opened this issue 2 years ago • 1 comments

Close https://github.com/unifyai/ivy/issues/6317

Nunyapa avatar Nov 05 '22 03:11 Nunyapa

Hey:) Got some problem with implementation promote_integers argument for the sum function. How is better to implement it?

Nunyapa avatar Nov 05 '22 04:11 Nunyapa

Excerpt from Jax _reduction source:

if dtype is None and promote_integers:
    # Note: NumPy always promotes to 64-bit; jax instead promotes to the
    # default dtype as defined by dtypes.int_ or dtypes.uint.
    if dtypes.issubdtype(result_dtype, np.bool_):
      result_dtype = dtypes.int_
    elif dtypes.issubdtype(result_dtype, np.unsignedinteger):
      if np.iinfo(result_dtype).bits < np.iinfo(dtypes.uint).bits:
        result_dtype = dtypes.uint
    elif dtypes.issubdtype(result_dtype, np.integer):
      if np.iinfo(result_dtype).bits < np.iinfo(dtypes.int_).bits:
        result_dtype = dtypes.int_

dtypes.int_ will normally be a int64 and dtypes.uint is a uint64 but you should check what is available during function call.

Ivy has types listed under ivy/__init__.py that you can use to implement the type comparison logic.

Nightcrab avatar Nov 08 '22 22:11 Nightcrab

Hello:) I've implemented the argument with your help. Thank you so much! Could you please have a look?

Nunyapa avatar Nov 09 '22 12:11 Nunyapa

Looks good to me, just needs a merge.

Nightcrab avatar Nov 10 '22 23:11 Nightcrab

@Nightcrab Thank you:) Should we ping someone?

Nunyapa avatar Nov 11 '22 02:11 Nunyapa

No need, I'm able to merge the PR into ivy as long as there aren't conflicts.

Nightcrab avatar Nov 13 '22 21:11 Nightcrab

@Nightcrab Done

Nunyapa avatar Nov 14 '22 00:11 Nunyapa