@@ -62,7 +62,7 @@ public void SquaredDifference_1D()
6262 // Calcute the gradient of (x1-x2)^2
6363 // by Automatic Differentiation in Eager mode
6464 // Expected is 2*(abs(x1-x2))
65- Tensor x1 = new NDArray ( new float [ ] { 1 , 3 , 5 , 21 , 19 , 17 } ) ;
65+ Tensor x1 = new NDArray ( new float [ ] { 1 , 3 , 5 , 21 , 19 , 17 } ) ;
6666 Tensor x2 = new NDArray ( new float [ ] { 29 , 27 , 23 , 7 , 11 , 13 } ) ;
6767 float [ ] expected = new float [ ]
6868 {
@@ -173,5 +173,34 @@ public void ConditionalMultiply()
173173 var result = grad ( x , 4 ) ;
174174 Assert . AreEqual ( ( float ) result , 4.0f ) ;
175175 }
176+
177+ [ TestMethod ]
178+ public void Tile ( )
179+ {
180+ var a = tf . constant ( new int [ ] { 1 } , TF_DataType . TF_FLOAT ) ;
181+ var b = tf . constant ( new int [ ] { 2 } ) ;
182+ using ( var tape = tf . GradientTape ( ) )
183+ {
184+ tape . watch ( a ) ;
185+ var y = tf . tile ( a , b ) ;
186+ var grad = tape . gradient ( y , a ) ;
187+ Assert . AreEqual ( ( float ) grad . numpy ( ) , 2.0f ) ;
188+ }
189+ }
190+
191+ [ TestMethod ]
192+ public void GatherNdTest ( )
193+ {
194+ var x = tf . constant ( new float [ , ] { { 1.0f , 2.0f , 3.0f } , { 1.0f , 2.0f , 3.0f } , { 1.0f , 2.0f , 3.0f } } , dtype : TF_DataType . TF_FLOAT ) ;
195+ var indices = tf . constant ( new int [ , ] { { 0 , 1 } , { 1 , 1 } , { 2 , 1 } } , dtype : TF_DataType . TF_INT32 ) ;
196+ using ( var tape = tf . GradientTape ( ) )
197+ {
198+ tape . watch ( x ) ;
199+ var res = tf . gather_nd ( x , indices ) ;
200+ var grad = tape . gradient ( res , x ) ;
201+ var expected = np . array ( new float [ , ] { { 0f , 1f , 0f } , { 0f , 1f , 0f } , { 0f , 1f , 0f } } ) ;
202+ Assert . IsTrue ( Enumerable . SequenceEqual ( grad . ToArray < float > ( ) , expected . ToArray < float > ( ) ) ) ;
203+ }
204+ }
176205 }
177206}
0 commit comments