Begins the scope block. Returns: A VariableScope. Raises: ValueError: when trying to reuse within a create scope, or create within a reuse scope, or if reuse is not `None` or `True`. TypeError: when the types of some arguments are not appropriate.
(self)
| 2624 | self._cached_variable_scope_object = variable_scope_object |
| 2625 | |
| 2626 | def __enter__(self): |
| 2627 | """Begins the scope block. |
| 2628 | |
| 2629 | Returns: |
| 2630 | A VariableScope. |
| 2631 | Raises: |
| 2632 | ValueError: when trying to reuse within a create scope, or create within |
| 2633 | a reuse scope, or if reuse is not `None` or `True`. |
| 2634 | TypeError: when the types of some arguments are not appropriate. |
| 2635 | """ |
| 2636 | self._old = self._var_scope_store.current_scope |
| 2637 | if isinstance(self._name_or_scope, VariableScope): |
| 2638 | self._var_scope_store.open_variable_scope(self._new_name) |
| 2639 | self._old_subscopes = copy.copy( |
| 2640 | self._var_scope_store.variable_scopes_count) |
| 2641 | variable_scope_object = self._cached_variable_scope_object |
| 2642 | else: |
| 2643 | # Handler for the case when we just prolong current variable scope. |
| 2644 | # VariableScope with name extended by the provided one, and inherited |
| 2645 | # reuse and initializer (except if the user provided values to set). |
| 2646 | self._new_name = ( |
| 2647 | self._old.name + "/" + |
| 2648 | self._name_or_scope if self._old.name else self._name_or_scope) |
| 2649 | self._reuse = (self._reuse or |
| 2650 | self._old.reuse) # Re-using is inherited by sub-scopes. |
| 2651 | if self._old_name_scope is None: |
| 2652 | name_scope = self._name_or_scope |
| 2653 | else: |
| 2654 | name_scope = self._old_name_scope |
| 2655 | variable_scope_object = VariableScope( |
| 2656 | self._reuse, |
| 2657 | name=self._new_name, |
| 2658 | initializer=self._old.initializer, |
| 2659 | regularizer=self._old.regularizer, |
| 2660 | caching_device=self._old.caching_device, |
| 2661 | partitioner=self._old.partitioner, |
| 2662 | dtype=self._old.dtype, |
| 2663 | use_resource=self._old.use_resource, |
| 2664 | custom_getter=self._old.custom_getter, |
| 2665 | name_scope=name_scope, |
| 2666 | constraint=self._constraint) |
| 2667 | if self._initializer is not None: |
| 2668 | variable_scope_object.set_initializer(self._initializer) |
| 2669 | if self._regularizer is not None: |
| 2670 | variable_scope_object.set_regularizer(self._regularizer) |
| 2671 | if self._caching_device is not None: |
| 2672 | variable_scope_object.set_caching_device(self._caching_device) |
| 2673 | if self._partitioner is not None: |
| 2674 | variable_scope_object.set_partitioner(self._partitioner) |
| 2675 | if self._custom_getter is not None: |
| 2676 | variable_scope_object.set_custom_getter( |
| 2677 | _maybe_wrap_custom_getter(self._custom_getter, |
| 2678 | self._old.custom_getter)) |
| 2679 | if self._dtype is not None: |
| 2680 | variable_scope_object.set_dtype(self._dtype) |
| 2681 | if self._use_resource is not None: |
| 2682 | variable_scope_object.set_use_resource(self._use_resource) |
| 2683 | self._var_scope_store.open_variable_scope(self._new_name) |
nothing calls this directly
no test coverage detected