@@ -94,7 +94,7 @@ pub trait ExprImpl<T: TensorType>: Display + Debug {
94
94
/// rather than creating child operations itself.
95
95
fn create_operation ( & self ,
96
96
graph : & mut Graph ,
97
- children : & [ Rc < Operation > ] ,
97
+ children : & [ Operation ] ,
98
98
id_gen : & mut FnMut ( ) -> String )
99
99
-> Result < Operation , Status > ;
100
100
@@ -113,7 +113,7 @@ impl<T: TensorType> ExprImpl<T> for T {
113
113
114
114
fn create_operation ( & self ,
115
115
graph : & mut Graph ,
116
- _children : & [ Rc < Operation > ] ,
116
+ _children : & [ Operation ] ,
117
117
id_gen : & mut FnMut ( ) -> String )
118
118
-> Result < Operation , Status > {
119
119
let mut nd = try!( graph. new_operation ( "Const" , & id_gen ( ) ) ) ;
@@ -197,11 +197,11 @@ macro_rules! impl_bin_op {
197
197
vec![ Box :: new( self . left. clone( ) ) , Box :: new( self . right. clone( ) ) ]
198
198
}
199
199
200
- fn create_operation( & self , graph: & mut Graph , children: & [ Rc < Operation > ] ,
200
+ fn create_operation( & self , graph: & mut Graph , children: & [ Operation ] ,
201
201
id_gen: & mut FnMut ( ) -> String ) -> Result <Operation , Status > {
202
202
let mut nd = try!( graph. new_operation( $tf_op, & id_gen( ) ) ) ;
203
- nd. add_input( Output { operation: & children[ 0 ] , index: 0 } ) ;
204
- nd. add_input( Output { operation: & children[ 1 ] , index: 0 } ) ;
203
+ nd. add_input( Output { operation: children[ 0 ] . clone ( ) , index: 0 } ) ;
204
+ nd. add_input( Output { operation: children[ 1 ] . clone ( ) , index: 0 } ) ;
205
205
nd. finish( )
206
206
}
207
207
@@ -287,18 +287,18 @@ impl<T: TensorType> ExprImpl<T> for TruncateDiv<T> {
287
287
288
288
fn create_operation ( & self ,
289
289
graph : & mut Graph ,
290
- children : & [ Rc < Operation > ] ,
290
+ children : & [ Operation ] ,
291
291
id_gen : & mut FnMut ( ) -> String )
292
292
-> Result < Operation , Status > {
293
293
let mut nd = try!( graph. new_operation ( "TruncateDiv" , & id_gen ( ) ) ) ;
294
294
nd. add_input ( Output {
295
- operation : & children[ 0 ] ,
296
- index : 0 ,
297
- } ) ;
295
+ operation : children[ 0 ] . clone ( ) ,
296
+ index : 0 ,
297
+ } ) ;
298
298
nd. add_input ( Output {
299
- operation : & children[ 1 ] ,
300
- index : 0 ,
301
- } ) ;
299
+ operation : children[ 1 ] . clone ( ) ,
300
+ index : 0 ,
301
+ } ) ;
302
302
nd. finish ( )
303
303
}
304
304
@@ -351,14 +351,14 @@ impl<T: TensorType> ExprImpl<T> for Neg<T> {
351
351
352
352
fn create_operation ( & self ,
353
353
graph : & mut Graph ,
354
- children : & [ Rc < Operation > ] ,
354
+ children : & [ Operation ] ,
355
355
id_gen : & mut FnMut ( ) -> String )
356
356
-> Result < Operation , Status > {
357
357
let mut nd = try!( graph. new_operation ( "Neg" , & id_gen ( ) ) ) ;
358
358
nd. add_input ( Output {
359
- operation : & children[ 0 ] ,
360
- index : 0 ,
361
- } ) ;
359
+ operation : children[ 0 ] . clone ( ) ,
360
+ index : 0 ,
361
+ } ) ;
362
362
nd. finish ( )
363
363
}
364
364
@@ -409,7 +409,7 @@ impl<T: TensorType> ExprImpl<T> for Variable<T> {
409
409
410
410
fn create_operation ( & self ,
411
411
graph : & mut Graph ,
412
- _children : & [ Rc < Operation > ] ,
412
+ _children : & [ Operation ] ,
413
413
_id_gen : & mut FnMut ( ) -> String )
414
414
-> Result < Operation , Status > {
415
415
let mut nd = try!( graph. new_operation ( "Variable" , & self . name ) ) ;
@@ -469,7 +469,7 @@ impl<T: TensorType> ExprImpl<T> for Placeholder<T> {
469
469
470
470
fn create_operation ( & self ,
471
471
graph : & mut Graph ,
472
- _children : & [ Rc < Operation > ] ,
472
+ _children : & [ Operation ] ,
473
473
_id_gen : & mut FnMut ( ) -> String )
474
474
-> Result < Operation , Status > {
475
475
let mut nd = try!( graph. new_operation ( "Placeholder" , & self . name ) ) ;
@@ -523,18 +523,18 @@ impl<T: TensorType> ExprImpl<T> for Assign<T> {
523
523
524
524
fn create_operation ( & self ,
525
525
graph : & mut Graph ,
526
- children : & [ Rc < Operation > ] ,
526
+ children : & [ Operation ] ,
527
527
id_gen : & mut FnMut ( ) -> String )
528
528
-> Result < Operation , Status > {
529
529
let mut nd = try!( graph. new_operation ( "Assign" , & id_gen ( ) ) ) ;
530
530
nd. add_input ( Output {
531
- operation : & children[ 0 ] ,
532
- index : 0 ,
533
- } ) ;
531
+ operation : children[ 0 ] . clone ( ) ,
532
+ index : 0 ,
533
+ } ) ;
534
534
nd. add_input ( Output {
535
- operation : & children[ 1 ] ,
536
- index : 0 ,
537
- } ) ;
535
+ operation : children[ 1 ] . clone ( ) ,
536
+ index : 0 ,
537
+ } ) ;
538
538
nd. finish ( )
539
539
}
540
540
@@ -563,7 +563,7 @@ pub trait AnyExpr: Debug {
563
563
/// rather than creating child operations itself.
564
564
fn create_operation ( & self ,
565
565
graph : & mut Graph ,
566
- children : & [ Rc < Operation > ] ,
566
+ children : & [ Operation ] ,
567
567
id_gen : & mut FnMut ( ) -> String )
568
568
-> Result < Operation , Status > ;
569
569
@@ -586,7 +586,7 @@ impl<T: TensorType> AnyExpr for Expr<T> {
586
586
587
587
fn create_operation ( & self ,
588
588
graph : & mut Graph ,
589
- children : & [ Rc < Operation > ] ,
589
+ children : & [ Operation ] ,
590
590
id_gen : & mut FnMut ( ) -> String )
591
591
-> Result < Operation , Status > {
592
592
self . expr . create_operation ( graph, children, id_gen)
@@ -620,7 +620,7 @@ impl Hash for Key {
620
620
#[ derive( Debug ) ]
621
621
pub struct Compiler < ' l > {
622
622
graph : & ' l mut Graph ,
623
- operations : HashMap < Key , Rc < Operation > > ,
623
+ operations : HashMap < Key , Operation > ,
624
624
next_id : i32 ,
625
625
}
626
626
@@ -635,12 +635,12 @@ impl<'l> Compiler<'l> {
635
635
}
636
636
637
637
/// Compiles the expression.
638
- pub fn compile < T : TensorType > ( & mut self , expr : Expr < T > ) -> Result < Rc < Operation > , Status > {
638
+ pub fn compile < T : TensorType > ( & mut self , expr : Expr < T > ) -> Result < Operation , Status > {
639
639
self . compile_any ( Box :: new ( expr) )
640
640
}
641
641
642
642
/// Compiles the expression.
643
- pub fn compile_any ( & mut self , expr : Box < AnyExpr > ) -> Result < Rc < Operation > , Status > {
643
+ pub fn compile_any ( & mut self , expr : Box < AnyExpr > ) -> Result < Operation , Status > {
644
644
let mut child_operations = vec ! [ ] ;
645
645
for child in expr. children ( ) {
646
646
let key = Key ( child. clone_box ( ) ) ;
@@ -661,7 +661,7 @@ impl<'l> Compiler<'l> {
661
661
id
662
662
} ) ;
663
663
self . next_id = next_id;
664
- let operation = Rc :: new ( try! ( result) ) ;
664
+ let operation = result? ;
665
665
self . operations . insert ( Key ( expr) , operation. clone ( ) ) ;
666
666
Ok ( operation)
667
667
}
0 commit comments