tensorflow/compiler/tf2xla/shape_util.cc
// Populate the output layout unless the minor_to_major array contains all -1
// value, in which case the layout is considered missing and the API returns
// false.
Populate the output layout unless the minor_to_major array contains all -1
value, in which case the layout is considered missing and the API returns
false.
Populate the output layout unless the minor_to_major array contains all - 1 value in which case the layout is considered missing and the API returns false .
StatusOr<bool> MakeLayout(absl::Span<const int64_t> minor_to_major,
                          xla::Layout* layout) {
  if (std::all_of(minor_to_major.begin(), minor_to_major.end(),
                  [](int64_t dim) { return dim == -1; })) {
    return false;
  }
  std::vector<bool> dim_present(minor_to_major.size(), false);
  for (auto dim : minor_to_major) {
    const int minor_to_major_size = minor_to_major.size();
    if (dim < 0 || dim >= minor_to_major_size) {
      return errors::InvalidArgument("Layout dimension out of range: dim=", dim,
                                     " rank=", minor_to_major.size());
    }
    if (dim_present[dim]) {
      return errors::InvalidArgument("Repeated layout dimension: dim=", dim);
    }
    dim_present[dim] = true;
  }
  *layout = xla::LayoutUtil::MakeLayout(minor_to_major);
  return true;
}
StatusOr < bool > MakeLayout ( absl :: Span < const int64_t > minor_to_major , xla :: Layout * layout ) { if ( std :: all_of ( minor_to_major . begin ( ) , minor_to_major . end ( ) , [ ] ( int64_t dim ) { return dim == -1 ; } ) ) { return false ; } std :: vector < bool > dim_present ( minor_to_major . size ( ) , false ) ; for ( auto dim : minor_to_major ) { const int minor_to_major_size = minor_to_major . size ( ) ; if ( dim < 0 || dim >= minor_to_major_size ) { return errors :: InvalidArgument ( " " , dim , " " , minor_to_major . size ( ) ) ; } if ( dim_present [ dim ] ) { return errors :: InvalidArgument ( " " , dim ) ; } dim_present [ dim ] = true ; } * layout = xla :: LayoutUtil :: MakeLayout ( minor_to_major ) ; return true ; }
Populate the output layout unless the minor_to_major array contains all -1
value, in which case the layout is considered missing and the API returns
false.
Populate the output layout unless the minor_to_major array contains all - 1 value in which case the layout is considered missing and the API returns false .