0Pricing
Mojo Academy · درس

نمذجة موتر في Mojo

الأشكال والخطوات وتخطيط العناصر

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

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

What Is a Tensor?

A tensor is just an n-dimensional grid of numbers. A vector is 1D, a matrix is 2D, and an image batch is often 4D.

Flat Memory Underneath

However many dimensions you imagine, a tensor really lives as one flat buffer of values in memory, laid out end to end.

var data = List[Float32](0, 1, 2, 3, 4, 5)

Shape Describes the Grid

The shape is a tuple of sizes, one per dimension. A shape of (2, 3) means two rows of three columns.

var shape = (2, 3)  # 2 rows, 3 cols

Indices Pick an Element

You name an element with one index per dimension. In a (2, 3) tensor, (1, 2) is the last column of the second row.

Strides Map to Memory

A stride tells you how many flat slots to jump to move one step along a dimension. Strides turn indices into a single offset.

var strides = (3, 1)  # row jump 3, col jump 1

The Offset Formula

Flatten any index by a dot product: offset equals the sum of each index times its stride. That offset reaches the right slot.

offset = i * strides[0] + j * strides[1]

Row-Major Layout

Mojo numeric code usually stores rows contiguously, called row-major. The last dimension has stride 1, so columns sit side by side.

Why Strides Are Powerful

With clever strides you can view, slice, or transpose a tensor without copying data. Only the strides change, not the buffer.

Element Type Matters

Every tensor has a fixed dtype, like Float32 or Int64. A uniform type lets Mojo pack values tightly and compute fast.

alias dtype = DType.float32

A Minimal Tensor Struct

You can model a tensor as a struct that bundles a data pointer with its shape and strides, keeping layout info in one place.

struct Tensor:
    var data: UnsafePointer[Float32]
    var shape: (Int, Int)
    var strides: (Int, Int)

Contiguous vs Strided

A contiguous tensor has no gaps, so a linear scan is cheap. Strided views may skip around, which can slow memory access.

Quick Check

You have a (2, 3) row-major tensor. How do you reach element (1, 2)?

Recap

A tensor is a flat buffer plus shape and strides; the offset formula maps indices to memory, and row-major keeps columns contiguous. 🧮

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

هل درس «نمذجة موتر في Mojo» مجاني؟

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

ماذا ستتعلم في «نمذجة موتر في Mojo»؟

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

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

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

كم من الوقت يستغرق درس «نمذجة موتر في Mojo»؟

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

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

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

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

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