gpt4 book ai didi

c++ - Eigen sum() float

转载 作者:搜寻专家 更新时间:2023-10-31 00:53:20 29 4
gpt4 key购买 nike

我的自定义 tensorflow 操作中有一个 Eigen TensorMap

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

从中选择数字有效:

float a = Tbuf(0);

但是如果想把它求和为标量 float

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

关于c++ - Eigen sum() float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49068802/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com