Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7bf1ac

Browse files
Apply suggestions from code review
Accepting suggestions to avoid dynamic allocation issues. Fix for .notation pending.Co-authored-by: Michael Bartling <michael.bartling15@gmail.com>
1 parent949c3c4 commitc7bf1ac

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

‎src/uTensor/ops/Transpose.hpp‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =newTensorStrides(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 =newTensorShape(1,1,1,1);
40-
TensorStrides* output_strides =newTensorStrides(*output_shape);
41-
TensorShape* offsets =newTensorShape(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

4344
for (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

5152
for (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
6465
if (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
8384
uint32_t idx =0;
8485
for (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
9394
for (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) {
9697
break;
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
}
110103
private:
111104
TensorShape _axes;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp