Hi,
I programmed a not-so-complicated code to solve a nonlinear equation. But unfortunately all the time at initialization I receive an error in input parameters. Please tell me what's wrong. The code is below.When I comment on the result check after the strnlsp_init function, the strnlsp_check function succeeds.
#include <iostream> #include <vector> #include <iomanip> #include "mkl_rci.h" #include "mkl_types.h" #include "mkl_service.h" int main() { std::vector<float> fjac = { 0,1.0, 1,1.0, 2,1.0, 4,1.0, 5,1.0 }; std::cerr << "size fjac = "<< fjac.size() << std::endl; /* n - number of function variables m - dimension of function value */ MKL_INT n = 2, m = 5; std::cerr << "n = "<< n << std::endl; std::cerr << "m = "<< m << std::endl; std::vector<float> fvec = { 2.1, 2.4, 2.6, 2.8, 3.0 }; std::cerr << "size fvec = "<< fvec.size() << std::endl; std::vector<float> x ={ 0.0, 0.0 }; std::cerr << "size x = "<< x.size() << std::endl; _TRNSP_HANDLE_t handle = nullptr; // TR solver handle /* results of input parameter checking */ MKL_INT info[6]; /* precisions for stop-criteria (see manual for more details) */ std::vector< float > eps; eps.resize(6); /* set precisions for stop-criteria */ for (int32_t i = 0; i < static_cast<int32_t>(eps.size()); ++i) { eps[i] = 0.00001; } /* iter1 - maximum number of iterations iter2 - maximum number of iterations of calculation of trial-step */ MKL_INT iter1 = 1000, iter2 = 100; /* initial step bound */ float rs = 0.0; MKL_INT res; if(m >= n){ std::cerr << "YES\n"; } else{ std::cerr << "NO\n"; } res = strnlsp_init(&handle, &n, &m, x.data(), eps.data(), &iter1, &iter2, &rs) ; std::cerr << "res = "<< res << std::endl; if(res != TR_SUCCESS) { if(res == TR_INVALID_OPTION){ std::cerr << "there was an error in the input parameters.\n"; } if(res == TR_OUT_OF_MEMORY){ std::cerr << "there was a memory error.\n"; } /* if function does not complete successfully then print error message */ std::cerr << "| error in dtrnlsp_init"<< std::endl; /* Release internal Intel(R) MKL memory that might be used for computations */ /* NOTE: It is important to call the routine below to avoid memory leaks */ /* unless you disable Intel(R) MKL Memory Manager */ MKL_Free_Buffers (); return -1; } /* Checks the correctness of handle and arrays containing Jacobian matrix, objective function, lower and upper bounds, and stopping criteria. */ if (strnlsp_check (&handle, &n, &m, fjac.data(), fvec.data(), eps.data(), info) != TR_SUCCESS) { std::cerr << "info:\n"; for(int32_t i = 0; i < 6; ++i){ std::cerr << info[i] << ","; } std::cerr << std::endl; /* if function does not complete successfully then print error message */ std::cerr << "| error in dtrnlsp_init\n"<< std::endl; /* Release internal Intel(R) MKL memory that might be used for computations */ /* NOTE: It is important to call the routine below to avoid memory leaks */ /* unless you disable Intel(R) MKL Memory Manager */ MKL_Free_Buffers (); /* and exit */ return -1; } std::cerr << "info:\n"; for(int32_t i = 0; i < 6; ++i){ std::cerr << info[i] << ","; } std::cerr << std::endl; /* solve code */ return 0; }