coin-or / CppAD

A C++ Algorithmic Differentiation Package: Home Page
https://cppad.readthedocs.io
Other
446 stars 94 forks source link

Cannot find matching function for call: what is the definition for BaseVector? #127

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, I want to use Forward function to calculate zero order sweep.

CppAD::ADFun<double> getStateDerivative;
CPPAD_TESTVECTOR(double) x(31);
return getStateDerivative.Forward(size_t(0), x);

But the compiler reports

error: no matching function for call to ‘CppAD::ADFun<double, double>::Forward(size_t, CppAD::vector<double>&)

I have tried different ADFun with different Base type and different xq of different BaseVector type but it still does not work.

bradbell commented 2 years ago

I created the program

int main(void)
{
    CppAD::ADFun<double> getStateDerivative;
    CPPAD_TESTVECTOR(double) x(31), y(31);
    y = getStateDerivative.Forward(size_t(0), x);
    return 0;
}

It compiled fine with the following command

g++ -g -I $HOME/repo/cppad.git/include temp.cpp -o temp

The message I got when I tried to run the program was

cppad-20220201 error from a known source:
Forward(q, xq): xq.size() is not equal n or n*(q+1)
Error detected by false result for
    size_t(xq.size()) == n || size_t(xq.size()) == n*(q+1)
at line 119 in the file 
    /home/bradbell/repo/cppad.git/include/cppad/core/forward/forward.hpp
temp: /home/bradbell/repo/cppad.git/include/cppad/utility/error_handler.hpp:206: static void CppAD::ErrorHandler::Default(bool, int, const char*, const char*, const char*): Assertion `false' failed.
environment: line 13: 1211220 Aborted                 (core dumped) ./temp

This is because as defined the function getStateDerivative is empty.

bradbell commented 2 years ago

@xeonz1 Did the message above answer your quesiton ? If so, would you please close this issue.

ghost commented 2 years ago

@xeonz1 Did the message above answer your quesiton ? If so, would you please close this issue.

@bradbell Thanks for the reply. I have solved the problem above. However, I am running into another problem about codegen. In the generateSource part of zero order forward mode, It reports

GreaterThanZero cannot be called for non-parameters. I debugged for a while and found this exception happens when GreaterThanZero is called in 'forward_levv_op_0'. Can you give me some instruction?

bradbell commented 2 years ago

Converting to a discussion from issue #127