
    wi                        d dl mZ d dlZd dlZd dlZd dlZdZ G d dej        j                  Z	 G d dej
                  Z G d d	ej
                  ZdS )
    )annotationsNaH  <
    ir_version: 8,
    opset_import: ["" : 17, "local" : 1]
>
agraph (float[N] X) => (float[N] Y) {
    Y = local.foo (X)
}

<opset_import: ["" : 17, "local" : 1], domain: "local">
foo (x) => (y) {
    temp = Add(x, x)
    y = local.bar(temp)
}

<opset_import: ["" : 17], domain: "local">
bar (x) => (y) {
    y = Mul (x, x)
}c                  >    e Zd ZdZdZ edh          Zd
dZddZd	S )_OnnxTestTextualSerializerz:Serialize and deserialize the ONNX textual representation.onnxtextz	.onnxtextreturnbytesc                j    t           j                            |          }|                    d          S )Nutf-8)onnxprinterto_textencode)selfprototexts      l/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/onnx/test/serialization_test.pyserialize_protoz*_OnnxTestTextualSerializer.serialize_proto'   s)    |##E**{{7###    
serializedc                2   |                     d          }t          |t          j                  rt          j                            |          S t          |t          j                  rt          j                            |          S t          |t          j                  rt          j        	                    |          S t          |t          j
                  rt          j                            |          S t          dt          |                     )Nr
   zUnsupported proto type: )decode
isinstancer   
ModelProtoparserparse_model
GraphProtoparse_graphFunctionProtoparse_function	NodeProto
parse_node
ValueErrortype)r   r   r   r   s       r   deserialize_protoz,_OnnxTestTextualSerializer.deserialize_proto+   s      ))eT_-- 	1;**4000eT_-- 	1;**4000eT/00 	4;--d333eT^,, 	0;))$///ADKKAABBBr   N)r   r   )r   r   )	__name__
__module____qualname____doc__supported_format	frozensetfile_extensionsr   r$    r   r   r   r   !   s_        DD!i..O$ $ $ $
C 
C 
C 
C 
C 
Cr   r   c                  .    e Zd ZddZddZddZddZdS )	TestRegistryr   Nonec                ~    t                      | _        t          j        j                            | j                   d S )N)r   
serializerr   serializationregistryregisterr   s    r   setUpzTestRegistry.setUp9   s1    466#,,T_=====r   c                    t           j        j                            d          }|                     || j                   d S )Nr   )r   r2   r3   getassertIsr1   )r   r1   s     r   (test_get_returns_the_registered_instancez5TestRegistry.test_get_returns_the_registered_instance=   s7    '044Z@@
j$/22222r   c                    |                      t                    5  t          j        j                            d           d d d            d S # 1 swxY w Y   d S )Nunsupported)assertRaisesr"   r   r2   r3   r8   r5   s    r   &test_get_raises_for_unsupported_formatz3TestRegistry.test_get_raises_for_unsupported_formatA   s    z** 	; 	;'++M:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   %AAAc                   t           j                            t                    }t	          j                    5 }t          j                            |d          }t          j	        ||d           t          |d          5 }|                                }|                     |t           j                            |                     d d d            n# 1 swxY w Y   t          j        |d          }|                     |                    d          |                    d                     d d d            d S # 1 swxY w Y   d S )Nz
model.onnxr   )formatr
   )encodingTdeterministic)r   r   r   _TEST_MODELtempfileTemporaryDirectoryospathjoin
save_modelopenreadassertEqualr   r   
load_modelSerializeToString)r   modeltmpdir
model_pathfcontentloaded_models          r   4test_onnx_save_load_model_uses_the_custom_serializerzATestRegistry.test_onnx_save_load_model_uses_the_custom_serializerE   s   ''44(** 	ffl;;JOE:jAAAA j7333 Gq&&((  $,*>*>u*E*EFFFG G G G G G G G G G G G G G G  ?:jIIIL''d';;..T.BB  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s8   A	EAC	EC	EC	AEEENr   r/   )r%   r&   r'   r6   r:   r>   rV   r,   r   r   r.   r.   8   sd        > > > >3 3 3 3; ; ; ;     r   r.   c                      e Zd ZddZdS )TestCustomSerializerr   r/   c                ^   t                      }t          j                            t                    }|                    |          }|                    |t          j                              }|                     |	                    d          |	                    d                     d S )NTrB   )
r   r   r   r   rD   r   r$   r   rM   rO   )r   r1   rP   r   deserializeds        r    test_serialize_deserialize_modelz5TestCustomSerializer.test_serialize_deserialize_modelY   s    /11
''44//66
!33J@Q@QRR##$#77***>>	
 	
 	
 	
 	
r   NrW   )r%   r&   r'   r\   r,   r   r   rY   rY   X   s(        
 
 
 
 
 
r   rY   )
__future__r   rG   rE   unittestr   rD   r2   ProtoSerializerr   TestCaser.   rY   r,   r   r   <module>ra      s    # " " " " " 				   *C C C C C!3!C C C C.    8$   @	
 	
 	
 	
 	
8, 	
 	
 	
 	
 	
r   