int main(void) { auto_ptr<int> p(new int(10)), q(new int(20)); p = q; printf("size = %d\n", sizeof(auto_ptr<int>)); std::vector<auto_ptr<int> > v_ptr(10); }
void Fitter::performNl2sol(int nbit) { enum {vF0 = 12}; //the value of f(xinit) for final output double fxinit = 0; int nbParams = fitParameterList.size(); int nbResids = argumentsList.size(); // RN2GB: "LIV...... LENGTH OF IV... LIV MUST BE AT LEAST 4*P + 82" int liv = 4 * nbParams + 82; // RN2GB: "LV....... LENGTH OF V... LV MUST BE AT LEAST 105 + P*(N + 2*P + 17) + 2*N" int lv = 105 + nbParams * (nbResids + 2 * nbParams + 17) + 2 * nbResids; std::unique_ptr<double[]> x_ptr(new double[nbParams]); std::unique_ptr<double[]> xb_ptr(new double[2 * nbParams]); std::unique_ptr<int[]> iv_ptr(new int[liv]); std::unique_ptr<double[]> v_ptr(new double[lv]); //initialize nl2sol parameters for (size_t i = 0; i < fitParameterList.size(); ++i) { x_ptr[i] = fitParameterList[i].value; xb_ptr[2 * i] = fitParameterList[i].lbvalue; xb_ptr[2 * i + 1] = fitParameterList[i].ubvalue; } //initialize default values for iv and v optimization settings int kind = 1; iv_ptr[0] = 0; divset_(&kind, iv_ptr.get(), &liv, &lv, v_ptr.get()); //turn of output iv_ptr[20] = 0; //max iterations allowed iv_ptr[17] = 0; //try to execute optimization algorithm dn2fb_(&nbResids, &nbParams, x_ptr.get(), xb_ptr.get(), n2fbNormFunc, iv_ptr.get(), &liv, &lv, v_ptr.get(), reinterpret_cast<int *>(this), NULL, NULL); //storage size for iv_ptr or v_ptr was too small if((iv_ptr[0] == 15) || (iv_ptr[0] == 16)) { //reallocate iv_ptr and v_ptr liv = iv_ptr[43]; lv = iv_ptr[44]; iv_ptr.reset(new int[liv]); v_ptr.reset(new double[lv]); //reset defaults divset_(&kind, iv_ptr.get(), &liv, &lv, v_ptr.get()); //turn of output iv_ptr[20] = 0; //max iterations allowed iv_ptr[17] = 0; //execute optimization algorithm once to get f(xinit) dn2fb_(&nbResids, &nbParams, x_ptr.get(), xb_ptr.get(), n2fbNormFunc, iv_ptr.get(), &liv, &lv, v_ptr.get(), reinterpret_cast<int *>(this), NULL, NULL); //v(vF0 = 12) is the function value of f (x) at the start of the last iteration fxinit = v_ptr[vF0]; //max iterations allowed iv_ptr[17] = nbit; //execute optimization algorithm nbit-1 times to optimize dn2fb_(&nbResids, &nbParams, x_ptr.get(), xb_ptr.get(), n2fbNormFunc, iv_ptr.get(), &liv, &lv, v_ptr.get(), reinterpret_cast<int *>(this), NULL, NULL); } resetFParameters(x_ptr.get()); //reset v(vF0) to fxinit v_ptr[vF0] = fxinit; printNl2solInfo(iv_ptr.get(), v_ptr.get()); }