tensorflow/compiler/tf2xla/kernels/stack_ops.cc
// Since the element shape is not provided to the Stack operator,
// we lazily initialize the Stack at the time of the first write.
//
// If a Stack `resource` has not been initialized, constructs storage for the
// Stack with elements of `elem_shape`. For both initialized and
// uninitialized Stacks, checks that the tensor has a type compatible with
// 'dtype' and shape compatible with 'elem_shape'.
//
// TODO(phawkins): consider changing the API of the stack operators to
// allow an optional element shape at stack construction time.
Since the element shape is not provided to the Stack operator,
we lazily initialize the Stack at the time of the first write.

If a Stack `resource` has not been initialized, constructs storage for the
Stack with elements of `elem_shape`. For both initialized and
uninitialized Stacks, checks that the tensor has a type compatible with
'dtype' and shape compatible with 'elem_shape'.

consider changing the API of the stack operators to
allow an optional element shape at stack construction time.
Since the element shape is not provided to the Stack operator we lazily initialize the Stack at the time of the first write . If a Stack ` resource ` has not been initialized constructs storage for the Stack with elements of ` elem_shape ` . For both initialized and uninitialized Stacks checks that the tensor has a type compatible with ' dtype ' and shape compatible with ' elem_shape ' . consider changing the API of the stack operators to allow an optional element shape at stack construction time .
Status MaybeInitializeStack(xla::XlaBuilder* builder, XlaResource* resource,
                            DataType dtype, const TensorShape& elem_shape) {
  if (resource->type() != dtype) {
    return errors::InvalidArgument(
        "Stack dtype is ", DataTypeString(resource->type()),
        " but op has dtype ", DataTypeString(dtype), ".");
  }
  TensorShape stack_shape;
  stack_shape.AddDim(resource->max_array_size());
  stack_shape.AppendShape(elem_shape);
  if (!resource->initialized()) {
    TF_RETURN_IF_ERROR(resource->SetTypeAndShape(dtype, elem_shape));
    TF_RETURN_IF_ERROR(resource->SetZeroValue(builder));
  } else {
    TensorShape actual_shape;
    TF_RETURN_IF_ERROR(GetStackShape(builder, resource, &actual_shape));
    if (stack_shape != actual_shape) {
      return errors::InvalidArgument(
          "Mismatched Stack shapes: ", stack_shape.DebugString(), " vs ",
          actual_shape.DebugString());
    }
  }
  return Status::OK();
}
Status MaybeInitializeStack ( xla :: XlaBuilder * builder , XlaResource * resource , DataType dtype , const TensorShape & elem_shape ) { if ( resource -> type ( ) != dtype ) { return errors :: InvalidArgument ( " " , DataTypeString ( resource -> type ( ) ) , " " , DataTypeString ( dtype ) , " " ) ; } TensorShape stack_shape ; stack_shape . AddDim ( resource -> max_array_size ( ) ) ; stack_shape . AppendShape ( elem_shape ) ; if ( ! resource -> initialized ( ) ) { TF_RETURN_IF_ERROR ( resource -> SetTypeAndShape ( dtype , elem_shape ) ) ; TF_RETURN_IF_ERROR ( resource -> SetZeroValue ( builder ) ) ; } else { TensorShape actual_shape ; TF_RETURN_IF_ERROR ( GetStackShape ( builder , resource , & actual_shape ) ) ; if ( stack_shape != actual_shape ) { return errors :: InvalidArgument ( " " , stack_shape . DebugString ( ) , " " , actual_shape . DebugString ( ) ) ; } } return Status :: OK ( ) ; }
Since the element shape is not provided to the Stack operator,
we lazily initialize the Stack at the time of the first write.
Since the element shape is not provided to the Stack operator we lazily initialize the Stack at the time of the first write .
// Stack has not been initialized. // Checks the expected shape matches the actual shape.