File indexing completed on 2026-08-26 09:18:58
0001 #ifndef PROF_PARAMPOINTS_H
0002 #define PROF_PARAMPOINTS_H
0003
0004 #include <string>
0005 #include <iostream>
0006 #include <sstream>
0007 #include <vector>
0008 #include <cassert>
0009 #include <stdexcept>
0010
0011 namespace Professor {
0012
0013
0014
0015 struct ParamPointsError : public std::runtime_error {
0016 ParamPointsError(const std::string& reason) : std::runtime_error(reason) { }
0017 };
0018
0019
0020
0021 typedef std::vector<double> ParamPoint;
0022
0023
0024
0025
0026
0027
0028
0029 class ParamPoints {
0030 public:
0031
0032
0033
0034
0035
0036 ParamPoints(const std::vector< std::vector<double> >& ppoints);
0037
0038 ~ParamPoints() {
0039 _parampoints.clear();
0040 }
0041
0042
0043 operator std::vector< std::vector<double> > () const {
0044 return _parampoints;
0045 }
0046
0047
0048
0049 void addParamPoint(const std::vector<double>& p) {
0050 if (_locked) {
0051
0052 std::cerr << "Adding point to locked collection not implemented, aborting" << std::endl;
0053 abort();
0054 }
0055
0056 if (_parampoints.size() > 0)
0057 assert(p.size() == _parampoints[0].size());
0058 _parampoints.push_back(p);
0059 }
0060
0061
0062 int numPoints() const { return _parampoints.size(); }
0063
0064
0065 int dim() const {
0066 assert(!_parampoints.empty());
0067 return _parampoints.front().size();
0068 }
0069
0070
0071 std::vector<double> ptcenters() const;
0072
0073
0074 std::vector<double> ptmins() const;
0075
0076
0077 std::vector<double> ptmaxs() const;
0078
0079
0080 std::vector< std::pair<double, double> > ptedges() const;
0081
0082
0083
0084 void printPoints() const;
0085
0086
0087
0088 void printMeta() const;
0089
0090
0091
0092
0093 void reset() { _parampoints.clear(); _locked = false; };
0094
0095
0096 std::string toString(const std::string& info="") const {
0097 std::stringstream ss;
0098 if (!info.empty()) ss << "# INFO " << info << "\n";
0099 ss << "# MINV ";
0100 for (const double& a : ptmins()) ss << a<< " ";
0101 ss << " \n";
0102 ss << "# MAXV ";
0103 for (const double& a : ptmaxs()) ss << a<< " ";
0104 ss << " \n";
0105
0106 ss << "# DIM ";
0107 ss << dim();
0108 ss << "\n";
0109
0110 if (names().size()>0) {
0111 ss << "# PARAMS ";
0112 for (const std::string& s : names()) ss << s<< " ";
0113 ss << "\n";
0114 }
0115
0116 return ss.str();
0117 }
0118
0119
0120 const std::vector< std::vector<double> >& points() const { return _parampoints; }
0121
0122
0123 const std::vector< std::string >& names() const { return _names; }
0124
0125 void setNames(std::vector<std::string >);
0126
0127
0128
0129 const std::vector<double>& point(size_t i) const { return points().at(i); }
0130
0131
0132 private:
0133
0134 std::vector< std::vector<double> > _parampoints;
0135
0136 std::vector< std::string > _names;
0137
0138 bool _locked;
0139
0140 };
0141
0142
0143 }
0144
0145 #endif