Eigen sum() 浮动

Eigen sum() to float

我的自定义张量流操作中有一个 Eigen TensorMap

Eigen::TensorMap<Eigen::Tensor<float, 1, 1, long int>, 16, Eigen::MakePointer>

从中选择号码有效:

float a = Tbuf(0);

但如果想将其求和为标量浮点数

float b = Tbuf.sum();

我收到一个错误

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();

好吧,我忘记了张量需要先求值

float b = ((Eigen::Tensor<float, 0, 1, long int> )Tbuf.sum())(0);