Skip to content

Commit

Permalink
Add FooWithStatus methods for all Foo methods with CHECK fails.
Browse files Browse the repository at this point in the history
This is part of eliminating CHECK fails from `tensor_shape.cc`.

The goal is to provide options for the callers to either test the `CHECK` conditions before calling the `Foo` methods or to call the `FooWithStatus` methods and receive a `Status` to act on instead of just crashing.

PiperOrigin-RevId: 350218073
Change-Id: I4238ba3a2eff16a224e61bafb58b6553d706bb4b
  • Loading branch information
mihaimaruseac committed Oct 29, 2021
1 parent 227f89f commit 27f0e82
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tensorflow/core/framework/tensor_shape.h
Expand Up @@ -210,6 +210,10 @@ class TensorShapeBase : public TensorShapeRep {
/// Use if unsure is `size >= 0`, to prevent `CHECK`-crashes.
Status AddDimWithStatus(int64 size);

/// Same as `AddDim` but returns a `Status`.
/// Use if unsure is `size >= 0`, to prevent `CHECK`-crashes.
Status AddDimWithStatus(int64 size);

/// Appends all the dimensions from `shape`.
void AppendShape(const TensorShapeBase& shape);

Expand Down Expand Up @@ -325,7 +329,7 @@ class TensorShapeBase : public TensorShapeRep {

private:
Status RecomputeNumElements();
void InitDims(gtl::ArraySlice<int64> dim_sizes);
Status InitDims(gtl::ArraySlice<int64> dim_sizes);

// True for PartialTensorShape, false for TensorShape
static constexpr bool kIsPartial =
Expand Down Expand Up @@ -580,9 +584,12 @@ class PartialTensorShapeUtils {
// ----------------------------------------------------------------------------

template <int NDIMS, typename IndexType>
Eigen::DSizes<IndexType, NDIMS> TensorShape::AsEigenDSizes() const {
CheckDimsEqual(NDIMS);
return AsEigenDSizesWithPadding<NDIMS, IndexType>();
Eigen::DSizes<IndexType, NDIMS> TensorShape::AsEigenDSizesCopy() const {
Eigen::DSizes<IndexType, NDIMS> dsizes;
for (int d = 0; d < NDIMS; d++) {
dsizes[d] = static_cast<IndexType>(dim_size(d));
}
return dsizes;
}

template <int NDIMS, typename IndexType>
Expand Down

0 comments on commit 27f0e82

Please sign in to comment.