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

Check variables were defined during block parsing #3832

Closed
wangkuiyi opened this issue Sep 3, 2017 · 1 comment
Closed

Check variables were defined during block parsing #3832

wangkuiyi opened this issue Sep 3, 2017 · 1 comment
Assignees

Comments

@wangkuiyi
Copy link
Collaborator

wangkuiyi commented Sep 3, 2017

This discussion is related to #3708.

Think of the running process of the following example derived from the design of IfOp, where the global block has two sub-blocks, one as the left branch of an IfElseOp, the other as the right branch.

import paddle as pd

x1 = var()
x2 = var()

c = pd.create_ifelseop_builder(inputs=[x1, x2], output_num=2)
with c.true_block() as b:
    x1, x2 = b.inputs()
    z = mul(x1, x2))
    b.set_output(0, z)
    b.set_output(1, add(x1, x2))

with c.false_block() as b:
    x1, x2 = c1.inputs()
    b.set_output(0, add(x1, x2))
    b.set_output(1, mul(x1, x2))

cond = var()
out1, out2 = c(cond)

During the execution of above program, we want error as long as a line just executed refers to an undefined variable. For example, if we remove z = mul(x1, x2)) from above example, the execution of b.set_output(0, z) must report an error about "undefined variable z".

@wangkuiyi
Copy link
Collaborator Author

OK. Python would report such kind of errors. We don't need to do anything.

In particular, above example doesn't require that a block must record its parent block.

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

No branches or pull requests

2 participants