Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add how to use eigen cn doc #3750

Merged
merged 3 commits into from
Sep 6, 2017
Merged

Conversation

QiJune
Copy link
Member

@QiJune QiJune commented Aug 30, 2017

Fix #3751


Paddle Tensor定义在framework目录下,其主要接口如下:

```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用```cpp,给代码加上语法高亮

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


From是EigenTensor模板提供的一个接口,可以实现从paddle::framework::Tensor到对EigenTensor的转换。由于Tensor的rank是模板参数,因此在转换时需要显示的指定。

需要额外注意的是,EigenVector<T>::From方法是把paddle中的一维Tensor转为Eigen的一维Tensor,在这里用EigenVector来表示;而EigenVector<T>::Flatten方法是把paddle中的一个Tensor进行reshape操作,压扁成为Eigen的一维Tensor,类型仍然为EigenVector。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以先介绍下EigenVector,再讲它的FlattenFrom的区别。还可以加个例子。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. 具体的例子可以参考eigen_test.cc


Eigen Tensor模块对element-wise计算提供了强大的支持,并且书写一份代码,可以同时在CPU、GPU执行。但Eigen Tensor是一个正在开发中的模块,因此可能测试不够完备,文档较少。

关于Eigen Tensor模块的详细介绍请参考[文档](https://github.com/RLovelett/eigen/blob/master/unsupported/Eigen/CXX11/src/Tensor/README.md)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

inline T* data();

/**
* @brief Return a pointer to mutable memory block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为是_cn.md这里的function的文档可否也替换成中文?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码注释还好吧,,也不复杂

t.mutable_data(place);
```

下面以AddOp为例说明Tensor的使用过程:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用过程,可以加一个标题比如### 使用Tensor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@xinghai-sun
Copy link
Contributor

Great doc!

One quick question: how to do slicing on Eigen::Array? (not Eigen::Tensor or Eigen::TensorMap)

e.g. auto dims = X.dimensions(); how can I get dims_new = dims[1:], since I need to reduce X to its first dimension with dims_new, e.g. X.sum(new_dims).

@QiJune
Copy link
Member Author

QiJune commented Aug 31, 2017

@xinghai-sun You can have a look at this https://github.com/PaddlePaddle/Paddle/pull/3774/files, could this sample meet your requirements?

};
```

`Placeholder`的作用的延迟分配内存,即我们可以先定义一个Tensor,然后使用Resize接口设置Tensor的大小,最后再调用mutable_data接口分配实际的内存。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的作用的=>的作用是

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


output->mutable_data<T>(context.GetPlace());

auto X = EigenVector<T>::Flatten(*input0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of variables are all lowercase.
https://google.github.io/styleguide/cppguide.html#Variable_Names

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@QiJune QiJune merged commit d924a65 into PaddlePaddle:develop Sep 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants