The role of the calling object (self) in MtxVec operations follows three simple rules:
Rule 1: Transform operations — self is the DESTINATION
self.Sin(X)→ reads from X, stores result in selfself.AddAndMul(X, Y, Z)→ computes (X+Y)*Z, stores in self- Parameters named X, Y, Z, Vec1, Vec2, Src, Source are inputs
- Summary pattern: "Compute ... " or "Calculate ... and store the results in calling object"
Rule 2: Scalar-returning methods — self is the SOURCE
result = self.Sum()→ reads from self, returns scalarresult = self.StdDev()→ reads from self, returns scalar- Methods: Sum, Min, Max, Norm, NormL1, NormL2, StdDev, Product, Mean, Variance
- These never modify self.
Rule 3: In-place operations — self is BOTH source and destination
self.Sin()→ reads from self, stores result back in self (no arguments)self.Abs()→ in-place absolute value- Pattern: 0-argument form of a transform method.
Formula convention: When a summary contains a formula like "Compute (X + Y)*Z", the named variables (X, Y, Z) are the source parameters; self receives the result.
Quick reference:
| Form | Self role | Example |
|---|---|---|
self.Op(X) | Destination | self.Sin(X) — self = sin(X) |
self.Op(X, Y) | Destination | self.Add(X, Y) — self = X + Y |
self.Op() | Both (in-place) | self.Sin() — self = sin(self) |
val = self.Op() | Source | val = self.Sum() — returns sum of self |