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

Function TestReadTensorReadAll

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

Source from the content-addressed store, hash-verified

228}
229
230func TestReadTensorReadAll(t *testing.T) {
231 // Get the bytes of a tensor.
232 a := []float32{1.1, 1.2, 1.3}
233 ats, err := NewTensor(a)
234 if err != nil {
235 t.Fatal(err)
236 }
237 abuf := new(bytes.Buffer)
238 if _, err := ats.WriteContentsTo(abuf); err != nil {
239 t.Fatal(err)
240 }
241
242 // Get the bytes of another tensor.
243 b := []float32{1.1, 1.2, 1.3}
244 bts, err := NewTensor(b)
245 if err != nil {
246 t.Fatal(err)
247 }
248 bbuf := new(bytes.Buffer)
249 if _, err := bts.WriteContentsTo(bbuf); err != nil {
250 t.Fatal(err)
251 }
252
253 // Check that ReadTensor reads all bytes of both tensors, when the situation
254 // requires one than reads.
255 abbuf := io.MultiReader(abuf, bbuf)
256 abts, err := ReadTensor(Float, []int64{2, 3}, abbuf)
257 if err != nil {
258 t.Fatal(err)
259 }
260 abtsf32 := abts.Value().([][]float32)
261 expected := [][]float32{a, b}
262
263 if len(abtsf32) != 2 {
264 t.Fatalf("first dimension %d is not 2", len(abtsf32))
265 }
266 for i := 0; i < 2; i++ {
267 if len(abtsf32[i]) != 3 {
268 t.Fatalf("second dimension %d is not 3", len(abtsf32[i]))
269 }
270 for j := 0; j < 3; j++ {
271 if abtsf32[i][j] != expected[i][j] {
272 t.Errorf("value at %d %d not equal %f %f", i, j, abtsf32[i][j], expected[i][j])
273 }
274 }
275 }
276}
277
278func benchmarkNewTensor(b *testing.B, v interface{}) {
279 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected