How does one store the scalar result of an Eigen matrix operation ? #202
Replies: 5 comments
-
You may want to look at the following example: I am getting a different compiler error from you. Would you please be more precise in your example; i.e., specify the entire example file including includes and specify the compile command. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your timely reply. I have provided the full cpp example and cmakelis as shown below, and at the end of the reply I have also provided the full error message, which is generated by vscode's cmaketools. #include <Eigen/Eigen>
#include <cppad/cppad.hpp>
#include <cppad/example/cppad_eigen.hpp>
using std::cout;
using std::endl;
using CppAD::AD;
int main() {
Eigen::Matrix<AD<double>, 2, 2> smooth_weight_Mat_;
smooth_weight_Mat_ << 1, 0, 0, 1;
Eigen::Matrix<AD<double>, 6, 2> C_ = Eigen::Matrix<double, 6, 2>::Ones();
std::vector<AD<double>> smooth_weigths_perPiece_(6);
int i = 0;
smooth_weigths_perPiece_[0] = C_.row(6 * i + 3)*smooth_weight_Mat_ * C_.row(6 * i + 3).transpose();
return 0;
} cmakelist.txt # The cmake config kit is GCC 9.4.0 X86_64-linux-gnu
cmake_minimum_required(VERSION 3.20.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message("Setting default build type to Release")
endif()
project(my_project_name VERSION 0.0.1 LANGUAGES C CXX)
include_directories(
${PROJECT_SOURCE_DIR}/include
/usr/include/eigen3
/usr/include/python3.8
)
add_executable(test0
test0.cpp
)
target_link_libraries(test0
PUBLIC
cppad_lib
) The Full Error Message
Looking forward to your reply, thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay.
to
|
Beta Was this translation helpful? Give feedback.
-
@dujinpeng0249 |
Beta Was this translation helpful? Give feedback.
-
Hi. Sorry for the delay. I have found a solution like this smooth_weigths_perPiece_[0] = C_.row(6 * i + 3).dot(smooth_weight_Mat_ * C_.row(6 * i + 3).transpose()); Thanks for your patience, I'll close this issue. |
Beta Was this translation helpful? Give feedback.
-
The test code is as follows:
the build error is:
/usr/local/include/cppad/core/ad_assign.hpp:130:12: error: invalid cast from type ‘const Eigen::Product<Eigen::Product<Eigen::Block<Eigen::Matrix<CppAD::AD, 6, 2>, 1, 2, false>, Eigen::Matrix<CppAD::AD, 2, 2, 0, 2, 2>, 0>, Eigen::Transpose<Eigen::Block<Eigen::Matrix<CppAD::AD, 6, 2>, 1, 2, false> >, 0>’ to type ‘double’
I think the problem is in the last line
smooth_weigths_perPiece_[1]= C_.row(6 * i + 3) * smooth_weight_Mat_ * C_.row(6 * i + 3).transpose();
However, I don't know what's wrong with that.Also, even if I change the type of smooth_weigths_perPiece_ to Eigen::Matrix<AD,-1,1> it does not work too.
Eigen::Matrix<AD<double>,-1,1> smooth_weigths_perPiece_(6);
The only way to build successfully is to:
But I think it's inconvenient and shouldn't be the right way.
Can you help me see what the problem is, I would greatly appreciate it!
Beta Was this translation helpful? Give feedback.
All reactions