File indexing completed on 2025-08-06 08:14:12
0001 #ifndef noiBinVec__h
0002 #define noiBinVec__h
0003
0004 #ifndef tuClass__h
0005
0006
0007
0008 struct tuBinVec {
0009
0010 double* ptr;
0011 int size;
0012 vector<double> vec;
0013
0014 void build_ptr() {
0015 size = vec.size();
0016 ptr = new double[size];
0017 for (int i{0}; i<size; ++i) ptr[i] = vec[i];
0018 };
0019
0020 tuBinVec(vector<double> V) {
0021
0022
0023
0024
0025
0026 vec.push_back(V[0]);
0027 int S = V.size();
0028 int i{1};
0029 while (i<(int)S) {
0030 if ( V[i] == V[i-1] ) {
0031 if (i>(S-3)) throw std::runtime_error( "fatal in tuBinVec with range_repeat");
0032 double step = (V[i+2]-V[i])/V[i+1];
0033 for (int k{1}; k<=V[i+1]; ++k) vec.push_back(V[i]+k*step);
0034 i+=3;
0035 } else {
0036 vec.push_back(V[i]);
0037 ++i;
0038 }
0039 }
0040 build_ptr();
0041 };
0042
0043 operator int () const { return size-1; };
0044 operator double* () const { return ptr; };
0045 operator vector<double> () { return vec; };
0046 int bin_from_0(double val) const {
0047 auto loc = upper_bound(vec.begin(), vec.end(), val);
0048 return loc-vec.begin()-1;
0049 };
0050 int bin_from_1(double val) const {
0051 return bin_from_0(val) + 1;
0052 };
0053 };
0054 #endif
0055
0056 #endif