MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ShouldSwapFreeAndContract

Function ShouldSwapFreeAndContract

tensorflow/core/kernels/einsum_op.cc:417–431  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
417bool 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
433template <typename Device, typename T>
434Status ReduceOperand(OpKernelContext* ctx, const Tensor& input,

Callers 1

ReduceOperandFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected