Maned

Per-axis reductions

Generated by tools/gen_example_pages.py from mnd_scripts/examples/example_axis_reductions.mnd — the output below is a real run, not a transcription. Regenerating the page reruns it.

per-axis reductions (gap_006) - {axis: k} on tensor_sum/mean/max/min. Reducing axis k keeps the rank and sets that dimension to 1: axis 0 of a (2,3) matrix gives (1,3) column results, axis 1 gives (2,1) row results. The bare forms still reduce the whole tensor to a rank-1 [1] value. The ML-campaign idiom this replaces: matmul-against-ones tricks for per-class scores / per-feature stats.

The program#

# ============================================================================
# example_axis_reductions.mnd
# ----------------------------------------------------------------------------
# FUNCTIONALITY: per-axis reductions (gap_006) - `{axis: k}` on
# tensor_sum/mean/max/min. Reducing axis k keeps the rank and sets that
# dimension to 1: axis 0 of a (2,3) matrix gives (1,3) column results,
# axis 1 gives (2,1) row results. The bare forms still reduce the whole
# tensor to a rank-1 [1] value. The ML-campaign idiom this replaces:
# matmul-against-ones tricks for per-class scores / per-feature stats.
#
# NOTE: per-axis reductions dispatch correctly as of IR v3 (gap_060). Between
# gap_009 and gap_060 they did neither: the promised refusal had been removed
# and the worker decode had not landed, so a routed {axis: k} silently
# returned the whole-tensor reduction. A worker advertising "ir": 3 decodes
# the axis; the coordinator refuses to send one to anything older.
#
# RUN: ../maned-run examples/example_axis_reductions.mnd
# ============================================================================
mnd::quantmax=1000;
mnd::quantmin=-1000;
mnd::quantres=0;

in::scores = [[1,2,3],[4,5,6]];

calc::lambda_flow stats(scores) {
    scores {axis: 0} tensor_sum per_class_sum =
    scores {axis: 1} tensor_sum per_row_sum =
    scores {axis: 0} tensor_mean per_class_mean =
    scores {axis: 1} tensor_max per_row_max =
    scores tensor_sum grand_total =
} return per_class_sum, per_row_sum, per_class_mean, per_row_max, grand_total;

The run#

$ maned-run mnd_scripts/examples/example_axis_reductions.mnd
flow 'stats' outputs:
per_class_sum : [1x3] = [5, 7, 9]
per_row_sum : [2x1] = [6, 15]
per_class_mean : [1x3] = [2, 3, 4]
per_row_max : [2x1] = [3, 6]
grand_total : [1] = [21]

Next#

© 2026 Fabiano Dicheti · Found a problem on this page? Open an issue