114114 "prod" ,
115115 "proj" ,
116116 "real" ,
117+ "real_if_close" ,
117118 "remainder" ,
118119 "rint" ,
119120 "round" ,
@@ -505,6 +506,10 @@ def _process_ediff1d_args(arg, arg_name, ary_dtype, ary_sycl_queue, usm_type):
505506:obj:`dpnp.arctan2` : Element-wise arc tangent of `x1/x2` choosing the quadrant correctly.
506507:obj:`dpnp.arctan` : Trigonometric inverse tangent, element-wise.
507508:obj:`dpnp.absolute` : Calculate the absolute value element-wise.
509+ :obj:`dpnp.real` : Return the real part of the complex argument.
510+ :obj:`dpnp.imag` : Return the imaginary part of the complex argument.
511+ :obj:`dpnp.real_if_close` : Return the real part of the input is complex
512+ with all imaginary parts close to zero.
508513
509514Examples
510515--------
@@ -2201,6 +2206,9 @@ def gradient(f, *varargs, axis=None, edge_order=1):
22012206See Also
22022207--------
22032208:obj:`dpnp.real` : Return the real part of the complex argument.
2209+ :obj:`dpnp.angle` : Return the angle of the complex argument.
2210+ :obj:`dpnp.real_if_close` : Return the real part of the input is complex
2211+ with all imaginary parts close to zero.
22042212:obj:`dpnp.conj` : Return the complex conjugate, element-wise.
22052213:obj:`dpnp.conjugate` : Return the complex conjugate, element-wise.
22062214
@@ -3054,6 +3062,28 @@ def prod(
30543062 the same data type. If the input is a complex floating-point
30553063 data type, the returned array has a floating-point data type
30563064 with the same floating-point precision as complex input.
3065+
3066+ See Also
3067+ --------
3068+ :obj:`dpnp.real_if_close` : Return the real part of the input is complex
3069+ with all imaginary parts close to zero.
3070+ :obj:`dpnp.imag` : Return the imaginary part of the complex argument.
3071+ :obj:`dpnp.angle` : Return the angle of the complex argument.
3072+
3073+ Examples
3074+ --------
3075+ >>> import dpnp as np
3076+ >>> a = np.array([1+2j, 3+4j, 5+6j])
3077+ >>> a.real
3078+ array([1., 3., 5.])
3079+ >>> a.real = 9
3080+ >>> a
3081+ array([9.+2.j, 9.+4.j, 9.+6.j])
3082+ >>> a.real = np.array([9, 8, 7])
3083+ >>> a
3084+ array([9.+2.j, 8.+4.j, 7.+6.j])
3085+ >>> np.real(np.array(1 + 1j))
3086+ array(1.)
30573087"""
30583088
30593089real = DPNPReal (
@@ -3064,6 +3094,69 @@ def prod(
30643094)
30653095
30663096
3097+ def real_if_close (a , tol = 100 ):
3098+ """
3099+ If input is complex with all imaginary parts close to zero, return real
3100+ parts.
3101+
3102+ "Close to zero" is defined as `tol` * (machine epsilon of the type for `a`).
3103+
3104+ For full documentation refer to :obj:`numpy.real_if_close`.
3105+
3106+ Parameters
3107+ ----------
3108+ a : {dpnp.ndarray, usm_ndarray}
3109+ Input array.
3110+ tol : scalar, optional
3111+ Tolerance in machine epsilons for the complex part of the elements in
3112+ the array. If the tolerance is <=1, then the absolute tolerance is used.
3113+ Default: ``100``.
3114+
3115+ Returns
3116+ -------
3117+ out : dpnp.ndarray
3118+ If `a` is real, the type of `a` is used for the output. If `a` has
3119+ complex elements, the returned type is float.
3120+
3121+ See Also
3122+ --------
3123+ :obj:`dpnp.real` : Return the real part of the complex argument.
3124+ :obj:`dpnp.imag` : Return the imaginary part of the complex argument.
3125+ :obj:`dpnp.angle` : Return the angle of the complex argument.
3126+
3127+ Examples
3128+ --------
3129+ >>> import dpnp as np
3130+ >>> np.finfo(np.float64).eps
3131+ 2.220446049250313e-16 # may vary
3132+
3133+ >>> a = np.array([2.1 + 4e-14j, 5.2 + 3e-15j])
3134+ >>> np.real_if_close(a, tol=1000)
3135+ array([2.1, 5.2])
3136+
3137+ >>> a = np.array([2.1 + 4e-13j, 5.2 + 3e-15j])
3138+ >>> np.real_if_close(a, tol=1000)
3139+ array([2.1+4.e-13j, 5.2+3.e-15j])
3140+
3141+ """
3142+
3143+ dpnp .check_supported_arrays_type (a )
3144+
3145+ if not dpnp .issubdtype (a .dtype , dpnp .complexfloating ):
3146+ return a
3147+
3148+ if not dpnp .isscalar (tol ):
3149+ raise TypeError (f"Tolerance must be a scalar, but got { type (tol )} " )
3150+
3151+ if tol > 1 :
3152+ f = dpnp .finfo (a .dtype .type )
3153+ tol = f .eps * tol
3154+
3155+ if dpnp .all (dpnp .abs (a .imag ) < tol ):
3156+ return a .real
3157+ return a
3158+
3159+
30673160_REMAINDER_DOCSTRING = """
30683161Calculates the remainder of division for each element `x1_i` of the input array
30693162`x1` with the respective element `x2_i` of the input array `x2`.
0 commit comments