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

Function ComputeStrides

tensorflow/compiler/xla/service/hlo_evaluator.cc:950–970  ·  view source on GitHub ↗

Helper to compute strides for creating linear indices into multidimensional data from the dimension lengths and the layout. Returns a new vector of size lengths.size() + 1. The last element of the returned vector at index [lengths.size()] contains the product of all dimension lengths.

Source from the content-addressed store, hash-verified

948// lengths.size() + 1. The last element of the returned vector at index
949// [lengths.size()] contains the product of all dimension lengths.
950std::vector<int64> ComputeStrides(const absl::Span<const int64> lengths,
951 const Layout& layout) {
952 const int64 num_dimensions = lengths.size();
953
954 // Make sure that the layout length matches the number of dimensions.
955 CHECK_EQ(num_dimensions, layout.minor_to_major_size());
956
957 // Calculate strides using layout-specified ordering of the dimensions and
958 // place the stride for axis 0 at index 0, for axis 1 at index 1, etc.
959 std::vector<int64> strides(num_dimensions + 1);
960 int64 stride = 1;
961 for (int64 i = 0; i < num_dimensions; i++) {
962 // Reverse the ordering of the dimensions in the layout.
963 const int64 index = (num_dimensions - 1) - layout.minor_to_major(i);
964 strides[index] = stride;
965 stride *= lengths[index];
966 }
967 strides[num_dimensions] = stride;
968
969 return strides;
970}
971
972// Compute strides as above using the default layout.
973std::vector<int64> ComputeStrides(const absl::Span<const int64> lengths) {

Callers 1

HandleFftMethod · 0.70

Calls 6

minor_to_major_sizeMethod · 0.80
minor_to_majorMethod · 0.80
has_layoutMethod · 0.80
sizeMethod · 0.45
shapeMethod · 0.45
layoutMethod · 0.45

Tested by

no test coverage detected