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

Method AsStringOp

tensorflow/core/kernels/as_string_op.cc:33–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 using OpKernel::OpKernel;
32
33 explicit AsStringOp(OpKernelConstruction* ctx) : OpKernel(ctx) {
34 int32 precision;
35 bool scientific;
36 bool shortest;
37 int32 width;
38 string fill_string;
39 DataType dtype;
40 OP_REQUIRES_OK(ctx, ctx->GetAttr("T", &dtype));
41 OP_REQUIRES_OK(ctx, ctx->GetAttr("precision", &precision));
42 OP_REQUIRES_OK(ctx, ctx->GetAttr("scientific", &scientific));
43 OP_REQUIRES_OK(ctx, ctx->GetAttr("shortest", &shortest));
44 OP_REQUIRES_OK(ctx, ctx->GetAttr("width", &width));
45 OP_REQUIRES_OK(ctx, ctx->GetAttr("fill", &fill_string));
46 switch (dtype) {
47 case DT_FLOAT:
48 case DT_DOUBLE:
49 case DT_COMPLEX64:
50 case DT_COMPLEX128:
51 break;
52 default:
53 OP_REQUIRES(ctx, !(scientific || shortest),
54 errors::InvalidArgument("scientific and shortest format "
55 "not supported for datatype ",
56 DataTypeString(dtype)));
57 OP_REQUIRES(ctx, precision < 0,
58 errors::InvalidArgument("precision not supported "
59 "for datatype ",
60 DataTypeString(dtype)));
61 }
62 OP_REQUIRES(
63 ctx, fill_string.size() <= 1,
64 errors::InvalidArgument("Fill string must be one or fewer characters"));
65 OP_REQUIRES(ctx, !(scientific && shortest),
66 errors::InvalidArgument(
67 "Cannot select both scientific and shortest notation"));
68
69 format_ = "%";
70 if (!fill_string.empty()) {
71 switch (fill_string[0]) {
72 case ' ':
73 case '+':
74 case '-':
75 case '0':
76 case '#':
77 strings::Appendf(&format_, "%s", fill_string.c_str());
78 break;
79 default:
80 bool fill_not_supported = true;
81 OP_REQUIRES(ctx, !fill_not_supported,
82 errors::InvalidArgument("Fill argument not supported: \"",
83 fill_string, "\""));
84 }
85 }
86 if (width > -1) {
87 strings::Appendf(&format_, "%d", width);
88 }
89 if (precision > -1) {
90 strings::Appendf(&format_, ".%d", precision);

Callers

nothing calls this directly

Calls 8

InvalidArgumentFunction · 0.85
AppendfFunction · 0.85
PrintfFunction · 0.85
c_strMethod · 0.80
DataTypeStringFunction · 0.50
GetAttrMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected