tests_high_five_base.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 
10 #include <cstdio>
11 #include <cstdlib>
12 #include <ctime>
13 #include <complex>
14 #include <iostream>
15 #include <random>
16 #include <string>
17 #include <typeinfo>
18 #include <vector>
19 #include <memory>
20 
21 #include <stdio.h>
22 
23 #include <highfive/H5DataSet.hpp>
24 #include <highfive/H5DataSpace.hpp>
25 #include <highfive/H5File.hpp>
26 #include <highfive/H5Group.hpp>
27 #include <highfive/H5Utility.hpp>
28 
29 #define BOOST_TEST_MAIN HighFiveTest
30 
31 #include <boost/mpl/list.hpp>
32 #include <boost/test/unit_test.hpp>
33 
34 #ifdef H5_USE_BOOST
35 #include <boost/multi_array.hpp>
36 #endif
37 
38 using namespace HighFive;
39 using complex = std::complex<double>;
40 
41 typedef boost::mpl::list<float, double> floating_numerics_test_types;
42 typedef boost::mpl::list<int, unsigned int, long, unsigned long, unsigned char,
43  char, float, double, long long, unsigned long long,
44  complex>
46 typedef boost::mpl::list<int, unsigned int, long, unsigned long, unsigned char,
47  char, float, double, std::string>
49 
50 template <typename T, typename Func>
51 void generate2D(T* table, size_t x, size_t y, Func& func) {
52  for (size_t i = 0; i < x; i++) {
53  for (size_t j = 0; j < y; j++) {
54  table[i][j] = func();
55  }
56  }
57 }
58 
59 template <typename T, typename Func>
60 void generate2D(std::vector<std::vector<T>>& vec, size_t x, size_t y,
61  Func& func) {
62  vec.resize(x);
63  for (size_t i = 0; i < x; i++) {
64  vec[i].resize(y);
65  for (size_t j = 0; j < y; j++) {
66  vec[i][j] = func();
67  }
68  }
69 }
70 
71 template <typename T>
73  ContentGenerate() : _init(0), _inc(T(1) + T(1) / T(10)) {}
74 
75  T operator()() {
76  T ret = _init;
77  _init += _inc;
78  return ret;
79  }
80 
81  T _init, _inc;
82 };
83 
84 template <>
86  : _init(0, 0)
87  , _inc(complex(1, 1) + complex(1, 1) / complex(10))
88 {}
89 
90 template <>
91 struct ContentGenerate<char> {
92  ContentGenerate() : _init('a') {}
93 
94  char operator()() {
95  char ret = _init;
96  if (++_init >= ('a' + 26))
97  _init = 'a';
98  return ret;
99  }
100 
101  char _init;
102 };
103 
104 template <>
105 struct ContentGenerate<std::string> {
107 
108  std::string operator()() {
110  std::string random_string;
111  std::mt19937_64 rgen;
112  rgen.seed(88);
113  std::uniform_int_distribution<int> int_dist(0, 1000);
114  const size_t size_string = int_dist(rgen);
115 
116  random_string.resize(size_string);
117  std::generate(random_string.begin(), random_string.end(), gen);
118  return random_string;
119  }
120 };
121 
122 BOOST_AUTO_TEST_CASE(HighFiveBasic) {
123  const std::string FILE_NAME("h5tutr_dset.h5");
124  const std::string DATASET_NAME("dset");
125 
126  // Create a new file using the default property lists.
127  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
128 
129  BOOST_CHECK_EQUAL(file.getName(), FILE_NAME);
130 
131  // Create the data space for the dataset.
132  std::vector<size_t> dims{4,6};
133 
134  DataSpace dataspace(dims);
135 
136  // check if the dataset exist
137  bool dataset_exist = file.exist(DATASET_NAME + "_double");
138  BOOST_CHECK_EQUAL(dataset_exist, false);
139 
140  // Create a dataset with double precision floating points
141  DataSet dataset_double = file.createDataSet(
142  DATASET_NAME + "_double", dataspace, AtomicType<double>());
143 
144  BOOST_CHECK_EQUAL(file.getObjectName(0), DATASET_NAME + "_double");
145 
146  {
147  // check if it exist again
148  dataset_exist = file.exist(DATASET_NAME + "_double");
149  BOOST_CHECK_EQUAL(dataset_exist, true);
150 
151  // and also try to recreate it to the sake of exception testing
152  BOOST_CHECK_THROW(
153  {
154  DataSet fail_duplicated = file.createDataSet(
155  DATASET_NAME + "_double", dataspace, AtomicType<double>());
156  },
158  }
159 
160  DataSet dataset_size_t =
161  file.createDataSet<size_t>(DATASET_NAME + "_size_t", dataspace);
162 }
163 
164 BOOST_AUTO_TEST_CASE(HighFiveSilence) {
165  // Setting up a buffer for stderr so we can detect if the stack trace
166  // was disabled
167  fflush(stderr);
168  char buffer[1024];
169  memset(buffer, 0, sizeof(char) * 1024);
170  setvbuf(stderr, buffer, _IOLBF, 1023);
171 
172  try {
173  SilenceHDF5 silence;
174  File file("nonexistent", File::ReadOnly);
175  } catch (const FileException&) {
176  }
177  BOOST_CHECK_EQUAL(buffer[0], '\0');
178 
179  // restore the dyn allocated buffer
180  // or using stderr will segfault when buffer get out of scope
181  fflush(stderr);
182  setvbuf(stderr, NULL, _IONBF, 0);
183 }
184 
185 BOOST_AUTO_TEST_CASE(HighFiveOpenMode) {
186  const std::string FILE_NAME("openmodes.h5");
187  const std::string DATASET_NAME("dset");
188 
189  std::remove(FILE_NAME.c_str());
190 
191  // Attempt open file only ReadWrite should fail (wont create)
192  BOOST_CHECK_THROW(
193  { File file(FILE_NAME, File::ReadWrite); },
194  FileException);
195 
196  // But with Create flag should be fine
197  { File file(FILE_NAME, File::ReadWrite | File::Create); }
198 
199  // But if its there and exclusive is given, should fail
200  BOOST_CHECK_THROW(
201  { File file(FILE_NAME, File::ReadWrite | File::Excl); },
202  FileException);
203  // ReadWrite and Excl flags are fine together (posix)
204  std::remove(FILE_NAME.c_str());
205  { File file(FILE_NAME, File::ReadWrite | File::Excl); }
206  // All three are fine as well (as long as the file does not exist)
207  std::remove(FILE_NAME.c_str());
208  { File file(FILE_NAME, File::ReadWrite | File::Create | File::Excl); }
209 
210  // Just a few combinations are incompatible, detected by hdf5lib
211  BOOST_CHECK_THROW(
212  { File file(FILE_NAME, File::Truncate | File::Excl); },
213  FileException);
214 
215  std::remove(FILE_NAME.c_str());
216  BOOST_CHECK_THROW(
217  { File file(FILE_NAME, File::Truncate | File::Excl); },
218  FileException);
219 
220  // But in most cases we will truncate and that should always work
221  { File file(FILE_NAME, File::Truncate); }
222  std::remove(FILE_NAME.c_str());
223  { File file(FILE_NAME, File::Truncate); }
224 
225  // Last but not least, defaults should be ok
226  { File file(FILE_NAME); } // ReadOnly
227  { File file(FILE_NAME, 0); } // force empty-flags, does open without flags
228 }
229 
230 
231 BOOST_AUTO_TEST_CASE(HighFiveGroupAndDataSet) {
232  const std::string FILE_NAME("h5_group_test.h5");
233  const std::string DATASET_NAME("dset");
234  const std::string CHUNKED_DATASET_NAME("chunked_dset");
235  const std::string CHUNKED_DATASET_SMALL_NAME("chunked_dset_small");
236  const std::string GROUP_NAME1("/group1");
237  const std::string GROUP_NAME2("group2");
238  const std::string GROUP_NESTED_NAME("group_nested");
239 
240  {
241  // Create a new file using the default property lists.
242  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
243 
244  // absolute group
245  file.createGroup(GROUP_NAME1);
246  // nested group absolute
247  file.createGroup(GROUP_NAME1 + "/" + GROUP_NESTED_NAME);
248  // relative group
249  Group g1 = file.createGroup(GROUP_NAME2);
250  // relative group
251  Group nested = g1.createGroup(GROUP_NESTED_NAME);
252 
253  // Create the data space for the dataset.
254  std::vector<size_t> dims{4, 6};
255 
256  DataSpace dataspace(dims);
257 
258  DataSet dataset_absolute = file.createDataSet(
259  GROUP_NAME1 + "/" + GROUP_NESTED_NAME + "/" + DATASET_NAME,
260  dataspace, AtomicType<double>());
261 
262  DataSet dataset_relative =
263  nested.createDataSet(DATASET_NAME, dataspace, AtomicType<double>());
264 
265  DataSetCreateProps goodChunking;
266  goodChunking.add(Chunking(std::vector<hsize_t>{2, 2}));
267  DataSetAccessProps cacheConfig;
268  cacheConfig.add(Caching(13, 1024, 0.5));
269 
270  // will fail because exceeds dimensions
271  DataSetCreateProps badChunking0;
272  badChunking0.add(Chunking(std::vector<hsize_t>{10, 10}));
273 
274  DataSetCreateProps badChunking1;
275  badChunking1.add(Chunking(std::vector<hsize_t>{1, 1, 1}));
276 
277 
278  BOOST_CHECK_THROW(file.createDataSet(CHUNKED_DATASET_NAME, dataspace,
280  badChunking0),
282 
283  BOOST_CHECK_THROW(file.createDataSet(CHUNKED_DATASET_NAME, dataspace,
285  badChunking1),
287 
288  // here we use the other signature
289  DataSet dataset_chunked = file.createDataSet<float>(
290  CHUNKED_DATASET_NAME, dataspace, goodChunking, cacheConfig);
291 
292  // Here we resize to smaller than the chunking size
293  DataSet dataset_chunked_small = file.createDataSet<float>(
294  CHUNKED_DATASET_SMALL_NAME, dataspace, goodChunking);
295 
296  dataset_chunked_small.resize({1, 1});
297  }
298  // read it back
299  {
300  File file(FILE_NAME, File::ReadOnly);
301  Group g1 = file.getGroup(GROUP_NAME1);
302  Group g2 = file.getGroup(GROUP_NAME2);
303  Group nested_group2 = g2.getGroup(GROUP_NESTED_NAME);
304 
305  DataSet dataset_absolute = file.getDataSet(
306  GROUP_NAME1 + "/" + GROUP_NESTED_NAME + "/" + DATASET_NAME);
307  BOOST_CHECK_EQUAL(4, dataset_absolute.getSpace().getDimensions()[0]);
308 
309  DataSet dataset_relative = nested_group2.getDataSet(DATASET_NAME);
310  BOOST_CHECK_EQUAL(4, dataset_relative.getSpace().getDimensions()[0]);
311 
312  DataSetAccessProps accessProps;
313  accessProps.add(Caching(13, 1024, 0.5));
314  DataSet dataset_chunked = file.getDataSet(CHUNKED_DATASET_NAME,
315  accessProps);
316  BOOST_CHECK_EQUAL(4, dataset_chunked.getSpace().getDimensions()[0]);
317 
318  DataSet dataset_chunked_small =
319  file.getDataSet(CHUNKED_DATASET_SMALL_NAME);
320  BOOST_CHECK_EQUAL(1,
321  dataset_chunked_small.getSpace().getDimensions()[0]);
322  }
323 }
324 
325 BOOST_AUTO_TEST_CASE(HighFiveExtensibleDataSet) {
326  const std::string FILE_NAME("create_extensible_dataset_example.h5");
327  const std::string DATASET_NAME("dset");
328  constexpr double t1[3][1] = {{2.0}, {2.0}, {4.0}};
329  constexpr double t2[1][3] = {{4.0, 8.0, 6.0}};
330 
331  {
332  // Create a new file using the default property lists.
333  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
334 
335  // Create a dataspace with initial shape and max shape
336  DataSpace dataspace = DataSpace({4, 5}, {17, DataSpace::UNLIMITED});
337 
338  // Use chunking
339  DataSetCreateProps props;
340  props.add(Chunking(std::vector<hsize_t>{2, 2}));
341 
342  // Create the dataset
343  DataSet dataset = file.createDataSet(DATASET_NAME, dataspace,
344  AtomicType<double>(), props);
345 
346  // Write into the initial part of the dataset
347  dataset.select({0, 0}, {3, 1}).write(t1);
348 
349  // Resize the dataset to a larger size
350  dataset.resize({4, 6});
351 
352  BOOST_CHECK_EQUAL(4, dataset.getSpace().getDimensions()[0]);
353  BOOST_CHECK_EQUAL(6, dataset.getSpace().getDimensions()[1]);
354 
355  // Write into the new part of the dataset
356  dataset.select({3, 3}, {1, 3}).write(t2);
357 
358  // Try resize out of bounds
359  BOOST_CHECK_THROW(dataset.resize({18, 1}), DataSetException);
360  // Try resize invalid dimensions
361  BOOST_CHECK_THROW(dataset.resize({1, 2, 3}), DataSetException);
362  }
363 
364  // read it back
365  {
366  File file(FILE_NAME, File::ReadOnly);
367 
368  DataSet dataset_absolute = file.getDataSet("/" + DATASET_NAME);
369  const auto dims = dataset_absolute.getSpace().getDimensions();
370  double values[4][6];
371  dataset_absolute.read(values);
372  BOOST_CHECK_EQUAL(4, dims[0]);
373  BOOST_CHECK_EQUAL(6, dims[1]);
374 
375  BOOST_CHECK_EQUAL(t1[0][0], values[0][0]);
376  BOOST_CHECK_EQUAL(t1[1][0], values[1][0]);
377  BOOST_CHECK_EQUAL(t1[2][0], values[2][0]);
378 
379  BOOST_CHECK_EQUAL(t2[0][0], values[3][3]);
380  BOOST_CHECK_EQUAL(t2[0][1], values[3][4]);
381  BOOST_CHECK_EQUAL(t2[0][2], values[3][5]);
382  }
383 }
384 
385 BOOST_AUTO_TEST_CASE(HighFiveRefCountMove) {
386  const std::string FILE_NAME("h5_ref_count_test.h5");
387  const std::string DATASET_NAME("dset");
388  const std::string GROUP_NAME1("/group1");
389  const std::string GROUP_NAME2("/group2");
390 
391  // Create a new file using the default property lists.
392  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
393 
394  std::unique_ptr<DataSet> d1_ptr;
395  std::unique_ptr<Group> g_ptr;
396 
397  {
398  // create group
399  Group g1 = file.createGroup(GROUP_NAME1);
400 
401  // override object
402  g1 = file.createGroup(GROUP_NAME2);
403 
404  // Create the data space for the dataset.
405  std::vector<size_t> dims = {10, 10};
406 
407  DataSpace dataspace(dims);
408 
409  DataSet d1 = file.createDataSet(GROUP_NAME1 + DATASET_NAME, dataspace,
411 
412  double values[10][10] = {{0}};
413  values[5][0] = 1;
414  d1.write(values);
415 
416  // force move
417  d1_ptr.reset(new DataSet(std::move(d1)));
418 
419  // force copy
420  g_ptr.reset(new Group(g1));
421  }
422  // read it back
423  {
424  DataSet d2(std::move(*d1_ptr));
425  d1_ptr.reset();
426 
427  double values[10][10];
428  memset(values, 255, 10 * 10);
429 
430  d2.read(values);
431 
432  for (std::size_t i = 0; i < 10; ++i) {
433  for (std::size_t j = 0; j < 10; ++j) {
434  double v = values[i][j];
435 
436  if (i == 5 && j == 0) {
437  BOOST_CHECK_EQUAL(v, 1);
438  } else {
439  BOOST_CHECK_EQUAL(v, 0);
440  }
441  }
442  }
443 
444  // force copy
445  Group g2 = *g_ptr;
446 
447  // add a subgroup
448  g2.createGroup("blabla");
449  }
450 }
451 
452 BOOST_AUTO_TEST_CASE(HighFiveSimpleListing) {
453  const std::string FILE_NAME("h5_list_test.h5");
454  const std::string GROUP_NAME_CORE("group_name");
455  const std::string GROUP_NESTED_NAME("/group_nested");
456 
457  // Create a new file using the default property lists.
458  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
459 
460  {
461  // absolute group
462  for (int i = 0; i < 2; ++i) {
463  std::ostringstream ss;
464  ss << "/" << GROUP_NAME_CORE << "_" << i;
465  file.createGroup(ss.str());
466  }
467 
468  size_t n_elem = file.getNumberObjects();
469  BOOST_CHECK_EQUAL(2, n_elem);
470 
471  std::vector<std::string> elems = file.listObjectNames();
472  BOOST_CHECK_EQUAL(2, elems.size());
473  std::vector<std::string> reference_elems;
474  for (int i = 0; i < 2; ++i) {
475  std::ostringstream ss;
476  ss << GROUP_NAME_CORE << "_" << i;
477  reference_elems.push_back(ss.str());
478  }
479 
480  BOOST_CHECK_EQUAL_COLLECTIONS(elems.begin(), elems.end(),
481  reference_elems.begin(),
482  reference_elems.end());
483  }
484 
485  {
486  file.createGroup(GROUP_NESTED_NAME);
487  Group g_nest = file.getGroup(GROUP_NESTED_NAME);
488 
489  for (int i = 0; i < 50; ++i) {
490  std::ostringstream ss;
491  ss << GROUP_NAME_CORE << "_" << i;
492  g_nest.createGroup(ss.str());
493  }
494 
495  size_t n_elem = g_nest.getNumberObjects();
496  BOOST_CHECK_EQUAL(50, n_elem);
497 
498  std::vector<std::string> elems = g_nest.listObjectNames();
499  BOOST_CHECK_EQUAL(50, elems.size());
500  std::vector<std::string> reference_elems;
501 
502  for (int i = 0; i < 50; ++i) {
503  std::ostringstream ss;
504  ss << GROUP_NAME_CORE << "_" << i;
505  reference_elems.push_back(ss.str());
506  }
507  // there is no guarantee on the order of the hdf5 index, let's sort it
508  // to put them in order
509  std::sort(elems.begin(), elems.end());
510  std::sort(reference_elems.begin(), reference_elems.end());
511 
512  BOOST_CHECK_EQUAL_COLLECTIONS(elems.begin(), elems.end(),
513  reference_elems.begin(),
514  reference_elems.end());
515  }
516 }
517 
518 BOOST_AUTO_TEST_CASE(DataTypeEqualSimple) {
519  using namespace HighFive;
520 
521  AtomicType<double> d_var;
522  AtomicType<size_t> size_var;
523  AtomicType<double> d_var_test;
524  AtomicType<size_t> size_var_cpy(size_var);
525  AtomicType<int> int_var;
526  AtomicType<unsigned int> uint_var;
527 
528  // check different type matching
529  BOOST_CHECK(d_var == d_var_test);
530  BOOST_CHECK(d_var != size_var);
531 
532  // check type copy matching
533  BOOST_CHECK(size_var_cpy == size_var);
534 
535  // check sign change not matching
536  BOOST_CHECK(int_var != uint_var);
537 }
538 
539 BOOST_AUTO_TEST_CASE(DataTypeEqualTakeBack) {
540  using namespace HighFive;
541 
542  const std::string FILE_NAME("h5tutr_dset.h5");
543  const std::string DATASET_NAME("dset");
544 
545  // Create a new file using the default property lists.
547 
548  // Create the data space for the dataset.
549  std::vector<size_t> dims{10, 1};
550 
551  DataSpace dataspace(dims);
552 
553  // Create a dataset with double precision floating points
554  DataSet dataset =
555  file.createDataSet<size_t>(DATASET_NAME + "_double", dataspace);
556 
559 
560  BOOST_CHECK(s == dataset.getDataType());
561  BOOST_CHECK(d != dataset.getDataType());
562 }
563 
564 BOOST_AUTO_TEST_CASE(DataSpaceTest) {
565  using namespace HighFive;
566 
567  const std::string FILE_NAME("h5tutr_space.h5");
568  const std::string DATASET_NAME("dset");
569 
570  // Create a new file using the default property lists.
572 
573  // Create the data space for the dataset.
574  DataSpace dataspace{std::vector<size_t>{10, 1}};
575 
576  // Create a dataset with size_t type
577  DataSet dataset = file.createDataSet<size_t>(DATASET_NAME, dataspace);
578 
579  DataSpace space = dataset.getSpace();
580  DataSpace space2 = dataset.getSpace();
581 
582  // verify space id are different
583  BOOST_CHECK_NE(space.getId(), space2.getId());
584 
585  // verify space id are consistent
586  BOOST_CHECK_EQUAL(space.getDimensions().size(), 2);
587  BOOST_CHECK_EQUAL(space.getDimensions()[0], 10);
588  BOOST_CHECK_EQUAL(space.getDimensions()[1], 1);
589 }
590 
591 BOOST_AUTO_TEST_CASE(DataSpaceVectorTest) {
592  using namespace HighFive;
593 
594  // Create 1D shortcut dataspace
595  DataSpace space(7);
596 
597  BOOST_CHECK_EQUAL(space.getDimensions().size(), 1);
598  BOOST_CHECK_EQUAL(space.getDimensions()[0], 7);
599 
600  // Initializer list (explicit)
601  DataSpace space3({8, 9, 10});
602  auto space3_res = space3.getDimensions();
603  std::vector<size_t> space3_ans{8, 9, 10};
604 
605  BOOST_CHECK_EQUAL_COLLECTIONS(space3_res.begin(), space3_res.end(),
606  space3_ans.begin(), space3_ans.end());
607 
608  // Verify 2D works (note that without the {}, this matches the iterator constructor)
609  DataSpace space2(std::vector<size_t>{3, 4});
610 
611  auto space2_res = space2.getDimensions();
612  std::vector<size_t> space2_ans{3, 4};
613 
614  BOOST_CHECK_EQUAL_COLLECTIONS(space2_res.begin(), space2_res.end(),
615  space2_ans.begin(), space2_ans.end());
616 
617 }
618 
619 BOOST_AUTO_TEST_CASE(DataSpaceVariadicTest) {
620  using namespace HighFive;
621 
622  // Create 1D shortcut dataspace
623  DataSpace space1 {7};
624 
625  auto space1_res = space1.getDimensions();
626  std::vector<size_t> space1_ans{7};
627 
628  BOOST_CHECK_EQUAL_COLLECTIONS(space1_res.begin(), space1_res.end(),
629  space1_ans.begin(), space1_ans.end());
630 
631 
632  // Initializer list (explicit)
633  DataSpace space3{8, 9, 10};
634 
635  auto space3_res = space3.getDimensions();
636  std::vector<size_t> space3_ans{8, 9, 10};
637 
638  BOOST_CHECK_EQUAL_COLLECTIONS(space3_res.begin(), space3_res.end(),
639  space3_ans.begin(), space3_ans.end());
640 
641  // Verify 2D works using explicit syntax
642  DataSpace space2{3, 4};
643 
644  auto space2_res = space2.getDimensions();
645  std::vector<size_t> space2_ans{3, 4};
646 
647  BOOST_CHECK_EQUAL_COLLECTIONS(space2_res.begin(), space2_res.end(),
648  space2_ans.begin(), space2_ans.end());
649 
650  // Verify 2D works using old syntax (this used to match the iterator!)
651  DataSpace space2b(3, 4);
652 
653  auto space2b_res = space2b.getDimensions();
654  std::vector<size_t> space2b_ans{3, 4};
655 
656  BOOST_CHECK_EQUAL_COLLECTIONS(space2b_res.begin(), space2b_res.end(),
657  space2b_ans.begin(), space2b_ans.end());
658 }
659 
660 BOOST_AUTO_TEST_CASE(ChunkingConstructorsTest) {
661  Chunking first(1,2,3);
662 
663  auto first_res = first.getDimensions();
664  std::vector<hsize_t> first_ans{1,2,3};
665 
666  BOOST_CHECK_EQUAL_COLLECTIONS(first_res.begin(), first_res.end(),
667  first_ans.begin(), first_ans.end());
668 
669  Chunking second{1,2,3};
670 
671  auto second_res = second.getDimensions();
672  std::vector<hsize_t> second_ans{1,2,3};
673 
674  BOOST_CHECK_EQUAL_COLLECTIONS(second_res.begin(), second_res.end(),
675  second_ans.begin(), second_ans.end());
676 
677  Chunking third({1,2,3});
678 
679  auto third_res = third.getDimensions();
680  std::vector<hsize_t> third_ans{1,2,3};
681 
682  BOOST_CHECK_EQUAL_COLLECTIONS(third_res.begin(), third_res.end(),
683  third_ans.begin(), third_ans.end());
684 }
685 
686 template <typename T>
688  std::ostringstream filename;
689  filename << "h5_rw_2d_array_" << typeid(T).name() << "_test.h5";
690  const std::string DATASET_NAME("dset");
691  const size_t x_size = 100;
692  const size_t y_size = 10;
693 
694  // Create a new file using the default property lists.
695  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
696 
697  // Create the data space for the dataset.
698  std::vector<size_t> dims{x_size, y_size};
699 
700  DataSpace dataspace(dims);
701 
702  // Create a dataset with arbitrary type
703  DataSet dataset = file.createDataSet<T>(DATASET_NAME, dataspace);
704 
705  T array[x_size][y_size];
706 
707  ContentGenerate<T> generator;
708  generate2D(array, x_size, y_size, generator);
709 
710  dataset.write(array);
711 
712  T result[x_size][y_size];
713 
714  dataset.read(result);
715 
716  for (size_t i = 0; i < x_size; ++i) {
717  for (size_t j = 0; j < y_size; ++j) {
718  BOOST_CHECK_EQUAL(result[i][j], array[i][j]);
719  }
720  }
721 }
722 
724  readWrite2DArrayTest<T>();
725 }
726 
727 BOOST_AUTO_TEST_CASE(HighFiveReadWriteShortcut) {
728  using namespace HighFive;
729 
730  std::ostringstream filename;
731  filename << "h5_rw_vec_shortcut_test.h5";
732 
733  const size_t x_size = 800;
734  const std::string DATASET_NAME("dset");
735  std::vector<int> vec;
736  vec.resize(x_size);
737  for(size_t i=0; i < x_size; i++)
738  vec[i] = i * 2;
739  std::string at_contents("Contents of string");
740  int my_int = 3;
741  std::vector<std::vector<int>> my_nested = {{1,2},{3,4}};
742 
743  // Create a new file using the default property lists.
745 
746  // Create a dataset with int points
747  DataSet dataset = file.createDataSet(DATASET_NAME, vec);
748  dataset.createAttribute("str", at_contents);
749 
750  DataSet ds_int = file.createDataSet("/TmpInt", my_int);
751  DataSet ds_nested = file.createDataSet("/TmpNest", my_nested);
752 
753  std::vector<int> result;
754  dataset.read(result);
755  BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(),
756  result.begin(), result.end());
757 
758  std::string read_in;
759  dataset.getAttribute("str").read(read_in);
760  BOOST_CHECK_EQUAL(read_in, at_contents);
761 
762  int out_int = 0;
763  ds_int.read(out_int);
764  BOOST_CHECK_EQUAL(my_int, out_int);
765 
766  decltype(my_nested) out_nested;
767  ds_nested.read(out_nested);
768 
769  for (size_t i = 0; i < 2; ++i) {
770  for (size_t j = 0; j < 2; ++j) {
771  BOOST_CHECK_EQUAL(my_nested[i][j], out_nested[i][j]);
772  }
773  }
774 }
775 
776 template <typename T>
778  using namespace HighFive;
779 
780  std::ostringstream filename;
781  filename << "h5_rw_vec_" << typeid(T).name() << "_test.h5";
782 
783  const size_t x_size = 800;
784  const std::string DATASET_NAME("dset");
785  typename std::vector<T> vec;
786  vec.resize(x_size);
787  ContentGenerate<T> generator;
788  std::generate(vec.begin(), vec.end(), generator);
789 
790  // Create a new file using the default property lists.
792 
793  // Create a dataset with type T points
794  DataSet dataset = file.createDataSet<T>(DATASET_NAME, DataSpace::From(vec));
795 
796  dataset.write(vec);
797 
798  typename std::vector<T> result;
799 
800  dataset.read(result);
801 
802  BOOST_CHECK_EQUAL(vec.size(), x_size);
803  BOOST_CHECK_EQUAL(result.size(), x_size);
804 
805  BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(),
806  vec.begin(), vec.end());
807 }
809  readWriteVectorTest<T>();
810 }
811 
812 template <typename T>
814  using namespace HighFive;
815 
816  std::ostringstream filename;
817  filename << "h5_rw_arr_" << typeid(T).name() << "_test.h5";
818 
819  const size_t x_size = 800;
820  const std::string DATASET_NAME("dset");
821  typename std::array<T, x_size> vec;
822  ContentGenerate<T> generator;
823  std::generate(vec.begin(), vec.end(), generator);
824 
825  // Create a new file using the default property lists.
827 
828  // Create a dataset with type T points
829  DataSet dataset = file.createDataSet<T>(DATASET_NAME, DataSpace::From(vec));
830 
831  dataset.write(vec);
832 
833  typename std::array<T, x_size> result;
834 
835  dataset.read(result);
836 
837  BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(),
838  vec.begin(), vec.end());
839 
840  typename std::array<T, 1> tooSmall;
841  BOOST_CHECK_THROW(dataset.read(tooSmall), DataSpaceException);
842 }
844  readWriteArrayTest<T>();
845 }
846 
847 template <typename T>
849  using namespace HighFive;
850 
851  std::ostringstream filename;
852  filename << "h5_rw_attribute_vec_" << typeid(T).name() << "_test.h5";
853 
854  std::srand((unsigned int)std::time(0));
855  const size_t x_size = 25;
856  const std::string DATASET_NAME("dset");
857  typename std::vector<T> vec;
858 
859  // Create a new file using the default property lists.
861 
862  vec.resize(x_size);
863  ContentGenerate<T> generator;
864  std::generate(vec.begin(), vec.end(), generator);
865 
866  {
867  // Create a dummy group to annotate with an attribute
868  Group g = file.createGroup("dummy_group");
869 
870  // check that no attributes are there
871  std::size_t n = g.getNumberAttributes();
872  BOOST_CHECK_EQUAL(n, 0);
873 
874  std::vector<std::string> all_attribute_names = g.listAttributeNames();
875  BOOST_CHECK_EQUAL(all_attribute_names.size(), 0);
876 
877  bool has_attribute = g.hasAttribute("my_attribute");
878  BOOST_CHECK_EQUAL(has_attribute, false);
879 
880  Attribute a1 =
881  g.createAttribute<T>("my_attribute", DataSpace::From(vec));
882  a1.write(vec);
883 
884  // check now that we effectively have an attribute listable
885  std::size_t n2 = g.getNumberAttributes();
886  BOOST_CHECK_EQUAL(n2, 1);
887 
888  has_attribute = g.hasAttribute("my_attribute");
889  BOOST_CHECK_EQUAL(has_attribute, true);
890 
891  all_attribute_names = g.listAttributeNames();
892  BOOST_CHECK_EQUAL(all_attribute_names.size(), 1);
893  BOOST_CHECK_EQUAL(all_attribute_names[0], std::string("my_attribute"));
894 
895  // Create the same attribute on a newly created dataset
896  DataSet s =
897  g.createDataSet("dummy_dataset", DataSpace(1), AtomicType<int>());
898 
899  Attribute a2 =
900  s.createAttribute<T>("my_attribute_copy", DataSpace::From(vec));
901  a2.write(vec);
902  }
903 
904  typename std::vector<T> result1, result2;
905 
906  {
907  Attribute a1_read =
908  file.getGroup("dummy_group").getAttribute("my_attribute");
909  a1_read.read(result1);
910 
911  BOOST_CHECK_EQUAL(vec.size(), x_size);
912  BOOST_CHECK_EQUAL(result1.size(), x_size);
913 
914  for (size_t i = 0; i < x_size; ++i)
915  BOOST_CHECK_EQUAL(result1[i], vec[i]);
916 
917  Attribute a2_read = file.getDataSet("/dummy_group/dummy_dataset")
918  .getAttribute("my_attribute_copy");
919  a2_read.read(result2);
920 
921  BOOST_CHECK_EQUAL(vec.size(), x_size);
922  BOOST_CHECK_EQUAL(result2.size(), x_size);
923 
924  for (size_t i = 0; i < x_size; ++i)
925  BOOST_CHECK_EQUAL(result2[i], vec[i]);
926  }
927 }
928 
929 BOOST_AUTO_TEST_CASE_TEMPLATE(ReadWriteAttributeVector, T, dataset_test_types) {
930  readWriteAttributeVectorTest<T>();
931 }
932 
933 template <typename T>
935  using namespace HighFive;
936 
937  std::ostringstream filename;
938  filename << "h5_rw_vec_2d_" << typeid(T).name() << "_test.h5";
939 
940  const size_t x_size = 10;
941  const size_t y_size = 10;
942  const std::string DATASET_NAME("dset");
943  typename std::vector<std::vector<T>> vec;
944 
945  // Create a new file using the default property lists.
947 
948  vec.resize(x_size);
949  ContentGenerate<T> generator;
950 
951  generate2D(vec, x_size, y_size, generator);
952 
953  // Create a dataset with type T points
954  DataSet dataset = file.createDataSet<T>(DATASET_NAME, DataSpace::From(vec));
955 
956  dataset.write(vec);
957 
958  typename std::vector<std::vector<T>> result;
959 
960  dataset.read(result);
961 
962  BOOST_CHECK_EQUAL(vec.size(), x_size);
963  BOOST_CHECK_EQUAL(result.size(), x_size);
964 
965  BOOST_CHECK_EQUAL(vec[0].size(), y_size);
966  BOOST_CHECK_EQUAL(result[0].size(), y_size);
967 
968  for (size_t i = 0; i < x_size; ++i) {
969  for (size_t j = 0; i < y_size; ++i) {
970  BOOST_CHECK_EQUAL(result[i][j], vec[i][j]);
971  }
972  }
973 }
974 
976  readWriteVector2DTest<T>();
977 }
978 
979 BOOST_AUTO_TEST_CASE(datasetOffset) {
980  std::string filename = "datasetOffset.h5";
981  std::string dsetname = "dset";
982  const size_t size_dataset = 20;
983 
984  File file(filename, File::ReadWrite | File::Create | File::Truncate);
985  std::vector<int> data(size_dataset);
986  DataSet ds = file.createDataSet<int>(dsetname, DataSpace::From(data));
987  ds.write(data);
988  DataSet ds_read = file.getDataSet(dsetname);
989  BOOST_CHECK(ds_read.getOffset() > 0);
990 }
991 
992 #ifdef H5_USE_BOOST
993 
994 template <typename T>
995 void MultiArray3DTest() {
996  typedef typename boost::multi_array<T, 3> MultiArray;
997 
998  std::ostringstream filename;
999  filename << "h5_rw_multiarray_" << typeid(T).name() << "_test.h5";
1000 
1001  const size_t size_x = 10, size_y = 10, size_z = 10;
1002  const std::string DATASET_NAME("dset");
1003  MultiArray array(boost::extents[size_x][size_y][size_z]);
1004 
1005  ContentGenerate<T> generator;
1006  std::generate(array.data(), array.data() + array.num_elements(), generator);
1007 
1008  // Create a new file using the default property lists.
1009  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
1010 
1011  DataSet dataset =
1012  file.createDataSet<T>(DATASET_NAME, DataSpace::From(array));
1013 
1014  dataset.write(array);
1015 
1016  // read it back
1017  MultiArray result;
1018 
1019  dataset.read(result);
1020 
1021  for (size_t i = 0; i < size_x; ++i) {
1022  for (size_t j = 0; j < size_y; ++j) {
1023  for (size_t k = 0; k < size_z; ++k) {
1024  BOOST_CHECK_EQUAL(array[i][j][k], result[i][j][k]);
1025  }
1026  }
1027  }
1028 }
1029 
1031  MultiArray3DTest<T>();
1032 }
1033 
1034 template <typename T>
1035 void ublas_matrix_Test() {
1036  typedef typename boost::numeric::ublas::matrix<T> Matrix;
1037 
1038  std::ostringstream filename;
1039  filename << "h5_rw_multiarray_" << typeid(T).name() << "_test.h5";
1040 
1041  const size_t size_x = 10, size_y = 10;
1042  const std::string DATASET_NAME("dset");
1043 
1044  Matrix mat(size_x, size_y);
1045 
1046  ContentGenerate<T> generator;
1047  for (std::size_t i = 0; i < mat.size1(); ++i) {
1048  for (std::size_t j = 0; j < mat.size2(); ++j) {
1049  mat(i, j) = generator();
1050  }
1051  }
1052 
1053  // Create a new file using the default property lists.
1054  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
1055 
1056  DataSet dataset = file.createDataSet<T>(DATASET_NAME, DataSpace::From(mat));
1057 
1058  dataset.write(mat);
1059 
1060  // read it back
1061  Matrix result;
1062 
1063  dataset.read(result);
1064 
1065  for (size_t i = 0; i < size_x; ++i) {
1066  for (size_t j = 0; j < size_y; ++j) {
1067  BOOST_CHECK_EQUAL(mat(i, j), result(i, j));
1068  }
1069  }
1070 }
1071 
1073  ublas_matrix_Test<T>();
1074 }
1075 
1076 #endif
1077 
1078 template <typename T>
1080  typedef typename std::vector<T> Vector;
1081 
1082  std::ostringstream filename;
1083  filename << "h5_rw_select_test_" << typeid(T).name() << "_test.h5";
1084 
1085  const size_t size_x = 10;
1086  const size_t offset_x = 2, count_x = 5;
1087 
1088  const std::string DATASET_NAME("dset");
1089 
1090  Vector values(size_x);
1091 
1092  ContentGenerate<T> generator;
1093  std::generate(values.begin(), values.end(), generator);
1094 
1095  // Create a new file using the default property lists.
1096  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
1097 
1098  DataSet dataset =
1099  file.createDataSet<T>(DATASET_NAME, DataSpace::From(values));
1100 
1101  dataset.write(values);
1102 
1103  file.flush();
1104 
1105  // select slice
1106  {
1107  // read it back
1108  Vector result;
1109  std::vector<size_t> offset{offset_x};
1110  std::vector<size_t> size{count_x};
1111 
1112  Selection slice = dataset.select(offset, size);
1113 
1114  BOOST_CHECK_EQUAL(slice.getSpace().getDimensions()[0], size_x);
1115  BOOST_CHECK_EQUAL(slice.getMemSpace().getDimensions()[0], count_x);
1116 
1117  slice.read(result);
1118 
1119  BOOST_CHECK_EQUAL(result.size(), 5);
1120 
1121  for (size_t i = 0; i < count_x; ++i) {
1122  BOOST_CHECK_EQUAL(values[i + offset_x], result[i]);
1123  }
1124  }
1125 
1126  // select cherry pick
1127  {
1128  // read it back
1129  Vector result;
1130  std::vector<size_t> ids{1,3,4,7};
1131 
1132  Selection slice = dataset.select(ElementSet(ids));
1133 
1134  BOOST_CHECK_EQUAL(slice.getSpace().getDimensions()[0], size_x);
1135  BOOST_CHECK_EQUAL(slice.getMemSpace().getDimensions()[0], ids.size());
1136 
1137  slice.read(result);
1138 
1139  BOOST_CHECK_EQUAL(result.size(), ids.size());
1140 
1141  for (size_t i = 0; i < ids.size(); ++i) {
1142  const std::size_t id = ids[i];
1143  BOOST_CHECK_EQUAL(values[id], result[i]);
1144  }
1145  }
1146 }
1147 
1149  selectionArraySimpleTest<T>();
1150 }
1151 
1152 template <typename T>
1154  std::ostringstream filename;
1155  filename << "h5_rw_select_column_test_" << typeid(T).name() << "_test.h5";
1156 
1157  const size_t x_size = 10;
1158  const size_t y_size = 7;
1159 
1160  const std::string DATASET_NAME("dset");
1161 
1162  T values[x_size][y_size];
1163 
1164  ContentGenerate<T> generator;
1165  generate2D(values, x_size, y_size, generator);
1166 
1167  // Create a new file using the default property lists.
1168  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
1169 
1170  // Create the data space for the dataset.
1171  std::vector<size_t> dims{x_size, y_size};
1172 
1173  DataSpace dataspace(dims);
1174  // Create a dataset with arbitrary type
1175  DataSet dataset = file.createDataSet<T>(DATASET_NAME, dataspace);
1176 
1177  dataset.write(values);
1178 
1179  file.flush();
1180 
1181  std::vector<size_t> columns{1, 3, 5};
1182 
1183  Selection slice = dataset.select(columns);
1184  T result[x_size][3];
1185  slice.read(result);
1186 
1187  BOOST_CHECK_EQUAL(slice.getSpace().getDimensions()[0], x_size);
1188  BOOST_CHECK_EQUAL(slice.getMemSpace().getDimensions()[0], x_size);
1189 
1190  for (size_t i = 0; i < 3; ++i)
1191  for (size_t j = 0; j < x_size; ++j)
1192  BOOST_CHECK_EQUAL(result[j][i], values[j][columns[i]]);
1193 }
1194 
1196  columnSelectionTest<T>();
1197 }
1198 
1199 template <typename T>
1201  std::ostringstream filename;
1202  filename << "h5_rw_attribute_scalar_rw" << typeid(T).name() << "_test.h5";
1203 
1204  File h5file(filename.str(),
1205  File::ReadWrite | File::Create | File::Truncate);
1206 
1207  ContentGenerate<T> generator;
1208 
1209  const T attribute_value(generator());
1210 
1211  Group g = h5file.createGroup("metadata");
1212 
1213  bool family_exist = g.hasAttribute("family");
1214  BOOST_CHECK_EQUAL(family_exist, false);
1215 
1216  // write a scalar attribute
1217  {
1218  T out(attribute_value);
1219  Attribute att = g.createAttribute<T>("family", DataSpace::From(out));
1220  att.write(out);
1221  }
1222 
1223  h5file.flush();
1224 
1225  // test if attribute exist
1226  family_exist = g.hasAttribute("family");
1227  BOOST_CHECK_EQUAL(family_exist, true);
1228 
1229  // read back a scalar attribute
1230  {
1231  T res;
1232  Attribute att = g.getAttribute("family");
1233  att.read(res);
1234  BOOST_CHECK_EQUAL(res, attribute_value);
1235  }
1236 }
1237 
1239  attribute_scalar_rw<T>();
1240 }
1241 
1242 // regression test https://github.com/BlueBrain/HighFive/issues/98
1243 BOOST_AUTO_TEST_CASE(HighFiveOutofDimension) {
1244  std::string filename("h5_rw_reg_zero_dim_test.h5");
1245 
1246  const std::string DATASET_NAME("dset");
1247 
1248  {
1249  // Create a new file using the default property lists.
1250  File file(filename, File::ReadWrite | File::Create | File::Truncate);
1251 
1252  DataSpace d_null(DataSpace::DataspaceType::datascape_null);
1253 
1254  DataSet d1 = file.createDataSet<double>(DATASET_NAME, d_null);
1255 
1256  file.flush();
1257 
1258  DataSpace recovered_d1 = d1.getSpace();
1259 
1260  auto ndim = recovered_d1.getNumberDimensions();
1261  BOOST_CHECK_EQUAL(ndim, 0);
1262 
1263  auto dims = recovered_d1.getDimensions();
1264  BOOST_CHECK_EQUAL(dims.size(), 0);
1265  }
1266 }
1267 
1268 template <typename T>
1270  std::ostringstream filename;
1271  filename << "h5_rw_deflate_" << typeid(T).name() << "_test.h5";
1272  const std::string DATASET_NAME("dset");
1273  const size_t x_size = 128;
1274  const size_t y_size = 32;
1275  const size_t x_chunk = 16;
1276  const size_t y_chunk = 16;
1277 
1278  const int deflate_level = 9;
1279 
1280  T array[x_size][y_size];
1281 
1282  // write a compressed file
1283  {
1284  File file(filename.str(), File::ReadWrite | File::Create | File::Truncate);
1285 
1286  // Create the data space for the dataset.
1287  std::vector<size_t> dims{x_size, y_size};
1288 
1289  DataSpace dataspace(dims);
1290 
1291  // Use chunking
1292  DataSetCreateProps props;
1293  props.add(Chunking(std::vector<hsize_t>{x_chunk, y_chunk}));
1294 
1295  // Enable shuffle
1296  props.add(Shuffle());
1297 
1298  // Enable deflate
1299  props.add(Deflate(deflate_level));
1300 
1301  // Create a dataset with arbitrary type
1302  DataSet dataset = file.createDataSet<T>(DATASET_NAME, dataspace, props);
1303 
1304  ContentGenerate<T> generator;
1305  generate2D(array, x_size, y_size, generator);
1306 
1307  dataset.write(array);
1308 
1309  file.flush();
1310  }
1311 
1312  // read it back
1313  {
1314  File file_read(filename.str(), File::ReadOnly);
1315  DataSet dataset_read = file_read.getDataSet("/" + DATASET_NAME);
1316 
1317  T result[x_size][y_size];
1318 
1319  dataset_read.read(result);
1320 
1321  for (size_t i = 0; i < x_size; ++i) {
1322  for (size_t j = 0; i < y_size; ++i) {
1323  BOOST_CHECK_EQUAL(result[i][j], array[i][j]);
1324  }
1325  }
1326  }
1327 }
1328 
1330  readWriteShuffleDeflateTest<T>();
1331 }
1332 
1333 // Broadcasting is supported
1334 BOOST_AUTO_TEST_CASE(ReadInBroadcastDims) {
1335 
1336  const std::string FILE_NAME("h5_missmatch1_dset.h5");
1337  const std::string DATASET_NAME("dset");
1338 
1339  // Create a new file using the default property lists.
1340  File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
1341 
1342  // Create the data space for the dataset.
1343  std::vector<size_t> dims_a{1,3};
1344  std::vector<size_t> dims_b{3,1};
1345 
1346  // 1D input / output vectors
1347  std::vector<double> some_data{5.0, 6.0, 7.0};
1348  std::vector<double> data_a;
1349  std::vector<double> data_b;
1350 
1351  DataSpace dataspace_a(dims_a);
1352  DataSpace dataspace_b(dims_b);
1353 
1354  // Create a dataset with double precision floating points
1355  DataSet dataset_a = file.createDataSet(DATASET_NAME + "_a", dataspace_a,
1356  AtomicType<double>());
1357  DataSet dataset_b = file.createDataSet(DATASET_NAME + "_b", dataspace_b,
1358  AtomicType<double>());
1359 
1360  dataset_a.write(some_data);
1361  dataset_b.write(some_data);
1362 
1363  DataSet out_a = file.getDataSet(DATASET_NAME + "_a");
1364  DataSet out_b = file.getDataSet(DATASET_NAME + "_b");
1365 
1366  out_a.read(data_a);
1367  out_b.read(data_b);
1368 
1369  BOOST_CHECK_EQUAL_COLLECTIONS(
1370  data_a.begin(), data_a.end(),
1371  some_data.begin(), some_data.end());
1372 
1373  BOOST_CHECK_EQUAL_COLLECTIONS(
1374  data_b.begin(), data_b.end(),
1375  some_data.begin(), some_data.end());
1376 }
size_x
const size_t size_x
Definition: boost_multi_array_2D.cpp:21
ContentGenerate< std::string >::ContentGenerate
ContentGenerate()
Definition: tests_high_five_base.cpp:106
HighFive::Selection
Selection: represent a view on a slice/part of a dataset.
Definition: H5Selection.hpp:27
HighFive::DataSet::getDataType
DataType getDataType() const
getDataType
Definition: H5DataSet_misc.hpp:40
H5Utility.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HighFiveBasic)
Definition: tests_high_five_base.cpp:122
ContentGenerate< char >
Definition: tests_high_five_base.cpp:91
dataset_test_types
boost::mpl::list< int, unsigned int, long, unsigned long, unsigned char, char, float, double, std::string > dataset_test_types
Definition: tests_high_five_base.cpp:48
ContentGenerate::ContentGenerate
ContentGenerate()
Definition: tests_high_five_base.cpp:73
HighFive::NodeTraits::createGroup
Group createGroup(const std::string &group_name)
create a new group with the name group_name
Definition: H5Node_traits_misc.hpp:97
HighFive::DataSpace::getDimensions
std::vector< size_t > getDimensions() const
getDimensions
Definition: H5Dataspace_misc.hpp:104
readWriteShuffleDeflateTest
void readWriteShuffleDeflateTest()
Definition: tests_high_five_base.cpp:1269
size_dataset
const size_t size_dataset
Definition: read_write_vector_dataset.cpp:21
H5File.hpp
HighFive::Attribute::read
void read(T &array) const
Definition: H5Attribute_misc.hpp:58
HighFive::AnnotateTraits::getNumberAttributes
size_t getNumberAttributes() const
return the number of attributes of the node / group
Definition: H5Annotate_traits_misc.hpp:77
HighFive::NodeTraits::getDataSet
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
Definition: H5Node_traits_misc.hpp:84
ContentGenerate::_init
T _init
Definition: tests_high_five_base.cpp:81
readWriteVectorTest
void readWriteVectorTest()
Definition: tests_high_five_base.cpp:777
ContentGenerate< char >::_init
char _init
Definition: tests_high_five_base.cpp:101
HighFive::SilenceHDF5
Utility class to disable HDF5 stack printing inside a scope.
Definition: H5Utility.hpp:18
HighFive::AnnotateTraits::createAttribute
Attribute createAttribute(const std::string &attribute_name, const DataSpace &space, const DataType &type)
create a new attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:29
numerical_test_types
boost::mpl::list< int, unsigned int, long, unsigned long, unsigned char, char, float, double, long long, unsigned long long, complex > numerical_test_types
Definition: tests_high_five_base.cpp:45
HighFive::Object::getId
hid_t getId() const
getId
Definition: H5Object_misc.hpp:51
HighFive::SliceTraits::read
void read(T &array) const
Definition: H5Slice_traits_misc.hpp:149
NULL
#define NULL
Definition: mydefs.hpp:141
readWriteVector2DTest
void readWriteVector2DTest()
Definition: tests_high_five_base.cpp:934
HighFive::AnnotateTraits::hasAttribute
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition: H5Annotate_traits_misc.hpp:109
ContentGenerate< char >::ContentGenerate
ContentGenerate()
Definition: tests_high_five_base.cpp:92
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
H5DataSet.hpp
H5DataSpace.hpp
readWrite2DArrayTest
void readWrite2DArrayTest()
Definition: tests_high_five_base.cpp:687
complex
std::complex< double > complex
Definition: tests_high_five_base.cpp:39
HighFive::NodeTraits::getNumberObjects
size_t getNumberObjects() const
return the number of leaf objects of the node / group
Definition: H5Node_traits_misc.hpp:121
HighFive::SliceTraits::select
Selection select(const std::vector< size_t > &offset, const std::vector< size_t > &count, const std::vector< size_t > &stride=std::vector< size_t >()) const
Definition: H5Slice_traits_misc.hpp:66
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:210
H5Group.hpp
BOOST_AUTO_TEST_CASE_TEMPLATE
BOOST_AUTO_TEST_CASE_TEMPLATE(ReadWrite2DArray, T, numerical_test_types)
Definition: tests_high_five_base.cpp:723
ContentGenerate
Definition: tests_high_five_base.cpp:72
HighFive::ElementSet
Definition: H5Slice_traits.hpp:28
ContentGenerate< char >::operator()
char operator()()
Definition: tests_high_five_base.cpp:94
HighFive::DataSetCreateProps
Definition: H5PropertyList.hpp:67
HighFive::Deflate
Definition: H5PropertyList.hpp:95
HighFive::DataSet::getSpace
DataSpace getSpace() const
getSpace
Definition: H5DataSet_misc.hpp:46
attribute_scalar_rw
void attribute_scalar_rw()
Definition: tests_high_five_base.cpp:1200
ContentGenerate< std::string >::operator()
std::string operator()()
Definition: tests_high_five_base.cpp:108
HighFive::Group
Definition: H5Group.hpp:20
HighFive::File::Create
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40
HighFive::Chunking
Definition: H5PropertyList.hpp:77
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60
HighFive::Chunking::getDimensions
const std::vector< hsize_t > & getDimensions() const
Definition: H5PropertyList.hpp:87
scripts.create_png.values
values
Definition: create_png.py:26
HighFive::DataSetException
Exception specific to HighFive DataSet interface.
Definition: H5Exception.hpp:114
HighFive::NodeTraits::getGroup
Group getGroup(const std::string &group_name) const
open an existing group with the name group_name
Definition: H5Node_traits_misc.hpp:110
HighFive::Properties::add
void add(const Property &property)
Definition: H5PropertyList_misc.hpp:51
selectionArraySimpleTest
void selectionArraySimpleTest()
Definition: tests_high_five_base.cpp:1079
FILE_NAME
const std::string FILE_NAME("boost_multiarray_example.h5")
HighFive::File
File class.
Definition: H5File.hpp:25
HighFive::DataSetAccessProps
Definition: H5PropertyList.hpp:72
HighFive::AtomicType
create an HDF5 DataType from a C++ type
Definition: H5DataType.hpp:41
HighFive::Selection::getMemSpace
DataSpace getMemSpace() const
getMemSpace
Definition: H5Selection_misc.hpp:23
HighFive::FileException
Exception specific to HighFive File interface.
Definition: H5Exception.hpp:90
readWriteAttributeVectorTest
void readWriteAttributeVectorTest()
Definition: tests_high_five_base.cpp:848
HighFive::Attribute
Definition: H5Attribute.hpp:23
file
FILE * file
Definition: arithmeticencoder.cpp:77
HighFive::AnnotateTraits::listAttributeNames
std::vector< std::string > listAttributeNames() const
list all attribute name of the node / group
Definition: H5Annotate_traits_misc.hpp:88
HighFive::DataSet::getOffset
size_t getOffset() const
getOffset
Definition: H5DataSet_misc.hpp:57
floating_numerics_test_types
boost::mpl::list< float, double > floating_numerics_test_types
Definition: tests_high_five_base.cpp:41
ContentGenerate::operator()
T operator()()
Definition: tests_high_five_base.cpp:75
HighFive::AnnotateTraits::getAttribute
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:64
HighFive::DataSet::resize
void resize(const std::vector< size_t > &dims)
Change the size of the dataset.
Definition: H5DataSet_misc.hpp:66
std
Definition: HalfEdge.hpp:124
HighFive::DataSpace
Definition: H5DataSpace.hpp:30
scripts.create_png.ds
ds
Definition: create_png.py:15
HighFive::Shuffle
Definition: H5PropertyList.hpp:106
HighFive::Selection::getSpace
DataSpace getSpace() const
getSpace
Definition: H5Selection_misc.hpp:21
scripts.create_png.y_size
y_size
Definition: create_png.py:21
first
void first(int id)
Definition: example.cpp:7
HighFive::File::flush
void flush()
flush
Definition: H5File_misc.hpp:83
HighFive::File::ReadWrite
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
readWriteArrayTest
void readWriteArrayTest()
Definition: tests_high_five_base.cpp:813
HighFive::NodeTraits::createDataSet
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps(), const DataSetAccessProps &accessProps=DataSetAccessProps())
createDataSet Create a new dataset in the current file of datatype type and of size space
Definition: H5Node_traits_misc.hpp:36
HighFive::DataSpace::getNumberDimensions
size_t getNumberDimensions() const
getNumberDimensions
Definition: H5Dataspace_misc.hpp:95
HighFive::DataSet
Definition: H5DataSet.hpp:27
scripts.create_png.x_size
x_size
Definition: create_png.py:20
generate2D
void generate2D(T *table, size_t x, size_t y, Func &func)
Definition: tests_high_five_base.cpp:51
HighFive::File::Truncate
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
columnSelectionTest
void columnSelectionTest()
Definition: tests_high_five_base.cpp:1153
HighFive
Definition: H5Annotate_traits.hpp:14
HighFive::Caching
Definition: H5PropertyList.hpp:118
HighFive::DataSpaceException
Exception specific to HighFive DataSpace interface.
Definition: H5Exception.hpp:98
HighFive::Attribute::write
void write(const T &buffer)
Definition: H5Attribute_misc.hpp:93
DATASET_NAME
const std::string DATASET_NAME("dset")
HighFive::NodeTraits::listObjectNames
std::vector< std::string > listObjectNames() const
list all leaf objects name of the node / group
Definition: H5Node_traits_misc.hpp:152
size_y
const size_t size_y
Definition: boost_multi_array_2D.cpp:22


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:25