@@ -31,34 +31,35 @@ class TransposeOperator : public OperatorInterface<1, 1> {
3131
3232// Strides are used to iterate over the dataset, and transfer
3333// the input tensor data, into the output tensor
34- TensorStrides* input_strides =new TensorStrides (input_shape);
34+ TensorStrides input_strides =TensorStrides (input_shape);
3535
3636 Tensor& output_tensor = outputs[output].tensor ();
3737
3838// Create a placeholder to calculate the output shape
39- TensorShape* output_shape =new TensorShape (1 ,1 ,1 ,1 );
40- TensorStrides* output_strides =new TensorStrides (*output_shape);
41- TensorShape* offsets =new TensorShape (input_shape.num_dims ());
39+ // Normally this would reference output shape, but since this could (usually would) be referencing the input, let's keep a dedicated value
40+ TensorShape output_shape =TensorShape (1 ,1 ,1 ,1 );
41+ TensorStrides output_strides =TensorStrides (output_shape);
42+ TensorShape offsets =TensorShape (input_shape.num_dims ());
4243
4344for (size_t i =0 ; i <4 ; ++i) {
4445 output_shape[i] =0 ;
45- (* output_strides) [i] =0 ;
46+ output_strides[i] =0 ;
4647
4748// Offsets are used to avoid multiple for loops
48- (* offsets) [i] =0 ;
49+ offsets[i] =0 ;
4950 }
5051
5152for (size_t i =0 ; i < (size_t ) input_shape.num_dims (); ++i) {
52- (* output_shape) [_axes[i]] = input_shape[i];
53+ output_shape[_axes[i]] = input_shape[i];
5354
5455// output_strides(i) is derived from axes and input_strides
55- (* output_strides) [_axes[i]] = (*input_strides)[i];
56+ output_strides[_axes[i]] = (*input_strides)[i];
5657 }
5758
5859// Output shape can be asserted once the transform
5960// effect has been determined
6061 output_shape->update_dims ();
61- output_tensor->resize (* output_shape);
62+ output_tensor->resize (output_shape);
6263
6364// Perform some basic checks
6465if (input_tensor->num_elems () != output_tensor->num_elems ()){
@@ -82,7 +83,7 @@ class TransposeOperator : public OperatorInterface<1, 1> {
8283// using the output strides and output shape
8384uint32_t idx =0 ;
8485for (uint32_t j =0 ; j < output_shape->num_dims (); j++) {
85- idx +=(* offsets) [j] *(* output_strides) [j];
86+ idx += offsets[j] * output_strides[j];
8687 }
8788
8889// this is not copy: `output_tensor(i) = input_tensor(i);`
@@ -91,21 +92,13 @@ class TransposeOperator : public OperatorInterface<1, 1> {
9192// Update offsets, to iterate sequentially along strides
9293// in the order of axes
9394for (int32_t j = output_shape->num_dims () -1 ; j >=0 ; j--) {
94- (* offsets) [j] = ((* offsets) [j] +1 ) % (* output_shape) [j];
95- if ((* offsets) [j] >0 ) {
95+ offsets[j] = (offsets[j] +1 ) % (output_shape[j]) ;
96+ if ( offsets[j] >0 ) {
9697break ;
9798 }
9899 }
99100 }
100101
101- delete input_strides;
102- input_strides =0 ;
103-
104- delete output_shape;
105- output_shape =0 ;
106-
107- delete offsets;
108- offsets =0 ;
109102 }
110103private:
111104 TensorShape _axes;