Skip to content

Commit 979479a

Browse files
committed
Add test to assign chunked array to chunked array
1 parent b745689 commit 979479a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/test_xchunk_store_manager.cpp

Lines changed: 39 additions & 0 deletions
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_TRUE(xt::all(equal(data, ref)));
48+
in_file.close();
49+
}
50+
4051
TEST(xchunked_array, disk_array)
4152
{
4253
std::vector<size_t> shape = {4, 4};
@@ -121,4 +132,32 @@ namespace xt
121132
EXPECT_EQ(v, init_value);
122133
}
123134
}
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+
}
124163
}

0 commit comments

Comments
 (0)