0Pricing
Mojo Academy · Lektion

Numerische Korrektheit überprüfen

Vergleichen Sie Ergebnisse mit einer Referenz.

Numerische Korrektheit überprüfen ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Fast but Wrong Is Useless

An optimized kernel only counts if it computes the right answer. Always verify before you trust a speedup.

Keep a Reference

Hold on to the simple, obviously correct version. It is your reference, the source of truth every fast kernel must match.

Floats Are Not Exact

Floating-point math rounds, so reordering sums can shift the last digits. Optimized results may differ slightly without being wrong.

Avoid Exact Equality

Because of rounding, never compare floats with ==. Tiny differences will make correct code look broken.

if fast == ref:  # fragile, avoid

Compare With a Tolerance

Instead, check that values are close within a small tolerance. If the gap is under epsilon, treat them as equal.

if abs(fast - ref) <= 1e-5:
    pass  # close enough

Absolute vs Relative Error

Absolute error is the raw gap; relative error scales it by magnitude. Big numbers need relative checks to stay fair.

rel = abs(fast - ref) / abs(ref)

Check Every Element

Loop over the whole result and test each cell. One mismatch beyond tolerance means the optimization broke something.

for i in range(n):
    if abs(fast[i] - ref[i]) > tol:
        print("mismatch at", i)

Track the Worst Gap

Record the largest difference you see. The max error across all elements is a clear, single health number for the kernel.

Test the Edge Cases

Try empty inputs, a single element, and odd sizes that do not divide evenly by the SIMD width. Edges expose tail bugs fast.

Use Known Answers

Multiply by the identity matrix or sum a vector of ones. Predictable inputs give answers you can verify by hand.

Automate the Check

Wrap verification in a small test that fails loudly on any mismatch. Run it after every change so regressions never slip by.

Quick Check

Your SIMD matmul is off from the reference by 0.0000007. What should you conclude?

Recap

Verify fast code against a trusted reference, compare with a tolerance not ==, check edges and known answers, and automate it. ✅

Häufig gestellte Fragen

Ist die Lektion „Numerische Korrektheit überprüfen“ kostenlos?

Ja — der vollständige Text von „Numerische Korrektheit überprüfen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Numerische Korrektheit überprüfen“?

Vergleichen Sie Ergebnisse mit einer Referenz. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Numerische Korrektheit überprüfen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Einen Tensor in Mojo modellieren
  2. Matmul Schritt für Schritt erstellen
  3. Das Skalarprodukt optimieren
  4. Numerische Korrektheit überprüfen
← Zurück zu Mojo Academy