From 8a4bd171c7b41dc9218dcde76af4aae24dbccf4e Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Mon, 15 May 2017 20:06:36 +0800 Subject: [PATCH] add brief explanation of DDim usage --- paddle/majel/README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/paddle/majel/README.md b/paddle/majel/README.md index 5539853056..0f49b83c2a 100644 --- a/paddle/majel/README.md +++ b/paddle/majel/README.md @@ -48,7 +48,9 @@ int main() } ``` -In Majel, `DDimVar` is derived from `Dim`, `DArrayVar` is from `Array`. +In Majel, `DDimVar` is derived from `Dim`, `DArrayVar` is from +`Array`. + ```c++ template @@ -68,8 +70,8 @@ private: Dim stride_; T* ptr_; }; -``` - +``` + ```c++ typedef boost::variant Place; typedef boost::variant, Dim<2>, Dim<3>, Dim<4>, Dim<5>, @@ -93,6 +95,20 @@ typedef boost::variant< Because `variant` may be thought of as "multi-type, single value", we can utilize it to implement unified interfaces for PaddlePaddle. +`DDim` plays two kinds of roles in Majel. First, it is used to indicate the size of a tensor. For example, we can construct a new `DArray` by following way: + + ```c++ + DArray arr = make_darray(make_ddim({2,3}), 0.0f); + ``` + It means that `arr` will be a two-dimension tensor, or a matrix. The size of its first dimension is 2 and the second is 3. All the element value of `arr` will be initialized as 0.0 . + + The second meaning of `DDim` is tensor index. For example, if we want to access the value in the 1st row and 2nd column of `arr` and set it to 1.0, we can do like this: + + ```c++ + arr[make_ddim({0, 1})] = 1.0; + ``` + + ## implement Tensor in Paddle Before writing code, please make sure you already look through Majel Source Code and grabbed the design philosophy of `DArray` in Majel. @@ -113,8 +129,8 @@ To assign subtasks to our colleagues, we have to discuss how to divide it to ind - [ ] 3. Re-implement `Dim`. - `Dim` is an excellent implementation in Majel. - + `Dim` is an excellent implementation in Majel. + > ??? - [ ] 4. Re-implement `Array/Tensor`. -- GitLab