We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Production ML — Training Stack step 11 of 12
Medium
Framework
JIT Compile a Function
Use JIT compilation to optimize a function that computes f(x) = sin(x)^2 + cos(x)^2.
This should always return 1.0 for any input (by the Pythagorean identity), but the goal is to demonstrate JIT compilation, not simplify the math.
Input: A tensor x of any shape.
Output: A tensor of the same shape where every element is 1.0 (within floating-point tolerance).
API Reference:
-
JAX:
jax.jit(fn) -
PyTorch:
torch.compile(fn)(PyTorch 2.0+)Loading visualization…
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.