@@ -553,6 +553,60 @@ def pad(
553553 return _funcs .pad (x , pad_width , constant_values = constant_values , xp = xp )
554554
555555
556+ def setdiff1d (
557+ x1 : Array | complex ,
558+ x2 : Array | complex ,
559+ / ,
560+ * ,
561+ assume_unique : bool = False ,
562+ xp : ModuleType | None = None ,
563+ ) -> Array :
564+ """
565+ Find the set difference of two arrays.
566+
567+ Return the unique values in `x1` that are not in `x2`.
568+
569+ Parameters
570+ ----------
571+ x1 : array | int | float | complex | bool
572+ Input array.
573+ x2 : array
574+ Input comparison array.
575+ assume_unique : bool
576+ If ``True``, the input arrays are both assumed to be unique, which
577+ can speed up the calculation. Default is ``False``.
578+ xp : array_namespace, optional
579+ The standard-compatible namespace for `x1` and `x2`. Default: infer.
580+
581+ Returns
582+ -------
583+ array
584+ 1D array of values in `x1` that are not in `x2`. The result
585+ is sorted when `assume_unique` is ``False``, but otherwise only sorted
586+ if the input is sorted.
587+
588+ Examples
589+ --------
590+ >>> import array_api_strict as xp
591+ >>> import array_api_extra as xpx
592+
593+ >>> x1 = xp.asarray([1, 2, 3, 2, 4, 1])
594+ >>> x2 = xp.asarray([3, 4, 5, 6])
595+ >>> xpx.setdiff1d(x1, x2, xp=xp)
596+ Array([1, 2], dtype=array_api_strict.int64)
597+ """
598+
599+ if xp is None :
600+ xp = array_namespace (x1 , x2 )
601+
602+ if is_numpy_namespace (xp ) or is_cupy_namespace (xp ) or is_jax_namespace (xp ):
603+ # https://github.com/microsoft/pyright/issues/10103
604+ x1_ , x2_ = asarrays (x1 , x2 , xp = xp )
605+ return xp .setdiff1d (x1_ , x2_ , assume_unique = assume_unique )
606+
607+ return _funcs .setdiff1d (x1 , x2 , assume_unique = assume_unique , xp = xp )
608+
609+
556610def sinc (x : Array , / , * , xp : ModuleType | None = None ) -> Array :
557611 r"""
558612 Return the normalized sinc function.
0 commit comments