| Re: [eigen] Overloading componentwise binary operators for vectors |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
include_directories(eigen/install/include/eigen3)
De: "Gael Guennebaud" <gael.guennebaud@xxxxxxxxx>
À: "eigen" <eigen@xxxxxxxxxxxxxxxxxxx>
Envoyé: Samedi 3 Octobre 2015 00:10:05
Objet: Re: [eigen] Overloading componentwise binary operators for vectorsOn Fri, Oct 2, 2015 at 10:25 PM, Cedric Doucet <cedric.doucet@xxxxxxxx> wrote:========================================================template<typename ScalarType>Vector<ScalarType> operator+(Vector<ScalarType> const & lhs, Vector<ScalarType> const & rhs){ return lhs.wrapped_ + right.wrapped_; }========================================================does not work. I guess it is because an _expression_ template is returned by operator + in Eigen.
This should work if your Vector class has a template constructor from an Eigen::DenseBase<Derived>. Of course, this way you will loose the benefits of Eigen's _expression_ templates.========================================================
erreur: ambiguous overload for ‘operator+’ (operand types are ‘Vector<double>’ and ‘Vector<double>’)
CPPUNIT_ASSERT_EQUAL(sum, left+right);
========================================================Please show what are the multiple versions of operator+ found by the compiler.Anyways, instead of writing a wrapper, maybe extending MatrixBase<> to add compatibility methods or inherit Matrix<> could work for you? See:gael
cmake_minimum_required (VERSION 2.6)
project (eigen_overloading CXX)
#==============
# INCLUDE FILES
#==============
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
include(CheckCXXCompilerFlag)
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(CMAKE_BUILD_FLAGS -j${N})
endif()
#====================
# EXECUTABLE SETTINGS
#====================
add_executable(main main.cpp)
#=============
# USER OPTIONS
#=============
#=============================
# DOWNLOAD 3RD-PARTY LIBRARIES
#=============================
include_directories(eigen/install/include/eigen3)
#==================
# COMPILER SETTINGS
#==================
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMOL_CXX_FLAGS} -Wall -Wextra")
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} does not support -std=c++11 flag. Please use a different C++ compiler.")
endif()
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |