@@ -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_EQ (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 };
@@ -59,21 +70,18 @@ namespace xt
59
70
std::ifstream in_file;
60
71
xt::xarray<double > data;
61
72
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);
64
74
EXPECT_EQ (data (1 ), v1);
65
75
in_file.close ();
66
76
67
77
a1.chunks ().flush ();
68
78
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);
71
80
EXPECT_EQ (data (2 ), v2);
72
81
in_file.close ();
73
82
74
83
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);
77
85
EXPECT_EQ (data (0 ), v3);
78
86
in_file.close ();
79
87
}
@@ -125,6 +133,34 @@ namespace xt
125
133
}
126
134
}
127
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
+ 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
+
128
164
TEST (xchunked_array, shape_initializer_list)
129
165
{
130
166
std::vector<size_t > shape = {4 , 4 };
0 commit comments