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

Function TestSessionWithStringTensors

tensorflow/go/session_test.go:124–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestSessionWithStringTensors(t *testing.T) {
125 // Construct the graph:
126 // AsString(StringToHashBucketFast("PleaseHashMe")) Will be much
127 // prettier if using the ops package, but in this package graphs are
128 // constructed from first principles.
129 var (
130 g = NewGraph()
131 feed, _ = Const(g, "input", "PleaseHashMe")
132 hash, _ = g.AddOperation(OpSpec{
133 Type: "StringToHashBucketFast",
134 Input: []Input{feed},
135 Attrs: map[string]interface{}{
136 "num_buckets": int64(1 << 32),
137 },
138 })
139 str, _ = g.AddOperation(OpSpec{
140 Type: "AsString",
141 Input: []Input{hash.Output(0)},
142 })
143 )
144 s, err := NewSession(g, nil)
145 if err != nil {
146 t.Fatal(err)
147 }
148 output, err := s.Run(nil, []Output{str.Output(0)}, nil)
149 if err != nil {
150 t.Fatal(err)
151 }
152 if len(output) != 1 {
153 t.Fatal(len(output))
154 }
155 got, ok := output[0].Value().(string)
156 if !ok {
157 t.Fatalf("Got %T, wanted string", output[0].Value())
158 }
159 if want := "1027741475"; got != want {
160 t.Fatalf("Got %q, want %q", got, want)
161 }
162}
163
164func TestConcurrency(t *testing.T) {
165 tensor, err := NewTensor(int64(1))

Callers

nothing calls this directly

Calls 8

RunMethod · 0.95
NewGraphFunction · 0.85
int64Function · 0.85
NewSessionFunction · 0.70
ConstFunction · 0.50
AddOperationMethod · 0.45
OutputMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected