@@ -37,6 +37,17 @@ namespace xt
37
37
}
38
38
}
39
39
40
+ template <class T >
41
+ inline void check_file_equal (const std::string& path, const T&& ref)
42
+ {
43
+ std::ifstream in_file;
44
+ in_file.open (path);
45
+ xt::xarray<double > data;
46
+ data = xt::load_bin<double >(in_file);
47
+ EXPECT_TRUE (xt::all (equal (data, ref)));
48
+ in_file.close ();
49
+ }
50
+
40
51
TEST (xchunked_array, disk_array)
41
52
{
42
53
std::vector<size_t > shape = {4 , 4 };
@@ -121,4 +132,32 @@ namespace xt
121
132
EXPECT_EQ (v, init_value);
122
133
}
123
134
}
135
+
136
+ TEST (xchunked_array, chunked_assign_chunked)
137
+ {
138
+ std::vector<size_t > shape = {4 , 4 };
139
+ std::vector<size_t > chunk_shape = {2 , 2 };
140
+ std::string chunk_dir1 = " files4" ;
141
+ fs::create_directory (chunk_dir1);
142
+ auto a1 = chunked_file_array<double , xio_disk_handler<xio_binary_config>>(shape, chunk_shape, chunk_dir1);
143
+ std::string chunk_dir2 = " files5" ;
144
+ fs::create_directory (chunk_dir2);
145
+ auto a2 = chunked_file_array<double , xio_disk_handler<xio_binary_config>>(shape, chunk_shape, chunk_dir2);
146
+ auto a3 = arange (4 * 4 ).reshape ({4 , 4 });
147
+ a2 = a3;
148
+ a2.chunks ().flush ();
149
+ // check that a2 has correct chunks
150
+ check_file_equal (chunk_dir2 + " /0.0" , xt::xarray<double >({{0 , 1 }, {4 , 5 }}));
151
+ check_file_equal (chunk_dir2 + " /1.0" , xt::xarray<double >({{8 , 9 }, {12 , 13 }}));
152
+ check_file_equal (chunk_dir2 + " /0.1" , xt::xarray<double >({{2 , 3 }, {6 , 7 }}));
153
+ check_file_equal (chunk_dir2 + " /1.1" , xt::xarray<double >({{10 , 11 }, {14 , 15 }}));
154
+
155
+ a1 = a2;
156
+ a1.chunks ().flush ();
157
+ // check that a1 has correct chunks
158
+ check_file_equal (chunk_dir1 + " /0.0" , xt::xarray<double >({{0 , 1 }, {4 , 5 }}));
159
+ check_file_equal (chunk_dir1 + " /1.0" , xt::xarray<double >({{8 , 9 }, {12 , 13 }}));
160
+ check_file_equal (chunk_dir1 + " /0.1" , xt::xarray<double >({{2 , 3 }, {6 , 7 }}));
161
+ check_file_equal (chunk_dir1 + " /1.1" , xt::xarray<double >({{10 , 11 }, {14 , 15 }}));
162
+ }
124
163
}
0 commit comments