Fleet  0.0.9
Inference in the LOT
RuntimeCounter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <atomic>
4 #include <vector>
5 #include "Instruction.h"
6 #include "Miscellaneous.h"
7 
17 public:
18  using T = unsigned long;
19 
20  // counts of each type of primitive
21  std::vector<T> builtin_count;
22  std::vector<T> primitive_count;
23 
24  T total; // overall count of everything
25 
26  // we defaulty initialize these
27  RuntimeCounter() : builtin_count(16,0), primitive_count(16,0), total(0) { }
28 
33  void increment(Instruction& i, T count=1) {
34  //CERR ">>" TAB builtin_count.size() TAB primitive_count.size() TAB i TAB this ENDL;
35  total += count;
36 // if(i.is<BuiltinOp>()) {
37 // // this general vector increment lives in miscellaneous
38 // ::increment(builtin_count, (size_t)i.as<BuiltinOp>(), (T)count);
39 // }
40 // else {
41 // ::increment(primitive_count, (size_t)i.as<PrimitiveOp>(), (T)count);
42 // }
43  }
44 
50  // we'll go in decreasing order so we don't have to resize each time
51 
52  // FOR NOW:
53  total += rc.total;
54 
55 // for(size_t i=rc.builtin_count.size()-1; i != 0; i--) {
56 // ::increment(builtin_count, i, (T)rc.builtin_count[i]);
57 // }
58 // for(size_t i=rc.primitive_count.size()-1; i != 0; i--) {
59 // ::increment(primitive_count, i, (T)rc.primitive_count[i]);
60 // }
61  }
62 
68  // retrieve the count corresponding to some grammar rule
69  size_t get(Instruction& i) {
70  throw NotImplementedError();
71 // if(i.is<BuiltinOp>()) {
72 // auto idx = (size_t)i.as<BuiltinOp>();
73 // if(idx >= builtin_count.size()) return 0;
74 // else return builtin_count[idx];
75 // }
76 // else {
77 // auto idx = (size_t)i.as<PrimitiveOp>();
78 // if(idx >= primitive_count.size()) return 0;
79 // else return primitive_count[idx];
80 // }
81  }
82 
83 
84 
89  std::string string() const {
90  std::string out = "< ";
91  out += str(total);
92 // for(auto& n : builtin_count) {
93 // out += str(n) + " ";
94 // }
95 // out += " : ";
96 // for(auto& n : primitive_count) {
97 // out += str(n) + " ";
98 // }
99  out += ">";
100  return out;
101  }
102 
103 };
104 
105 
106 
108 // Just some functions to help with runtime calculations. Note that these re-run the data,
109 // so if you are otherwise computing the likelihood, this would be inefficient.
111 
112 
113 template<typename HYP>
114 RuntimeCounter runtime(HYP& h, typename HYP::datum_t& di) {
115  return h.callOne_vms(di.input).runtime_counter;
116 }
117 
118 template<typename HYP>
119 RuntimeCounter runtime(HYP& h, typename HYP::data_t& d) {
120  RuntimeCounter rt;
121  for(auto& di: d) {
122  rt.increment(runtime(h,di));
123  }
124  return rt;
125 }
126 
void increment(RuntimeCounter &rc)
Add the results of another runtime counter.
Definition: RuntimeCounter.h:49
std::string string() const
Display a runtime counter – NOTE This may not display all zeros if instructions have not been run...
Definition: RuntimeCounter.h:89
RuntimeCounter()
Definition: RuntimeCounter.h:27
T total
Definition: RuntimeCounter.h:24
size_t count(const std::string &str, const std::string &sub)
Definition: Strings.h:153
RuntimeCounter runtime(HYP &h, typename HYP::datum_t &di)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
Definition: RuntimeCounter.h:114
std::vector< T > primitive_count
Definition: RuntimeCounter.h:22
void increment(Instruction &i, T count=1)
Add count number of items to this instruction&#39;s count.
Definition: RuntimeCounter.h:33
Definition: Instruction.h:20
std::vector< T > builtin_count
Definition: RuntimeCounter.h:21
f here is a point to a void(VirtualMachineState_t* vms, int arg), where arg is just a supplemental ar...
std::string str(BindingTree *t)
Definition: BindingTree.h:195
unsigned long T
Definition: RuntimeCounter.h:18
Definition: Errors.h:7
Definition: RuntimeCounter.h:16