// autodiff_test.sy — Test automatic differentiation in Scyla.
// Reverse-mode AD: the foundation of neural network training.
// Aislinn McCubbins, April 2026

fn main() {
    println("=== Scyla Autodiff Test ===")

    // Start recording the computation graph
    begin_tape()

    // Create weights and register them as trainable parameters
    let w = ones(2, 2)
    let w = register_param("w", w)

    // Create input
    let x = ones(2, 2)

    // Forward pass: y = relu(x @ w)
    let h = t_matmul(x, w)
    println("h = x @ w:")
    println(h)

    let y = t_relu(h)
    println("y = relu(h):")
    println(y)

    // "Loss" = sum of output (simplest possible loss)
    let loss = t_softmax(y)
    println("loss = softmax(y):")
    println(loss)

    // Stop recording
    end_tape()

    // Backward pass — compute gradients!
    backward(loss)
    println("Backward pass complete!")

    // Get gradient of loss w.r.t. weights
    let grad_w = get_grad("w")
    println("Gradient of loss w.r.t. w:")
    println(grad_w)

    println("=== Autodiff operational! ===")
}
