boost_ublas_double.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse
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 #include <iostream>
10 
11 #undef H5_USE_BOOST
12 #define H5_USE_BOOST
13 
14 #include <boost/numeric/ublas/io.hpp>
15 #include <boost/numeric/ublas/matrix.hpp>
16 #include <highfive/H5File.hpp>
17 
18 using namespace HighFive;
19 
20 const std::string FILE_NAME("boost_ublas_double.h5");
21 const std::string DATASET_NAME("dset");
22 
23 const size_t size_x = 10;
24 const size_t size_y = 10;
25 
26 int main(void) {
27 
28  try {
29  typedef typename boost::numeric::ublas::matrix<double> Matrix;
30 
31  // create a 10x10 matrix
32  Matrix mat(size_x, size_y);
33 
34  // fill it
35  for (std::size_t i = 0; i < size_x; ++i) {
36  mat(i, i) = i;
37  }
38 
39  // Create a new HDF5 file
41 
42  // create a new dataset with the 10x10 Matrix dimension
43  DataSet dataset =
44  file.createDataSet<double>(DATASET_NAME, DataSpace::From(mat));
45 
46  // write it
47  dataset.write(mat);
48 
49  // now, let read it back
50  Matrix result;
51  dataset.read(result);
52 
53  // print what we read
54  std::cout << "Matrix result:\n" << result << std::endl;
55 
56  } catch (Exception& err) {
57  // catch and print any HDF5 error
58  std::cerr << err.what() << std::endl;
59  }
60 
61  return 0; // successfully terminated
62 }
main
int main(void)
Definition: boost_ublas_double.cpp:26
size_x
const size_t size_x
Definition: boost_ublas_double.cpp:23
H5File.hpp
DATASET_NAME
const std::string DATASET_NAME("dset")
HighFive::SliceTraits::read
void read(T &array) const
Definition: H5Slice_traits_misc.hpp:149
size_y
const size_t size_y
Definition: boost_ublas_double.cpp:24
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:210
HighFive::File::Create
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40
HighFive::File
File class.
Definition: H5File.hpp:25
file
FILE * file
Definition: arithmeticencoder.cpp:77
HighFive::Exception::what
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
HighFive::Exception
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
HighFive::File::ReadWrite
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
HighFive::DataSet
Definition: H5DataSet.hpp:27
HighFive::File::Truncate
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
HighFive
Definition: H5Annotate_traits.hpp:14
FILE_NAME
const std::string FILE_NAME("boost_ublas_double.h5")


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:22