SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
-
A deprecated autotools procedure can be used for this purpose, but it will eventually be removed.
get_sarted demonstrates using CppAD by computing the derivative of a simple example function.
A C++ Algorithmic Differentiation Package: Home Page
Home Page: https://cppad.readthedocs.io
License: Other
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
A deprecated autotools procedure can be used for this purpose, but it will eventually be removed.
get_sarted demonstrates using CppAD by computing the derivative of a simple example function.
Hello,
I'm experiencing random segfaults when using the ColPack coloring method to compute a sparse jacobian. I can reproduce them with sparse_exemple
. To make them occur more frequently I've changed the line of sparse.cpp
:
Run( colpack_jacobian, "colpack_jacobian" );
with
for (int i = 0; i < 10000; i++) {
Run( colpack_jacobian, "colpack_jacobian" );
}
This problem might be related to this issue: coin-or/Adol-C/19, and in that case the problem could come from ColPack
. I'm not completely convinced it's the same issue, because the bug in Adol-C
only appears with column coloring and not with row coloring, and CppAD
uses row coloring.
OS: Debian 10
CppAD version: 20200000.2
I am trying to install the latest version of CppAD from the GitHub master branch (15-Nov-2017). At make check, I get the following error:
[ 78%] Built target check_example_general
Scanning dependencies of target example_get_started
[ 78%] Building CXX object example/get_started/CMakeFiles/example_get_started.dir/get_started.cpp.o
[ 80%] Linking CXX executable example_get_started
[ 80%] Built target example_get_started
Scanning dependencies of target check_example_get_started
f'(3) computed by CppAD = 142
[ 80%] Built target check_example_get_started
Scanning dependencies of target example_ipopt_solve
[ 80%] Building CXX object example/ipopt_solve/CMakeFiles/example_ipopt_solve.dir/get_started.cpp.o
In file included from /Users/braunm/cppad/example/ipopt_solve/get_started.cpp:52:
In file included from /Users/braunm/cppad/cppad/ipopt/solve.hpp:405:
/Users/braunm/cppad/cppad/ipopt/solve_callback.hpp:16:11: fatal error: 'coin/IpIpoptApplication.hpp' file not found
# include <coin/IpIpoptApplication.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[3]: *** [example/ipopt_solve/CMakeFiles/example_ipopt_solve.dir/get_started.cpp.o] Error 1
make[2]: *** [example/ipopt_solve/CMakeFiles/example_ipopt_solve.dir/all] Error 2
make[1]: *** [example/CMakeFiles/check_example.dir/rule] Error 2
make: *** [check_example] Error 2
mbraun: ~/cppad/build $
eps =0.0 on Visual Studio 2010. The issue was resolved by changing std::numeric_limits< zdouble>::epsilon() to std::numeric_limits< double>::epsilon() in zdouble.hpp
Similar for std::numeric_limits::min() and std::numeric_limits::max()
Hi,
I'm trying to get the sparsity apttern for a simple function, which adds up every second item from a given list. SO the sparsity pattern should show this.
template <class Type>
Type TotalTimeConstraint(std::vector<Type>& ts){
auto n = ts.size();
Type total(0);
for (int i = 0; i < n; i+=2) {
total += ts[i];
}
return total;
}
In the example (code below) I create 10 variables and get one output, so n=10
and m=1
. However running this gives me the following error:
cppad-20170410 error from a known source:
for_jac_sparsity: number rows in R is not equal number of independent variables.
Error detected by false result for
n == Domain()
at line 227 in the file
/home/lange/Downloads/cppad-20170410/cppad/core/for_jac_sparsity.hpp
introduction_exp_apx: /home/lange/Downloads/cppad-20170410/cppad/utility/error_handler.hpp:206: static void CppAD::ErrorHandler::Default(bool, int, const char*, const char*, const char*): Assertion `false' failed.
I can work around this by setting m2 =n2
but it feels wrong and I don't understand the problem here.
However, if I fix this I get a running problem and get shown the following sparsity pattern, which is wrong. I would be really happy about hints or tips on how to fix this.
n_sweep: 5
0,0
0,1
0,2
0,3
0,4
Code:
// main program
int main(void)
{
using CppAD::AD; // use AD as abbreviation for CppAD::AD
using std::vector; // use vector as abbreviation for std::vector
using CppAD::sparse_rc;
using CppAD::sparse_rcv;
// sparse test
size_t n2 = 10;
vector< AD<double> > X2(n2);
for (int j = 0; j < n2; ++j) {
X2[j] = (int)ceil(j / 2.0);
}
// declare independent variables and start recording operation sequence
CppAD::Independent(X2);
// range space vector
size_t m2 = 1;
vector< AD<double> > Y2(m2);
Y2[0] = TotalTimeConstraint(X2);
// store operation sequence in f: X2 -> Y2 and stop recording
CppAD::ADFun<double> g(X2, Y2);
// compute derivative using operation sequence stored in g
vector<double> jac2(m2 * n2);
vector<double> x2(n2);
for (int j = 0; j < n2; ++j) {
x2[j] = (int)floor(j / 2.0) + 1;
}
jac2 = g.Jacobian(x2);
auto y2 = g.Forward(1, x2);
typedef std::vector<double> d_vector;
typedef std::vector<size_t> s_vector;
// n by n identity matrix sparsity
sparse_rc<s_vector> pattern_in;
pattern_in.resize(m2, n2, n2);
for(size_t k = 0; k < 5; k++)
pattern_in.set(k, 0, k);
// sparsity for J(x)
bool transpose = false;
bool dependency = false;
bool internal_bool = true;
sparse_rc<s_vector> pattern_jac;
g.for_jac_sparsity(
pattern_in, transpose, dependency, internal_bool, pattern_jac
);
sparse_rcv<s_vector, d_vector> subset(pattern_jac);
CppAD::sparse_jac_work work;
std::string coloring = "cppad";
size_t group_max = 10;
auto n_sweep = g.sparse_jac_for(group_max, x2, subset, pattern_in, coloring, work);
// print the results
std::cout << "g(t2) = " << y2[0] << std::endl;
for (int i = 0; i < n2; ++i) {
std::cout << "g'_t" << i << "(ts) computed by CppAD = " << jac2[i] << std::endl;
}
std::cout << "n_sweep: " << n_sweep << std::endl;
const auto& c = pattern_jac.col();
const auto& r = pattern_jac.row();
for (int l = 0; l < pattern_jac.nnz(); ++l) {
std::cout << r[l] << "," << c[l]<< std::endl;
}
return 0;
}
Hi,
The following code produces the wrong result:
#include <cppad/example/cppad_eigen.hpp>
#include <Eigen/Dense>
#include <iostream>
using CppAD::AD;
using CppAD::ADFun;
using CppAD::Independent;
using Eigen::Matrix;
using Eigen::Dynamic;
using Eigen::VectorXd;
using Eigen::MatrixXd;
int main() {
typedef Matrix< AD<double> , Dynamic, Dynamic > a_MatrixXd;
typedef Matrix< AD<double> , Dynamic , 1> a_VectorXd;
int size = 3, i , j;
a_VectorXd a_x(size);
VectorXd x(size);
x << 1, 2, 3;
for(i = 0; i < size; i++) {
a_x[i] = x[i];
}
a_MatrixXd a_X(size, size);
a_X << 1, 2, 3, 4, 5, 6, 7, 8, 9;
Independent(a_x);
AD<double> dd = 2.0;
a_VectorXd a_y = (a_x.transpose() * a_X * a_x)/dd;
// create f: x -> y and stop tape recording
ADFun<double> f(a_x, a_y);
VectorXd jac = f.Jacobian(x);
VectorXd H = f.Hessian(x,0);
MatrixXd Hss(size,size);
Hss = H;
Hss.resize(size,size);
std::cout << "True Jacobian/gradient =\n" << a_X * a_x << "\n\n";
std::cout << "CppAD Jacobian/gradient =\n" << jac << " [FAIL]\n\n";
std::cout << "True Hessian =\n" << a_X << "\n\n";
std::cout << "CppAD Hessian =\n" << Hss << " [FAIL]\n\n";
return 0;
}
I'm running Ubuntu 15.10 on an x86-64 machine using CppAD master and the most recent stable release of Eigen (3.2.7). If I set a_X and a_b using for loops I get the correct result.
Thanks,
Jason
I have a simple question. I'm using CLANG (Apple LLVM version 9.1.0 (clang-902.0.39.2)) and when I write these lines:
CppAD::AD<Scalar> ad_value; ad_value = -1.; abs(ad_value);
my compiler does the job without any error. While I never explicitly call CppAD::abs
and this code should not compile.
Do you know what is the machinery that allows my compiler to guess this call to abs
?
Hello,
First I want to take you for your awesome work which is very helpful to me. I just have a question. When I get the Jacobian of my recoded function, I get a big vector instead of a matrix. For example, My Jacobian should me a 313 matrix, but instead, I get a 391 vector. This is ok because I guess all the ellements of my matrix are inside this vector, but how can I know in which order they are ?
Thank you very much for you feedback, and do not hesitate to ask me if I weren't clear enough.
I am completely new to cppad and I apologize if this is a stupid question. I have been trying to install cppad and ipopt for a day now and it's getting really frustrating as I don't know how to solve this problem. I am trying to use Cppad in my program but I run into the error:
In function void CppAD::ipopt::solve<CppAD::vector<double>, (anonymous namespace)::FG_eval>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CppAD::vector<double> const&,CppAD::vector<double> const&, CppAD::vector<double> const&, CppAD::vector<double> const&, CppAD::vector<double> const&, (anonymous namespace)::FG_eval&, CppAD::ipopt::solve_result<CppAD::vector<double> >&)': ipopt_test.cpp:(.text+0xe0a): undefined reference to
Ipopt::IpoptApplication::IpoptApplication(bool, bool)'
collect2: error: ld returned 1 exit status
I can't find many resources online of people having the same problem. To check if it is my program I tried running the following example but I get the same error. Wondering if you guys know about it
Hello Brad,
What would be the best way to determine the version of CppAD with CMake after it has been installed to a custom folder?
PkgConfig is easy to use to extract the version if CppAD is installed in the system but not in a custom folder.
If there was a generated file with the version next to the sources would be great.
Thanks a lot for your valuable package. Please help me in converting from AD<> datatype to its base type. Normal Typecasting is not working. Thanks a lot :)
Good evening
I am a new user of the CppAD library. I tried to build it using Visual Studio 2015.
I performed all the preliminary steps, making the solution by the simplest command:
C:\cppad-20170805\build>cmake ..
When rebuilding the solution in Visual Studio 2015 I got the error message:
c1xx : fatal error C1083: Cannot open source file: 'NOTFOUND': No such file or directory
Surely, I missed something in the cmake command.
Please, can you help me fix this problem?
Thank you
Liviu Sandu
I get the following output from make check
:
[ 3%] Built target introduction
Begin test group introduction
exp_2 OK
exp_2_cppad OK
exp_2_for0 OK
exp_2_for1 OK
exp_2_for2 OK
exp_2_rev1 OK
exp_2_rev2 OK
exp_eps OK
exp_eps_cppad OK
exp_eps_for0 OK
exp_eps_for1 OK
exp_eps_for2 OK
exp_eps_rev1 OK
exp_eps_rev2 OK
memory_leak OK
All 15 tests passed.
End test group introduction
[ 3%] Built target check_introduction
[ 5%] Built target speed_example
[ 7%] Built target speed_src
det_of_minor OK
det_by_minor OK
det_by_lu OK
elapsed_seconds OK
mat_sum_sq OK
ode_evaluate OK
sparse_hes_fun OK
sparse_jac_fun OK
speed_test OK
time_test OK
Check above to see if all 10 tests passed.
possible exceptions are: elapsed_seconds, speed_test, time_test
[ 7%] Built target check_speed_example
[ 9%] Built target speed_cppad
cppad_det_lu_ok = true
cppad_det_minor_ok = true
cppad_mat_mul_ok = true
cppad_ode_ok = true
cppad_poly_ok = true
cppad_sparse_hessian_ok = true
cppad_sparse_jacobian_ok = true
All 7 correctness tests passed.
memory allocated at end of last cppad speed test = 18805
speed main: OK
[ 9%] Built target check_speed_cppad
[ 12%] Built target speed_double
double_det_lu_ok = true
double_det_minor_ok = true
double_mat_mul_ok = true
double_ode_ok = true
double_poly_ok = true
double_sparse_hessian_ok = true
double_sparse_jacobian_ok = true
All 7 correctness tests passed.
speed main: OK
[ 12%] Built target check_speed_double
[ 12%] Built target check_speed
[ 18%] Built target example_utility
Begin test group example/utility
CheckNumericType OK
CheckSimpleVector OK
CppAD_vector OK
ErrorHandler OK
index_sort OK
LuFactor OK
LuInvert OK
LuSolve OK
nan OK
Near_Equal OK
OdeErrControl OK
OdeErrMaxabs OK
OdeGearControl OK
OdeGear OK
RombergMul OK
RombergOne OK
runge_45_1 OK
set_union OK
SimpleVector OK
thread_alloc OK
sparse_rc OK
sparse_rcv OK
to_string Error
vectorBool OK
memory_leak OK
1 tests failed.
End test group example/utility
make[3]: *** [example/utility/CMakeFiles/check_example_utility.dir/build.make:57: example/utility/CMakeFiles/check_example_utility] Error 1
make[2]: *** [CMakeFiles/Makefile2:1327: example/utility/CMakeFiles/check_example_utility.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/check.dir/rule] Error 2
make: *** [Makefile:164: check] Error 2
CMAKE_BUILD_TYPE
is "Release", compiler version is "g++ (Ubuntu 8.3.0-6ubuntu1) 8.3.0".
When compiling a program that includes CppAD with clang-7, the following error is thrown:
cppad/utility/check_simple_vector.hpp:134:10: error: no member named 'value' in 'CppAD::ok_if_S_same_as_T<double, float>'
The line in question is as shown below (const Scalar& x
is input to the function in question):
typedef typename Vector::value_type value_type;
struct ok_if_S_same_as_T<Scalar, value_type x_copy;
x_copy.value = x;
The structure in question is defined as below:
template <class S, class T> struct ok_if_S_same_as_t { };
template <class T> struct ok_if_S_same_as_T<T,T> {T value;};
The member value is referenced again on line 159 of the same file, and again an error is thrown during compilation with clang-7. I guess this has something to do with how the templated struct members are defined in the class after compilation. In this case, the member T value
is not defined in the struct that is instantiated (or it seems not to be just by looking at the struct definition).
class ADTape
is now in CppAD::local::
instead of CppAD::
This prevents compilation with Visual C++ 2015 with errors like this one:
1>e:\DevTools\CppAD\cppad/core/pow.hpp(110): error C2248: 'CppAD::local::ADTape<Base>::id_': cannot access private member declared in class 'CppAD::local::ADTape<Base>'
To fix Visual C++ compilation, all these friend
declarations:
friend AD<Base> pow <Base> (const AD<Base> &x, const AD<Base> &y);
should be changed to:
friend AD<Base> CppAD::pow <Base> (const AD<Base> &x, const AD<Base> &y);
because, for Visual C++, pow
is actually CppAD::local::pow
, and thus CppAD::pow
is not a friend of a class in CppAD::local::
namespace, unless the namespace is explicitly provided.
Would you like me to try to provide a pull request?
I'm trying to port CppAD
on vckg
. The compilation on arm64 - windows platform fails with the following error
-- cppad_tape_id_type_is_unsigned = 0
-- Warning: using a signed cppad_tape_id_type is for CppAD developers only !
-- Performing Test cppad_tape_addr_type_is_unsigned
-- Performing Test cppad_tape_addr_type_is_unsigned - Failed
-- cppad_tape_addr_type_is_unsigned = 0
-- Warning: using a signed cppad_tape_addr_type is for CppAD developers only !
-- Performing Test cppad_max_num_threads_is_integer_ge_4
-- Performing Test cppad_max_num_threads_is_integer_ge_4 - Failed
CMake Error at include/cppad/CMakeLists.txt:256 (MESSAGE):
cppad_max_num_threads is not an integer greater than or equal 4
Here the related comment written by @NancyLi1013: microsoft/vcpkg#12560 (comment)
The trailing comma in the enum here causes an error with gcc when called -pedantic-errors
.
There are two problems with the installation of header files using the autoconf set-up (I know you do not like it and that it's deprecated, but it is what we need to build the OS and the Optimization Suite). The first problem that is relatively easy to fix is that in makefile.am
here, you have
nobase_myinclude_HEADERS = \
include/cppad/base_require.hpp \
include/cppad/CMakeLists.txt \
include/cppad/configure.hpp.in \
...
the nobase
means that these files get installed with the full prefix (including the include
, see here) , so they end up in
<prefix>/include/include/cppad`
which I assume is not what you intend. I'm not actually sure what the right fix is here. I guess there must be a way to say "strip all prefixes and replace them with just cppad/
" (headers are already put into the include
directory by default).
A second issue is that you are installing configure.hpp.in
rather than configure.hpp
(see here).
Typically, these auto-generated headers are not installed (they are for internal use in building the project), but you are pulling it into a number of the other user-facing headers and source files and this is why it needs to be installed. I'm not sure if you want or need to address this. In the the other COIN-OR projects, we generate two different configuration headers---one with internal symbols only needed to build the libraries and one with symbols meant to be exported.
I know you probably want a PR, but I can't easily re-generate makefile.in
for reasons we've discussed. It should be straightforward to fix these two issues and then I can test to see if everything is OK.
It would be really useful to add additional methods to CppAD::vector so that for each and std algorithms could be used.
The following methods would be useful:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
reference front() noexcept;
const_reference front() const noexcept;
reference back() noexcept;
const_reference back() const noexcept;
In the file cppad/utility/check_simple_vector.hpp
, it appears that the size of a vector built with the default constructor should be zero.
// size member function
CPPAD_ASSERT_KNOWN(
d.size() == 0,
"default construtor result does not have size zero"
);
My question is why this aspect is required (at least in debug mode)?
In this case, it appears impossible to use Eigen fixed-size vector for instance.
Building OS from COIN-OR fails when building with the Microsoft compiler using the autotools from CYGWIN because OS automatically prefers the Microsoft compiler when the option --enable-msvc
is given, whereas CppAD prefers the CYGWIN version of gcc
. When the Microsoft compiler is 32-bit, but the gcc
compiler found is 64-bit, then the check for whether size_t
is different from unsigned int
gets an incorrect result for the actual platform.
A workaround is to specify CC=cl
, which fixes the problem, but this is not necessary for OS because the --enable-msvc
option does it automatically. This option was implemented for convenience in building with Visual Studio without the IDE and invokes some additional logic which is needed when building with cl
.
I realize you are trying to deprecate the use of the autotools, but would you be willing to consider adding the --enable-msvc
option to CppAD? If you would prefer, I can make the change myself and then submit a pull request.
Hi all. I'm trying to compile this library on Windows using VisualStudio2019
+ CMake
.
The project is generated without any error. However, when I compile the code on VisualStudio
I obtain the following errors
1>------ Build started: Project: cppad_lib, Configuration: RelWithDebInfo x64 ------
1>cppad_colpack.cpp
1>C:\Users\gromualdi\robot-code\CppAD\cppad_lib\cppad_colpack.cpp(21,5): error C2491: 'CppAD::local::this_routine_should_never_get_called': definition of dllimport function not allowed
1>json_parser.cpp
1>C:\Users\gromualdi\robot-code\CppAD\cppad_lib\json_parser.cpp(23,44): error C2375: 'CppAD::local::graph::json_parser': redefinition; different linkage
1>C:\Users\gromualdi\robot-code\CppAD\include\cppad/local/graph/json_parser.hpp(45): message : see declaration of 'CppAD::local::graph::json_parser'
1>C:\Users\gromualdi\robot-code\CppAD\cppad_lib\json_parser.cpp(26,1): error C2491: 'CppAD::local::graph::json_parser': definition of dllimport function not allowed
1>json_writer.cpp
1>C:\Users\gromualdi\robot-code\CppAD\cppad_lib\json_writer.cpp(20,44): error C2375: 'CppAD::local::graph::json_writer': redefinition; different linkage
1>C:\Users\gromualdi\robot-code\CppAD\include\cppad/local/graph/json_writer.hpp(44): message : see declaration of 'CppAD::local::graph::json_writer'
1>C:\Users\gromualdi\robot-code\CppAD\cppad_lib\json_writer.cpp(23,1): error C2491: 'CppAD::local::graph::json_writer': definition of dllimport function not allowed
1>Generating Code...
1>Done building project "cppad_lib.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
The error is given by the usage of the maco
CPPAD_LIB_EXPORT
(alias of __declspec(dllimport)
). Indeed as written in the Microsoft documentation, __declspec(dllimport)
keyword cannot be applied to implement a function. The issue can be easily solved by moving the keyword to the declaration of the function.
For instance this patch solves the problem (in mine configuration). If you want I can open a PR, however the problem cannot be considered solved by this patch
. Indeed unexplored preprocessor if branches
may have the similar problem.
See for instance:
CppAD/cppad_lib/cppad_colpack.cpp
Line 55 in 650e5df
diff --git a/cppad_lib/cppad_colpack.cpp b/cppad_lib/cppad_colpack.cpp
index dc3327053..c815275f4 100644
--- a/cppad_lib/cppad_colpack.cpp
+++ b/cppad_lib/cppad_colpack.cpp
@@ -17,7 +17,9 @@ in the Eclipse Public License, Version 2.0 are satisfied:
# if CPPAD_HAS_COLPACK == 0
namespace CppAD { namespace local {
- CPPAD_LIB_EXPORT void this_routine_should_never_get_called(void)
+ CPPAD_LIB_EXPORT void this_routine_should_never_get_called(void);
+
+ void this_routine_should_never_get_called(void)
{ CPPAD_ASSERT_UNKNOWN(false); }
} }
# else // CPPAD_HAS_COLPACK
diff --git a/cppad_lib/json_parser.cpp b/cppad_lib/json_parser.cpp
index fac417d9f..ac0910cee 100644
--- a/cppad_lib/json_parser.cpp
+++ b/cppad_lib/json_parser.cpp
@@ -20,7 +20,7 @@ in the Eclipse Public License, Version 2.0 are satisfied:
// documentation for this routine is in the file below
# include <cppad/local/graph/json_parser.hpp>
-CPPAD_LIB_EXPORT void CppAD::local::graph::json_parser(
+void CppAD::local::graph::json_parser(
const std::string& json ,
cpp_graph& graph_obj )
{ using std::string;
diff --git a/cppad_lib/json_writer.cpp b/cppad_lib/json_writer.cpp
index 250345c6e..add4b20a9 100644
--- a/cppad_lib/json_writer.cpp
+++ b/cppad_lib/json_writer.cpp
@@ -17,7 +17,7 @@ in the Eclipse Public License, Version 2.0 are satisfied:
// documentation for this routine is in the file below
# include <cppad/local/graph/json_writer.hpp>
-CPPAD_LIB_EXPORT void CppAD::local::graph::json_writer(
+void CppAD::local::graph::json_writer(
std::string& json ,
const cpp_graph& graph_obj )
{ using std::string;
diff --git a/include/cppad/local/graph/json_parser.hpp b/include/cppad/local/graph/json_parser.hpp
index 17bcc7c7e..a28d2c045 100644
--- a/include/cppad/local/graph/json_parser.hpp
+++ b/include/cppad/local/graph/json_parser.hpp
@@ -42,7 +42,7 @@ Upon return it is a $cref cpp_ad_graph$$ representation of this function.
$head Prototype$$
$srccode%hpp% */
namespace CppAD { namespace local { namespace graph {
- void json_parser(
+ CPPAD_LIB_EXPORT void json_parser(
const std::string& json ,
cpp_graph& graph_obj
);
diff --git a/include/cppad/local/graph/json_writer.hpp b/include/cppad/local/graph/json_writer.hpp
index 36a4cb39f..299c56cc0 100644
--- a/include/cppad/local/graph/json_writer.hpp
+++ b/include/cppad/local/graph/json_writer.hpp
@@ -41,7 +41,7 @@ This is a $code cpp_graph$$ object.
$head Prototype$$
$srccode%hpp% */
namespace CppAD { namespace local { namespace graph {
- void json_writer(
+ CPPAD_LIB_EXPORT void json_writer(
std::string& json ,
const cpp_graph& graph_obj
);
Hello,
The new CppAD 2017 is computing a different sparsity pattern for a Jacobian than the 2016 version.
The model where I observe this behavior involves atomic functions (CppAD::checkpoint).
The following code will compile in both versions but return different sparsity patterns.
The model is a bit large but I don't detect any issues in my small examples.
It was checked by valgrind and no issues were detected.
#include <cppad/cppad.hpp>
#include <assert.h>
#include <vector>
using namespace CppAD;
std::vector<CppAD::AD<double> > evaluateModel(const std::vector<CppAD::AD<double> >& x,
size_t repeat,
CppAD::atomic_base<double>& atomModel);
std::vector<double> getTypicalValues(std::vector<double> xa,
size_t repeat);
const size_t K_ = 3;
const size_t ns_ = 4;
const size_t nm_ = 2;
const size_t npar_ = 22;
const size_t na_ = ns_ + nm_ + npar_;
int main(int argc, char *argv[]) {
/**
* create atomic function
*/
auto atomicFunction = [](const std::vector <AD<double>>& ind,
std::vector <AD<double>>& dxdt) {
// temporary variables
std::vector<AD<double> > v(17);
v[0] = ind[8] * ind[10];
v[1] = ind[9] * ind[11];
v[2] = 0.1768325928384763 * ind[0];
v[3] = 0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[2] + -0.00191 * ind[2] * ind[2] + 1.8211e-06 * ind[2] * ind[2] * ind[2]);
v[4] = v[2] * v[3];
v[5] = ((v[4] - 1.0e-15 * ind[1] * v[2]) / 0.0180152833) / v[2];
v[6] = (v[5] * v[2]) / (ind[1] * v[2] + v[5] * v[2]);
v[7] = 1 - v[6];
v[8] = (0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[2] + -0.00191 * ind[2] * ind[2] + 1.8211e-06 * ind[2] * ind[2] * ind[2]) * ind[5]) / (1.0e-15 * v[7] + 0.0180152833 * v[6]);
v[9] = exp(log(ind[6]) - (8.31447215 * ind[7]) / (8.31447215 * ind[2]));
v[7] = v[0] + v[1] - v[7] * v[8] + -1 * v[9] * v[2];
v[10] = 0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[12] + -0.00191 * ind[12] * ind[12] + 1.8211e-06 * ind[12] * ind[12] * ind[12]) * ind[10];
v[11] = 0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[13] + -0.00191 * ind[13] * ind[13] + 1.8211e-06 * ind[13] * ind[13] * ind[13]) * ind[11];
v[12] = ind[12] * ind[12];
v[13] = ind[2] * ind[2];
v[14] = ind[13] * ind[13];
v[15] = ind[2] * ind[2];
v[16] = ind[22] * (0.1768325928384763 + 1.4906857141283567 * ind[0]) * (ind[2] - ind[3]);
dxdt[2] = (1.0e-15 * v[0] * ind[15] * (ind[12] - ind[2]) + v[10] * (15340.863387921299 * (ind[12] - ind[2]) + -58.009079435348092 * (ind[12] * ind[12] - ind[2] * ind[2]) + 0.1503353174209219 * (ind[12] * ind[12] * ind[12] - ind[2] * ind[2] * ind[2]) + -0.00019588923145049848 * (ind[12] * ind[12] * ind[12] * ind[12] - ind[2] * ind[2] * ind[2] * ind[2]) + 1.0402389841962685e-07 * (v[12] * v[12] * ind[12] - v[13] * v[13] * ind[2])) + 1.0e-15 * v[1] * ind[15] * (ind[13] - ind[2]) + v[11] * (15340.863387921299 * (ind[13] - ind[2]) + -58.009079435348092 * (ind[13] * ind[13] - ind[2] * ind[2]) + 0.1503353174209219 * (ind[13] * ind[13] * ind[13] - ind[2] * ind[2] * ind[2]) + -0.00019588923145049848 * (ind[13] * ind[13] * ind[13] * ind[13] - ind[2] * ind[2] * ind[2] * ind[2]) + 1.0402389841962685e-07 * (v[14] * v[14] * ind[13] - v[15] * v[15] * ind[2])) - ind[16] * v[9] * v[2] + 0 - v[16]) / (v[4] * (1.0e-15 * ind[1] * ind[15] + 0.0180152833 * v[5] * (15340.863387921299 + -116.01815887069618 * ind[2] + 0.45100595226276569 * ind[2] * ind[2] + -0.00078355692580199391 * ind[2] * ind[2] * ind[2] + 5.2011949209813426e-07 * ind[2] * ind[2] * ind[2] * ind[2])) / (1.0e-15 * ind[1] + 0.0180152833 * v[5]) + ind[27]);
v[11] = (1.0e-15 * v[7] + 0.0180152833 * (v[10] / 0.0180152833 + v[11] / 0.0180152833 - v[6] * v[8]) - v[2] * 0.0180152833 * 1000 * (0.64038 + -0.00382 * ind[2] + 5.4633e-06 * ind[2] * ind[2]) * dxdt[2]) / v[3];
dxdt[0] = v[11] / 0.1768325928384763;
dxdt[1] = (v[7] - ind[1] * v[11]) / v[2];
v[11] = ind[17] * ind[17];
v[7] = ind[3] * ind[3];
dxdt[3] = (0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[17] + -0.00191 * ind[17] * ind[17] + 1.8211e-06 * ind[17] * ind[17] * ind[17]) * ind[4] * (15340.863387921299 * (ind[17] - ind[3]) + -58.009079435348092 * (ind[17] * ind[17] - ind[3] * ind[3]) + 0.1503353174209219 * (ind[17] * ind[17] * ind[17] - ind[3] * ind[3] * ind[3]) + -0.00019588923145049848 * (ind[17] * ind[17] * ind[17] * ind[17] - ind[3] * ind[3] * ind[3] * ind[3]) + 1.0402389841962685e-07 * (v[11] * v[11] * ind[17] - v[7] * v[7] * ind[3])) + v[16]) / (0.0180152833 * (0.0180152833 * 1000 * (-13.851 + 0.64038 * ind[3] + -0.00191 * ind[3] * ind[3] + 1.8211e-06 * ind[3] * ind[3] * ind[3])) / 0.0180152833 * ind[26] * (15340.863387921299 + -116.01815887069618 * ind[3] + 0.45100595226276569 * ind[3] * ind[3] + -0.00078355692580199391 * ind[3] * ind[3] * ind[3] + 5.2011949209813426e-07 * ind[3] * ind[3] * ind[3] * ind[3]) + ind[19]);
};
std::vector<double> xx(na_);
xx[0] = 0.3; // h
xx[1] = 7.82e3; // Ca
xx[2] = 304.65; // Tr
xx[3] = 301.15; // Tj
xx[4] = 2.3333e-04; // u1
xx[5] = 6.6667e-05; // u2
xx[6] = 6.2e14; //
xx[7] = 10080; //
xx[8] = 2e3; //
xx[9] = 10e3; //
xx[10] = 1e-11; //
xx[11] = 6.6667e-05; //
xx[12] = 294.15; //
xx[13] = 294.15; //
xx[14] = 1000; //
xx[15] = 4184; //Cp
xx[16] = -33488; //deltaH
xx[17] = 299.15; // Tj0
xx[18] = 302.65; // Tj2
xx[19] = 7e5; // cwallj
xx[20] = 1203; // csteam
xx[21] = 3.22; //dsteam
xx[22] = 950.0; //Ug
xx[23] = 0.48649427192323; //vc6in
xx[24] = 1000; //rhoj
xx[25] = 4184; //Cpj
xx[26] = 0.014; //Vj
xx[27] = 1e-7; //cwallr
std::vector<AD<double>> ay(ns_), ax(na_);
for(size_t i = 0; i < na_; ++i)
ax[i] = xx[i];
checkpoint<double> atomic("cstr",
atomicFunction,
ax,
ay,
atomic_base<double>::set_sparsity_enum);
/**
* create tape
*/
size_t repeat = 6;
std::vector<double> xTypical = getTypicalValues(xx, repeat);
size_t n = xTypical.size();
std::vector <AD<double>> u(n);
for (size_t j = 0; j < n; j++)
u[j] = xTypical[j];
CppAD::Independent(u);
std::vector<AD<double>> v = evaluateModel(u, repeat, atomic);
ADFun<double> fun;
fun.Dependent(v);
/**
* determine Jacobian sparsity
*/
size_t m = fun.Range();
std::vector<std::set<size_t> > s_s(m);
for (size_t i = 0; i < m; i++)
s_s[i].insert(i);
auto sparsity = fun.RevSparseJac(m, s_s);
size_t nnz = 0;
for (const auto& s: sparsity) {
nnz += s.size();
}
std::cout << "expects: 1260" << std::endl;
std::cout << "computed: " << nnz << std::endl;
assert(nnz == 1260);
}
std::vector<double> getTypicalValues(std::vector<double> xa,
size_t repeat) {
/**
* collocation model values
*/
size_t nvarsk = ns_;
size_t nMstart = npar_ + nvarsk * K_ * repeat + nvarsk;
std::vector<double> x(nMstart + repeat * nm_, 1.0);
// parameters
for (size_t j = 0; j < npar_; j++)
x[j] = xa[ns_ + nm_ + j];
size_t s = npar_;
// i = 0 K = 0
// states
for (size_t j = 0; j < ns_; j++) {
x[s++] = xa[j];
}
for (size_t i = 0; i < repeat; i++) {
// controls
for (size_t j = 0; j < nm_; j++) {
x[nMstart + nm_ * i + j] = xa[ns_ + j];
}
// K = 1
// states
for (size_t j = 0; j < ns_; j++) {
x[s] = 1.0 + 0.01 * i;
x[s++] = xa[j];
}
// K = 2
// states
for (size_t j = 0; j < ns_; j++) {
x[s++] = xa[j];
}
// K = 3
// states
for (size_t j = 0; j < ns_; j++) {
x[s++] = xa[j];
}
}
return x;
}
std::vector<CppAD::AD<double> > evaluateModel(const std::vector<CppAD::AD<double> >& x,
size_t repeat,
CppAD::atomic_base<double>& atomModel) {
size_t m2 = repeat * K_ * ns_;
// dependent variable vector
std::vector<AD<double> > dep(m2);
std::vector<AD<double> > dxikdt(ns_);
std::vector<AD<double> > xik(na_);
// parameters
for (size_t j = 0; j < npar_; j++)
xik[ns_ + nm_ + j] = x[j];
size_t s = npar_;
size_t nvarsk = ns_;
size_t nMstart = npar_ + nvarsk * K_ * repeat + nvarsk;
size_t eq = 0;
for (size_t i = 0; i < repeat; i++) {
size_t s0 = s;
// controls
for (size_t j = 0; j < nm_; j++) {
xik[ns_ + j] = x[nMstart + nm_ * i + j];
}
// K = 1
for (size_t j = 0; j < ns_; j++) {
xik[j] = x[s + j]; // states
}
s += nvarsk;
// xik[ns + nm + npar] = x[s + ns];// time
atomModel(xik, dxikdt); // ODE
for (size_t j = 0; j < ns_; j++) {
dep[eq + j] = dxikdt[j]
+ 0.13797958971132715 * x[s0 + j]
+ -0.10749149571305303 * x[s0 + nvarsk + j]
+ -0.038928002823013501 * x[s0 + 2 * nvarsk + j]
+ 0.008439908824739363 * x[s0 + 3 * nvarsk + j];
}
eq += ns_;
// K = 2
for (size_t j = 0; j < ns_; j++) {
xik[j] = x[s + j]; // states
}
s += nvarsk;
// xik[ns + nm + npar] = x[s + ns];// time
atomModel(xik, dxikdt); // ODE
for (size_t j = 0; j < ns_; j++) {
dep[eq + j] = dxikdt[j]
+ -0.057979589711327127 * x[s0 + j]
+ 0.11892800282301351 * x[s0 + nvarsk + j]
+ -0.025841837620280327 * x[s0 + 2 * nvarsk + j]
+ -0.035106575491406049 * x[s0 + 3 * nvarsk + j];
}
eq += ns_;
// K = 3
for (size_t j = 0; j < ns_; j++) {
xik[j] = x[s + j]; // states
}
s += nvarsk;
// xik[ns + nm + npar] = x[s + ns];// time
atomModel(xik, dxikdt); // ODE
for (size_t j = 0; j < ns_; j++) {
dep[eq + j] = dxikdt[j]
+ 0.099999999999999978 * x[s0 + j]
+ -0.18439908824739357 * x[s0 + nvarsk + j]
+ 0.25106575491406025 * x[s0 + 2 * nvarsk + j]
+ -0.16666666666666669 * x[s0 + 3 * nvarsk + j];
}
eq += ns_;
}
return dep;
}
I have a x^0.3 * y^0.7 and try to differentiate at 0. I would expect some NaN or Inf in the Jacobian or some error, but I get a (0,0):
#include <cstdio>
#include "cppad/cppad.hpp"
using namespace std;
template <class Type>
void eval(const vector<Type>& x, vector<Type>& y)
{
y[0] = pow(x[0], 0.3) * pow(x[1], 0.7);
}
int main(int argc, char** argv)
{
vector< double> x(2);
vector< CppAD::AD<double> > X(2);
vector< CppAD::AD<double> > Y(1);
X[0] = x[0] = 0.0;
X[1] = x[1] = 0.0;
CppAD::Independent(X);
eval(X, Y);
CppAD::ADFun<double> f;
f.Dependent(X, Y);
printf("val in 0: %g\n", CppAD::Value(Y[0]));
vector<double> jac = f.Jacobian(x);
printf("grad in 0: %g %g\n", jac[0], jac[1]);
return 0;
}
I'm trying to port CppAD
on vckg
. The compilation on universal windows platform fails with the following error
Make Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
cppad_has_signed_long_long_EXITCODE (advanced)
cppad_has_signed_long_long_EXITCODE__TRYRUN_OUTPUT (advanced)
For details see D:/buildtrees/cppad/x64-uwp-dbg/TryRunResults.cmake
-- Performing Test cppad_has_signed_long_long - Failed
-- cppad_has_signed_long_long = 1
-- Performing Test cppad_has_rvalue
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
cppad_has_rvalue_EXITCODE (advanced)
cppad_has_rvalue_EXITCODE__TRYRUN_OUTPUT (advanced)
For details see D:/buildtrees/cppad/x64-uwp-dbg/TryRunResults.cmake
-- Performing Test cppad_has_rvalue - Failed
-- cppad_has_rvalue = 1
-- Performing Test cppad_has_nullptr
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
cppad_has_nullptr_EXITCODE (advanced)
cppad_has_nullptr_EXITCODE__TRYRUN_OUTPUT (advanced)
For details see D:/buildtrees/cppad/x64-uwp-dbg/TryRunResults.cmake
-- Performing Test cppad_has_nullptr - Failed
-- cppad_has_nullptr = 1
-- Performing Test cppad_has_long_long
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
cppad_has_long_long_EXITCODE (advanced)
cppad_has_long_long_EXITCODE__TRYRUN_OUTPUT (advanced)
Here the related comment written by @NancyLi1013: microsoft/vcpkg#12560 (comment)
The optimize()
method in ADFun will determine which operations can be skipped when using conditional expressions so that only the required branch needs to be evaluated.
When using AD<AD<double> >
or AD<CG<double> >
these operations should not be skipped.
Here is a file to reproduce the issue:
#! /bin/bash -e
# $Id$
# -----------------------------------------------------------------------------
# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
#
# CppAD is distributed under multiple licenses. This distribution is under
# the terms of the
# Eclipse Public License Version 1.0.
#
# A copy of this license is included in the COPYING file of this distribution.
# Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
# -----------------------------------------------------------------------------
cat << EOF
Description
EOF
cat << EOF > bug.$$
#include <iostream>
#include <cppad/cppad.hpp>
int main(void) {
using namespace CppAD;
typedef AD<double> adouble;
typedef AD<adouble> a2double;
std::vector<double> x{0, 1};
/**
* First tape
* (using AD<AD<double> >)
*/
std::vector<a2double> a2x(x.size());
for (size_t i = 0; i < a2x.size(); i++) {
a2x[i] = adouble(x[i]);
}
Independent(a2x);
std::vector<a2double> a2y(1);
a2double a = a2x[0] * a2x[1];
a2y[0] = CondExpEq(a2x[0], a2double(1.0), a, a2double(0.0));
// create f: X -> Y
ADFun<adouble> f1(a2x, a2y);
f1.optimize(); // <<<<<<<<<<<<<<< causes the issue
/**
* Second tape
* (using AD<double>)
*/
std::vector<adouble> ax{adouble(1), adouble(0)};
Independent(ax);
std::vector<adouble> ay = f1.Forward(0, ax);// <<<<<<<<<<<< assertion fails here!
CppAD::ADFun<double> f2(ax, ay);
/**
* Use second tape
*/
x = {1, 0.5};
std::vector<double> y = f2.Forward(0, x);
//std::cout << y[0] << std::endl;
assert(std::abs(y[0] - x[0] * x[1]) < 1e-10);
}
EOF
# -----------------------------------------------------------------------------
if [ ! -e build ]
then
mkdir build
fi
cd build
echo "$0"
name=`echo $0 | sed -e 's|.*/||' -e 's|\..*||'`
mv ../bug.$$ $name.cpp
echo "g++ -I../.. --std=c++11 -g $name.cpp -o $name"
g++ -I../.. --std=c++11 -g $name.cpp -o $name
#
echo "./$name"
if ./$name
then
echo "OK"
else
echo "Error"
fi
Not sure if this is a feature or a bug, but the following code generates not a number derivatives while the actual derivatives should be zero.
#! /bin/bash -e
# $Id$
# -----------------------------------------------------------------------------
# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
#
# CppAD is distributed under multiple licenses. This distribution is under
# the terms of the
# Eclipse Public License Version 1.0.
#
# A copy of this license is included in the COPYING file of this distribution.
# Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
# -----------------------------------------------------------------------------
cat << EOF
The program fails with following assertion
cppad-20141230 error from a known source:
dw = f.Reverse(q, w): has a nan,
but none of its Taylor coefficents are nan.
Error detected by false result for
! ( hasnan(value) && check_for_nan_ )
at line 202 in the file
../../cppad/local/reverse.hpp
EOF
cat << EOF > bug.$$
#include <cppad/cppad.hpp>
using namespace CppAD;
int main(void) {
std::vector<AD<double>> X(2);
X[0] = 1.;
X[1] = 1.;
Independent(X);
std::vector<AD<double>> Y(1);
// Y[0] = X[1] > 1.0 ? X[0] / X[1] : 0;
Y[0] = CondExpGt(X[1], AD<double>(1.0), X[0] / X[1], AD<double>(0.0));
ADFun<double> fun(X, Y);
std::vector<double> u(2);
u[0] = 1.;
u[1] = 0.;
std::vector<double> J(2);
J = fun.Jacobian(u);
assert(J[0] == 0.0);
assert(J[1] == 0.0);
return 0;
}
EOF
# -----------------------------------------------------------------------------
if [ ! -e build ]
then
mkdir build
fi
cd build
echo "$0"
name=`echo $0 | sed -e 's|.*/||' -e 's|\..*||'`
mv ../bug.$$ $name.cpp
echo "g++ -I../.. --std=c++11 -g $name.cpp -o $name"
g++ -I../.. --std=c++11 -g $name.cpp -o $name
#
echo "./$name"
if ./$name
then
echo "OK"
else
echo "Error"
fi
Would it be possible to expand the atomic function class to allow the definition of parameters?
when I use cppad I get this error:
cppad-20200905 error from a known source:
vector: index greater than or equal vector size
Error detected by false result for
i < length
at line 341 in the file
/usr/local/include/cppad/utility/vector.hpp
MPC_Node: /usr/local/include/cppad/utility/error_handler.hpp:206: static void CppAD::ErrorHandler::Default(bool, int, const char*, const char*, const char*): Assertion false failed
Aborted (core dumped)_
Does anyone know how to fix it? I'm very appreciate it!
With recent updates to Eigen and CppAD, I finally found time to ensure my code is compatible with the latest versions of both. However, I am now getting the following error after make check example. I did not have the problem with Eigen 3.2.9, but I don’t know if it’s something that needs to be changed in Eigen or CppAD.
Thanks,
braunm: ~/cppad/build $ make check example
[ 3%] Built target speed_example
[ 6%] Built target speed_src
det_of_minor OK
det_by_minor OK
det_by_lu OK
elapsed_seconds OK
mat_sum_sq OK
ode_evaluate OK
sparse_hes_fun OK
sparse_jac_fun OK
speed_test OK
time_test
rel_diff = 0.144506
Error: perhaps too many other programs running
All 9 tests passed (possibly excepting elapsed_seconds).
[ 6%] Built target check_speed_example
[ 9%] Built target speed_cppad
cppad_det_lu_ok = true
cppad_det_minor_ok = true
cppad_mat_mul_ok = true
cppad_ode_ok = true
cppad_poly_ok = true
cppad_sparse_hessian_ok = true
cppad_sparse_jacobian_ok = true
All 7 correctness tests passed.
[ 9%] Built target check_speed_cppad
[ 11%] Built target speed_double
double_det_lu_ok = true
double_det_minor_ok = true
double_mat_mul_ok = true
double_ode_ok = true
double_poly_ok = true
double_sparse_hessian_ok = true
double_sparse_jacobian_ok = true
All 7 correctness tests passed.
[ 11%] Built target check_speed_double
[ 11%] Built target check_speed
[ 11%] Built target introduction_get_started
f'(3) computed by CppAD = 142
[ 11%] Built target check_introduction_get_started
[ 16%] Built target introduction_exp_apx
exp_2 OK
exp_2_cppad OK
exp_2_for0 OK
exp_2_for1 OK
exp_2_for2 OK
exp_2_rev1 OK
exp_2_rev2 OK
exp_eps OK
exp_eps_cppad OK
exp_eps_for0 OK
exp_eps_for1 OK
exp_eps_for2 OK
exp_eps_rev1 OK
exp_eps_rev2 OK
All 14 tests passed.
[ 16%] Built target check_introduction_exp_apx
[ 16%] Built target check_introduction
[ 22%] Built target example_atomic
OK: atomic: checkpoint
OK: atomic: extended_ode
OK: atomic: for_sparse_hes
OK: atomic: for_sparse_jac
OK: atomic: forward
OK: atomic: get_started
OK: atomic: mat_mul
OK: atomic: mul_level
OK: atomic: norm_sq
OK: atomic: ode
OK: atomic: reciprocal
OK: atomic: rev_sparse_hes
OK: atomic: rev_sparse_jac
OK: atomic: reverse
OK: atomic: set_sparsity
OK: atomic: tangent
OK: atomic: eigen_cholesky
OK: atomic: eigen_mat_inv
OK: atomic: eigen_mat_mul
OK: No memory leak detected
All 20 tests passed.
[ 22%] Built target check_example_atomic
[ 24%] Built target example_optimize
OK: optimize: compare_op
OK: optimize: cumulative_sum
OK: optimize: conditional_skip
OK: optimize: forward_active
OK: optimize: nest_conditional
OK: optimize: print_for
OK: optimize: reverse_active
OK: No memory leak detected
All 8 tests passed.
[ 24%] Built target check_example_optimize
[ 31%] Built target example_sparse
OK: sparse: sub_sparse_hes
OK: sparse: sparsity_sub
OK: sparse: sparse_sub_hes
OK: sparse: sparse_hes
OK: sparse: sparse_jac_for
OK: sparse: sparse_jac_rev
OK: sparse: sparse_jacobian
OK: sparse: sparse_hessian
OK: sparse: rev_hes_sparsity
OK: sparse: rev_jac_sparsity
OK: sparse: RevSparseJac
OK: sparse: rev_sparse_hes
OK: sparse: for_hes_sparsity
OK: sparse: for_jac_sparsity
OK: sparse: ForSparseJac
OK: sparse: for_sparse_hes
OK: sparse: dependency
OK: sparse: conj_grad
OK: sparse: rc_sparsity
OK: No memory leak detected
All 20 tests passed.
[ 31%] Built target check_example_sparse
[ 38%] Built target example_utility
OK: utility: CheckNumericType
OK: utility: CheckSimpleVector
OK: utility: CppAD_vector
OK: utility: ErrorHandler
OK: utility: index_sort
OK: utility: LuFactor
OK: utility: LuInvert
OK: utility: LuSolve
OK: utility: nan
OK: utility: Near_Equal
OK: utility: OdeErrControl
OK: utility: OdeErrMaxabs
OK: utility: OdeGearControl
OK: utility: OdeGear
OK: utility: RombergMul
OK: utility: RombergOne
OK: utility: runge_45_1
OK: utility: set_union
OK: utility: SimpleVector
OK: utility: thread_alloc
OK: utility: sparse_rc
OK: utility: sparse_rcv
OK: utility: to_string
OK: utility: vectorBool
OK: No memory leak detected
All 25 tests passed.
[ 38%] Built target check_example_utility
[ 39%] Building CXX object example/CMakeFiles/example.dir/eigen_det.cpp.o
In file included from /Users/braunm/cppad/example/eigen_det.cpp:30:
/Users/braunm/cppad/cppad/example/cppad_eigen.hpp:149:10: error: no template named
'significant_decimals_default_impl'; did you mean 'significant_decimals_impl'?
struct significant_decimals_default_impl< CppAD::AD<Base>, false>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
significant_decimals_impl
/opt/eigen/include/Eigen/src/Core/IO.h:118:8: note: 'significant_decimals_impl' declared here
struct significant_decimals_impl
^
In file included from /Users/braunm/cppad/example/eigen_det.cpp:30:
/Users/braunm/cppad/cppad/example/cppad_eigen.hpp:149:10: error: too many template arguments for
class template 'significant_decimals_impl'
struct significant_decimals_default_impl< CppAD::AD<Base>, false>
^ ~~~~~~
/opt/eigen/include/Eigen/src/Core/IO.h:118:8: note: template is declared here
struct significant_decimals_impl
^
In file included from /Users/braunm/cppad/example/eigen_det.cpp:30:
In file included from /Users/braunm/cppad/cppad/example/cppad_eigen.hpp:73:
In file included from /opt/eigen/include/Eigen/Core:348:
/opt/eigen/include/Eigen/src/Core/util/XprHelper.h:64:98: error: no type named 'Literal' in
'Eigen::NumTraits<CppAD::AD<double> >'
...: promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/opt/eigen/include/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:50:1: note: in instantiation
of template class 'Eigen::internal::promote_scalar_arg<CppAD::AD<double>,
Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, false>' requested here
EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product)
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:958:3: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP'
EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME)
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:940:120: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT'
...EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<Sca...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:492:30: note: while substituting deduced template
arguments into function template 'operator*' [with T =
Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>]
A22.noalias() -= A21 * A12;
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:509:7: note: in instantiation of member function
'Eigen::internal::partial_lu_impl<CppAD::AD<double>, 0, int>::blocked_lu' requested here
::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpo...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:530:13: note: in instantiation of function
template specialization
'Eigen::internal::partial_lu_inplace<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
Eigen::Transpositions<-1, -1, int> >' requested here
internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:131:7: note: in instantiation of member function
'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::compute'
requested here
compute();
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:323:3: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::compute<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested here
compute(matrix.derived());
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:591:10: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested
here
return PartialPivLU<PlainObject>(eval());
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:41:14: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::partialPivLu'
requested here
return m.partialPivLu().determinant();
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:96:83: note: in instantiation of member function
'Eigen::internal::determinant_impl<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
-1>::run' requested here
return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(de...
^
/Users/braunm/cppad/example/eigen_det.cpp:77:20: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::determinant'
requested here
a_y[0] = log( a_X.determinant() );
^
In file included from /Users/braunm/cppad/example/eigen_det.cpp:30:
In file included from /Users/braunm/cppad/cppad/example/cppad_eigen.hpp:73:
In file included from /opt/eigen/include/Eigen/Core:348:
/opt/eigen/include/Eigen/src/Core/util/XprHelper.h:64:98: error: no type named 'Literal' in
'Eigen::NumTraits<CppAD::AD<double> >'
...: promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/opt/eigen/include/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:50:1: note: in instantiation
of template class 'Eigen::internal::promote_scalar_arg<CppAD::AD<double>,
Eigen::VectorBlock<Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>,
-1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, 1, -1, false>, -1>, false>'
requested here
EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product)
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:958:3: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP'
EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME)
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:940:120: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT'
...EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<Sca...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:406:78: note: while substituting deduced template
arguments into function template 'operator*' [with T =
Eigen::VectorBlock<Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>,
-1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, 1, -1, false>, -1>]
lu.bottomRightCorner(rrows,rcols).noalias() -= lu.col(k).tail(rrows) * lu.row(k)...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:436:14: note: in instantiation of member function
'Eigen::internal::partial_lu_impl<CppAD::AD<double>, 0, int>::unblocked_lu' requested here
return unblocked_lu(lu, row_transpositions, nb_transpositions);
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:509:7: note: in instantiation of member function
'Eigen::internal::partial_lu_impl<CppAD::AD<double>, 0, int>::blocked_lu' requested here
::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpo...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:530:13: note: in instantiation of function
template specialization
'Eigen::internal::partial_lu_inplace<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
Eigen::Transpositions<-1, -1, int> >' requested here
internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:131:7: note: (skipping 1 context in backtrace;
use -ftemplate-backtrace-limit=0 to see all)
compute();
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:323:3: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::compute<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested here
compute(matrix.derived());
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:591:10: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested
here
return PartialPivLU<PlainObject>(eval());
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:41:14: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::partialPivLu'
requested here
return m.partialPivLu().determinant();
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:96:83: note: in instantiation of member function
'Eigen::internal::determinant_impl<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
-1>::run' requested here
return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(de...
^
/Users/braunm/cppad/example/eigen_det.cpp:77:20: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::determinant'
requested here
a_y[0] = log( a_X.determinant() );
^
In file included from /Users/braunm/cppad/example/eigen_det.cpp:30:
In file included from /Users/braunm/cppad/cppad/example/cppad_eigen.hpp:73:
In file included from /opt/eigen/include/Eigen/Core:348:
/opt/eigen/include/Eigen/src/Core/util/XprHelper.h:64:98: error: no type named 'Literal' in
'Eigen::NumTraits<CppAD::AD<double> >'
...: promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/opt/eigen/include/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:50:1: note: in instantiation
of template class 'Eigen::internal::promote_scalar_arg<CppAD::AD<double>,
Eigen::VectorBlock<Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>,
-1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, 1, true>, -1>, false>'
requested here
EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product)
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:957:3: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP'
EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
^
/opt/eigen/include/Eigen/src/Core/util/Macros.h:949:112: note: expanded from macro
'EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT'
...EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<Scalar EIGE...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:406:78: note: while substituting deduced template
arguments into function template 'operator*' [with T =
Eigen::VectorBlock<Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<CppAD::AD<double>,
-1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, 1, true>, -1>]
lu.bottomRightCorner(rrows,rcols).noalias() -= lu.col(k).tail(rrows) * lu.row(k)...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:436:14: note: in instantiation of member function
'Eigen::internal::partial_lu_impl<CppAD::AD<double>, 0, int>::unblocked_lu' requested here
return unblocked_lu(lu, row_transpositions, nb_transpositions);
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:509:7: note: in instantiation of member function
'Eigen::internal::partial_lu_impl<CppAD::AD<double>, 0, int>::blocked_lu' requested here
::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpo...
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:530:13: note: in instantiation of function
template specialization
'Eigen::internal::partial_lu_inplace<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
Eigen::Transpositions<-1, -1, int> >' requested here
internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:131:7: note: (skipping 1 context in backtrace;
use -ftemplate-backtrace-limit=0 to see all)
compute();
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:323:3: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::compute<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested here
compute(matrix.derived());
^
/opt/eigen/include/Eigen/src/LU/PartialPivLU.h:591:10: note: in instantiation of function
template specialization 'Eigen::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0,
-1, -1> >::PartialPivLU<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >' requested
here
return PartialPivLU<PlainObject>(eval());
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:41:14: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::partialPivLu'
requested here
return m.partialPivLu().determinant();
^
/opt/eigen/include/Eigen/src/LU/Determinant.h:96:83: note: in instantiation of member function
'Eigen::internal::determinant_impl<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1>,
-1>::run' requested here
return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(de...
^
/Users/braunm/cppad/example/eigen_det.cpp:77:20: note: in instantiation of member function
'Eigen::MatrixBase<Eigen::Matrix<CppAD::AD<double>, -1, -1, 0, -1, -1> >::determinant'
requested here
a_y[0] = log( a_X.determinant() );
^
5 errors generated.
make[3]: *** [example/CMakeFiles/example.dir/eigen_det.cpp.o] Error 1
make[2]: *** [example/CMakeFiles/example.dir/all] Error 2
make[1]: *** [CMakeFiles/check.dir/rule] Error 2
make: *** [check] Error 2
Michael Braun
Associate Professor of Marketing
Cox School of Business
Southern Methodist University
Dallas, TX 75275
braunm --at-- smu.edu
I am attempting to build COIN-OS from the latest trunk version. During the make step, the following error results:
Making all in cppad
make[1]: Entering directory /c/coin-os/5287.1/cppad' cp cppad/configure.hpp ../../cppad/cppad/configure.hpp SPEED_DIRS = make[1]: SPEED_DIRS: Command not found make[1]: *** [../../cppad/cppad/configure.hpp] Error 127 make[1]: Leaving directory
/c/coin-os/5287.1/cppad'
make: *** [all-recursive] Error 1
Do you have any idea what would cause this error and what the fix would be?
(make.log and config.log for cppad are attached.)
make 1-4-18 141pm.log
config-cppad.log
The cppad.pc
file generated by the library does not contain the usual structure
prefix=${pcfiledir}/../..
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
However, this creates several problems when I tried to import the library in vcpkg
microsoft/vcpkg#12560
Indeed as @Neumann-A suggested in microsoft/vcpkg#12560 (comment) the prefix
variable must be defined in every pkg-config file.
FYI @traversaro
For some reason, the following line appears in cppad-uninstalled.pc
Libs: -L@cppad_BINARY_DIR@/lib -lcppad_lib
although there is no cppad_lib
installed by default and the variable @cppad_BINARY_DIR@
is not defined during configuration. the Libs
line that line appears in cppad.pc.in
is empty, which seems correct.
At the moment, the OS
build fails with a git checkout on Linux because cppad.pc
is not installed in the default location, which means that it is not found by the configure
script of OS. The fallback is to check for an uninstalled version of CppAD, which is found, but with the line above. This then adds -lcppad_lib
to the link line and the linking fails.
Emptying the Libs
line in cppad-uninstalled.pc
fixes the issue, although it is still the case that the .pc
file is installed in the wrong location
<build_dir>/CppAD/pkgconfig
rather than
<build_dir>/lib/pkgconfig
By the way, the include directory is listed as
<build_dir>/include
rather than
<build_dir>/include/cppad
but this may be intentional.
I would like to cite CppAD in a scientific paper.
@bradbell Do you have any preference for the citation? Any paper that describes the framework?
Thanks in advance!
The file check_for_nan.hpp
includes unistd.h
. With the Visual Studio 2015 compiler, it seems this should be io.h
(or at least this is enough to make the OS build go through). I'm not sure how you prefer to fix this. I can submit a PR with #ifdef _MSC_VER
or you may prefer to add checks for unistd.h
and io.h
to configure.ac
.
I'm building using the autotools and cl
in MSys2, but this isn't specific to the autotools, as far as I can see. This should also break the build with CMake on Windows.
I was looking at chkpoint_two/hes_sparsity.hpp and I may have spotted a defect.
Please look at lines
63 and 73.
I believe it should be:
if( select_x[j] && select_x[i] )
The bitwise &
operator was replace with a logical &&
operator (not particularly important).
The select_y
was replaced with select_x
.
AD AngleDiff( AD valueA, AD valueB)
{
return CppAD::acos( (CppAD::cos(valueA)*CppAD::cos(valueB)) + (CppAD::sin(valueA)*CppAD::sin(valueB)) );
}
AD output = CppAD::pow( AngleDiff(AD Variable1, AD Variable2 ),2)
I'm getting nan value in the output. I just checked the inputs they all are right. Kindly help me with this. Will be greatly appreciated. The error I got is..
cppad-20160000.1 error from a known source:
yq = f.Forward(q, xq): has a non-zero order Taylor coefficient
with the value nan (but zero order coefficients are not nan).
Error detected by false result for
ok
at line 244 in the file
/usr/include/cppad/local/forward.hpp
mpc: /usr/include/cppad/utility/error_handler.hpp:207: static void CppAD::ErrorHandler::Default(bool, int, const char*, const char*, const char*): Assertion `false' failed.
Aborted (core dumped)
Hi,
I am new to CppAD ipopt optimization. Previously, I used python and Matlab's lambda expression to construct the function which need to be solved, and they worked perfectly to obtain the good results. Currently, I wanna deploy the python and Matlab optimization codes to C++, and I used CppAD for help. However, it seems like the solver loses track when histogram operations are performed.
Consider, y = f(x), and I need to calculate m = hist(y - f(x)), then, fg[0] = sum(g(m)). Since this histogram calculation will create another vector m which has no direct relationship with input vars, and the final cost function is related to the histogram vector m, CppAD cannot find the relations between the vars and the histogram vector. CppAD considers fg[0] is a constant, so that there is no optimization in this situation.
I tried a lot of optimization toolboxes to tackle the issue, but unfortunately, neither of them work with my situation. I am wondering if CppAD can handle this kind of optimization, or does CppAD have build-in function for histogram calculation which can be tracked with the solver?
Thank you so much.
Is there any way to use CppAD with the tensor module? I recently tried:
#include <cppad/cppad.hpp>
#include <cppad/example/cppad_eigen.hpp>
#include <unsupported/Eigen/CXX11/Tensor>
int main(void){
Eigen::Tensor<CppAD::AD<double>, 3> epsilon(3,3,3);
epsilon.setZero();
CppAD::Independent(epsilon);
}
But this gives me the following error:
usr/bin/cmake --build /home/aespielberg/ResearchCode/autodiffprojectDir/cmake-build-debug --target autodiffproject -- -j 1
Scanning dependencies of target autodiffproject
[ 50%] Building CXX object autodiffproject/CMakeFiles/autodiffproject.dir/src/main.cpp.o
In file included from /home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/ad_fun.hpp:742:0,
from /home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/cppad.hpp:63,
from /home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/src/main.cpp:3:
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/independent.hpp: In instantiation of ‘void CppAD::Independent(VectorAD&, size_t) [with VectorAD = Eigen::Tensor<CppAD::AD<double>, 3>; Base = double; size_t = long unsigned int]’:
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/independent.hpp:170:13: required from ‘void CppAD::Independent(VectorAD&) [with VectorAD = Eigen::Tensor<CppAD::AD<double>, 3>]’
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/src/main.cpp:10:31: required from here
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/independent.hpp:147:41: error: no type named ‘value_type’ in ‘class Eigen::Tensor<CppAD::AD<double>, 3>’
{ typedef typename VectorAD::value_type ADBase;
^
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/independent.hpp:155:23: error: no type named ‘value_type’ in ‘class Eigen::Tensor<CppAD::AD<double>, 3>’
local::ADTape<Base>* tape = ADBase::tape_manage(tape_manage_new);
^
/home/aespielberg/ResearchCode/autodiffprojectDir/autodiffproject/../ExternalLibs/CppAD/cppad/core/independent.hpp:155:23: error: no type named ‘value_type’ in ‘class Eigen::Tensor<CppAD::AD<double>, 3>’
autodiffproject/CMakeFiles/autodiffproject.dir/build.make:65: recipe for target 'autodiffproject/CMakeFiles/autodiffproject.dir/src/main.cpp.o' failed
make[3]: *** [autodiffproject/CMakeFiles/autodiffproject.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:2025: recipe for target 'autodiffproject/CMakeFiles/autodiffproject.dir/all' failed
make[2]: *** [autodiffproject/CMakeFiles/autodiffproject.dir/all] Error 2
CMakeFiles/Makefile2:2037: recipe for target 'autodiffproject/CMakeFiles/autodiffproject.dir/rule' failed
make[1]: *** [autodiffproject/CMakeFiles/autodiffproject.dir/rule] Error 2
Makefile:671: recipe for target 'autodiffproject' failed
make: *** [autodiffproject] Error 2
I assume that this is not something supported, but I wanted to check if there was a quick thing that I could do to make it work.
Support for the operation type ErfOp is not yet implemented in forward2sweep() which is used, for instance, to determine the sparse Jacobian.
Here is an example showing the issue:
using CppAD::AD;
// domain space vector
size_t n = 1;
double x0 = 0.5;
CPPAD_TESTVECTOR(AD<double>) ax(n);
ax[0] = x0;
// declare independent variables and start tape recording
CppAD::Independent(ax);
// range space vector
size_t m = 1;
CPPAD_TESTVECTOR(AD<double>) ay(m);
ay[0] = CppAD::erf(ax[0]);
// create f: x -> y and stop tape recording
CppAD::ADFun<double> f(ax, ay); // OK
// forward computation of first partial w.r.t. x[0]
CPPAD_TESTVECTOR(double) dx(n);
CPPAD_TESTVECTOR(double) dy(m);
dx[0] = 1.;
dy = f.Forward(1, dx); // OK
// reverse computation of derivative of y[0]
CPPAD_TESTVECTOR(double) w(m);
CPPAD_TESTVECTOR(double) dw(n);
w[0] = 1.;
dw = f.Reverse(1, w); // OK
// sparse Jacobian
f.SparseJacobian(dx); // Failure here
It's been over a year since I had to re-install CppAD, but I now need to, on a new computer. Although make_check runs, nothing is copied to my cppad_prefix directory. I'm installing to /opt/cppad because of permissions issues in writing to /usr under MacOS 10.14.2. cmake is version 3.13.2.
Here's the simplest version of what I am doing, starting with a brand new computer and a clean clone of the CppAD source.
git clone https://github.com/coin-or/CppAD.git
(latest master branch, but this happens with earlier stable branches as well).cmake -D cppad_prefix=/opt/cppad ..
braunm: ~/CppAD/build $ sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/cppad/share/pkgconfig/cppad.pc
-- Installing: /opt/cppad/lib/pkgconfig/cppad.pc
This is what appears in /opt/cppad:
braunm: /opt/cppad $ ls -R
lib share
./lib:
pkgconfig
./lib/pkgconfig:
cppad.pc
./share:
pkgconfig
./share/pkgconfig:
cppad.pc
So the header files are all missing. At first, I thought the problem was with the cmake files. But it could also be something with MacOS Mojave 10.14.2. I don't think it's a permissions problem, because I can't install to my home directory either. In any case, I know nothing about cmake and have hit the edge of my debugging skills on this issue. Any ideas?
Thanks,
Michael
edit: this happens on my old computer as well.
Hello Brad Bell,
I've had to fix an issue in the compilation of a library and an executable using CppAD with different NDEBUG definitions.
The library was compiled without NDEBUG while the executable was compiled with NDEBUG defined.
This caused an issue when a CppAD tape was provided by the executable to the library because they assume different sizes for the AD tape object.
I found that the class player has a member variable that is only defined when NDEBUG is not defined.
There may be more.
Therefore I cannot compile my executable with NDEBUG.
Probably if I do the oposite, that is, if I compile my library with NDEBUG and then try to use it with my executable without NDEBUG, there will also be a problem.
This would be common while developing the source for the executable.
Is this an issue or feature of CppAD?
Perhaps there could be a special flag for CppAD different from NDEBUG or NDEBUG should not be used to add/remove member variables of classes in CppAD.
Best regards,
João Leal
Hello Brad,
Is there a chance of CppAD supporting metadata associated with each variable.
One could call something like
AD<type> var = (...);
add_metadata(var, "key", "value");
This information could then be used to store information such as variable names and units.
An additional call to new functions (e.g., process_metadata_forward()
and process_metadata_reverse()
) could be added in
cppad/local/forward0sweep.hpp
cppad/local/forward1sweep.hpp
cppad/local/forward2sweep.hpp
cppad/local/reverse_sweep.hpp
By default process_metadata_*()
functions would be empty (no performance penalty would occur for types such as double/float).
These functions could be specialized for specific data types such as CppAD::cg::CG<>
.
This would allow me to recover the additional information that I need which cannot currently be saved in the tape.
Best regards,
João Leal
The following operator can be added to zdouble to allow it to be assigned to a double:
// Return double version of zdouble
operator double() const
{
return dbl_;
}
Is this indeed meant to be an assignment, or you mean ==
?
CppAD/include/cppad/local/play/player.hpp
Line 258 in f0c5edc
Visual Studio 2010 generates warning when using zdouble in place of double. To silence then, the following constructors are added:
/// Constructor from size_t
zdouble(const size_t& ulong)
: dbl_((double)ulong)
{ }
/// Constructor from int
zdouble(const int& signint)
: dbl_((double)signint)
{ }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.