@@ -50,6 +50,21 @@ executorch.Graph = class {
50
50
this . outputs = [ ] ;
51
51
this . nodes = [ ] ;
52
52
const values = new Map ( ) ;
53
+ values . tensors = ( index , items ) => {
54
+ const list = [ ] ;
55
+ for ( let i = 0 ; i < items . length ; i ++ ) {
56
+ const item = items [ i ] ;
57
+ const type = item ? new executorch . TensorType ( item ) : null ;
58
+ let initializer = null ;
59
+ if ( item && item . data_buffer_idx > 0 ) {
60
+ initializer = new executorch . Tensor ( item , target ) ;
61
+ }
62
+ const identifier = items . length > 1 ? `${ index } .${ i } ` : index . toString ( ) ;
63
+ const value = new executorch . Value ( identifier , type , initializer ) ;
64
+ list . push ( value ) ;
65
+ }
66
+ return list ;
67
+ } ;
53
68
values . map = ( index , output ) => {
54
69
if ( ! values . has ( index ) ) {
55
70
const executorch_flatbuffer = executorch . schema . executorch_flatbuffer ;
@@ -58,34 +73,32 @@ executorch.Graph = class {
58
73
if ( output && ! tensor ) {
59
74
const value = [ new executorch . Value ( index . toString ( ) , null , null ) ] ;
60
75
values . set ( index , { type : null , value } ) ;
61
- } else if ( tensor ) {
62
- const tensors = val instanceof executorch_flatbuffer . Tensor ? [ val ] : Array . from ( val . items ) . map ( ( arg ) => plan . values [ arg ] . val ) ;
63
- const list = [ ] ;
64
- for ( let i = 0 ; i < tensors . length ; i ++ ) {
65
- const tensor = tensors [ i ] ;
66
- const type = new executorch . TensorType ( tensor ) ;
67
- let initializer = null ;
68
- if ( val . data_buffer_idx > 0 ) {
69
- initializer = new executorch . Tensor ( tensor , target ) ;
70
- }
71
- const identifier = tensors . length > 1 ? `${ index } .${ i } ` : index . toString ( ) ;
72
- const value = new executorch . Value ( identifier , type , initializer ) ;
73
- list . push ( value ) ;
74
- }
75
- values . set ( index , { type : null , value : list } ) ;
76
- } else if ( val instanceof executorch_flatbuffer . Bool ) {
77
- values . set ( index , { type : 'int64' , value : val . bool_val } ) ;
76
+ } else if ( val instanceof executorch_flatbuffer . Null ) {
77
+ values . set ( index , { type : 'attribute' , value : null } ) ;
78
78
} else if ( val instanceof executorch_flatbuffer . Int ) {
79
79
values . set ( index , { type : 'int64' , value : val . int_val } ) ;
80
- } else if ( val instanceof executorch_flatbuffer . IntList ) {
81
- const list = val . items . map ( ( index ) => plan . values [ index ] . val . int_val ) ;
82
- values . set ( index , { type : 'int64[]' , value : list } ) ;
80
+ } else if ( val instanceof executorch_flatbuffer . Bool ) {
81
+ values . set ( index , { type : 'int64' , value : val . bool_val } ) ;
83
82
} else if ( val instanceof executorch_flatbuffer . Double ) {
84
83
values . set ( index , { type : 'float64' , value : val . double_val } ) ;
84
+ } else if ( val instanceof executorch_flatbuffer . Tensor ) {
85
+ const items = [ val ] ;
86
+ values . set ( index , { type : null , value : values . tensors ( index , items ) } ) ;
85
87
} else if ( val instanceof executorch_flatbuffer . String ) {
86
88
values . set ( index , { type : 'string' , value : val . string_val } ) ;
87
- } else if ( val instanceof executorch_flatbuffer . Null ) {
88
- values . set ( index , { type : 'attribute' , value : null } ) ;
89
+ } else if ( val instanceof executorch_flatbuffer . IntList ) {
90
+ const list = val . items . map ( ( index ) => plan . values [ index ] . val . int_val ) ;
91
+ values . set ( index , { type : 'int64[]' , value : list } ) ;
92
+ } else if ( val instanceof executorch_flatbuffer . DoubleList ) {
93
+ throw new executorch . Error ( 'executorch_flatbuffer.DoubleList not implemented.' ) ;
94
+ } else if ( val instanceof executorch_flatbuffer . BoolList ) {
95
+ throw new executorch . Error ( 'executorch_flatbuffer.BoolList not implemented.' ) ;
96
+ } else if ( val instanceof executorch_flatbuffer . TensorList ) {
97
+ const items = Array . from ( val . items ) . map ( ( arg ) => arg === - 1 ? null : plan . values [ arg ] . val ) ;
98
+ values . set ( index , { type : null , value : values . tensors ( index , items ) } ) ;
99
+ } else if ( val instanceof executorch_flatbuffer . OptionalTensorList ) {
100
+ const items = Array . from ( val . items ) . map ( ( arg ) => arg === - 1 ? null : plan . values [ arg ] . val ) ;
101
+ values . set ( index , { type : null , value : values . tensors ( index , items ) } ) ;
89
102
} else {
90
103
throw new Error ( `Value type '${ val . constructor . name } ' not implemented.` ) ;
91
104
}
0 commit comments