العرضar

tensor-shape-generic

Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.

Shape-generic tensor functions: a حجم shape param binds implicitly at call sites.

Syntax: دالة name<T, حجم Figura>(موتر<T, Figura> …) → موتر<T, Figura>

Category#

type

Examples#

radix/corpus/tensor/generic-shape.fab (canonical · concept)#

Shape-generic tensor functions: a حجم shape param binds implicitly at call sites.

# =============================================================================
# tensor-shape-generic — shape-generic موتر functions (حجم Figura)
# =============================================================================
#
# What this teaches:
#   • A `حجم Figura` shape param stands for the whole موتر shape; the
#     shape is rank-agnostic, so one signature covers `[4]`, `[2, 2]`, `[1, 2]`,
#     and `[]` witnesses.
#   • The typechecker binds the shape param implicitly at call sites from the
#     argument shapes or the expected type — no explicit figura arguments.
#   • Fully static bodies compose elementwise ops (`reple`, `multiplica`,
#     `subtrahe`) whose results keep the same shape symbolically.
#
# Common mistakes:
#   • Spelling the shape as a rank-1 tuple `[Figura]` — that only matches
#     rank-1 witnesses; use the bare `Figura` for rank-agnostic shapes.
#   • Expecting a shape param bound by neither arguments nor the expected type
#     to guess: it errors (SEM014) instead.
#
# See also: موتر, حجم, دالة, متجه
# =============================================================================

# One generic `sgd_step` replaces the concrete [4]/[2,2]/[1,2]/[] overloads:
# the param/grad pair shares `Figura`, so every elementwise step proves the
# same-shape result.

دالة sgd_step<حجم Figura>(موتر<f32, Figura> param, موتر<f32, Figura> grad, f32 lr) → موتر<f32, Figura> {
    ثابت موتر<f32, Figura> lr_fill ← param.املأ(lr)
    ثابت موتر<f32, Figura> scaled ← grad.اضرب(lr_fill)
    أعد param.اطرح(scaled)
}

اعرض "shape-generic sgd_step parata"

Expected output:

shape-generic sgd_step parata