From 6bf1283cbebba1b795896c6dea4eb7f5a407e159 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Wed, 13 Sep 2017 13:48:39 -0700 Subject: [PATCH] Add doc for `Variable` --- doc/design/python_api.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/design/python_api.md b/doc/design/python_api.md index 05875eeb21..e515f8594d 100644 --- a/doc/design/python_api.md +++ b/doc/design/python_api.md @@ -82,18 +82,16 @@ After creating a C++ `OpDesc`, `Operator` in Python can only reads the attribute ### Variable - +Operators' intputs, outputs and parameters are all variables. In our design, a variable has four key attributes: its name(`name`), the block it belongs to(`block`), a pointer pointed to its C++ Protobuf object(`cpp_var_desc_ptr`), and the operator it is created by(`op`). All of these attributes are initialized in constructor, except the `op`. The `op` will keep being `None` till the variable is taken as an operator's output. ```python class Variable(object): def __init__(self, shape, dtype="float32", name=None, block=None): if name is None: - if prefix is not None: - name = unique_name_generator(prefix) - else: - name = unique_name_generator("unknown") + name = unique_name_generator() self.name = name self.block = block + # build C++ Protobuf object self.cpp_var_desc_ptr = ... self.op = None @@ -102,6 +100,10 @@ class Variable(object): return [None if elem < 0 else elem for elem in cpp_shape] ``` +Protobuf object should be created in C++ not Python because it is needed by infershape, and infershape is implementated by C++ code. The C++ Protobuf object is accessible for Python through the `cpp_var_desc_ptr` pointer. + +The user is allowed to build an variable without specifying its name. If so, it is going to be assigned with an automatically generated unique name. + ### Parameter -- GitLab