Repository navigation
feat: MarshalBinary/UnmarshalBinary, NumPy-style Repr, notebook Display - #44
Merged
Merged
Conversation
MarshalBinary writes dtype, shape and row-major little-endian elements, the same bytes on every architecture; UnmarshalBinary checks the shape against the data length (by division: size*16 overflows for complex128) before allocating, so bytes from anywhere cannot make it allocate what they do not carry. Arrays now survive gob, and the go-notebook kernel keeps them instead of re-running the cell that made them. Repr lays an array out as NumPy prints it: nested brackets, one width for every element, 75-column lines, first/last three items per axis above 1000 elements, dtype and shape suffixes. Display returns it as text/plain and, for 1-D and 2-D, an HTML table summarised the same way. Tests: round trip of every dtype incl. views, 0-d and empty arrays; pinned bytes; 13 malformed inputs; gob; repr layouts. An encoder switched to big-endian fails 5 of them. 100% coverage under the CI gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two things a notebook needs from an array.
Keeping it.
MarshalBinary/UnmarshalBinary(encoding.BinaryMarshaler): magic + version, dtype, shape as uvarints, then the elements row-major and little-endian, the same bytes on every architecture (s390x included; a test pins them).UnmarshalBinarytreats its input as untrusted: the shape must account exactly for the data length (checked by division, since size×16 overflows for complex128 shapesvalidateShapeallows) before anything is allocated. With this, gob keeps arrays and the go-notebook kernel (go-notebook/notebook#1) restores them after a rebuild instead of re-running the cell that made them.Showing it.
Reprprints as NumPy does: nested brackets, one width for all elements, 75-column lines, the first and last three items of each axis above 1000 elements, thendtype=/shape=suffixes.Displayreturns that astext/plainplus, for 1-D and 2-D, an HTML table summarised the same way. Element digits use the package's shortest exact form, so they can differ from NumPy's padded precision; the layout matches.Tests: round trip for every dtype (views, 0-d, empty), pinned bytes, 13 malformed inputs, gob, layouts. Negative control: a big-endian encoder fails 5 tests. 100% coverage.
🤖 Generated with Claude Code