Skip to content

Commit fbcb58b

Browse files
asimshankartensorflower-gardener
authored andcommitted
Change: 149490754
1 parent 8633b22 commit fbcb58b

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

tensorflow/go/genop/internal/genop.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func makeOutputList(op *tf.Operation, start int, output string) ([]tf.Output, in
162162
"Identifier": identifier,
163163
"IsListArg": isListArg,
164164
"IsListAttr": isListAttr,
165+
"StripLeadingColon": stripLeadingColon,
165166
}).Parse(`
166167
{{if .OptionalAttrs -}}
167168
{{/* Type for specifying all optional attributes. */ -}}
@@ -174,7 +175,7 @@ type {{.Op.Name}}Attr func(optionalAttr)
174175
//
175176
// value: {{MakeComment .Description}}
176177
{{- end}}
177-
// If not specified, defaults to {{.DefaultValue}}
178+
// If not specified, defaults to {{StripLeadingColon .DefaultValue}}
178179
{{- if .HasMinimum}}
179180
//
180181
// {{if IsListAttr .}}REQUIRES: len(value) >= {{.Minimum}}{{else}}REQUIRES: value >= {{.Minimum}}{{end}}
@@ -452,6 +453,23 @@ func isListAttr(attrdef *pb.OpDef_AttrDef) bool {
452453
return list
453454
}
454455

456+
// stripLeadingColon removes the prefix of the string up to the first colon.
457+
//
458+
// This is useful when 's' corresponds to a "oneof" protocol buffer message.
459+
// For example, consider the protocol buffer message:
460+
// oneof value { bool b = 1; int64 i = 2; }
461+
// String() on a Go corresponding object (using proto.CompactTextString) will
462+
// print "b:true", or "i:7" etc. This function strips out the leading "b:" or
463+
// "i:".
464+
func stripLeadingColon(s fmt.Stringer) string {
465+
x := s.String()
466+
y := strings.SplitN(x, ":", 2)
467+
if len(y) < 2 {
468+
return x
469+
}
470+
return y[1]
471+
}
472+
455473
func parseTFType(tfType string) (list bool, typ string) {
456474
const (
457475
listPrefix = "list("

tensorflow/go/genop/internal/genop_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ type DecodeJpegAttr func(optionalAttr)
189189
// DecodeJpegChannels sets the optional channels attribute to value.
190190
//
191191
// value: Number of color channels for the decoded image.
192-
// If not specified, defaults to i:0
192+
// If not specified, defaults to 0
193193
func DecodeJpegChannels(value int64) DecodeJpegAttr {
194194
return func(m optionalAttr) {
195195
m["channels"] = value
@@ -200,7 +200,7 @@ func DecodeJpegChannels(value int64) DecodeJpegAttr {
200200
//
201201
// value: If true use a slower but nicer upscaling of the
202202
// chroma planes (yuv420/422 only).
203-
// If not specified, defaults to b:true
203+
// If not specified, defaults to true
204204
func DecodeJpegFancyUpscaling(value bool) DecodeJpegAttr {
205205
return func(m optionalAttr) {
206206
m["fancy_upscaling"] = value
@@ -211,7 +211,7 @@ func DecodeJpegFancyUpscaling(value bool) DecodeJpegAttr {
211211
//
212212
// value: The minimum required fraction of lines before a truncated
213213
// input is accepted.
214-
// If not specified, defaults to f:1
214+
// If not specified, defaults to 1
215215
func DecodeJpegAcceptableFraction(value float32) DecodeJpegAttr {
216216
return func(m optionalAttr) {
217217
m["acceptable_fraction"] = value
@@ -332,7 +332,7 @@ description: "Some description here."
332332
type ShapeNAttr func(optionalAttr)
333333
334334
// ShapeNOutType sets the optional out_type attribute to value.
335-
// If not specified, defaults to type:DT_INT32
335+
// If not specified, defaults to DT_INT32
336336
func ShapeNOutType(value tf.DataType) ShapeNAttr {
337337
return func(m optionalAttr) {
338338
m["out_type"] = value

0 commit comments

Comments
 (0)