@@ -794,6 +794,23 @@ function nntest.MultiMarginCriterion()
794
794
criterionJacobianTest1D (cri , input , target )
795
795
end
796
796
797
+ function nntest .MarginRankingCriterion ()
798
+ local input = {torch .rand (1 ), torch .rand (1 )}
799
+ local mrc = nn .MarginRankingCriterion ()
800
+ local output = mrc :forward (input , 1 )
801
+ local gradInput = mrc :backward (input , 1 )
802
+ -- cast to float
803
+ local input2 = {input [1 ]:float (), input [2 ]:float ()}
804
+ local mrc2 = mrc :clone ():float ()
805
+ local output2 = mrc2 :forward (input2 , 1 )
806
+ local gradInput2 = mrc2 :backward (input2 , 1 )
807
+ mytester :assert (math.abs (output2 - output ) < 0.00001 , " MRC:type() forward error" )
808
+ mytester :assertTensorEq (gradInput [1 ]:float (), gradInput2 [1 ], 0.00001 , " MRC:type() backward error 1" )
809
+ mytester :assert (torch .type (gradInput2 [1 ]) == ' torch.FloatTensor' , " MRC:type() error 1" )
810
+ mytester :assertTensorEq (gradInput [2 ]:float (), gradInput2 [2 ], 0.00001 , " MRC:type() backward error 2" )
811
+ mytester :assert (torch .type (gradInput2 [2 ]) == ' torch.FloatTensor' , " MRC:type() error 2" )
812
+ end
813
+
797
814
function nntest .WeightedMSECriterion ()
798
815
local input = torch .rand (10 )
799
816
local target = input :clone ():add (torch .rand (10 ))
0 commit comments