GitHub

Original file line numberDiff line numberDiff line change

@@ -645,20 +645,15 @@ efficient machine code that varies with both task size and hardware.

645645

We saw the power of JAX's JIT compiler combined with parallel hardware when we

646646

{ref}`above <jax_speed>`, when we applied `cos` to a large array.

647647
648-

Let's try the same thing with a more complex function.

649-
650-
651-

### Evaluating a more complicated function

652-
653-

Consider the function

648+

Let's try the same thing with a more complex function:

654649
655650

```{code-cell}

656651

def f(x):

657652

y = np.cos(2 * x**2) + np.sqrt(np.abs(x)) + 2 * np.sin(x**4) - x**2

658653

return y

659654

```

660655
661-

#### With NumPy

656+

### With NumPy

662657
663658

We'll try first with NumPy

664659

@@ -675,7 +670,7 @@ with qe.Timer():

675670
676671
677672
678-

#### With JAX

673+

### With JAX

679674
680675

Now let's try again with JAX.

681676

@@ -712,10 +707,10 @@ The outcome is similar to the `cos` example --- JAX is faster, especially on the

712707

second run after JIT compilation.

713708
714709

However, with JAX, we have another trick up our sleeve --- we can JIT-compile

715-

the *entire* function, not just individual operations.

710+

the entire function, not just individual operations.

716711
717712
718-

### Compiling the whole function

713+

### Compiling the Whole Function

719714
720715

The JAX just-in-time (JIT) compiler can accelerate execution within functions by fusing array

721716

operations into a single optimized kernel.

Read the original on github.com ↗