@@ -176,34 +176,40 @@ end
176176# TODO Clean this up
177177for reduction in [:sum , :prod , :min , :max , :all , :any , :mean ]
178178 @eval @op function $ (Symbol (" reduce_" , reduction))(n:: AbstractTensor ; axis= nothing , keep_dims= false , name= nothing )
179- local desc
180- with_op_name (name, string (" reduce_" , $ (reduction))) do
181- node_name = get_cur_node_name ()
182-
183- if axis == nothing
184- n = Tensor (n) # TODO : rewrite this
185- range_start = constant (Int32 (0 ))
186- range_delta = constant (Int32 (1 ))
187- rank_desc = NodeDescription (" Rank" , " $node_name /rank" )
188- add_input (rank_desc, n)
189- rank = Tensor (Operation (rank_desc), 1 )
190- desc_range = NodeDescription (" Range" , " $node_name /range" )
191- add_input (desc_range, range_start)
179+ if name == nothing
180+ name = $ (capitalize (reduction))
181+ end
182+
183+ if axis == nothing
184+ n = Tensor (n) # TODO : rewrite this
185+ desc_rank = tf. with_op_name (nothing , " Rank" ) do
186+ NodeDescription (" Rank" )
187+ end
188+ add_input (desc_rank, n)
189+ rank = Tensor (Operation (desc_rank), 1 )
190+ range = tf. with_op_name (nothing , " range" ) do
191+ @tf start = constant (Int32 (0 ))
192+ @tf delta = constant (Int32 (1 ))
193+ desc_range = NodeDescription (" Range" )
194+ add_input (desc_range, start)
192195 add_input (desc_range, rank)
193- add_input (desc_range, range_delta)
194- range = Tensor (Operation (desc_range), 1 )
196+ add_input (desc_range, delta)
197+ Tensor (Operation (desc_range), 1 )
198+ end
199+ desc = tf. with_op_name (nothing , name) do
195200 desc = NodeDescription ($ (capitalize (reduction)))
196201 add_input (desc, n)
197202 add_input (desc, range)
198- else
199- if isa (axis, Number)
200- axis = [axis]
201- end
202- axis = [ Int32 (idx - 1 ) for idx in axis]
203+ desc
204+ end
205+ else
206+ desc = tf . with_op_name ( nothing , name) do
207+ @tf reduction_indices = constant ( Int32 .(axis . -1 ))
203208 desc = NodeDescription ($ (capitalize (reduction)))
204209 add_input (desc, Tensor (n))
205- add_input (desc, Tensor (axis) )
210+ add_input (desc, reduction_indices )
206211 desc[" keep_dims" ] = keep_dims
212+ desc
207213 end
208214 end
209215 Tensor (Operation (desc), 1 )
0 commit comments