提交 ab9d59c5 编写于 作者: W wanghaoshuang

Fix double type error while using eigen api

上级 d0246e24
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace paddle { namespace paddle {
namespace operators { namespace operators {
using framework::Tensor; using Tensor = framework::Tensor;
template <typename T, int MajorType = Eigen::RowMajor, template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex> typename IndexType = Eigen::DenseIndex>
...@@ -107,12 +107,11 @@ class NCEKernel : public framework::OpKernel<T> { ...@@ -107,12 +107,11 @@ class NCEKernel : public framework::OpKernel<T> {
auto input_mat = EigenMatrix<T>::From(*(context.Input<Tensor>("Input"))); auto input_mat = EigenMatrix<T>::From(*(context.Input<Tensor>("Input")));
auto weight_mat = EigenMatrix<T>::From(*(context.Input<Tensor>("Weight"))); auto weight_mat = EigenMatrix<T>::From(*(context.Input<Tensor>("Weight")));
for (size_t i = 0; i < sample_labels->numel(); ++i) { for (size_t i = 0; i < sample_labels->numel(); ++i) {
Eigen::Tensor<float, 0, Eigen::RowMajor, Eigen::DenseIndex> result = Eigen::Tensor<T, 0, Eigen::RowMajor, Eigen::DenseIndex> result =
(input_mat.chip((int)(i / sample_labels->dims()[1]), 0) * (input_mat.chip((int)(i / sample_labels->dims()[1]), 0) *
weight_mat.chip(sample_labels_data[i], 0)) weight_mat.chip(sample_labels_data[i], 0))
.sum(); .sum();
sample_out_data[i] += result(0); sample_out_data[i] += result(0);
// activation_->forward
sample_out_data[i] = (1. / (1. + exp(-sample_out_data[i]))); sample_out_data[i] = (1. / (1. + exp(-sample_out_data[i])));
} }
// forward cost // forward cost
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册