Skip to content

Commit 367f7dc

Browse files
davidbrochartJohanMabille
authored andcommitted
Add test to assign chunked array to chunked array
1 parent db080a4 commit 367f7dc

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

test/test_xchunk_store_manager.cpp

+42-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ namespace xt
3737
}
3838
}
3939

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_EQ(data, ref);
48+
in_file.close();
49+
}
50+
4051
TEST(xchunked_array, disk_array)
4152
{
4253
std::vector<size_t> shape = {4, 4};
@@ -59,21 +70,18 @@ namespace xt
5970
std::ifstream in_file;
6071
xt::xarray<double> data;
6172
in_file.open(chunk_dir + "/1.0");
62-
auto i1 = xt::xistream_wrapper(in_file);
63-
data = xt::load_bin<double>(i1);
73+
data = xt::load_bin<double>(in_file);
6474
EXPECT_EQ(data(1), v1);
6575
in_file.close();
6676

6777
a1.chunks().flush();
6878
in_file.open(chunk_dir + "/0.1");
69-
auto i2 = xt::xistream_wrapper(in_file);
70-
data = xt::load_bin<double>(i2);
79+
data = xt::load_bin<double>(in_file);
7180
EXPECT_EQ(data(2), v2);
7281
in_file.close();
7382

7483
in_file.open(chunk_dir + "/0.0");
75-
auto i3 = xt::xistream_wrapper(in_file);
76-
data = xt::load_bin<double>(i3);
84+
data = xt::load_bin<double>(in_file);
7785
EXPECT_EQ(data(0), v3);
7886
in_file.close();
7987
}
@@ -125,6 +133,34 @@ namespace xt
125133
}
126134
}
127135

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+
noalias(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+
noalias(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+
}
163+
128164
TEST(xchunked_array, shape_initializer_list)
129165
{
130166
std::vector<size_t> shape = {4, 4};

0 commit comments

Comments
 (0)