How would one go about using Eigen's internal functions like Eigen::internal::scalar_product_op in a custom Tensorflow op? After going through the Tensorflow codebase, like cwise_ops_common.h and cwise_ops.h, I came up with the following (barebones) implementation:
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/numeric_types.h"
#include "tensorflow/core/framework/tensor_types.h"
#include "tensorflow/core/platform/types.h"
using namespace tensorflow;
typedef Eigen::ThreadPoolDevice CPUDevice;
REGISTER_OP("CustomMul")
.Input("to_zero: int8")
.Output("zeroed: int8")
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
c->set_output(0, c->input(0));
return Status::OK();
});
class CustomMulOp : public OpKernel {
public:
explicit CustomMulOp(OpKernelConstruction* context) : OpKernel(context) {}
void Compute(OpKernelContext* context) override {
// Grab the input tensor
const Tensor& a_tensor = context->input(0);
const Tensor& b_tensor = context->input(0);
auto a = a_tensor.flat<int8>();
auto b = b_tensor.flat<int8>();
// Create an output tensor
Tensor* output_tensor = NULL;
OP_REQUIRES_OK(context, context->allocate_output(0, b_tensor.shape(),
&output_tensor));
auto output = output_tensor->flat<int8>();
const CPUDevice& d = context->eigen_device<CPUDevice>();
// Multiply the tensors
To32Bit(output).device(d) =
To32Bit(a).binaryExpr(b, typename Eigen::internal::scalar_product_op<int8>());
}
};
REGISTER_KERNEL_BUILDER(Name("CustomMul").Device(DEVICE_CPU), CustomMulOp);
Compiling the above code with
TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
g++ -std=c++11 -shared custom_mul.cc -o custom_mul.so -fPIC -I $TF_INC -O2
produces the following error:
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<Derived, Device>::CoeffReturnType = signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:123:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:59:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)dest, m_data, sizeof(Scalar) * m_dims.TotalSize());
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
^~~~~~~~~~~~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<const Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType = const signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:404:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType*) [with BinaryOp = Eigen::internal::scalar_product_op<signed char, signed char>; LeftArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:128:62: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:186:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)data, m_data, m_dims.TotalSize() * sizeof(Scalar));
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
^~~~~~~~~~~~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<const Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType = const signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:405:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType*) [with BinaryOp = Eigen::internal::scalar_product_op<signed char, signed char>; LeftArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:128:62: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:186:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)data, m_data, m_dims.TotalSize() * sizeof(Scalar));
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
I'm using TensorFlow v.1.0.1 and GCC 6.3.1.
You need to add #define EIGEN_USE_THREADS before including third_party/eigen3/unsupported/Eigen/CXX11/Tensor, otherwise the ThreadPoolDevice will not be available.
struct ThreadPoolDevice is only forward-declared initially (at custom_mul.cc:2) but it must be fully defined. This means you miss some include. Move this include
#include <third_party/eigen3/unsupported/Eigen/CXX11/Tensor>
up to the beginning of your code. I think that should fully define ThreadPoolDevice.
Related
For some reason, verification of ReadWritePropertyMapConcept for std::map of vertex descriptors and colors fails:
Live on godbolt
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>
#include <boost/property_map/property_map.hpp>
#include <map>
struct Vertex {};
using graph_type = boost::adjacency_list<boost::vecS, boost::vecS,
boost::bidirectionalS, Vertex>;
using vertex_descriptor = boost::graph_traits<graph_type>::vertex_descriptor;
using map_type = std::map<vertex_descriptor, boost::default_color_type>;
BOOST_CONCEPT_ASSERT(
(boost::ReadWritePropertyMapConcept<map_type, vertex_descriptor>));
with errors:
In file included from /opt/compiler-explorer/libs/boost_1_78_0/boost/graph/adjacency_list.hpp:27,
from <source>:1:
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp: In instantiation of 'struct boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>':
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
<source>:13:1: required from here
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:203:54: error: no type named 'category' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
203 | typedef typename property_traits<PMap>::category Category;
| ^~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp: In instantiation of 'struct boost::ReadablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>':
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::ReadablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::ReadablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::ReadablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::ReadablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:206:7: required from 'void boost::ReadWritePropertyMapConcept<PMap, Key>::constraints() [with PMap = std::map<long unsigned int, boost::default_color_type>; Key = long unsigned int]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
<source>:13:1: required from here
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:143:54: error: no type named 'key_type' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
143 | typedef typename property_traits<PMap>::key_type key_type;
| ^~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:144:55: error: no type named 'reference' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
144 | typedef typename property_traits<PMap>::reference reference;
| ^~~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:145:54: error: no type named 'category' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
145 | typedef typename property_traits<PMap>::category Category;
| ^~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:154:48: error: no type named 'value_type' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
154 | typename property_traits<PMap>::value_type val;
| ^~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp: In instantiation of 'struct boost::WritablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>':
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::WritablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::WritablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::WritablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::WritablePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:207:7: required from 'void boost::ReadWritePropertyMapConcept<PMap, Key>::constraints() [with PMap = std::map<long unsigned int, boost::default_color_type>; Key = long unsigned int]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
<source>:13:1: required from here
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:176:54: error: no type named 'key_type' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
176 | typedef typename property_traits<PMap>::key_type key_type;
| ^~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:177:54: error: no type named 'category' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
177 | typedef typename property_traits<PMap>::category Category;
| ^~~~~~~~
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:185:48: error: no type named 'value_type' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
185 | typename property_traits<PMap>::value_type val;
| ^~~
In file included from /opt/compiler-explorer/libs/boost_1_78_0/boost/concept/assert.hpp:35,
from /opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:19,
from /opt/compiler-explorer/libs/boost_1_78_0/boost/graph/adjacency_list.hpp:27,
from <source>:1:
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp: In instantiation of 'void boost::ReadWritePropertyMapConcept<PMap, Key>::constraints() [with PMap = std::map<long unsigned int, boost::default_color_type>; Key = long unsigned int]':
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:32:62: required by substitution of 'template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model::constraints)>*) [with Model = boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>]'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:42:5: required from 'const bool boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >::value'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/has_constraints.hpp:45:51: required from 'struct boost::concepts::not_satisfied<boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int> >'
/opt/compiler-explorer/libs/boost_1_78_0/boost/concept/detail/general.hpp:72:8: required from 'struct boost::concepts::requirement_<void (*)(boost::ReadWritePropertyMapConcept<std::map<long unsigned int, boost::default_color_type>, long unsigned int>)>'
<source>:13:1: required from here
/opt/compiler-explorer/libs/boost_1_78_0/boost/property_map/property_map.hpp:208:7: error: no type named 'category' in 'struct boost::property_traits<std::map<long unsigned int, boost::default_color_type> >'
208 | BOOST_CONCEPT_ASSERT((ConvertibleConcept<Category, ReadWriteTag>));
| ^~~~~~~~~~~~~~~~~~~~
Compiler returned: 1
However, std::map surely has key_type, value_type etc. I have also used it in boost::depth_first_search() as color_map as in this question, and it seemed to work.
On the contrary, when the property map is constructed from adapter, the check passes:
int main() {
graph_type g;
std::vector<boost::default_color_type> colors(num_vertices(g));
auto color_map = boost::make_iterator_property_map(
colors.begin(), get(boost::vertex_index, g));
BOOST_CONCEPT_ASSERT(
(boost::ReadWritePropertyMapConcept<decltype(color_map),
boost::default_color_type>));
}
Why is the concept check failing?
A container doesn't usually satisfy the concept requirements for property maps. Put simply: the map is not a property map. At all.
In principle you need to adapt it. Certainly in the case of this associative property map:
std::map<V, C> colors;
auto color_map = make_assoc_property_map(colors);
Live On Compiler Explorer
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <fmt/ranges.h>
using C = boost::default_color_type;
template <> struct fmt::formatter<C> {
auto format(C c, auto& ctx) const { return format_to(ctx.out(), "{}", std::array{"white", "gray", "green", "red", "black"}.at(c)); }
};
struct Vertex {};
using G = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
Vertex>;
int main() {
using V = G::vertex_descriptor;
std::map<V, C> colors;
auto color_map = make_assoc_property_map(colors);
G g(10);
add_edge(0, 1, g);
add_edge(1, 3, g);
add_edge(1, 4, g);
add_edge(3, 2, g);
add_edge(2, 7, g);
breadth_first_search(g, vertex(0, g), boost::color_map(color_map));
fmt::print("{}\n", fmt::join(colors, "\n"));
}
Prints
(0, black)
(1, black)
(2, black)
(3, black)
(4, black)
(5, white)
(6, white)
(7, black)
(8, white)
(9, white)
I was trying to get the element with largest size from a vector of elements, as succinct as possible. The original code looks like,
std::cout << ((*std::max_element(rooms.begin(), rooms.end(),
[](auto a, auto b){a.size() < b.size();})).size()) << std::endl;
which g++ complains,
wall3.cpp: In function ‘int main()’:
wall3.cpp:150:47: error: ‘class __gnu_cxx::__normal_iterator<std::set<std::pair<long unsigned int, long unsigned int> >*, std::vector<std::set<std::pair<long unsigned int, long unsigned int> > > >’ has no member named ‘size’
150 | [](auto a, auto b){a.size() < b.size();}).size() << std::endl;
| ^~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/string:40,
from /usr/include/c++/9/bitset:47,
from wall3.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::set<std::pair<long unsigned int, long unsigned int> >*, std::vector<std::set<std::pair<long unsigned int, long unsigned int> > > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::set<std::pair<long unsigned int, long unsigned int> >*, std::vector<std::set<std::pair<long unsigned int, long unsigned int> > > >; _Compare = main()::<lambda(auto:1, auto:2)>]’:
/usr/include/c++/9/bits/stl_algo.h:5692:12: required from ‘constexpr _ForwardIterator std::__max_element(_ForwardIterator, _ForwardIterator, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::set<std::pair<long unsigned int, long unsigned int> >*, std::vector<std::set<std::pair<long unsigned int, long unsigned int> > > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:1, auto:2)> >]’
/usr/include/c++/9/bits/stl_algo.h:5743:43: required from ‘constexpr _FIter std::max_element(_FIter, _FIter, _Compare) [with _FIter = __gnu_cxx::__normal_iterator<std::set<std::pair<long unsigned int, long unsigned int> >*, std::vector<std::set<std::pair<long unsigned int, long unsigned int> > > >; _Compare = main()::<lambda(auto:1, auto:2)>]’
wall3.cpp:150:45: required from here
/usr/include/c++/9/bits/predefined_ops.h:143:18: error: void value not ignored as it ought to be
143 | { return bool(_M_comp(*__it1, *__it2)); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It turns out that I forgot to use return in the lambda expression. Adding return solved the problem.
Lesson: use a different compiler and turn on the strictest warning configurations to reveal the problem faster. The output from clang++ is far more explicit,
wall3.cpp:150:33: warning: relational comparison result unused [-Wunused-comparison]
[](auto a, auto b){a.size() < b.size();})).size()) << std::endl;
~~~~~~~~~^~~~~~~~~~
I am trying to define a vector of tuples in C++ 11 as shown below:
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
typedef unsigned char uchar;
typedef std::tuple<uchar, std::string, uchar, float> fruitInfoTuple;
const std::vector<fruitInfoTuple> jointsInfo{
{ 0, "mango", 100, -6.01},
{10, "apple", 144, 6.25},
{12, "orange", 159, 2.59},
{33, "banana", 144, -28.96},
{ 4, "grapes", 128, 3.79},
};
I compile the program with C++11 flag enabled. However, it is showing complication errors as shown below:
ravi#lab:~/Desktop/a$ g++ -std=c++11 learn.cpp
learn.cpp:14:1: error: converting to ‘std::tuple<unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float>’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, const char (&)[6], int, double}; <template-parameter-2-2> = void; _Elements = {unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float}]’
};
^
learn.cpp:14:1: error: converting to ‘std::tuple<unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float>’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, const char (&)[6], int, double}; <template-parameter-2-2> = void; _Elements = {unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float}]’
learn.cpp:14:1: error: converting to ‘std::tuple<unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float>’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, const char (&)[7], int, double}; <template-parameter-2-2> = void; _Elements = {unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float}]’
learn.cpp:14:1: error: converting to ‘std::tuple<unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float>’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, const char (&)[7], int, double}; <template-parameter-2-2> = void; _Elements = {unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float}]’
learn.cpp:14:1: error: converting to ‘std::tuple<unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float>’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int, const char (&)[7], int, double}; <template-parameter-2-2> = void; _Elements = {unsigned char, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char, float}]’
I guess GCC 4.8 is not supporting tuple feature. Is there any workaround, please? Please note that I can use boost if needed. I just want a clean way of definig the tuple as done above.
You might try:
const std::vector<fruitInfoTuple> jointsInfo{
fruitInfoTuple{ 0, "mango", 100, -6.01},
fruitInfoTuple{10, "apple", 144, 6.25},
fruitInfoTuple{12, "orange", 159, 2.59},
fruitInfoTuple{33, "banana", 144, -28.96},
fruitInfoTuple{ 4, "grapes", 128, 3.79},
};
In C++11 you should use std::make_tuple to construct the tuple:
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
typedef unsigned char uchar;
typedef std::tuple<uchar, std::string, uchar, float> fruitInfoTuple;
const std::vector<fruitInfoTuple> jointsInfo{
std::make_tuple( 0, "mango", 100, -6.01),
std::make_tuple(10, "apple", 144, 6.25),
std::make_tuple(12, "orange", 159, 2.59),
std::make_tuple(33, "banana", 144, -28.96),
std::make_tuple( 4, "grapes", 128, 3.79),
};
int main()
{
for(int i = 0 ; i < jointsInfo.size(); ++i)
{
std::cout << std::get<1>(jointsInfo[i]) << std::endl;
}
}
Result :
mango
apple
orange
banana
grapes
I have the following function that is throwing an error. I can isolate the problem to the line
A.template triangularView<Lower>().solveInPlace(MatrixXd::Identity(p,p)); // the problem line
But I am having trouble figuring out how what the problem is an how to fix it.
template <typename T, typename RNG>
inline void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<T>& A,
const int v,
const Eigen::Ref<const Eigen::MatrixXd>& Psi,
RNG& rng){
int p = Psi.rows();
MatrixXd PsiInv = Psi.llt().solve(MatrixXd::Identity(p,p));
if (v <= p-1)
Rcpp::stop("v must be > Psi.rows - 1");
VectorXd z(p*(p-1)/2);
fillUnitNormal_thread(z, rng);
MatrixXd X = MatrixXd::Zero(p, p);
for (int i=0; i<p; i++){
boost::random::chi_squared_distribution<> rchisq(v-i);
X(i,i) = sqrt(rchisq(rng));
}
int pos = 0;
for (int i=1; i<p; i++){
for (int j=0; j<i; j++){
X(i,j) = z(pos);
pos++;
}
}
A.template noalias() = PsiInv.llt().matrixL()*X;
A.template triangularView<Lower>().solveInPlace(MatrixXd::Identity(p,p)); // the problem line
A.template transposeInPlace();
}
Here is the error message:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:496:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h: In instantiation of 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with int Side = 1; OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]':
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/TriangularMatrix.h:511:37: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
../inst/include/MatDist_thread.h:153:3: required from 'void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<Derived>&, int, const Eigen::Ref<const Eigen::Matrix<double, -1, -1> >&, RNG&) [with T = Eigen::Matrix<double, -1, -1>; RNG = boost::random::mersenne_twister_engine<unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>]'
MongrelCollapsed_Uncollapse.cpp:162:72: required from here
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:182:11: error: use of deleted function 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >& Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::operator=(const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >&)'
other = otherCopy;
~~~~~~^~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: note: 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >& Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::operator=(const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >&)' is implicitly deleted because the default definition would be ill-formed:
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: 'Eigen::internal::no_assignment_operator& Eigen::internal::no_assignment_operator::operator=(const Eigen::internal::no_assignment_operator&)' is private within this context
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:92:29: note: declared private here
no_assignment_operator& operator=(const no_assignment_operator&);
^~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::variable_if_dynamic<long int, -1>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:115:28: note: in call to 'Eigen::internal::variable_if_dynamic<long int, -1>& Eigen::internal::variable_if_dynamic<long int, -1>::operator=(const Eigen::internal::variable_if_dynamic<long int, -1>&)'
template<typename T> class variable_if_dynamic<T, Dynamic>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::variable_if_dynamic<long int, -1>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:115:28: note: in call to 'Eigen::internal::variable_if_dynamic<long int, -1>& Eigen::internal::variable_if_dynamic<long int, -1>::operator=(const Eigen::internal::variable_if_dynamic<long int, -1>&)'
template<typename T> class variable_if_dynamic<T, Dynamic>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::scalar_identity_op<double>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:425:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/functors/NullaryFunctors.h:31:34: note: in call to 'Eigen::internal::scalar_identity_op<double>& Eigen::internal::scalar_identity_op<double>::operator=(const Eigen::internal::scalar_identity_op<double>&)'
template<typename Scalar> struct scalar_identity_op {
^~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:496:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h: In instantiation of 'static void Eigen::internal::triangular_solver_selector<Lhs, Rhs, Side, Mode, 0, -1>::run(const Lhs&, Rhs&) [with Lhs = Eigen::Matrix<double, -1, -1>; Rhs = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; int Side = 1; int Mode = 1]':
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:179:21: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with int Side = 1; OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/TriangularMatrix.h:511:37: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
../inst/include/MatDist_thread.h:153:3: required from 'void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<Derived>&, int, const Eigen::Ref<const Eigen::Matrix<double, -1, -1> >&, RNG&) [with T = Eigen::Matrix<double, -1, -1>; RNG = boost::random::mersenne_twister_engine<unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>]'
MongrelCollapsed_Uncollapse.cpp:162:72: required from here
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:102:81: error: no matching function for call to 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::coeffRef(int, int)'
::run(size, othersize, &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.outerStride(), blocking);
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:434:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:273:10: note: candidate: void Eigen::DenseCoeffsBase<Derived, 0>::coeffRef() [with Derived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >]
void coeffRef();
^~~~~~~~
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:273:10: note: candidate expects 0 arguments, 2 provided
make: *** [MongrelCollapsed_Uncollapse.o] Error 1
ERROR: compilation failed for package ‘mongrel’
* removing ‘/private/var/folders/x1/9_lpy_fs0kvg0p88td6_df200000gq/T/Rtmp7seVyi/devtools_install_1385330e7ebb0/mongrel’
Error: Command failed (1)
Any advice would be much appreciated!
solveInPlace requires its argument to be writable, MatrixXd::Identity(p,p) is a read-only expression. (Where would you expect to get the result from that function?)
Maybe what you want is this?
A.noalias() = (PsiInv.llt().matrixL()*X).transpose()
.template triangularView<Upper>().solve(MatrixXd::Identity(p,p));
I have a series of vectors which I am adding into a DataFrame object to return to R.
The problem comes when I try and add a vector with long long elements.
// [[Rcpp::export]]
DataFrame test()
{
std::vector<long long> x;
return DataFrame::create(Named("x") = x);
}
The error returned is
g++ -m64 -I"C:/R/R-30~1.1/include" -DNDEBUG -I"C:/R/R-3.0.1/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c quotes.cpp -o quotes.o In file included from C:/R/R-3.0.1/library/Rcpp/include/RcppCommon.h:117:0, from C:/R/R-3.0.1/library/Rcpp/include/Rcpp.h:27, from quotes.cpp:1: C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h: In function 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]': C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:691:98: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:723:96: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:740:80: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:760:99: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = long long int, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:863:104: instantiated from 'SEXPREC* Rcpp::wrap(const T&) [with T = long long int, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:193:3: [ skipping 14 instantiation contexts ] C:/R/R-3.0.1/library/Rcpp/include/Rcpp/vector/Vector.h:395:9: instantiated from 'static void Rcpp::Vector::replace_element__dispatch(Rcpp::traits::true_type, Rcpp::Vector::iterator, SEXP, int, const U&) [with U = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::traits::true_type = Rcpp::traits::integral_constant, Rcpp::Vector::iterator = Rcpp::internal::Proxy_Iterator >, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/vector/Vector.h:384:9: instantiated from 'static void Rcpp::Vector::replace_element(Rcpp::Vector::iterator, SEXP, int, const U&) [with U = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector::iterator = Rcpp::internal::Proxy_Iterator >, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/Vector_create.h:318:2: instantiated from 'static Rcpp::Vector Rcpp::Vector::create_dispatch(Rcpp::traits::true_type, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector = Rcpp::Vector<19>, Rcpp::traits::true_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/Vector__create.h:288:37: instantiated from 'static Rcpp::Vector Rcpp::Vector::create(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector = Rcpp::Vector<19>]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/DataFrame_generated.h:59:73: instantiated from 'static Rcpp::DataFrame Rcpp::DataFrame::create(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, Rcpp::DataFrame = Rcpp::DataFrame]' quotes.cpp:58:26: instantiated from here C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:474:11: error: invalid conversion from 'long long int' to 'SEXP' [-fpermissive] make: * [quotes.o] Error 1 .
Is there a way to add a vector of this type into a DataFrame?
There is not, sadly, as CRAN only allows a C standard without long long.
Also, R itself only has numeric (aka double) and integer. So I would suggest you just use double as a type.