0Pricing
Mojo Academy · Lektion

Elementweise SIMD-Mathematik

Addieren und multiplizieren Sie ganze Vektoren auf einmal.

Elementweise SIMD-Mathematik ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 2 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.

Math on Whole Vectors

The best part of SIMD is that arithmetic works on the entire vector at once. One operation touches every lane together.

Adding Two Vectors

Add two SIMD values and each lane is added to its matching lane. This is called element-wise addition.

var a = SIMD[DType.int32, 4](1, 2, 3, 4)
var b = SIMD[DType.int32, 4](10, 20, 30, 40)
var c = a + b

Lane Lines Up with Lane

In a + b, lane 0 adds to lane 0 and lane 1 adds to lane 1. The lanes never mix, they stay aligned.

print(c[0])

Multiplying Vectors

Multiplication is element-wise too. Each lane of one vector is multiplied by the same lane of the other vector.

var p = a * b

Subtract and Divide

Subtraction and division follow the same rule. Every lane is handled independently and in parallel across the pack.

var d = b - a

Scalar Meets Vector

Add a single number to a vector and Mojo applies it to every lane. The scalar spreads across all positions at once.

var bumped = a + 100

Widths Must Match

To combine two SIMD values they need the same DType and the same width. Mismatched lane counts will not line up.

Comparisons Go Lane by Lane

Comparing two vectors gives a SIMD of Bools, one True or False per lane. Each lane reports its own result.

var mask = a > SIMD[DType.int32, 4](2)

Reducing to One Number

Sometimes you want a single answer. reduce_add sums all lanes into one scalar, perfect for totals.

var total = a.reduce_add()
print(total)

Built-in Math Functions

Standard math like sqrt also works lane-wise on SIMD, computing the result for every element in one call.

from math import sqrt
var roots = sqrt(a.cast[DType.float32]())

Same Code, Many Results

Writing a + b looks like scalar math but produces many results at once. That readability with speed is Mojo's promise.

Quick Check

You compute a + b where both are SIMD[DType.int32, 4]. How is the addition done?

Recap

Element-wise SIMD math runs +, -, *, and / on every lane at once, scalars spread to all lanes, and reduce_add folds a vector into one number. ✨

Häufig gestellte Fragen

Ist die Lektion „Elementweise SIMD-Mathematik“ kostenlos?

Ja — der vollständige Text von „Elementweise SIMD-Mathematik“ 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 „Elementweise SIMD-Mathematik“?

Addieren und multiplizieren Sie ganze Vektoren auf einmal. 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 2 von 4.

Wie lange dauert die Lektion „Elementweise SIMD-Mathematik“?

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. Der SIMD-Typ
  2. Elementweise SIMD-Mathematik
  3. Die passende SIMD-Breite wählen
  4. Eine Schleife vektorisieren
← Zurück zu Mojo Academy