Update the feed dict, remove the feed item which is pruned in program. Notes: This is a very low level API. Users should not use this API directly. Args: program(Program): the pruned program. feed(list|dict): feed dict or list. Retu
(cls, program, feed)
| 1609 | |
| 1610 | @classmethod |
| 1611 | def _update_feed(cls, program, feed): |
| 1612 | """ |
| 1613 | Update the feed dict, remove the feed item which is pruned in program. |
| 1614 | |
| 1615 | Notes: This is a very low level API. Users should not use this API |
| 1616 | directly. |
| 1617 | |
| 1618 | Args: |
| 1619 | program(Program): the pruned program. |
| 1620 | feed(list|dict): feed dict or list. |
| 1621 | |
| 1622 | Returns: |
| 1623 | feed:(list|dict) updated feed. |
| 1624 | """ |
| 1625 | compiled = isinstance(program, compiler.CompiledProgram) |
| 1626 | if compiled: |
| 1627 | if program._program: |
| 1628 | global_block = program._program.global_block() |
| 1629 | else: |
| 1630 | warnings.warn( |
| 1631 | "The program holds no _program, maybe it is constructed by graph." |
| 1632 | ) |
| 1633 | return feed |
| 1634 | else: |
| 1635 | global_block = program.global_block() |
| 1636 | |
| 1637 | if isinstance(feed, dict): |
| 1638 | for feed_name in list(feed.keys()): |
| 1639 | if not global_block.has_var(feed_name): |
| 1640 | feed.pop(feed_name) |
| 1641 | warnings.warn( |
| 1642 | f"The variable {feed_name} is not found in program. It is not declared or is pruned." |
| 1643 | ) |
| 1644 | |
| 1645 | elif isinstance(feed, (list, tuple)): |
| 1646 | for i, each in enumerate(feed): |
| 1647 | for feed_name in list(each.keys()): |
| 1648 | if not global_block.has_var(feed_name): |
| 1649 | each.pop(feed_name) |
| 1650 | warnings.warn( |
| 1651 | f"The variable {feed_name} is not found in program. It is not declared or is pruned." |
| 1652 | ) |
| 1653 | return feed |
| 1654 | |
| 1655 | ''' |
| 1656 | TODO(typhoonzero): Define "no longer use" meaning? Can user create |