@@ -22,18 +22,15 @@ void ReshapeLayer::run(const std::vector<Tensor>& input,
2222 }
2323 }
2424
25- std::vector<int64_t > original_requested_shape = target_shape;
2625 auto final_shape =
2726 calculate_output_shape (data_tensor.get_shape (), target_shape);
2827
2928 switch (data_tensor.get_type ()) {
3029 case Type::kFloat :
31- reshape_impl<float >(data_tensor, output[0 ], original_requested_shape,
32- final_shape);
30+ reshape_impl<float >(data_tensor, output[0 ], target_shape, final_shape);
3331 break ;
3432 case Type::kInt :
35- reshape_impl<int >(data_tensor, output[0 ], original_requested_shape,
36- final_shape);
33+ reshape_impl<int >(data_tensor, output[0 ], target_shape, final_shape);
3734 break ;
3835 default :
3936 throw std::runtime_error (" Unsupported tensor data type for Reshape" );
@@ -96,17 +93,17 @@ std::vector<int64_t> ReshapeLayer::calculate_output_shape(
9693}
9794
9895template <typename T>
99- void ReshapeLayer::reshape_impl (
100- const Tensor& input, Tensor& output,
101- const std::vector<int64_t >& original_requested_shape,
102- const std::vector<int64_t >& final_shape) const {
96+ void ReshapeLayer::reshape_impl (const Tensor& input, Tensor& output,
97+ const std::vector<int64_t >& target_shape,
98+ const std::vector<int64_t >& final_shape) const {
10399 const auto * input_data = input.as <T>();
104100 const Shape& input_shape = input.get_shape ();
105101
106- if (input_shape[0 ] > 1 && original_requested_shape [0 ] == 1 ) {
107- apply_per_batch_reshape<T>(input, output, original_requested_shape );
102+ if (input_shape[0 ] > 1 && target_shape [0 ] == 1 ) {
103+ apply_per_batch_reshape<T>(input, output, target_shape );
108104 } else {
109105 std::vector<size_t > shape_size_t ;
106+ shape_size_t .reserve (final_shape.size ());
110107 for (int64_t dim : final_shape) {
111108 shape_size_t .push_back (static_cast <size_t >(dim));
112109 }
@@ -117,12 +114,12 @@ void ReshapeLayer::reshape_impl(
117114template <typename T>
118115void ReshapeLayer::apply_per_batch_reshape (
119116 const Tensor& input, Tensor& output,
120- const std::vector<int64_t >& original_requested_shape ) const {
117+ const std::vector<int64_t >& target_shape ) const {
121118 const auto * input_data = input.as <T>();
122119 const Shape& input_shape = input.get_shape ();
123120 size_t batch_size = input_shape[0 ];
124121 size_t elements_per_batch = input_shape.count () / batch_size;
125- std::vector<int64_t > per_batch_target = original_requested_shape ;
122+ std::vector<int64_t > per_batch_target = target_shape ;
126123 per_batch_target[0 ] = 1 ;
127124
128125 Shape single_batch_input_shape = input_shape;
@@ -132,6 +129,7 @@ void ReshapeLayer::apply_per_batch_reshape(
132129 calculate_output_shape (single_batch_input_shape, per_batch_target);
133130
134131 std::vector<size_t > final_output_shape_size_t ;
132+ final_output_shape_size_t .reserve (single_batch_output_shape.size ());
135133 final_output_shape_size_t .push_back (batch_size);
136134 for (size_t i = 1 ; i < single_batch_output_shape.size (); ++i) {
137135 final_output_shape_size_t .push_back (
0 commit comments