HPCToolkit
Metric-AExpr.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // class Prof::Metric::AExpr and derived classes
50 //
51 // An abstract expression that can represents derived expressions that
52 // are directly computed in the sense that all inputs are known at the
53 // same time (cf. incrementally computed metrics where this is not true).
54 //
55 // Assumes all sources are known when evaluation rule is invoked.
56 //
57 // Currently supported expressions are
58 // Const : double constant : leaf
59 // Var : variable with a String name : leaf
60 // Neg : negation : unary
61 // Power : power expressed in base and exponent : binary
62 // Divide : division expression : binary
63 // Minus : subtraction expression : binary
64 // Plus : addition expression : n-ary
65 // Times : multiplication expression : n-ary
66 // Min : min expression : n-ary
67 // Max : max expression : n-ary
68 // Mean : mean (arithmetic) expression : n-ary
69 // StdDev : standard deviation expression : n-ary
70 // CoefVar: coefficient of variance : n-ary
71 // RStdDev: relative standard deviation : n-ary
72 //
73 //***************************************************************************
74 
75 #ifndef prof_Prof_Metric_AExpr_hpp
76 #define prof_Prof_Metric_AExpr_hpp
77 
78 //************************ System Include Files ******************************
79 
80 #include <iostream>
81 #include <string>
82 #include <algorithm>
83 
84 //************************* User Include Files *******************************
85 
86 #include <include/gcc-attr.h>
87 
88 #include "Metric-IData.hpp"
89 #include "Metric-IDBExpr.hpp"
90 
91 #include <lib/support/NaN.h>
92 #include <lib/support/Unique.hpp>
93 #include <lib/support/StrUtil.hpp>
94 
95 
96 //************************ Forward Declarations ******************************
97 
98 //****************************************************************************
99 
100 #define epsilon (0.000001)
101 
102 namespace Prof {
103 
104 namespace Metric {
105 
106 // ----------------------------------------------------------------------
107 // class AExpr
108 // The base class for all concrete evaluation classes
109 // ----------------------------------------------------------------------
110 
111 class AExpr
112  : public IDBExpr,
113  public Unique // disable copying, for now
114 {
115  // TODO: replace AExpr** with AExprVec
116 public:
117  typedef std::vector<AExpr*> AExprVec;
118 
119  // fixme: return this with 'constexpr' after switching to std C++11
120  // static const double epsilon = 0.000001;
121 
122 public:
124  : m_numSrcVarId(Metric::IData::npos)
125  {
126  for (uint i = 0; i < maxAccums; ++i)
128  }
129 
130  virtual ~AExpr()
131  { }
132 
133  // ------------------------------------------------------------
134  //
135  // ------------------------------------------------------------
136 
137  // eval: generate a finalized value and return result
138  virtual double
139  eval(const Metric::IData& mdata) const = 0;
140 
141  // evalNF: generate non-finalized values and store results in accumulators
142  virtual double
143  evalNF(Metric::IData& mdata) const
144  {
145  double z = eval(mdata);
146  accumVar(0, mdata) = z;
147  return z;
148  }
149 
150 
151  static bool
152  isok(double x)
153  { return !(c_isnan_d(x) || c_isinf_d(x)); }
154 
155 
156  // ------------------------------------------------------------
157  // Metric::IDBExpr: exported formulas for Flat and Callers view
158  // ------------------------------------------------------------
159 
160  virtual std::string
162  { DIAG_Die(DIAG_Unimplemented); return ""; }
163 
164  virtual std::string
166  { DIAG_Die(DIAG_Unimplemented); return ""; }
167 
168  virtual std::string
170  { DIAG_Die(DIAG_Unimplemented); return ""; }
171 
172 
173  // ------------------------------------------------------------
174  // Metric::IDBExpr: primitives
175  // ------------------------------------------------------------
176 
177  virtual uint
178  accumId(int i) const
179  { return m_accumId[i]; }
180 
181  void
182  accumId(int i, uint x)
183  { m_accumId[i] = x; }
184 
185 
186  // ------------------------------------------------------------
187  // Metric::IDBExpr: primitives
188  // ------------------------------------------------------------
189 
190  virtual uint
191  numAccum() const
192  { return 1; }
193 
194 
195  // ------------------------------------------------------------
196  // Metric::IDBExpr: primitives
197  // ------------------------------------------------------------
198 
199  virtual bool
200  hasNumSrcVar() const
201  { return false; }
202 
203 
204  virtual uint
205  numSrcFxd() const
206  { DIAG_Die(DIAG_Unimplemented); return 0; }
207 
208 
209  virtual uint
210  numSrcVarId() const
211  { return m_numSrcVarId; }
212 
213  void
215  { m_numSrcVarId = x; }
216 
217 
218  // ------------------------------------------------------------
219  //
220  // ------------------------------------------------------------
221 
222  static double&
223  var(Metric::IData& mdata, uint mId)
224  { return mdata.demandMetric(mId); }
225 
226  double&
227  accumVar(int i, Metric::IData& mdata) const
228  { return var(mdata, m_accumId[i]); }
229 
230 
231  // ------------------------------------------------------------
232  //
233  // ------------------------------------------------------------
234 
235  virtual std::string
236  toString() const;
237 
238 
239  virtual std::ostream&
240  dump(std::ostream& os = std::cout) const
241  {
242  dumpMe(os);
243  return os;
244  }
245 
246  virtual std::ostream&
247  dumpMe(std::ostream& os = std::cout) const = 0;
248 
249  // Metric::IDBExpr::ddump()
250 
251 protected:
252 
253  // ------------------------------------------------------------
254  //
255  // ------------------------------------------------------------
256 
257  static double
258  evalSum(const Metric::IData& mdata, AExpr** opands, uint sz)
259  {
260  double z = 0.0;
261  for (uint i = 0; i < sz; ++i) {
262  double x = opands[i]->eval(mdata);
263  z += x;
264  }
265  return z;
266  }
267 
268 
269  static std::pair<double, double>
270  evalSumSquares(const Metric::IData& mdata, AExpr** opands, uint sz)
271  {
272  double z1 = 0.0; // sum
273  double z2 = 0.0; // sum of squares
274  for (uint i = 0; i < sz; ++i) {
275  double x = opands[i]->eval(mdata);
276  z1 += x;
277  z2 += (x * x);
278  }
279  return std::make_pair(z1, z2);
280  }
281 
282 
283  static double
284  evalMean(const Metric::IData& mdata, AExpr** opands, uint sz)
285  {
286  double sum = evalSum(mdata, opands, sz);
287  double z = sum / (double) sz;
288  return z;
289  }
290 
291 
292  // returns <variance, mean>
293  static std::pair<double, double>
294  evalVariance(const Metric::IData& mdata, AExpr** opands, uint sz)
295  {
296  double x_mean = 0.0; // mean
297  double x_var = 0.0; // variance
298  for (uint i = 0; i < sz; ++i) {
299  double t = opands[i]->eval(mdata);
300  double delta = t - x_mean;
301  x_mean += delta / (i + 1);
302  x_var += delta * (t - x_mean);
303  }
304  x_var = x_var / sz;
305 
306  return std::make_pair(x_var, x_mean);
307  }
308 
309 
310  double
311  evalStdDevNF(Metric::IData& mdata, AExpr** opands, uint sz) const
312  {
313  std::pair<double, double> z = evalSumSquares(mdata, opands, sz);
314  double z1 = z.first; // sum
315  double z2 = z.second; // sum of squares
316  accumVar(0, mdata) = z1;
317  accumVar(1, mdata) = z2;
318  return z1;
319  }
320 
321 
322  static void
323  dump_opands(std::ostream& os, AExpr** opands, uint sz,
324  const char* sep = ", ");
325 
326 protected:
327  uint m_accumId[maxAccums]; // used only for Metric::IDBExpr routines
328  uint m_numSrcVarId; // used only for Metric::IDBExpr routines
329 };
330 
331 
332 // ----------------------------------------------------------------------
333 // class Const
334 // Represent a double constant
335 // ----------------------------------------------------------------------
336 
337 class Const
338  : public AExpr
339 {
340 public:
341  Const(double c)
342  : m_c(c)
343  { }
344 
346  { }
347 
348  virtual double
349  eval(const Metric::IData& GCC_ATTR_UNUSED mdata) const
350  { return m_c; }
351 
352 
353  // ------------------------------------------------------------
354  // Metric::IDBExpr: exported formulas for Flat and Callers view
355  // ------------------------------------------------------------
356 
357  virtual uint
358  numSrcFxd() const
359  { return 1; }
360 
361 
362  // ------------------------------------------------------------
363  //
364  // ------------------------------------------------------------
365 
366  virtual std::ostream&
367  dumpMe(std::ostream& os = std::cout) const;
368 
369 private:
370  double m_c;
371 };
372 
373 
374 // ----------------------------------------------------------------------
375 // class Neg
376 // Represent a negative value of an AExpr
377 // ----------------------------------------------------------------------
378 
379 class Neg
380  : public AExpr
381 {
382 public:
383  // Assumes ownership of AExpr
384  Neg(AExpr* expr)
385  { m_expr = expr; }
386 
388  { delete m_expr; }
389 
390  virtual double
391  eval(const Metric::IData& mdata) const;
392 
393 
394  // ------------------------------------------------------------
395  // Metric::IDBExpr: exported formulas for Flat and Callers view
396  // ------------------------------------------------------------
397 
398  virtual uint
399  numSrcFxd() const
400  { return 1; }
401 
402 
403  // TODO: combineString1(), finalizeString()
404 
405 
406  // ------------------------------------------------------------
407  //
408  // ------------------------------------------------------------
409 
410  virtual std::ostream&
411  dumpMe(std::ostream& os = std::cout) const;
412 
413 private:
415 };
416 
417 
418 // ----------------------------------------------------------------------
419 // class Var
420 // Represent a variable
421 // ----------------------------------------------------------------------
422 
423 class Var
424  : public AExpr
425 {
426 public:
427  Var(std::string name, int metricId)
428  : m_name(name), m_metricId(metricId)
429  { }
430 
432  { }
433 
434  virtual double
435  eval(const Metric::IData& mdata) const
436  { return mdata.demandMetric(m_metricId); }
437 
438 
439  // ------------------------------------------------------------
440  // Metric::IDBExpr: exported formulas for Flat and Callers view
441  // ------------------------------------------------------------
442 
443  virtual uint
444  numSrcFxd() const
445  { return 1; }
446 
447 
448  virtual std::string
450  { return combineString1Sum(); }
451 
452  virtual std::string
454  { return finalizeStringSum(); }
455 
456 
457  // ------------------------------------------------------------
458  //
459  // ------------------------------------------------------------
460 
461  virtual std::ostream&
462  dumpMe(std::ostream& os = std::cout) const;
463 
464 private:
465  std::string m_name;
467 };
468 
469 
470 // ----------------------------------------------------------------------
471 // class Power
472 // Represent a power expression
473 // ----------------------------------------------------------------------
474 
475 class Power
476  : public AExpr
477 {
478 public:
479  // Assumes ownership of AExpr
480  Power(AExpr* base, AExpr* exponent)
481  : m_base(base), m_exponent(exponent)
482  { }
483 
485  {
486  delete m_base;
487  delete m_exponent;
488  }
489 
490  virtual double
491  eval(const Metric::IData& mdata) const;
492 
493 
494  // ------------------------------------------------------------
495  // Metric::IDBExpr:
496  // ------------------------------------------------------------
497 
498  virtual uint
499  numSrcFxd() const
500  { return 2; }
501 
502 
503  // TODO: combineString1(), finalizeString()
504 
505 
506  // ------------------------------------------------------------
507  //
508  // ------------------------------------------------------------
509 
510  virtual std::ostream&
511  dumpMe(std::ostream& os = std::cout) const;
512 
513 private:
516 };
517 
518 
519 // ----------------------------------------------------------------------
520 // class Divide
521 // Represent the division
522 // ----------------------------------------------------------------------
523 
524 class Divide
525  : public AExpr
526 {
527 public:
528  // Assumes ownership of AExpr
529  Divide(AExpr* numerator, AExpr* denominator)
530  : m_numerator(numerator), m_denominator(denominator)
531  { }
532 
534  {
535  delete m_numerator;
536  delete m_denominator;
537  }
538 
539 
540  virtual double
541  eval(const Metric::IData& mdata) const;
542 
543  // ------------------------------------------------------------
544  // Metric::IDBExpr:
545  // ------------------------------------------------------------
546 
547  virtual uint
548  numSrcFxd() const
549  { return 2; }
550 
551 
552  // TODO: combineString1(), finalizeString()
553 
554  // ------------------------------------------------------------
555  //
556  // ------------------------------------------------------------
557 
558  virtual std::ostream&
559  dumpMe(std::ostream& os = std::cout) const;
560 
561 private:
564 };
565 
566 
567 // ----------------------------------------------------------------------
568 // class Minus
569 // Represent the subtraction
570 // ----------------------------------------------------------------------
571 
572 class Minus
573  : public AExpr
574 {
575 public:
576  // Assumes ownership of AExpr
577  Minus(AExpr* minuend, AExpr* subtrahend)
578  : m_minuend(minuend), m_subtrahend(subtrahend)
579  { }
580 
582  {
583  delete m_minuend;
584  delete m_subtrahend;
585  }
586 
587  virtual double
588  eval(const Metric::IData& mdata) const;
589 
590  // ------------------------------------------------------------
591  // Metric::IDBExpr:
592  // ------------------------------------------------------------
593 
594  virtual uint
595  numSrcFxd() const
596  { return 2; }
597 
598 
599  // TODO: combineString1(), finalizeString()
600 
601 
602  // ------------------------------------------------------------
603  //
604  // ------------------------------------------------------------
605 
606  virtual std::ostream&
607  dumpMe(std::ostream& os = std::cout) const;
608 
609 private:
612 };
613 
614 
615 // ----------------------------------------------------------------------
616 // class Plus
617 // Represent addition
618 // ----------------------------------------------------------------------
619 
620 class Plus
621  : public AExpr
622 {
623 public:
624  // Assumes ownership of AExpr
625  Plus(AExpr** oprnds, uint numOprnds)
626  : m_opands(oprnds), m_sz(numOprnds)
627  { }
628 
629  ~Plus();
630 
631  virtual double
632  eval(const Metric::IData& mdata) const;
633 
634  // ------------------------------------------------------------
635  // Metric::IDBExpr:
636  // ------------------------------------------------------------
637 
638  virtual uint
639  numSrcFxd() const
640  { return m_sz; }
641 
642 
643  virtual std::string
645  { return combineString1Sum(); }
646 
647  virtual std::string
649  { return finalizeStringSum(); }
650 
651 
652  // ------------------------------------------------------------
653  //
654  // ------------------------------------------------------------
655 
656  virtual std::ostream&
657  dumpMe(std::ostream& os = std::cout) const;
658 
659 private:
662 };
663 
664 
665 // ----------------------------------------------------------------------
666 // class Times
667 // Represent multiplication
668 // ----------------------------------------------------------------------
669 
670 class Times
671  : public AExpr
672 {
673 public:
674  // Assumes ownership of AExpr
675  Times(AExpr** oprnds, uint numOprnds)
676  : m_opands(oprnds), m_sz(numOprnds)
677  { }
678 
679  ~Times();
680 
681  virtual double
682  eval(const Metric::IData& mdata) const;
683 
684  // ------------------------------------------------------------
685  // Metric::IDBExpr:
686  // ------------------------------------------------------------
687 
688  virtual uint
689  numSrcFxd() const
690  { return m_sz; }
691 
692 
693  // TODO: combineString1(), finalizeString()
694 
695 
696  // ------------------------------------------------------------
697  //
698  // ------------------------------------------------------------
699 
700  virtual std::ostream&
701  dumpMe(std::ostream& os = std::cout) const;
702 
703 private:
706 };
707 
708 
709 // ----------------------------------------------------------------------
710 // Min: (observational min instead of absolute min)
711 // ----------------------------------------------------------------------
712 
713 // Computes observational min instead of absolute min. Reports
714 // DBL_MIN when there have been no obervations.
715 
716 class Min
717  : public AExpr
718 {
719 public:
720  // Assumes ownership of AExpr
721  Min(AExpr** oprnds, uint numOprnds)
722  : m_opands(oprnds), m_sz(numOprnds)
723  { }
724 
725  ~Min();
726 
727  virtual double
728  eval(const Metric::IData& mdata) const;
729 
730  // ------------------------------------------------------------
731  // Metric::IDBExpr:
732  // ------------------------------------------------------------
733 
734  virtual uint
735  numSrcFxd() const
736  { return m_sz; }
737 
738 
739  virtual std::string
741  { return combineString1Min(); }
742 
743  virtual std::string
745  { return finalizeStringMin(); }
746 
747 
748  // ------------------------------------------------------------
749  //
750  // ------------------------------------------------------------
751 
752  virtual std::ostream&
753  dumpMe(std::ostream& os = std::cout) const;
754 
755 private:
758 };
759 
760 
761 // ----------------------------------------------------------------------
762 // Max
763 // ----------------------------------------------------------------------
764 
765 class Max
766  : public AExpr
767 {
768 public:
769  // Assumes ownership of AExpr
770  Max(AExpr** oprnds, uint numOprnds)
771  : m_opands(oprnds), m_sz(numOprnds)
772  { }
773 
774  ~Max();
775 
776  virtual double
777  eval(const Metric::IData& mdata) const;
778 
779  // ------------------------------------------------------------
780  // Metric::IDBExpr:
781  // ------------------------------------------------------------
782 
783  virtual uint
784  numSrcFxd() const
785  { return m_sz; }
786 
787 
788  virtual std::string
790  { return combineString1Max(); }
791 
792  virtual std::string
794  { return finalizeStringMax(); }
795 
796 
797  // ------------------------------------------------------------
798  //
799  // ------------------------------------------------------------
800 
801  virtual std::ostream&
802  dumpMe(std::ostream& os = std::cout) const;
803 
804 private:
807 };
808 
809 
810 // ----------------------------------------------------------------------
811 // Mean
812 // ----------------------------------------------------------------------
813 
814 class Mean
815  : public AExpr
816 {
817 public:
818  // Assumes ownership of AExpr
819  Mean(AExpr** oprnds, uint numOprnds)
820  : m_opands(oprnds), m_sz(numOprnds)
821  { }
822 
823  ~Mean();
824 
825  virtual double
826  eval(const Metric::IData& mdata) const;
827 
828  virtual double
829  evalNF(Metric::IData& mdata) const
830  {
831  double z = evalSum(mdata, m_opands, m_sz);
832  accumVar(0, mdata) = z;
833  return z;
834  }
835 
836 
837  // ------------------------------------------------------------
838  // Metric::IDBExpr:
839  // ------------------------------------------------------------
840 
841  virtual bool
842  hasNumSrcVar() const
843  { return true; }
844 
845  virtual uint
846  numSrcFxd() const
847  { return m_sz; }
848 
849  virtual std::string
851  { return combineString1Mean(); }
852 
853  virtual std::string
855  { return finalizeStringMean(); }
856 
857 
858  // ------------------------------------------------------------
859  //
860  // ------------------------------------------------------------
861 
862  virtual std::ostream&
863  dumpMe(std::ostream& os = std::cout) const;
864 
865 private:
868 };
869 
870 
871 // ----------------------------------------------------------------------
872 // StdDev: standard deviation
873 // ----------------------------------------------------------------------
874 
875 class StdDev
876  : public AExpr
877 {
878 public:
879  // Assumes ownership of AExpr
880  StdDev(AExpr** oprnds, uint numOprnds)
881  : m_opands(oprnds), m_sz(numOprnds)
882  { }
883 
884  ~StdDev();
885 
886  virtual double
887  eval(const Metric::IData& mdata) const;
888 
889  virtual double
890  evalNF(Metric::IData& mdata) const
891  { return evalStdDevNF(mdata, m_opands, m_sz); }
892 
893 
894  // ------------------------------------------------------------
895  // Metric::IDBExpr: exported formulas for Flat and Callers view
896  // ------------------------------------------------------------
897 
898  virtual uint
899  numAccum() const
900  { return 2; }
901 
902  virtual bool
903  hasNumSrcVar() const
904  { return true; }
905 
906  virtual uint
907  numSrcFxd() const
908  { return m_sz; }
909 
910 
911  virtual std::string
913  { return combineString1StdDev(); }
914 
915  virtual std::string
917  { return combineString2StdDev(); }
918 
919  virtual std::string
921  { return finalizeStringStdDev(); }
922 
923 
924  // ------------------------------------------------------------
925  //
926  // ------------------------------------------------------------
927 
928  virtual std::ostream&
929  dumpMe(std::ostream& os = std::cout) const;
930 
931 private:
934 };
935 
936 
937 // ----------------------------------------------------------------------
938 // CoefVar: relative standard deviation
939 // ----------------------------------------------------------------------
940 
941 class CoefVar
942  : public AExpr
943 {
944 public:
945  // Assumes ownership of AExpr
946  CoefVar(AExpr** oprnds, uint numOprnds)
947  : m_opands(oprnds), m_sz(numOprnds)
948  { }
949 
950  ~CoefVar();
951 
952  virtual double
953  eval(const Metric::IData& mdata) const;
954 
955  virtual double
956  evalNF(Metric::IData& mdata) const
957  { return evalStdDevNF(mdata, m_opands, m_sz); }
958 
959 
960  // ------------------------------------------------------------
961  // Metric::IDBExpr: exported formulas for Flat and Callers view
962  // ------------------------------------------------------------
963 
964  virtual uint
965  numAccum() const
966  { return 2; }
967 
968  virtual bool
969  hasNumSrcVar() const
970  { return true; }
971 
972  virtual uint
973  numSrcFxd() const
974  { return m_sz; }
975 
976 
977  virtual std::string
979  { return combineString1StdDev(); }
980 
981  virtual std::string
983  { return combineString2StdDev(); }
984 
985  virtual std::string
987  { return finalizeStringCoefVar(); }
988 
989 
990  // ------------------------------------------------------------
991  //
992  // ------------------------------------------------------------
993 
994  virtual std::ostream&
995  dumpMe(std::ostream& os = std::cout) const;
996 
997 private:
1000 };
1001 
1002 
1003 // ----------------------------------------------------------------------
1004 // RStdDev: relative standard deviation
1005 // ----------------------------------------------------------------------
1006 
1007 class RStdDev
1008  : public AExpr
1009 {
1010 public:
1011  // Assumes ownership of AExpr
1012  RStdDev(AExpr** oprnds, uint numOprnds)
1013  : m_opands(oprnds), m_sz(numOprnds)
1014  { }
1015 
1016  ~RStdDev();
1017 
1018  virtual double
1019  eval(const Metric::IData& mdata) const;
1020 
1021  virtual double
1022  evalNF(Metric::IData& mdata) const
1023  { return evalStdDevNF(mdata, m_opands, m_sz); }
1024 
1025 
1026  // ------------------------------------------------------------
1027  // Metric::IDBExpr: exported formulas for Flat and Callers view
1028  // ------------------------------------------------------------
1029 
1030  virtual int
1031  hasAccum() const
1032  { return 2; }
1033 
1034  virtual bool
1036  { return true; }
1037 
1038  virtual uint
1039  numSrcFxd() const
1040  { return m_sz; }
1041 
1042 
1043  virtual std::string
1045  { return combineString1StdDev(); }
1046 
1047  virtual std::string
1049  { return combineString2StdDev(); }
1050 
1051  virtual std::string
1053  { return finalizeStringRStdDev(); }
1054 
1055 
1056  // ------------------------------------------------------------
1057  //
1058  // ------------------------------------------------------------
1059 
1060  virtual std::ostream&
1061  dumpMe(std::ostream& os = std::cout) const;
1062 
1063 private:
1066 };
1067 
1068 
1069 // ----------------------------------------------------------------------
1070 // NumSource
1071 // ----------------------------------------------------------------------
1072 
1074  : public AExpr
1075 {
1076 public:
1077  // Assumes ownership of AExpr
1078  NumSource(uint numSrc)
1079  : m_numSrc(numSrc)
1080  { }
1081 
1083  { }
1084 
1085  virtual double
1086  eval(const Metric::IData& GCC_ATTR_UNUSED mdata) const
1087  { return (double)m_numSrc; }
1088 
1089 
1090  // ------------------------------------------------------------
1091  // Metric::IDBExpr: exported formulas for Flat and Callers view
1092  // ------------------------------------------------------------
1093 
1094  virtual uint
1095  numSrcFxd() const
1096  { DIAG_Die(DIAG_Unimplemented); return 0; }
1097 
1098 
1099  virtual std::string
1101  { return combineString1NumSource(); }
1102 
1103  virtual std::string
1105  { return finalizeStringNumSource(); }
1106 
1107 
1108  // ------------------------------------------------------------
1109  //
1110  // ------------------------------------------------------------
1111 
1112  virtual std::ostream&
1113  dumpMe(std::ostream& os = std::cout) const;
1114 
1115 private:
1117 };
1118 
1119 
1120 //****************************************************************************
1121 
1122 } // namespace Metric
1123 
1124 } // namespace Prof
1125 
1126 //****************************************************************************
1127 
1128 #endif /* prof_Prof_Metric_AExpr_hpp */
virtual uint numSrcFxd() const
Plus(AExpr **oprnds, uint numOprnds)
std::string combineString2StdDev() const
virtual uint numSrcFxd() const
virtual std::string combineString1() const
virtual std::string finalizeString() const
std::string finalizeStringStdDev(std::string *meanRet=NULL) const
virtual double eval(const Metric::IData &GCC_ATTR_UNUSED mdata) const
std::string finalizeStringSum() const
std::string combineString1NumSource() const
std::string finalizeStringCoefVar() const
std::vector< AExpr * > AExprVec
RStdDev(AExpr **oprnds, uint numOprnds)
virtual double evalNF(Metric::IData &mdata) const
virtual bool hasNumSrcVar() const
CoefVar(AExpr **oprnds, uint numOprnds)
virtual uint numSrcFxd() const
virtual std::string finalizeString() const
virtual uint numSrcVarId() const
virtual uint accumId(int i) const
virtual double evalNF(Metric::IData &mdata) const
double evalStdDevNF(Metric::IData &mdata, AExpr **opands, uint sz) const
const char * DIAG_Unimplemented
virtual uint numSrcFxd() const
virtual uint numSrcFxd() const
bool c_isinf_d(double x)
Definition: NaN.c:85
virtual std::string combineString1() const
virtual std::string finalizeString() const
virtual std::string combineString2() const
void accumId(int i, uint x)
virtual std::string combineString1() const
virtual uint numSrcFxd() const
virtual std::ostream & dump(std::ostream &os=std::cout) const
virtual std::string combineString1() const
uint m_accumId[maxAccums]
virtual uint numSrcFxd() const
virtual std::string finalizeString() const
virtual uint numAccum() const
std::string finalizeStringNumSource() const
StdDev(AExpr **oprnds, uint numOprnds)
virtual std::string toString() const
virtual std::string combineString2() const
virtual uint numSrcFxd() const
virtual uint numSrcFxd() const
std::string finalizeStringRStdDev() const
virtual std::string finalizeString() const
virtual std::string finalizeString() const
static bool isok(double x)
virtual uint numAccum() const
virtual bool hasNumSrcVar() const
virtual bool hasNumSrcVar() const
Minus(AExpr *minuend, AExpr *subtrahend)
unsigned int uint
Definition: uint.h:124
virtual uint numSrcFxd() const
virtual double eval(const Metric::IData &GCC_ATTR_UNUSED mdata) const
virtual std::string finalizeString() const
std::string combineString1Max() const
Times(AExpr **oprnds, uint numOprnds)
virtual uint numSrcFxd() const
std::string finalizeStringMean() const
Neg(AExpr *expr)
std::string combineString1Min() const
virtual double eval(const Metric::IData &mdata) const =0
double & accumVar(int i, Metric::IData &mdata) const
virtual uint numSrcFxd() const
virtual bool hasNumSrcVar() const
std::string combineString1Mean() const
virtual std::string combineString2() const
virtual double evalNF(Metric::IData &mdata) const
virtual double eval(const Metric::IData &mdata) const
virtual uint numSrcFxd() const
bool c_isnan_d(double x)
Definition: NaN.c:78
virtual std::string combineString1() const
virtual int hasAccum() const
Mean(AExpr **oprnds, uint numOprnds)
virtual uint numSrcFxd() const
virtual double evalNF(Metric::IData &mdata) const
virtual std::string finalizeString() const
virtual std::string combineString1() const
virtual bool hasNumSrcVar() const
double demandMetric(size_t mId, size_t size=0) const
Max(AExpr **oprnds, uint numOprnds)
void numSrcVarId(uint x)
virtual uint numSrcFxd() const
Var(std::string name, int metricId)
std::string finalizeStringMin() const
static void dump_opands(std::ostream &os, AExpr **opands, uint sz, const char *sep=", ")
static double evalMean(const Metric::IData &mdata, AExpr **opands, uint sz)
Divide(AExpr *numerator, AExpr *denominator)
virtual std::ostream & dumpMe(std::ostream &os=std::cout) const =0
static std::pair< double, double > evalVariance(const Metric::IData &mdata, AExpr **opands, uint sz)
virtual std::string combineString1() const
static double evalSum(const Metric::IData &mdata, AExpr **opands, uint sz)
std::string finalizeStringMax() const
std::string combineString1Sum() const
std::string combineString1StdDev() const
#define DIAG_Die(...)
Definition: diagnostics.h:267
virtual std::string combineString2() const
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
static std::pair< double, double > evalSumSquares(const Metric::IData &mdata, AExpr **opands, uint sz)
virtual std::string combineString1() const
virtual std::string combineString1() const
Min(AExpr **oprnds, uint numOprnds)
virtual uint numSrcFxd() const
virtual uint numAccum() const
virtual std::string combineString1() const
virtual double evalNF(Metric::IData &mdata) const
std::string m_name
Power(AExpr *base, AExpr *exponent)
virtual std::string finalizeString() const
virtual std::string finalizeString() const
static double & var(Metric::IData &mdata, uint mId)
static const uint npos