Repository: scipy/scipy
File: benchmarks/benchmarks/common.py (Python)

Code before:
            skips = {n for n, _ in capabilities["skip_backends"]}
            skips |= {n for n, _ in capabilities["xfail_backends"]}
            if (((capabilities["cpu_only"] and device != "cpu")
                 or (capabilities["np_only"] and backend != "numpy"))
                and backend not in capabilities["exceptions"]):
                skips.add(backend)
            if backend in skips:
                raise SkipNotImplemented(f"{backend} skipped by @xp_capabilities")
        else:
            capabilities = {"jax_jit": False}

        # Potentially wrap namespace with array_api_compat
        xp = array_namespace(xp.empty(0))

        self.xp = xp
        self.func = func
        self.warmup = False

        if backend == "torch":
            import torch

            torch.set_default_dtype(torch.float64)
            try:
                torch.empty(0, device=device)
            except RuntimeError:
                raise SkipNotImplemented(f"{device=} not available")
            torch.set_default_device(device)

            if device == "cuda":
                def wrapper(*args, **kwargs):
                    res = func(*args, **kwargs)
                    torch.cuda.synchronize()
                    return res

                self.func = wrapper

        elif backend == "jax.numpy":
            import jax

            jax.config.update("jax_enable_x64", True)
            try:
                jax_device = jax.devices(device)[0]
            except RuntimeError:
                raise SkipNotImplemented(f"{device=} not available")
            jax.config.update("jax_default_device", jax_device)

            if capabilities["jax_jit"]:
                func = jax.jit(func, static_argnames=static_argnames,
                               static_argnums=static_argnums)
                self.warmup = True


Review comment (suggestion):
This is needed for me when running in the array-api pixi env on M1 mac

```suggestion
            try:
                torch.empty(0, device=device)
            except (RuntimeError, AssertionError):
                raise SkipNotImplemented(f"{device=} not available")
```

Code after:
            raise SkipNotImplemented(
                f"{backend} not available or skipped by SCIPY_ARRAY_API")

        if func and func in xp_capabilities_table:
            capabilities = xp_capabilities_table[func]
            skips = {n for n, _ in capabilities["skip_backends"]}
            skips |= {n for n, _ in capabilities["xfail_backends"]}
            if (((capabilities["cpu_only"] and device != "cpu")
                 or (capabilities["np_only"] and backend != "numpy"))
                and backend not in capabilities["exceptions"]):
                skips.add(backend)
            if backend in skips:
                raise SkipNotImplemented(f"{backend} skipped by @xp_capabilities")
        else:
            capabilities = {"jax_jit": False}

        # Potentially wrap namespace with array_api_compat
        xp = array_namespace(xp.empty(0))

        self.xp = xp
        self.func = func
        self.warmup = False

        if backend == "torch":
            import torch

            torch.set_default_dtype(torch.float64)
            try:
                torch.empty(0, device=device)
            except (RuntimeError, AssertionError):
                raise SkipNotImplemented(f"{device=} not available")
            torch.set_default_device(device)

            if device == "cuda":
                def wrapper(*args, **kwargs):
                    res = func(*args, **kwargs)
                    torch.cuda.synchronize()
                    return res

                self.func = wrapper

        elif backend == "jax.numpy":
            import jax

            jax.config.update("jax_enable_x64", True)
            try:
                jax_device = jax.devices(device)[0]
            except RuntimeError:
                raise SkipNotImplemented(f"{device=} not available")
            jax.config.update("jax_default_device", jax_device)