Closed tqtifnypmb closed 7 months ago
I wonder if you need to:
eval(src)
before writing it?
try MLX.save(array: src, url: url)
@davidkoski that should do an eval under the hood, https://github.com/ml-explore/mlx/blob/main/mlx/io/load.cpp#L36
E.g. in Python this works fine:
import mlx.core as mx
src = mx.full([1,2,3], 100)
mx.save("arr.npy", src)
print(mx.load("arr.npy"))
I wonder what's different about the Swift version 🤔
I wonder if you need to:
eval(src)
before writing it?
Actually, I was reading npy
written by mlx-python.
But I tried it, same.
aha:
public func loadArray(url: URL, stream: StreamOrDevice = .default) throws -> MLXArray {
precondition(url.isFileURL)
let path = url.path(percentEncoded: false)
if let fp = fopen(path, "r") {
defer { fclose(fp) }
switch url.pathExtension {
case "npy":
return MLXArray(mlx_load_file(fp, stream.ctx))
This needs to switch to the filename version of the call. I swear we already ran into this ...
I will get this tomorrow
Snippet to reproduce: