<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , division <EOL> import numpy as np <EOL> from theano . tests import unittest_tools as utt <EOL> from theano import function <EOL> import theano <EOL> from theano . tensor import dmatrix , dvector <EOL> from numpy import allclose <EOL> from theano . compile import as_op <EOL> import pickle <EOL> @ as_op ( [ dmatrix , dmatrix ] , dmatrix ) <EOL> def mul ( a , b ) : <EOL> return a * b <EOL> class OpDecoratorTests ( utt . InferShapeTester ) : <EOL> def test_1arg ( self ) : <EOL> x = dmatrix ( '<STR_LIT:x>' ) <EOL> @ as_op ( dmatrix , dvector ) <EOL> def cumprod ( x ) : <EOL> return np . cumprod ( x ) <EOL> fn = function ( [ x ] , cumprod ( x ) ) <EOL> r = fn ( [ [ <NUM_LIT> , <NUM_LIT:5> ] , [ <NUM_LIT:2> , <NUM_LIT:2> ] ] ) <EOL> r0 = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert allclose ( r , r0 ) , ( r , r0 ) <EOL> def test_2arg ( self ) : <EOL> x = dmatrix ( '<STR_LIT:x>' ) <EOL> x . tag . test_value = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> y = dvector ( '<STR_LIT:y>' ) <EOL> y . tag . test_value = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> @ as_op ( [ dmatrix , dvector ] , dvector ) <EOL> def cumprod_plus ( x , y ) : <EOL> return np . cumprod ( x ) + y <EOL> fn = function ( [ x , y ] , cumprod_plus ( x , y ) ) <EOL> r = fn ( [ [ <NUM_LIT> , <NUM_LIT:5> ] , [ <NUM_LIT:2> , <NUM_LIT:2> ] ] , [ <NUM_LIT:1> , <NUM_LIT:100> , <NUM_LIT:2> , <NUM_LIT:200> ] ) <EOL> r0 = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert allclose ( r , r0 ) , ( r , r0 ) <EOL> def test_infer_shape ( self ) : <EOL> x = dmatrix ( '<STR_LIT:x>' ) <EOL> x . tag . test_value = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> y = dvector ( '<STR_LIT:y>' ) <EOL> y . tag . test_value = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> def infer_shape ( node , shapes ) : <EOL> x , y = shapes <EOL> return [ y ] <EOL> @ as_op ( [ dmatrix , dvector ] , dvector , infer_shape ) <EOL> def cumprod_plus ( x , y ) : <EOL> return np . cumprod ( x ) + y <EOL> self . _compile_and_check ( [ x , y ] , [ cumprod_plus ( x , y ) ] , <EOL> [ [ [ <NUM_LIT> , <NUM_LIT:5> ] , [ <NUM_LIT:2> , <NUM_LIT:2> ] ] , [ <NUM_LIT:1> , <NUM_LIT:100> , <NUM_LIT:2> , <NUM_LIT:200> ] ] , <EOL> cumprod_plus . __class__ , warn = False ) <EOL> def test_pickle ( self ) : <EOL> x = dmatrix ( '<STR_LIT:x>' ) <EOL> y = dmatrix ( '<STR_LIT:y>' ) <EOL> m = mul ( x , y ) <EOL> s = pickle . dumps ( m ) <EOL> m2 = pickle . loads ( s ) <EOL> assert m2 . owner . op == m . owner . op <EOL> def test_shape_i_hash ( ) : <EOL> assert isinstance ( theano . tensor . opt . Shape_i ( np . int64 ( <NUM_LIT:1> ) ) . __hash__ ( ) , int ) </s>
