Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add writing numpy tensors back to disk #5

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Add writing numpy tensors back to disk #5

merged 1 commit into from
Nov 15, 2024

Conversation

seanmcl
Copy link
Collaborator

@seanmcl seanmcl commented Nov 14, 2024

This is needed because while we will generally mutate the data in place, we will need to write new headers, e.g. for the potentially changed shape and row/column ordering. Moreover, for tensors we create from scratch, we will not in general have bits representing the header.

Tested by round-tripping in the python repl.

Unit tests are forthcoming.

@seanmcl seanmcl closed this Nov 14, 2024
@seanmcl seanmcl reopened this Nov 14, 2024
Tested by round-tripping in the python repl.
Unit tests are forthcoming.
@@ -514,5 +526,57 @@ def parseFile (path: System.FilePath) : IO (Except String NumpyRepr) := do

end Parse

section Save

private def pushList (a : ByteArray) (xs : List UInt8) : ByteArray := xs.foldl (fun a b => a.push b) a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it more efficient to use ByteArray.append, List.toArray ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Will swap.


private def pushChars (a : ByteArray) (xs : List Char) : ByteArray := xs.foldl (fun a b => a.push (b.toUInt8)) a

private def pushString (a : ByteArray) (xs : String) : ByteArray := pushChars a xs.toList
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment: String.toUTF8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah didn't know about that one

@seanmcl seanmcl merged commit a5c409f into main Nov 15, 2024
1 check passed
@seanmcl seanmcl deleted the sm/save branch November 15, 2024 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants