Appendix B: Practice Quiz¶
Use these questions as retrieval practice. Work each numerical answer on paper before opening the explanation; the point is to reconstruct the invariant, not recognize a phrase.
Foundations¶
These questions check Mojo 1.0 syntax, ownership, shape, and layout.
- Which keyword declares all functions in Mojo 1.0?
- Why must a GPU kernel length argument use
Int32or another fixed-width type instead ofInt? - What are the row-major strides for shape
[2,3,4]? - What flat offset corresponds to coordinate
[1,2,3]for those strides? - What stride represents a broadcast axis that rereads one physical value?
Answers
def.- Host and device platform-sized integers may have different widths; a fixed width makes the ABI unambiguous.
[12,4,1].1×12+2×4+3=23.- Zero.
Autograd¶
These questions check graph identity, reverse traversal, and gradient accumulation.
- For
w=x*y+xatx=3,y=4, what aredw/dxanddw/dy? - Why does the tape store value IDs instead of copied tensor values inside nodes?
- Why must gradient updates use
+=rather than assignment? - Can the first-order tape in Chapters 6–8 compute second derivatives as written?
Answers
dw/dx=y+1=5;dw/dy=x=3.- Repeated uses then route to one value and one gradient slot, independent of copying or pointer aliasing.
- A value can reach the loss along multiple paths; the multivariable chain rule sums their contributions.
- No. Backward operations must themselves be recorded, or the framework needs forward-over-reverse support.
Numerics and performance¶
These questions check stable reductions, launch geometry, and benchmark interpretation.
- How many 256-thread blocks cover 1,000 elements, and how many threads take the tail guard?
- A length-10 loop uses SIMD width 4. How many elements are vectorized and how many are scalar tail work?
- Why is
mean(x²)-mean(x)²risky for variance? - Why is unsynchronized host enqueue time not a GPU kernel benchmark?
Answers
- Four blocks launch 1,024 threads; 24 are outside the logical range.
- Eight vectorized elements and two tail elements.
- Subtracting two large, nearly equal values can lose the small variance to cancellation; Welford's algorithm is more stable.
- Enqueue is asynchronous and may finish long before device work completes; time device events or synchronized boundaries.
Finance¶
These questions check signs, units, and independent financial calculations.
- A continuously compounded zero has price
P=F·exp(-yT). What isdP/dy? - If price is 90.48 and maturity is 2 years, what is positive DV01 approximately?
- Why is calibrated spread sensitivity to market price negative?
- What information must accompany a Monte Carlo price?
Answers
-T·P.T·P×10⁻⁴=2×90.48×0.0001≈$0.01810.- Higher price requires less discounting, hence a lower spread.
- At minimum: path count, seed/stream policy, estimator, standard error or confidence interval, model parameters, and implementation version.