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

Function TestReadTensorDoesNotReadBeyondContent

tensorflow/go/tensor_test.go:178–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestReadTensorDoesNotReadBeyondContent(t *testing.T) {
179 t1, _ := NewTensor(int8(7))
180 t2, _ := NewTensor(float32(2.718))
181 buf := new(bytes.Buffer)
182 if _, err := t1.WriteContentsTo(buf); err != nil {
183 t.Fatal(err)
184 }
185 if _, err := t2.WriteContentsTo(buf); err != nil {
186 t.Fatal(err)
187 }
188
189 t3, err := ReadTensor(t1.DataType(), t1.Shape(), buf)
190 if err != nil {
191 t.Fatal(err)
192 }
193 t4, err := ReadTensor(t2.DataType(), t2.Shape(), buf)
194 if err != nil {
195 t.Fatal(err)
196 }
197
198 if v, ok := t3.Value().(int8); !ok || v != 7 {
199 t.Errorf("Got (%v (%T), %v), want (7 (int8), true)", v, v, ok)
200 }
201 if v, ok := t4.Value().(float32); !ok || v != 2.718 {
202 t.Errorf("Got (%v (%T), %v), want (2.718 (float32), true)", v, v, ok)
203 }
204}
205
206func TestTensorSerializationErrors(t *testing.T) {
207 // String tensors cannot be serialized

Callers

nothing calls this directly

Calls 6

WriteContentsToMethod · 0.95
DataTypeMethod · 0.95
ShapeMethod · 0.95
NewTensorFunction · 0.85
ReadTensorFunction · 0.85
ValueMethod · 0.45

Tested by

no test coverage detected