0Pricing
Mojo Academy · درس

التحقق من الصحة العددية

تحقق من النتائج بمقارنتها بمرجع

التحقق من الصحة العددية درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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. ✅

الأسئلة الشائعة

هل درس «التحقق من الصحة العددية» مجاني؟

نعم — نص درس «التحقق من الصحة العددية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «التحقق من الصحة العددية»؟

تحقق من النتائج بمقارنتها بمرجع تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «التحقق من الصحة العددية»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. نمذجة موتر في Mojo
  2. بناء Matmul خطوة بخطوة
  3. تحسين الجداء الداخلي
  4. التحقق من الصحة العددية
← العودة إلى Mojo Academy