กระจัดกระจาย
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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