@@ -108,7 +108,7 @@ void convert_Tensor_slice_copy(Graph& graph)
108108 const int axes_rank = axes.size ();
109109
110110 bool has_select = false ;
111- std::vector<int > selected_axes ;
111+ std::vector<int > selected_axis_indices ;
112112 for (int i = 0 ; i < axes_rank; i++)
113113 {
114114 if (steps[i] == 0 )
@@ -118,7 +118,7 @@ void convert_Tensor_slice_copy(Graph& graph)
118118 ends[i] = selects[i] + 1 ;
119119 steps[i] = 1 ;
120120 has_select = true ;
121- selected_axes .push_back (axes[i] );
121+ selected_axis_indices .push_back (i );
122122 }
123123 else if (steps[i] != 1 )
124124 {
@@ -141,18 +141,18 @@ void convert_Tensor_slice_copy(Graph& graph)
141141 }
142142 }
143143
144+ int input_rank0 = op->inputs [0 ]->shape .size ();
144145 for (int i = 0 ; i < axes_rank; i++)
145146 {
146- if (axes[i] == batch_index && (starts[i] != 0 || ends[i] != INT_MAX ) )
147+ if (axes[i] < 0 && input_rank0 > 0 )
147148 {
148- fprintf (stderr, " slice_copy along batch axis is not supported\n " );
149- continue ;
149+ axes[i] = input_rank0 + axes[i];
150150 }
151151
152- if (axes[i] < 0 )
152+ if (axes[i] == batch_index && (starts[i] != 0 || ends[i] != INT_MAX ) )
153153 {
154- int input_rank = op-> inputs [ 0 ]-> shape . size ( );
155- axes[i] = input_rank + axes[i] ;
154+ fprintf (stderr, " slice_copy along batch axis is not supported \n " );
155+ continue ;
156156 }
157157
158158 if (axes[i] > batch_index)
@@ -203,9 +203,15 @@ void convert_Tensor_slice_copy(Graph& graph)
203203 in->consumers .push_back (reshape);
204204
205205 std::vector<int > shape = in->shape ;
206- for (auto sa : selected_axes )
206+ for (auto si : selected_axis_indices )
207207 {
208208 // unsqueeze
209+ int sa = axes[si];
210+ if (shape.empty ())
211+ continue ;
212+ if (sa < 0 || sa > (int )shape.size ())
213+ continue ;
214+
209215 shape.insert (shape.begin () + sa, 1 );
210216 }
211217
0 commit comments