ATLAS Offline Software
Loading...
Searching...
No Matches
test-half-precision.cxx File Reference
#include "HDF5Utils/Writer.h"
#include <random>
Include dependency graph for test-half-precision.cxx:

Go to the source code of this file.

Classes

struct  out_t

Macros

#define ADD(NAME)
#define HADD(NAME)

Typedefs

using consumer_t = H5Utils::Consumers<const out_t&>
using mt_t = decltype(std::mt19937())

Functions

consumer_t getFullConsumers ()
consumer_t getHalfConsumers ()
std::vector< out_tgetOutputs (size_t length, mt_t &rand)
void fill (H5::Group &out_file, size_t iterations)
int main (int nargs, char *argv[])

Macro Definition Documentation

◆ ADD

#define ADD ( NAME)
Value:
consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0)

Definition at line 19 of file test-half-precision.cxx.

◆ HADD

#define HADD ( NAME)
Value:
consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0, h)
Header file for AthHistogramAlgorithm.

Definition at line 20 of file test-half-precision.cxx.

Typedef Documentation

◆ consumer_t

Definition at line 17 of file test-half-precision.cxx.

◆ mt_t

using mt_t = decltype(std::mt19937())

Definition at line 42 of file test-half-precision.cxx.

Function Documentation

◆ fill()

void fill ( H5::Group & out_file,
size_t iterations )

Definition at line 64 of file test-half-precision.cxx.

64 {
65
66 const int deflate = 7;
67 const int max_width = 10;
68 std::mt19937 random(42);
69
70 // compare outputs
72 writer_t::configuration_type config;
73 config.name = "full";
74 config.extent = {max_width};
75 config.deflate = deflate;
76 writer_t full(out_file, getFullConsumers(), config);
77 config.name = "half";
78 writer_t half(out_file, getHalfConsumers(), config);
79 std::uniform_int_distribution<int> width(0, max_width+1);
80 for (size_t n = 0; n < iterations; n++) {
81 auto out = getOutputs(width(random), random);
82 full.fill(out);
83 half.fill(out);
84 }
85}
const double width
Writer.
Definition Writer.h:350
const int deflate
Definition defaults.h:10
consumer_t getHalfConsumers()
std::vector< out_t > getOutputs(size_t length, mt_t &rand)
consumer_t getFullConsumers()

◆ getFullConsumers()

consumer_t getFullConsumers ( )

Definition at line 23 of file test-half-precision.cxx.

23 {
24 consumer_t consumers;
25 ADD(ftype);
26 ADD(dtype);
27 ADD(btype);
28 return consumers;
29}
#define ADD(NAME)
H5Utils::Consumers< const out_t & > consumer_t

◆ getHalfConsumers()

consumer_t getHalfConsumers ( )

Definition at line 30 of file test-half-precision.cxx.

30 {
31 consumer_t consumers;
33 HADD(ftype);
34 HADD(dtype);
35 ADD(btype);
36 return consumers;
37}
#define HADD(NAME)

◆ getOutputs()

std::vector< out_t > getOutputs ( size_t length,
mt_t & rand )

Definition at line 44 of file test-half-precision.cxx.

44 {
45 std::vector<out_t> outvec;
46 std::uniform_int_distribution<int> exponent(-10, 2);
47 std::uniform_real_distribution<float> man(-0.0001, 0.0001);
48 std::uniform_int_distribution<short> booldist(0, 1);
49 for (size_t n = 0; n < length; n++) {
50 out_t out;
51 double value = std::exp2(exponent(rand)) * (1 + man(rand));
52 out.dtype = value;
53 out.ftype = value;
54 out.btype = booldist(rand);
55 outvec.push_back(out);
56 }
57 return outvec;
58}
double length(const pvec &v)

◆ main()

int main ( int nargs,
char * argv[] )

Definition at line 87 of file test-half-precision.cxx.

87 {
88 H5::H5File out_file("output.h5", H5F_ACC_TRUNC);
89 size_t iterations = 1;
90 if (nargs > 2) {
91 return 1;
92 }
93 if (nargs > 1) iterations = std::atoi(argv[1]);
94 fill(out_file, iterations);
95 return 0;
96}
void fill(H5::Group &out_file, size_t iterations)