LESSON 47 OF 52 · CHAPTER 06
Matrix Forward
Typed tile input, tileadd, tilescale, matvec, bias, softmax and contracts
06-matrix-forward.srp
pure funcra forward(weights: tile, features: vector, bias: vector) -> vector
needs width(weights) == len(features);
needs height(weights) == len(bias);
ensures len(result) == height(weights);
{
return softmax(add(matvec(weights, features), bias));
}
bind identity = tile([1.0, 0.0, 0.0, 1.0], 2, 2);
bind weights = tileadd(identity, tilescale(identity, 1.0));
print(forward(weights, [1.0, 1.0], [0.0, 0.0]));
stdout
[0.5, 0.5]
Write what you expect this program to print. Check prediction for a line-level hint without revealing the answer, or reveal the verified output when ready. This checks displayed text only; it does not run Scarp or save your input.
UNDERSTAND THE CODE
Explanation & practice
What this example teaches
Typed tile input, tileadd, tilescale, matvec, bias, softmax and contracts
Expected behavior
[0.5, 0.5]
Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.
बायस सहित सरल फ़ॉरवर्ड गणना
pure funcra forward में matvec का परिणाम बायस से जोड़ा जाता है और softmax से सामान्यीकृत किया जाता है। tileadd और tilescale छोटे वेट बनाते हैं। needs और ensures मैट्रिक्स व वेक्टर के आकार की शर्तें जाँचते हैं।
आउटपुट: दो बराबर स्कोरों से [0.5, 0.5] मिलता है। यहाँ कोई मॉडल लोड, GPU संचालन या स्वयं वेट सीखना नहीं होता।
अभ्यास: दोनों अंतिम स्कोर बराबर होने पर softmax में दोनों परिणाम 0.5 क्यों हैं?
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
LEARNING PROGRESS
Keep your place
Mark this lesson complete when you are ready.
Only saved in this browser. No account or tracking.
TRY IT LOCALLY
Verify, then execute
Use the pinned compiler from the course root. Keep any imported _support files next to the source.
scarp verify examples/06-ai-foundations/06-matrix-forward.srp
scarp exec examples/06-ai-foundations/06-matrix-forward.srpThe website does not run code. Read the CLI guide ↗
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.