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

Function Const

tensorflow/cc/ops/const_op.h:36–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35template <typename T>
36Output Const(const Scope& scope, const Input::Initializer& val) {
37 auto orig_const_output = Const(scope, val);
38 if (!scope.ok()) return Output();
39
40 typedef typename Input::Initializer::RealType<T>::type DstT;
41
42 if (val.tensor.dtype() == DataTypeToEnum<DstT>::v()) {
43 return orig_const_output;
44 }
45 if (val.tensor.NumElements() == 0) {
46 Tensor t(DataTypeToEnum<DstT>::v(), val.tensor.shape());
47 return Const(scope, Input::Initializer(t));
48 }
49
50 // TODO(keveman): Refactor Cast op's kernel implementation such that the code
51 // can be directly called here instead of adding the Cast op to the graph.
52 auto orig_const = AsNodeOut(scope, orig_const_output);
53 const auto cast_op_name = scope.GetUniqueNameForOp("Cast");
54
55 auto cast_builder = NodeBuilder(cast_op_name, "Cast")
56 .Input(orig_const)
57 .Attr("DstT", DataTypeToEnum<DstT>::v());
58 scope.UpdateBuilder(&cast_builder);
59 Node* ret;
60 scope.UpdateStatus(cast_builder.Finalize(scope.graph(), &ret));
61 if (!scope.ok()) return Output();
62 scope.UpdateStatus(scope.DoShapeInference(ret));
63 return Output(ret, 0);
64}
65
66template <typename T>
67Output Const(const Scope& scope, const T& v, const TensorShape shape) {

Callers 15

TESTFunction · 0.70
TEST_FFunction · 0.50
DynamicPartitionGradFunction · 0.50
FillGradFunction · 0.50
SliceGradFunction · 0.50
TileGradFunction · 0.50
ConstHelperFunction · 0.50
GetBatchIndicesFunction · 0.50
TEST_FFunction · 0.50
TEST_FFunction · 0.50
SquareGradFunction · 0.50
Log1pGradFunction · 0.50

Calls 15

AsNodeOutFunction · 0.85
GetUniqueNameForOpMethod · 0.80
UpdateBuilderMethod · 0.80
DoShapeInferenceMethod · 0.80
OutputClass · 0.50
InitializerClass · 0.50
NodeBuilderClass · 0.50
okMethod · 0.45
dtypeMethod · 0.45
NumElementsMethod · 0.45
shapeMethod · 0.45
AttrMethod · 0.45

Tested by 15

TESTFunction · 0.56
TEST_FFunction · 0.40
TEST_FFunction · 0.40
TEST_FFunction · 0.40
TEST_FFunction · 0.40
TESTFunction · 0.40
TESTFunction · 0.40
TEST_FFunction · 0.40
CheckGradMethod · 0.40