Kết xuấtvi

tensor

Translation status: Tiếng Việt reader-locale proof. Code fences render through the vi pipeline; prose is canonical Latin.

tensor<T, Figura> declaration shell with rank-0 vacua.

Syntax: tensor<T, Figura> | tensor<T, []>

Category#

collection

Examples#

radix/corpus/tensor/decl.fab (canonical · type)#

tensor<T, Figura> declaration shell with rank-0 vacua.

# =============================================================================
# tensor — tensor<T, Figura> declaration shell with rank-0 vacua.
# =============================================================================
#
# What this teaches:
#   • Tensor declaration — `tensor<T, Figura>` type syntax with `vacua` as the empty initializer
#   • Identity functions — passing tensors through functions preserves shape and rank
#
# Common mistakes:
#   • declaring tensor<T> without a Figura shape parameter — use tensor<T, Figura> with explicit dimensions
#
# See also: tensor, lista
# =============================================================================




# tensor — declaration shell for tensor<T, Figura>
#
# tensor<T, []> name ← vacua
# functio f(tensor<T, []> value) → tensor<T, []>
#
# GRAMMAR:
#   type :← 'tensor' '<' type ',' shape '>'
#
# EXPECTED OUTPUT:
#   Rank-0 tensor longitudo after round-trip identity call.

fn identity(tensor<float<f32>, []> value)  tensor<float<f32>, []> {
    return value
}

main {
    const tensor<float<f32>, []> empty  vacua
    const tensor<float<f32>, []> roundtrip  identity(empty)

    print roundtrip.longitudo()
}

Expected output:

0

radix/corpus/tensor/arithmetic-reject.fab (supporting · reject)#

Tensor arithmetic rejects non-numeric elements and mixed numeric widths.

# =============================================================================
# tensor — Tensor arithmetic rejects non-numeric elements and mixed numeric widths.
# =============================================================================
#
# What this teaches:
#   • Type guard — elementwise arithmetic rejects non-numeric element types at compile time
#   • Width safety — mixed-width operations (e.g. i32 + i64) require explicit `↦` conversion
#
# Common mistakes:
#   • expecting silent numeric widening between numerus<i32> and numerus<i64> — use explicit ↦ conversion instead
#
# See also: tensor, typus, conversio
# =============================================================================



# tensor arithmetic reject cases — expected compile failure
#
# WHY: documents the typecheck contract for elementwise tensor arithmetic.
# Both cases must reject:
#   1. tensor<textus, …> — non-numeric element (numeric gate).
#   2. numerus<i32> + numerus<i64> — mixed width is a ↦ conversio problem,
#      never silent promotion at the kernel.
#
# This exemplum intentionally fails to compile; it is registered in the
# per-backend EXPECTED_FAILURES lists.

main {
    const tensor<string, [2]> words_a  vacua
    const tensor<string, [2]> words_b  vacua
    const tensor<string, [2]> words_sum  words_a.addita(words_b)
    print words_sum.longitudo()

    const tensor<int<i32>, [2]> i32_a  vacua
    const tensor<int<i64>, [2]> i64_b  vacua
    const tensor<int<i32>, [2]> mixed  i32_a.addita(i64_b)
    print mixed.longitudo()
}

Expected: compilation rejects this example.