forked from ml-explore/mlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_tests.cpp
More file actions
83 lines (62 loc) · 1.65 KB
/
Copy pathload_tests.cpp
File metadata and controls
83 lines (62 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright © 2023 Apple Inc.
#include <filesystem>
#include <stdexcept>
#include <vector>
#include "doctest/doctest.h"
#include "mlx/mlx.h"
using namespace mlx::core;
std::string get_temp_file(const std::string& name) {
return std::filesystem::temp_directory_path().append(name);
}
TEST_CASE("test single array serialization") {
// Basic test
{
auto a = random::uniform(-5.f, 5.f, {2, 5, 12}, float32);
std::string file_path = get_temp_file("test_arr.npy");
save(file_path, a);
auto b = load(file_path);
CHECK_EQ(a.dtype(), b.dtype());
CHECK_EQ(a.shape(), b.shape());
CHECK(array_equal(a, b).item<bool>());
}
// Other shapes
{
auto a = random::uniform(
-5.f,
5.f,
{
1,
},
float32);
std::string file_path = get_temp_file("test_arr_0.npy");
save(file_path, a);
auto b = load(file_path);
CHECK_EQ(a.dtype(), b.dtype());
CHECK_EQ(a.shape(), b.shape());
CHECK(array_equal(a, b).item<bool>());
}
{
auto a = random::uniform(
-5.f,
5.f,
{
46,
},
float32);
std::string file_path = get_temp_file("test_arr_1.npy");
save(file_path, a);
auto b = load(file_path);
CHECK_EQ(a.dtype(), b.dtype());
CHECK_EQ(a.shape(), b.shape());
CHECK(array_equal(a, b).item<bool>());
}
{
auto a = random::uniform(-5.f, 5.f, {5, 2, 1, 3, 4}, float32);
std::string file_path = get_temp_file("test_arr_2.npy");
save(file_path, a);
auto b = load(file_path);
CHECK_EQ(a.dtype(), b.dtype());
CHECK_EQ(a.shape(), b.shape());
CHECK(array_equal(a, b).item<bool>());
}
}