渲染zh-Hant

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Glyph Hadamard divide: identical-shape elementwise division on tensors.

Syntax: <expression> ⊘ <expression>

Category#

arithmetic

Examples#

radix/corpus/tensor/glyph-hadamard-divide.fab (canonical · operator-group)#

Glyph Hadamard divide: identical-shape elementwise division on tensors.

# =============================================================================
# ⊘ — glyph Hadamard divide (identical-shape elementwise division).
# =============================================================================
#
# What this teaches:
#   • Hadamard divide — `a ⊘ b` divides elementwise under the same
#     identical-shape contract as `a ⊙ b`; it is the glyph spelling of the
#     tensor `divisio` method twin and the existing TensorDiv MIR operation.
#   • This is not broadcasting — mismatched static shapes reject at typecheck,
#     just as they do for `⊙`.
#   • Device posture — `⊘` remains fail-closed until its first device
#     consumer, matching the `⊗` family posture: it waits for that consumer
#     rather than claiming an unproved device recipe.
#
# EXPECTED stdout:
#   [2.0, 2.0, 3.0, 4.0]
#
# See also: tensor, arithmetic, ⊙, ⊘
# =============================================================================

fn hadamard_divide(tensor<f32, [2, 2]> numerator, tensor<f32, [2, 2]> denominator)  tensor<f32, [2, 2]> {
    return numerator ⊘ denominator
}

main {
    const list<f32> flat_numerator  [2.0, 4.0, 9.0, 16.0]
    const list<f32> flat_denominator  [1.0, 2.0, 3.0, 4.0]
    const tf32[] seed  empty
    var tf32[2, 2] numerator  seed.from_flat(flat_numerator, [2, 2])
    var tf32[2, 2] denominator  seed.from_flat(flat_denominator, [2, 2])
    const tf32[2, 2] result  hadamard_divide(numerator, denominator)
    print result.flatten()
}