@@ -185,24 +185,24 @@ import tensorflow.compat.v1 as tf
185
185
x = tf.placeholder(tf.float64, shape = (1, 1))
186
186
m = tf.broadcast_to(x, (2, 3))
187
187
g0 = tf.gradients(tf.reduce_sum(m), x)[0]
188
- g1 = tf.gradients(tf.reduce_sum(m, axis = 0), x)[0]
189
- g2 = tf.gradients(tf.reduce_sum(m, axis = 1), x)[0]
188
+ g1 = tf.gradients(tf.reduce_sum(m, axis = 0)[0] , x)[0]
189
+ g2 = tf.gradients(tf.reduce_sum(m, axis = 1)[0] , x)[0]
190
190
with tf.compat.v1.Session() as sess:
191
191
(r0, r1, r2) = sess.run((g0, g1, g2), {x: [[1.0]]})
192
192
*/
193
193
194
194
var x = tf . placeholder ( tf . float64 , shape : new Shape ( 1 , 1 ) ) ;
195
195
var m = tf . broadcast_to ( x , new Shape ( 2 , 3 ) ) ;
196
196
var g0 = tf . gradients ( tf . reduce_sum ( m ) , x ) [ 0 ] ;
197
- var g1 = tf . gradients ( tf . reduce_sum ( m , axis : 0 ) , x ) [ 0 ] ;
198
- var g2 = tf . gradients ( tf . reduce_sum ( m , axis : 1 ) , x ) [ 0 ] ;
197
+ var g1 = tf . gradients ( tf . reduce_sum ( m , axis : 0 ) [ 0 ] , x ) [ 0 ] ;
198
+ var g2 = tf . gradients ( tf . reduce_sum ( m , axis : 1 ) [ 0 ] , x ) [ 0 ] ;
199
199
200
200
using ( var session = tf . Session ( ) )
201
201
{
202
202
var ( r0 , r1 , r2 ) = session . run ( ( g0 , g1 , g2 ) , new FeedItem ( x , new [ , ] { { 1.0 } } ) ) ;
203
203
self . assertFloat64Equal ( 6.0 , r0 [ 0 ] , $ "tf.reduce_sum(...)") ;
204
- self . assertFloat64Equal ( 6 .0, r1 [ 0 ] , $ "tf.reduce_sum(..., axis = 0)") ;
205
- self . assertFloat64Equal ( 6 .0, r2 [ 0 ] , $ "tf.reduce_sum(..., axis = 1)") ;
204
+ self . assertFloat64Equal ( 2 .0, r1 [ 0 ] , $ "tf.reduce_sum(..., axis = 0)") ;
205
+ self . assertFloat64Equal ( 3 .0, r2 [ 0 ] , $ "tf.reduce_sum(..., axis = 1)") ;
206
206
}
207
207
}
208
208
0 commit comments