Kết xuấtvi

thưa

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Sparse tensor width sugar mirrors dense tensor sugar with an s prefix.

Syntax: sf32[2, 3] | si64[N] | su32[4]

Category#

collection

Examples#

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

thưa<T, Figura> declaration shell with all-zero tập_rỗng.

# =============================================================================
# thưa — thưa<T, Figura> declaration shell with all-zero tập_rỗng.
# =============================================================================
#
# What this teaches:
#   • Sparse ten_xo declaration — the `thưa<T, Figura>` type syntax and `tập_rỗng` initializer
#   • Identity functions — passing thưa values through functions preserves shape and rank
#
# Common mistakes:
#   • confusing thưa<T, Figura> with ten_xo<T, Figura> — sparse tensors use the same shape syntax but different storage semantics
#
# See also: thưa, ten_xo, tập_rỗng
# =============================================================================


# thưa — declaration shell for thưa<T, Figura>
#
# thưa<T, Figura> name ← tập_rỗng
# hàm f(thưa<T, Figura> value) → thưa<T, Figura>
#
# GRAMMAR:
#   type :← 'thưa' '<' type ',' shape '>'
#
# EXPECTED OUTPUT:
#   Rank and stored non-zero count after round-trip identity call.

fn identity(thưa<f32, [2, 3]> value) → thưa<f32, [2, 3]> {
    return value
}

main {
    const thưa<f32, [2, 3]> empty ← empty
    const thưa<f32, [2, 3]> roundtrip ← identity(empty)

    print roundtrip.length(), roundtrip.nonzero_count()
}

Expected output:

2 0

radix/corpus/sparsa/sugar.fab (canonical · type)#

Sparse tensor width sugar mirrors dense tensor sugar with an s prefix.

# =============================================================================
# thưa — Sparse ten_xo width sugar mirrors dense ten_xo sugar with an s prefix.
# =============================================================================
#
# What this teaches:
#   • Sugar syntax — `sf32[2, 3]` as shorthand for `thưa<f32, [2, 3]>`
#   • Naming convention — the `s` prefix distinguishes sparse from dense ten_xo sugar
#
# Common mistakes:
#   • forgetting the s prefix when declaring a sparse ten_xo with sugar syntax — sf32, si64, su32
#
# See also: ten_xo, numeric type sugar
# =============================================================================

# STYLE: sparse ten_xo sugar (sf32, si64[N]) — see docs/design/numeric-type-sugar.md

main {
    var sf32[2, 3] grid ← empty
    grid.set([0, 1], 4.0)

    const _ value ← grid.get([0, 1])
    const _ absent ← grid.get([1, 2])
    const _ count ← grid.nonzero_count()

    const tf32[2, 3] dense ← grid.densify()
    print value, absent, count, dense.length()
}

Expected output:

4.0 0.0 1 2