Reputation: 1348
I have a Eigen TensorMap in my custom tensorflow operation of type
Eigen::TensorMap<Eigen::Tensor<float, 1, 1, long int>, 16, Eigen::MakePointer>
Picking number from it works:
float a = Tbuf(0);
But If want to sum it to scalar float
float b = Tbuf.sum();
I am getting an error
word2vec_kernels.cc: In member function ‘virtual void tensorflow::NegTrainWord2vecOp::Compute(tensorflow::OpKernelContext*)’:
word2vec_kernels.cc:516:29: error: cannot convert ‘const Eigen::TensorReductionOp<Eigen::internal::SumReducer<float>, const Eigen::DimensionList<long int, 1ul>, const Eigen::TensorMap<Eigen::Tensor<float, 1, 1, long int>, 16, Eigen::MakePointer>, Eigen::MakePointer>’ to ‘float’ in initialization
float b = Tbuf.sum();
Upvotes: 2
Views: 903
Reputation: 1348
Okay, I forgot the tensor needs to be evaluated at first.
float b = ((Eigen::Tensor<float, 0, 1, long int> )Tbuf.sum())(0);
Upvotes: 4