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

Function TestTensorSerialization

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

Source from the content-addressed store, hash-verified

118}
119
120func TestTensorSerialization(t *testing.T) {
121 var tests = []interface{}{
122 bool(true),
123 int8(5),
124 int16(5),
125 int32(5),
126 int64(5),
127 uint8(5),
128 uint16(5),
129 float32(5),
130 float64(5),
131 complex(float32(5), float32(6)),
132 complex(float64(5), float64(6)),
133 []float64{1},
134 [][]float32{{1, 2}, {3, 4}, {5, 6}},
135 [][][]int8{
136 {{1, 2}, {3, 4}, {5, 6}},
137 {{7, 8}, {9, 10}, {11, 12}},
138 {{0, -1}, {-2, -3}, {-4, -5}},
139 {{-6, -7}, {-8, -9}, {-10, -11}},
140 },
141 []bool{true, false, true},
142 }
143 for _, v := range tests {
144 t1, err := NewTensor(v)
145 if err != nil {
146 t.Errorf("(%v): %v", v, err)
147 continue
148 }
149 buf := new(bytes.Buffer)
150 n, err := t1.WriteContentsTo(buf)
151 if err != nil {
152 t.Errorf("(%v): %v", v, err)
153 continue
154 }
155 if n != int64(buf.Len()) {
156 t.Errorf("(%v): WriteContentsTo said it wrote %v bytes, but wrote %v", v, n, buf.Len())
157 }
158 t2, err := ReadTensor(t1.DataType(), t1.Shape(), buf)
159 if err != nil {
160 t.Errorf("(%v): %v", v, err)
161 continue
162 }
163 if buf.Len() != 0 {
164 t.Errorf("(%v): %v bytes written by WriteContentsTo not read by ReadTensor", v, buf.Len())
165 }
166 if got, want := t2.DataType(), t1.DataType(); got != want {
167 t.Errorf("(%v): Got %v, want %v", v, got, want)
168 }
169 if got, want := t2.Shape(), t1.Shape(); !reflect.DeepEqual(got, want) {
170 t.Errorf("(%v): Got %v, want %v", v, got, want)
171 }
172 if got, want := t2.Value(), v; !reflect.DeepEqual(got, want) {
173 t.Errorf("(%v): Got %v, want %v", v, got, want)
174 }
175 }
176}
177

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected