浮点数的特征和()

时间:2018-03-02 12:05:43

标签: c++ tensorflow eigen

我在类型

的自定义张量流操作中有一个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();

1 个答案:

答案 0 :(得分:3)

好的,我忘记了张量需要首先进行评估。

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