#NEWLINE# def test_perform( self ) : #NEWLINE# #INDENT# x = tensor . matrix ( ) #NEWLINE# y = tensor . scalar ( ) #NEWLINE# f = function ( [ x , y ] , fill_diagonal ( x , y ) ) #NEWLINE# for shp in [ ( 8 , 8 ) , ( 5 , 8 ) , ( 8 , 5 ) ] : #NEWLINE# #INDENT# a = numpy . random . rand ( * shp ) . astype ( config . floatX ) #NEWLINE# val = numpy . cast [ config . floatX ] ( numpy . random . rand ( ) ) #NEWLINE# out = f ( a , val ) #NEWLINE# assert numpy . allclose ( numpy . diag ( out ) , val ) #NEWLINE# assert ( ( out == val ) . sum ( ) == min ( a . shape ) ) #NEWLINE# #UNINDENT# a = numpy . random . rand ( 3 , 3 , 3 ) . astype ( config . floatX ) #NEWLINE# x = tensor . tensor3 ( ) #NEWLINE# y = tensor . scalar ( ) #NEWLINE# f = function ( [ x , y ] , fill_diagonal ( x , y ) ) #NEWLINE# val = numpy . cast [ config . floatX ] ( ( numpy . random . rand ( ) + 10 ) ) #NEWLINE# out = f ( a , val ) #NEWLINE# assert ( out [ ( 0 , 0 , 0 ) ] == val ) #NEWLINE# assert ( out [ ( 1 , 1 , 1 ) ] == val ) #NEWLINE# assert ( out [ ( 2 , 2 , 2 ) ] == val ) #NEWLINE# assert ( ( out == val ) . sum ( ) == min ( a . shape ) )