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

Method SetZeroValue

tensorflow/compiler/tf2xla/xla_resource.cc:123–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123Status XlaResource::SetZeroValue(xla::XlaBuilder* builder) {
124 if (type_ == DT_INVALID) {
125 return errors::InvalidArgument(
126 "Resource '", name_,
127 "' must be initialized with a valid type before use.");
128 }
129 switch (kind_) {
130 case kVariable: {
131 value_ =
132 xla::Broadcast(XlaHelpers::Zero(builder, type_), shape_.dim_sizes());
133 break;
134 }
135 case kTensorArray: {
136 TensorShape ta_shape;
137 ta_shape.AddDim(max_array_size_);
138 ta_shape.AppendShape(shape_);
139 value_ = xla::Broadcast(XlaHelpers::Zero(builder, type_),
140 ta_shape.dim_sizes());
141 break;
142 }
143 case kStack: {
144 TensorShape ta_shape;
145 ta_shape.AddDim(max_array_size_);
146 ta_shape.AppendShape(shape_);
147 value_ =
148 xla::Tuple(builder, {xla::Broadcast(XlaHelpers::Zero(builder, type_),
149 ta_shape.dim_sizes()),
150 xla::ConstantR0<int32>(builder, 0)});
151 break;
152 }
153
154 case kInvalid:
155 default:
156 LOG(FATAL) << "Invalid resource type";
157 }
158 return Status::OK();
159}
160
161Status XlaResource::GetOrCreateTensorArrayGradient(const string& source,
162 xla::XlaBuilder* builder,

Callers 3

MaybeInitializeStackFunction · 0.80
CompileMethod · 0.80

Calls 7

InvalidArgumentFunction · 0.85
BroadcastFunction · 0.85
ZeroFunction · 0.50
TupleFunction · 0.50
dim_sizesMethod · 0.45
AddDimMethod · 0.45
AppendShapeMethod · 0.45

Tested by

no test coverage detected