Returns true if the input dimensions are already sorted in the order [batch, contract, free, reduce]. Used to implement an optimization to avoid an extra transpose and instead uses (adj_x and adj_y) in BatchMatMul.
| 415 | // [batch, contract, free, reduce]. Used to implement an optimization to avoid |
| 416 | // an extra transpose and instead uses (adj_x and adj_y) in BatchMatMul. |
| 417 | bool ShouldSwapFreeAndContract(const Labels& labels, |
| 418 | const std::vector<DimensionType>& label_types) { |
| 419 | // Check that ordering is according to dimension type, with the role of |
| 420 | // free and contract dimensions swapped. |
| 421 | gtl::InlinedVector<int, 5> remap = {0, 1, 3, 2, 4}; |
| 422 | for (int i = 0; i + 1 < labels.size(); ++i) { |
| 423 | const int dimtype_a = remap[label_types[labels[i]]]; |
| 424 | const int dimtype_b = remap[label_types[labels[i + 1]]]; |
| 425 | if (dimtype_a > dimtype_b || |
| 426 | (dimtype_a == dimtype_b && labels[i] > labels[i + 1])) { |
| 427 | return false; |
| 428 | } |
| 429 | } |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | template <typename Device, typename T> |
| 434 | Status ReduceOperand(OpKernelContext* ctx, const Tensor& input, |