-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for half-precision (16-bit) floating-point datasets (#587)
* Adding support for half-precision floating-point datasets. Depends on Half library (http://half.sourceforge.net/)
- Loading branch information
Showing
7 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c), 2022, Blue Brain Project | ||
* | ||
* Distributed under the Boost Software License, Version 1.0. | ||
* (See accompanying file LICENSE_1_0.txt or copy at | ||
* http://www.boost.org/LICENSE_1_0.txt) | ||
* | ||
*/ | ||
|
||
#ifdef H5_USE_HALF_FLOAT | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <highfive/H5DataSet.hpp> | ||
#include <highfive/H5DataSpace.hpp> | ||
#include <highfive/H5File.hpp> | ||
|
||
const std::string FILE_NAME("create_dataset_half_float_example.h5"); | ||
const std::string DATASET_NAME("dset"); | ||
|
||
// Create a dataset name "dset", size 4x6, and type float16_t (i.e., 16-bit half-precision | ||
// floating-point format) | ||
// | ||
int main(void) { | ||
using namespace HighFive; | ||
try { | ||
// Create a new file using the default property lists. | ||
File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate); | ||
|
||
// Define the size of our dataset: 4x6 | ||
std::vector<size_t> dims{4, 6}; | ||
|
||
// Create the dataset | ||
DataSet dataset = file.createDataSet<float16_t>(DATASET_NAME, DataSpace(dims)); | ||
|
||
std::vector<std::vector<float16_t>> data; | ||
for (size_t i = 0; i < 4; ++i) { | ||
data.emplace_back(); | ||
for (size_t j = 0; j < 6; ++j) | ||
data[i].emplace_back((i + 1) * (j + 1)); | ||
} | ||
|
||
// write it | ||
dataset.write(data); | ||
|
||
} catch (Exception& err) { | ||
// catch and print any HDF5 error | ||
std::cerr << err.what() << std::endl; | ||
} | ||
|
||
return 0; // successfully terminated | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters