[XLA] Clarify the dimension ordering.

This comment contradicts the behavior of the class. Both Linearize() and Delinearize() use major-first multi-dimensional semantics.

Apart from pure reasoning about the code, the following test cases also exhibit major-first behavior:

// Prints 42
IrArray::Index({llvm::ConstantInt::get(builder->getInt64Ty(), 4),
                llvm::ConstantInt::get(builder->getInt64Ty(), 2)},
               {10, 10}, index_type)
    .Linearize({10, 10}, builder)->dump();

// Prints 4
IrArray::Index({llvm::ConstantInt::get(builder->getInt64Ty(), 1),
                llvm::ConstantInt::get(builder->getInt64Ty(), 1)},
               {2, 3}, index_type)
    .Linearize({2, 3}, builder)->dump();

// Prints 4, 2
for (llvm::Value* digit : std::vector<llvm::Value*>(
         IrArray::Index(llvm::ConstantInt::get(builder->getInt64Ty(), 42),
                        {10, 10}, builder)
             .multidim())) {
  digit->dump();
}

// Prints 1, 1
for (llvm::Value* digit : std::vector<llvm::Value*>(
         IrArray::Index(llvm::ConstantInt::get(builder->getInt64Ty(), 4),
                        {2, 3}, builder)
             .multidim())) {
  digit->dump();
}

PiperOrigin-RevId: 246935221
This commit is contained in:
Tim Shen 2019-05-06 18:12:57 -07:00 committed by TensorFlower Gardener
parent 963bb1f156
commit f56ba9f6b3

View File

@ -43,12 +43,9 @@ namespace llvm_ir {
// are supported.
class IrArray {
public:
// A multidimensional index into an IrArray. The index for dimension zero is
// first in the vector. This is the reverse order of the notation used for
// describing the dimensions of an array. That is, for a [4 x 3 x 2] array
// dimension zero has size 2, dimension one has size 3, and dimension two has
// size 4. Thus the index {1, 2, 3} indexes the last element of this [4 x 3 x
// 2] array.
// A multidimensional index into an IrArray. All the runtime indices
// (multidim) and dimensions (Shape::dimensions(), absl::Span<const int64>)
// are major-first.
//
// This may also keep a linear index and the layout and dimensions it was
// emitted for; if the shape where this `Index` is used matches, the linear