@@ -416,6 +416,58 @@ def pad(
416416 return _funcs .pad (x , pad_width , constant_values = constant_values , xp = xp )
417417
418418
419+ def setdiff1d (
420+ x1 : Array | complex ,
421+ x2 : Array | complex ,
422+ / ,
423+ * ,
424+ assume_unique : bool = False ,
425+ xp : ModuleType | None = None ,
426+ ) -> Array :
427+ """
428+ Find the set difference of two arrays.
429+
430+ Return the unique values in `x1` that are not in `x2`.
431+
432+ Parameters
433+ ----------
434+ x1 : array | int | float | complex | bool
435+ Input array.
436+ x2 : array
437+ Input comparison array.
438+ assume_unique : bool
439+ If ``True``, the input arrays are both assumed to be unique, which
440+ can speed up the calculation. Default is ``False``.
441+ xp : array_namespace, optional
442+ The standard-compatible namespace for `x1` and `x2`. Default: infer.
443+
444+ Returns
445+ -------
446+ array
447+ 1D array of values in `x1` that are not in `x2`. The result
448+ is sorted when `assume_unique` is ``False``, but otherwise only sorted
449+ if the input is sorted.
450+
451+ Examples
452+ --------
453+ >>> import array_api_strict as xp
454+ >>> import array_api_extra as xpx
455+
456+ >>> x1 = xp.asarray([1, 2, 3, 2, 4, 1])
457+ >>> x2 = xp.asarray([3, 4, 5, 6])
458+ >>> xpx.setdiff1d(x1, x2, xp=xp)
459+ Array([1, 2], dtype=array_api_strict.int64)
460+ """
461+
462+ if xp is None :
463+ xp = array_namespace (x1 , x2 )
464+
465+ if is_numpy_namespace (xp ) or is_jax_namespace (xp ) or is_cupy_namespace (xp ):
466+ return xp .setdiff1d (x1 , x2 , assume_unique = assume_unique )
467+
468+ return _funcs .setdiff1d (x1 , x2 , assume_unique = assume_unique , xp = xp )
469+
470+
419471def sinc (x : Array , / , * , xp : ModuleType | None = None ) -> Array :
420472 r"""
421473 Return the normalized sinc function.
0 commit comments