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
Related#
Examples#
radix/corpus/sparsa/decl.fab (canonical · type)#
sparsa<T, Figura> declaration shell with all-zero vacua.
# =============================================================================
# sparsa — sparsa<T, Figura> declaration shell with all-zero vacua.
# =============================================================================
#
# What this teaches:
# • Sparse tensor declaration — the `sparsa<T, Figura>` type syntax and `vacua` initializer
# • Identity functions — passing sparsa values through functions preserves shape and rank
#
# Common mistakes:
# • confusing sparsa<T, Figura> with tensor<T, Figura> — sparse tensors use the same shape syntax but different storage semantics
#
# See also: sparsa, tensor, vacua
# =============================================================================
# sparsa — declaration shell for sparsa<T, Figura>
#
# sparsa<T, Figura> name ← vacua
# functio f(sparsa<T, Figura> value) → sparsa<T, Figura>
#
# GRAMMAR:
# type :← 'sparsa' '<' type ',' shape '>'
#
# EXPECTED OUTPUT:
# Rank and stored non-zero count after round-trip identity call.
fn identity(sparsa<float<f32>, [2, 3]> value) → sparsa<float<f32>, [2, 3]> {
return value
}
main {
const sparsa<float<f32>, [2, 3]> empty ← empty
const sparsa<float<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.
# =============================================================================
# sparsa — Sparse tensor width sugar mirrors dense tensor sugar with an s prefix.
# =============================================================================
#
# What this teaches:
# • Sugar syntax — `sf32[2, 3]` as shorthand for `sparsa<fractus<f32>, [2, 3]>`
# • Naming convention — the `s` prefix distinguishes sparse from dense tensor sugar
#
# Common mistakes:
# • forgetting the s prefix when declaring a sparse tensor with sugar syntax — sf32, si64, su32
#
# See also: tensor, numeric type sugar
# =============================================================================
# STYLE: sparse tensor 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