mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-16 01:49:05 +08:00
fix saving for non-contiguous arrays (#389)
This commit is contained in:
@@ -50,9 +50,14 @@ void save(std::shared_ptr<io::Writer> out_stream, array a, bool retain_graph) {
|
||||
throw std::invalid_argument("[save] cannot serialize an empty array");
|
||||
}
|
||||
|
||||
if (!a.flags().contiguous) {
|
||||
if (!(a.flags().row_contiguous || a.flags().col_contiguous)) {
|
||||
a = reshape(flatten(a), a.shape());
|
||||
a.eval(retain_graph);
|
||||
}
|
||||
// Check once more in-case the above ops change
|
||||
if (!(a.flags().row_contiguous || a.flags().col_contiguous)) {
|
||||
throw std::invalid_argument(
|
||||
"[save] cannot serialize a non-contiguous array");
|
||||
"[save] can only serialize row or col contiguous arrays");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user