متفرقة
Translation status: العربية reader-locale proof. Term names and code fences follow the ar 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
Related#
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