MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / OnlyTransposed

Function OnlyTransposed

paddle/phi/kernels/cpu/contiguous_kernel.cc:64–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64inline bool OnlyTransposed(const DDim& shape,
65 const DDim& stride,
66 const uint64_t& offset) {
67 if (offset != 0) {
68 return false;
69 }
70
71 DDim x_stride = stride;
72 DDim x_shape = shape;
73
74 std::set<int> visited_idx;
75 for (int i = 0; i < stride.size(); i++) {
76 int64_t max_num = 0;
77 int max_idx = -1;
78 for (int j = 0; j < stride.size(); j++) {
79 if (visited_idx.count(j)) {
80 continue;
81 }
82 if (stride[j] < 1) {
83 return false;
84 }
85 if (stride[j] > max_num) {
86 max_num = stride[j];
87 max_idx = j;
88 }
89 }
90 if (max_idx == -1) {
91 return false;
92 }
93 if (i != 0 && x_stride[i - 1] == max_num) {
94 return false;
95 }
96 visited_idx.insert(max_idx);
97 x_stride[i] = max_num;
98 x_shape[i] = shape[max_idx];
99 }
100
101 if (DenseTensorMeta::calc_strides(x_shape) == x_stride) {
102 return true;
103 } else {
104 return false;
105 }
106}
107
108inline bool FastContiguousJudge(const std::vector<int64_t>& coalesce_shape,
109 const DenseTensor& input) {

Callers 1

FastContiguousJudgeFunction · 0.85

Calls 3

sizeMethod · 0.45
countMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected