Skip to main content

recognize_scatter

Function recognize_scatter 

Source
pub fn recognize_scatter(
    stmts: &[Stmt<'_>],
    interner: &Interner,
) -> Result<ScatterSpec, ScatterReject>
Expand description

Recognize a scatter accumulation anywhere in a LOGOS statement list:

Let mutable r be 0.
While r is less than rows:
    Let label be item (r + 1) of y.
    Let mutable c be 0.
    While c is less than cols:
        If label is 1:
            Set item (c + 1) of sub to item (r * cols + c + 1) of x - item (c + 1) of mu1.
        Otherwise:
            Set item (c + 1) of sub to item (r * cols + c + 1) of x - item (c + 1) of mu0.
        Set c to c + 1.
    Let mutable i be 0.
    While i is less than cols:
        Let mutable j be 0.
        While j is less than cols:
            Let idx be i * cols + j + 1.
            Set item idx of sigma to item idx of sigma + item (i + 1) of sub * item (j + 1) of sub.
            Set j to j + 1.
        Set i to i + 1.
    Set r to r + 1.

Every loop is counted; the row loop writes the scratch row at its counter from reads at the row, the column, or the row-major element; the rank-1 update adds the scratch row’s outer product with itself to a zero-filled C × C matrix; and every body holds nothing else but immutable names.