Medusa  1.1
Coordinate Free Mehless Method implementation
printShapes.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_OPERATORS_PRINTSHAPES_HPP_
2 #define MEDUSA_BITS_OPERATORS_PRINTSHAPES_HPP_
3 
9 #include "shape_flags.hpp"
10 #include <iostream>
12 
13 namespace mm {
14 namespace shapes_internal {
15 
17 // recursive case
18 template <typename OpFamilies, size_t i>
19 struct name_printer {
20  static void print(std::ostream& os) {
21  name_printer<OpFamilies, i-1>::print(os);
22  os << ", " << std::tuple_element<i-1, OpFamilies>::type::name();
23  }
24 };
25 
26 // base case 1 element
27 template <typename OpFamilies>
28 struct name_printer<OpFamilies, 1> {
29  static void print(std::ostream& os) {
30  os << std::tuple_element<0, OpFamilies>::type::name();
31  }
32 };
33 
34 // base case 0 element
35 template <typename OpFamilies>
36 struct name_printer<OpFamilies, 0> {
37  static void print(std::ostream& os) {
38  os << "()";
39  }
40 };
41 
42 // recursive case
43 template <typename shape_storage_t, size_t op>
44 struct shape_printer {
45  static void print(std::ostream& os, const shape_storage_t& storage) {
46  shape_printer<shape_storage_t, op-1>::print(os, storage);
47  int N = std::min(storage.size(), 5);
48  using el = typename std::tuple_element<
49  op-1, typename shape_storage_t::op_families_tuple>::type;
50  os << " " << el::type_name() << " (family #" << op-1 << ") shape sample:\n";
51  for (int c = 0; c < el::size(); ++c) {
52  os << " Operator #" << c << ":\n";
53  for (int i = 0; i < N; ++i) {
54  os << " node " << i << ":";
55  for (int j = 0; j < storage.supportSize(i); ++j) {
56  os << " " << storage.template get<op-1>(c, i, j);
57  }
58  os << '\n';
59  }
60  }
61  }
62 };
63 
64 // base case
65 template <typename shape_storage_t> struct shape_printer<shape_storage_t, 0> {
66  static void print(std::ostream&, const shape_storage_t&) {}
67 };
69 
71 template <typename shape_storage_t>
72 std::ostream& printShapes(const shape_storage_t& storage, std::ostream& os) {
73  os << " dimension: " << storage.dim << '\n'
74  << " domain size: " << storage.size() << '\n'
75  << " operator families = ";
76  name_printer<typename shape_storage_t::op_families_tuple,
77  shape_storage_t::num_operators>::print(os);
78  os << "\n";
79  shape_printer<shape_storage_t, shape_storage_t::num_operators>::print(os, storage);
80 
81  std::size_t memory_used = storage.memoryUsed();
82  os << " mem used total: " << mem2str(memory_used);
83  return os;
84 }
85 
86 } // namespace shapes_internal
87 } // namespace mm
88 
89 #endif // MEDUSA_BITS_OPERATORS_PRINTSHAPES_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
shape_flags.hpp
memutils.hpp
mm::shapes_internal::printShapes
std::ostream & printShapes(const shape_storage_t &storage, std::ostream &os)
Output basic info about given shape storage to os.
Definition: printShapes.hpp:72
mm::mem2str
std::string mem2str(std::size_t bytes)
Simple function to help format memory amounts for printing.
Definition: memutils.cpp:10