रेंडरिंगhi

विरल

Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi 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)#

विरल<T, Figura> declaration shell with all-zero खाली.

# =============================================================================
# विरल — विरल<T, Figura> declaration shell with all-zero खाली.
# =============================================================================
#
# What this teaches:
#   • Sparse टेंसर declaration — the `विरल<T, Figura>` type syntax and `खाली` initializer
#   • Identity functions — passing विरल values through functions preserves shape and rank
#
# Common mistakes:
#   • confusing विरल<T, Figura> with टेंसर<T, Figura> — sparse tensors use the same shape syntax but different storage semantics
#
# See also: विरल, टेंसर, खाली
# =============================================================================


# विरल — declaration shell for विरल<T, Figura>
#
# विरल<T, Figura> name ← खाली
# फलन f(विरल<T, Figura> value) → विरल<T, Figura>
#
# GRAMMAR:
#   type :← 'विरल' '<' type ',' shape '>'
#
# EXPECTED OUTPUT:
#   Rank and stored non-zero count after round-trip identity call.

fn identity(विरल<f32, [2, 3]> value) → विरल<f32, [2, 3]> {
    return value
}

main {
    const विरल<f32, [2, 3]> empty ← empty
    const विरल<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.

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

# STYLE: sparse टेंसर 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