You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TensorStorageFactory violates its own copy/borrow contracts: "zero-copy" borrowFloatArray copies, "borrowed" fromTensorData owns #927
Two methods in skainet-lang-core/src/commonMain/kotlin/sk/ainet/lang/tensor/storage/TensorStorageFactory.kt do the opposite of what their docs and names promise:
borrowFloatArray (line ~38) — KDoc says "(zero-copy)". The implementation allocates a fresh ByteArray(data.size * 4), re-encodes every float into it, and wraps the copy in BufferHandleFactory.borrow(...). So the caller gets a buffer labeled Borrowed (with the "caller owns, must not free" contract) that is actually a private copy — both the performance promise and the ownership label are wrong.
fromTensorData (line ~128) — KDoc: "The underlying data is borrowed (not copied)." The FloatArrayTensorData / IntArrayTensorData branches call BufferHandleFactory.owned(...), which copies into a new array and labels it Owned. Only the packed-quant branches actually borrow. The else branch does data.copyToFloatArray() and then fromFloatArray(...) — a double copy.
Why it matters: BufferHandle.Ownership is the storage layer's authority on who may mutate/free a buffer, and MemoryTracker reports are keyed off it. Mislabeling copies as borrows makes both untrustworthy exactly where the layer is supposed to bring clarity, and hides real allocation cost from anyone profiling loads.
Suggested fix: make the labels truthful — borrowFloatArray should either genuinely alias (if a float-view representation is added) or be renamed/documented as an owned conversion; fromTensorData should borrow the backing arrays it can see (FloatArrayTensorData.buffer etc. are right there) and only copy in the else branch, with the doc updated to say which is which.
Activity
Merge pull request #935 from SKaiNET-developers/fix/storage-factory-o…
fix(lang): truthful ownership labels in TensorStorageFactory
release: prepare 0.39.0