U
    d                     @   s8   d dl mZmZ d dlmZ d dlZG dd deZdS )    )core	workspace)TestCaseNc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestSparseToDensec                 C   s   t dddgdg}tdtjddddgtjd tdtjd	dd
dgtjd t| td}t	| tj
dtjd}d|d< d|d< d
|d< | |j|j tj|| d S )NSparseToDenseindicesvaluesoutput        Zdtype         i     )r   CreateOperatorr   FeedBlobnparrayint32RunOperatorOnce	FetchBlobprintzerosassertEqualshapetestingassert_array_equalselfopr	   expected r#   F/tmp/pip-unpacked-wheel-ua33x9lu/caffe2/python/sparse_to_dense_test.pytest_sparse_to_dense   s,    

z&TestSparseToDense.test_sparse_to_densec                 C   s(  t jddddgt jd}t jddgddgddgddggt jd}t jt d	t jd}td
dddgdg}td| td| td| td}|	 j
|g tj|g|j|j|jdtjjtjjtjjdd\}}d|krd|kstd| |d d	dg | |d tjj d S )Nr
   r   r   r   r   r   r   r     r   r   r   data_to_infer_dimr	   Zsparse_to_dense)r   r   r'   )Zblob_dimensionsZ
blob_typesz+Failed to infer the shape or type of output)r   r   r   r   r   r   r   r   ZNetZProtor!   extendZInferShapesAndTypesr   ZDataTypeZINT32AssertionErrorr   )r    r   r   r'   r!   netZshapestypesr#   r#   r$   $test_sparse_to_dense_shape_inference$   s@    (

z6TestSparseToDense.test_sparse_to_dense_shape_inferencec              	   C   sv   t dddgdg}tdtjddddgtjd tdtjd	dd
gtjd | t t	| W 5 Q R X d S )Nr   r   r   r	   r
   r   r   r   r   r   )
r   r   r   r   r   r   r   assertRaisesRuntimeErrorr   )r    r!   r#   r#   r$   #test_sparse_to_dense_invalid_inputsF   s    z5TestSparseToDense.test_sparse_to_dense_invalid_inputsc                 C   s   t ddddgdg}tdtjddddgtjd	 tdtjd
dddgtjd	 tdtjtdtjd	 t| t	d}t
| tjdtjd	}d|d< d|d< d|d< | |j|j tj|| d S )Nr   r   r   r'   r	   r
   r   r   r   r   r   r   r&   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   r#   r$   +test_sparse_to_dense_with_data_to_infer_dimU   s4    

z=TestSparseToDense.test_sparse_to_dense_with_data_to_infer_dimN)__name__
__module____qualname__r%   r,   r/   r0   r#   r#   r#   r$   r      s   "r   )Zcaffe2.pythonr   r   Zcaffe2.python.test_utilr   Znumpyr   r   r#   r#   r#   r$   <module>   s   