
    6bi                         S r SSKrSSKrSSKJr  0 r0 r\R                  " 5       r\" SSS5       " S S5      5       r	\" S	S
5      S 5       r
\" SS5      SS j5       r\" SS5      S 5       r\" SS5      SS j5       r\	rg)z&Python utilities required by TF-Keras.    N)keras_exportz keras.saving.custom_object_scopezkeras.utils.custom_object_scopezkeras.utils.CustomObjectScopec                   *    \ rS rSrSrS rS rS rSrg)CustomObjectScope   a  Exposes custom classes/functions to TF-Keras deserialization internals.

Under a scope `with custom_object_scope(objects_dict)`, TF-Keras methods
such as `tf.keras.models.load_model` or `tf.keras.models.model_from_config`
will be able to deserialize any custom object referenced by a
saved config (e.g. a custom layer or metric).

Example:

Consider a custom regularizer `my_regularizer`:

```python
layer = Dense(3, kernel_regularizer=my_regularizer)
# Config contains a reference to `my_regularizer`
config = layer.get_config()
...
# Later:
with custom_object_scope({'my_regularizer': my_regularizer}):
  layer = Dense.from_config(config)
```

Args:
    *args: Dictionary or dictionaries of `{name: object}` pairs.
c                     Xl         S U l        g N)custom_objectsbackup)selfargss     a/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/saving/object_registration.py__init__CustomObjectScope.__init__<   s    "    c                     [         R                  R                  5       U l        U R                   H"  n[         R                  R                  U5        M$     U $ r   )_THREAD_LOCAL_CUSTOM_OBJECTS__dict__copyr
   r	   update)r   objectss     r   	__enter__CustomObjectScope.__enter__@   sA    2;;@@B**G(1188A +r   c                     [         R                  R                  5         [         R                  R                  U R                  5        g r   )r   r   clearr   r
   )r   r   kwargss      r   __exit__CustomObjectScope.__exit__F   s,    $--335$--44T[[Ar   )r
   r	   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r   r      s    2Br   r   zkeras.saving.get_custom_objectszkeras.utils.get_custom_objectsc                      [         $ )a  Retrieves a live reference to the global dictionary of custom objects.

Custom objects set using using `custom_object_scope` are not added to the
global dictionary of custom objects, and will not appear in the returned
dictionary.

Example:

```python
get_custom_objects().clear()
get_custom_objects()['MyObject'] = MyObject
```

Returns:
    Global dictionary mapping registered class names to classes.
)_GLOBAL_CUSTOM_OBJECTSr$   r   r   get_custom_objectsr'   K   s
    ( "!r   z(keras.saving.register_keras_serializablez'keras.utils.register_keras_serializablec                    ^ ^ UU 4S jnU$ )a*  Registers an object with the TF-Keras serialization framework.

This decorator injects the decorated class or function into the TF-Keras
custom object dictionary, so that it can be serialized and deserialized
without needing an entry in the user-provided custom object dict. It also
injects a function that TF-Keras will call to get the object's serializable
string key.

Note that to be serialized and deserialized, classes must implement the
`get_config()` method. Functions do not have this requirement.

The object will be registered under the key 'package>name' where `name`,
defaults to the object name if not passed.

Example:

```python
# Note that `'my_package'` is used as the `package` argument here, and since
# the `name` argument is not provided, `'MyDense'` is used as the `name`.
@keras.saving.register_keras_serializable('my_package')
class MyDense(keras.layers.Dense):
  pass

assert keras.saving.get_registered_object('my_package>MyDense') == MyDense
assert keras.saving.get_registered_name(MyDense) == 'my_package>MyDense'
```

Args:
  package: The package that this class belongs to. This is used for the
    `key` (which is `"package>name"`) to idenfify the class. Note that this
    is the first argument passed into the decorator.
  name: The name to serialize this class under in this package. If not
    provided or `None`, the class' name will be used (note that this is the
    case when the decorator is used with only one argument, which becomes
    the `package`).

Returns:
  A decorator that registers the decorated class with the passed names.
c                    > Tb  TOU R                   nTS-   U-   n[        R                  " U 5      (       a  [        U S5      (       d  [	        S5      eU [
        U'   U[        U '   U $ )z<Registers a class with the TF-Keras serialization framework.>
get_configzACannot register a class that does not have a get_config() method.)r   inspectisclasshasattr
ValueErrorr&   _GLOBAL_CUSTOM_NAMES)arg
class_nameregistered_namenamepackages      r   	decorator.register_keras_serializable.<locals>.decorator   sk    !-T3<<
!C-*4??3\(B(B' 
 36/$3S!
r   r$   )r5   r4   r6   s   `` r   register_keras_serializabler8   b   s    Z  r   z keras.saving.get_registered_namezkeras.utils.get_registered_namec                 @    U [         ;   a	  [         U    $ U R                  $ )a  Returns the name registered to an object within the TF-Keras framework.

This function is part of the TF-Keras serialization and deserialization
framework. It maps objects to the string names associated with those objects
for serialization/deserialization.

Args:
  obj: The object to look up.

Returns:
  The name associated with the object, or the default Python name if the
    object is not registered.
)r0   r   )objs    r   get_registered_namer;      s"    " ""#C((||r   z"keras.saving.get_registered_objectz!keras.utils.get_registered_objectc                     U [         R                  ;   a  [         R                  U    $ U [        ;   a	  [        U    $ U(       a	  X;   a  X   $ U(       a	  X;   a  X    $ g)a  Returns the class associated with `name` if it is registered with
TF-Keras.

This function is part of the TF-Keras serialization and deserialization
framework. It maps strings to the objects associated with them for
serialization/deserialization.

Example:

```python
def from_config(cls, config, custom_objects=None):
  if 'my_custom_object_name' in config:
    config['hidden_cls'] = tf.keras.saving.get_registered_object(
        config['my_custom_object_name'], custom_objects=custom_objects)
```

Args:
  name: The name to look up.
  custom_objects: A dictionary of custom objects to look the name up in.
    Generally, custom_objects is provided by the user.
  module_objects: A dictionary of custom objects to look the name up in.
    Generally, module_objects is provided by midlevel library implementers.

Returns:
  An instantiable class associated with `name`, or `None` if no such class
    exists.
N)r   r   r&   )r4   r	   module_objectss      r   get_registered_objectr>      s]    > +444+44T::	'	'%d++	D2##	D2##r   )CustomN)NN)r"   r,   	threading tensorflow.python.util.tf_exportr   r&   r0   localr   r   r'   r8   r;   r>   custom_object_scoper$   r   r   <module>rD      s    -   :  (0  &%#
&B &B
&BR %'G""( .-9	9x &(I( (*M$$P ( r   