message: Replace some CHECKs with returning an error Status
  The public functions already return Status objects, so there is no need to use CHECKs when we could signal an error more safely.
diff: @@ -321,23 +321,26 @@ Status CopyTF_TensorStringsToPyArray(const TF_Tensor* src, uint64 nelems,
  // Determine the dimensions of a numpy ndarray to be created to represent an
  // output Tensor.
  -gtl::InlinedVector<npy_intp, 4> GetPyArrayDimensionsForTensor(
  - const TF_Tensor* tensor, tensorflow::int64* nelems) {
  +Status GetPyArrayDimensionsForTensor(const TF_Tensor* tensor,
  + gtl::InlinedVector<npy_intp, 4>* dims,
  + tensorflow::int64* nelems) {
  + dims->clear();
  const int ndims = TF_NumDims(tensor);
  - gtl::InlinedVector<npy_intp, 4> dims(ndims);
  if (TF_TensorType(tensor) == TF_RESOURCE) {
  - CHECK_EQ(ndims, 0)
  - << "Fetching of non-scalar resource tensors is not supported.";
  - dims.push_back(TF_TensorByteSize(tensor));
  - *nelems = dims[0];
  + if (ndims != 0) {
  + return errors::InvalidArgument(
  + "Fetching of non-scalar resource tensors is not supported.");
  + }
  + dims->push_back(TF_TensorByteSize(tensor));
  + *nelems = dims->back();
  } else {
  *nelems = 1;
  for (int i = 0; i < ndims; ++i) {
  - dims[i] = TF_Dim(tensor, i);
  - *nelems *= dims[i];
  + dims->push_back(TF_Dim(tensor, i));
  + *nelems *= dims->back();
  }
  }
  - return dims;
  + return Status::OK();
  }
  // Determine the type description (PyArray_Descr) of a numpy ndarray to be
  @@ -418,8 +421,8 @@ Status TF_TensorToMaybeAliasedPyArray(Safe_TF_TensorPtr tensor,
  TF_Tensor* moved = tensor.release();
  int64 nelems = -1;
  - gtl::InlinedVector<npy_intp, 4> dims =
  - GetPyArrayDimensionsForTensor(moved, &nelems);
  + gtl::InlinedVector<npy_intp, 4> dims;
  + TF_RETURN_IF_ERROR(GetPyArrayDimensionsForTensor(moved, &dims, &nelems));
  return ArrayFromMemory(
  dims.size(), dims.data(), TF_TensorData(moved),
  static_cast<DataType>(dtype), [moved] { TF_DeleteTensor(moved); },
  @@ -437,14 +440,16 @@ Status TF_TensorToPyArray(Safe_TF_TensorPtr tensor, PyObject** out_ndarray) {
  return Status::OK();
  }
  int64 nelems = -1;
  - gtl::InlinedVector<npy_intp, 4> dims =
  - GetPyArrayDimensionsForTensor(tensor.get(), &nelems);
  + gtl::InlinedVector<npy_intp, 4> dims;
  + TF_RETURN_IF_ERROR(
  + GetPyArrayDimensionsForTensor(tensor.get(), &dims, &nelems));
  // If the type is neither string nor resource we can reuse the Tensor memory.
  TF_Tensor* original = tensor.get();
  TF_Tensor* moved = TF_TensorMaybeMove(tensor.release());
  if (moved != nullptr) {
  - if (ArrayFromMemory(dims.size(), dims.data(), TF_TensorData(moved),
  + if (ArrayFromMemory(
  + dims.size(), dims.data(), TF_TensorData(moved),
  static_cast<DataType>(TF_TensorType(moved)),
  [moved] { TF_DeleteTensor(moved); }, out_ndarray)
  .ok()) {
  