Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
f1c73840
Commit
f1c73840
authored
Jul 08, 2025
by
Michael Yang
Browse files
tests
parent
4a8fc3f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
776 additions
and
225 deletions
+776
-225
convert/tensor_test.go
convert/tensor_test.go
+776
-225
No files found.
convert/tensor_test.go
View file @
f1c73840
...
@@ -72,6 +72,7 @@ func mul(shape []uint64) int {
...
@@ -72,6 +72,7 @@ func mul(shape []uint64) int {
}
}
func
TestSplitDim
(
t
*
testing
.
T
)
{
func
TestSplitDim
(
t
*
testing
.
T
)
{
t
.
Run
(
"2d"
,
func
(
t
*
testing
.
T
)
{
r
:=
fakeTensor
{
r
:=
fakeTensor
{
name
:
"a.b"
,
name
:
"a.b"
,
shape
:
[]
uint64
{
3
,
4
},
shape
:
[]
uint64
{
3
,
4
},
...
@@ -84,8 +85,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -84,8 +85,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatalf
(
"expected name 'x', got '%s'"
,
tt
.
Name
)
t
.
Fatalf
(
"expected name 'x', got '%s'"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
3
,
4
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
4
})
;
diff
!=
""
{
t
.
Fatal
f
(
"expected shape
[3, 4], got %v"
,
tt
.
Shape
)
t
.
Error
f
(
"
un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -98,8 +99,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -98,8 +99,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
})
;
diff
!=
""
{
t
.
Fatal
f
(
"expected data
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], got %v"
,
f32s
)
t
.
Error
f
(
"
un
expected data
(-want +got):
\n
%s"
,
diff
)
}
}
}
}
})
})
...
@@ -121,8 +122,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -121,8 +122,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected shape
[3, 2], got"
,
tt
.
Shape
)
t
.
Errorf
(
"un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -135,8 +136,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -135,8 +136,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
0
,
1
,
4
,
5
,
8
,
9
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
4
,
5
,
8
,
9
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected data
[0, 1, 4, 5, 8, 9], got"
,
f32s
)
t
.
Errorf
(
"un
expected data
(-want +got):
\n
%s"
,
diff
)
}
}
}
}
...
@@ -150,8 +151,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -150,8 +151,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected shape
[3, 2], got"
,
tt
.
Shape
)
t
.
Errorf
(
"un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -164,8 +165,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -164,8 +165,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
2
,
3
,
6
,
7
,
10
,
11
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
2
,
3
,
6
,
7
,
10
,
11
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected data
[2, 3, 6, 7, 10, 11], got"
,
f32s
)
t
.
Errorf
(
"un
expected data
(-want +got):
\n
%s"
,
diff
)
}
}
}
}
})
})
...
@@ -187,8 +188,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -187,8 +188,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
2
,
4
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
2
,
4
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected shape
[2, 4], got"
,
tt
.
Shape
)
t
.
Errorf
(
"un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -201,8 +202,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -201,8 +202,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected data
[0, 1, 2, 3, 4, 5, 6, 7], got"
,
f32s
)
t
.
Errorf
(
"un
expected data
(-want +got):
\n
%s"
,
diff
)
}
}
}
}
...
@@ -216,8 +217,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -216,8 +217,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
1
,
4
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected shape
[1, 4], got"
,
tt
.
Shape
)
t
.
Errorf
(
"un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -230,8 +231,200 @@ func TestSplitDim(t *testing.T) {
...
@@ -230,8 +231,200 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
8
,
9
,
10
,
11
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
8
,
9
,
10
,
11
});
diff
!=
""
{
t
.
Fatal
(
"expected data [8, 9, 10, 11], got"
,
f32s
)
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
t
.
Run
(
"three way split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
0
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"z"
),
dim
:
1
},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
4
,
5
,
6
,
7
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.z"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
8
,
9
,
10
,
11
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
t
.
Run
(
"uneven three way split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
1
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
),
dim
:
2
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"z"
),
dim
:
1
},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
4
,
5
,
8
,
9
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
1
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
2
,
6
,
10
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.z"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
1
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
3
,
7
,
11
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
}
}
})
})
...
@@ -255,8 +448,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -255,8 +448,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected shape
[3, 2], got"
,
tt
.
Shape
)
t
.
Errorf
(
"un
expected shape
(-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -269,8 +462,8 @@ func TestSplitDim(t *testing.T) {
...
@@ -269,8 +462,8 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
0
,
1
,
4
,
5
,
8
,
9
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
4
,
5
,
8
,
9
})
;
diff
!=
""
{
t
.
Fatal
(
"
expected data
[0, 1, 4, 5, 8, 9], got"
,
f32s
)
t
.
Errorf
(
"un
expected data
(-want +got):
\n
%s"
,
diff
)
}
}
}
}
...
@@ -284,8 +477,41 @@ func TestSplitDim(t *testing.T) {
...
@@ -284,8 +477,41 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
}
}
if
!
slices
.
Equal
(
tt
.
Shape
,
[]
uint64
{
3
,
2
})
{
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
});
diff
!=
""
{
t
.
Fatal
(
"expected shape [3, 2], got"
,
tt
.
Shape
)
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
2
,
6
,
10
,
3
,
7
,
11
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
})
t
.
Run
(
"3d"
,
func
(
t
*
testing
.
T
)
{
r
:=
fakeTensor
{
name
:
"a.b"
,
shape
:
[]
uint64
{
3
,
4
,
2
},
data
:
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
},
}
t
.
Run
(
"no split"
,
func
(
t
*
testing
.
T
)
{
for
tt
:=
range
splitDim
(
&
r
,
0
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
)})
{
if
tt
.
Name
!=
"x.b"
{
t
.
Fatalf
(
"expected name 'x', got '%s'"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
...
@@ -298,10 +524,335 @@ func TestSplitDim(t *testing.T) {
...
@@ -298,10 +524,335 @@ func TestSplitDim(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
slices
.
Equal
(
f32s
,
[]
float32
{
2
,
6
,
10
,
3
,
7
,
11
})
{
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
});
diff
!=
""
{
t
.
Fatal
(
"expected data [2, 6, 10, 3, 7, 11], got"
,
f32s
)
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
}
})
t
.
Run
(
"even split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
1
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
)},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
)},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
8
,
9
,
10
,
11
,
16
,
17
,
18
,
19
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
}
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
4
,
5
,
6
,
7
,
12
,
13
,
14
,
15
,
20
,
21
,
22
,
23
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
t
.
Run
(
"uneven split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
0
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
),
dim
:
2
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
),
dim
:
1
},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
2
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'a.y', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
t
.
Run
(
"three way split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
0
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"z"
),
dim
:
1
},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.z"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
1
,
4
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
t
.
Run
(
"uneven three way split"
,
func
(
t
*
testing
.
T
)
{
next
,
stop
:=
iter
.
Pull
(
splitDim
(
&
r
,
1
,
split
{
Replacer
:
strings
.
NewReplacer
(
"a"
,
"x"
),
dim
:
2
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"y"
),
dim
:
1
},
split
{
Replacer
:
strings
.
NewReplacer
(
"b"
,
"z"
),
dim
:
1
},
))
defer
stop
()
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"x.b"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
2
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
0
,
1
,
2
,
3
,
8
,
9
,
10
,
11
,
16
,
17
,
18
,
19
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.y"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
1
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
4
,
5
,
12
,
13
,
20
,
21
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
{
tt
,
ok
:=
next
()
if
!
ok
{
t
.
Fatal
(
"expected at least one split"
)
}
if
tt
.
Name
!=
"a.z"
{
t
.
Fatal
(
"expected name 'x.b', got"
,
tt
.
Name
)
}
if
diff
:=
cmp
.
Diff
(
tt
.
Shape
,
[]
uint64
{
3
,
1
,
2
});
diff
!=
""
{
t
.
Errorf
(
"unexpected shape (-want +got):
\n
%s"
,
diff
)
}
var
b
bytes
.
Buffer
if
_
,
err
:=
tt
.
WriteTo
(
&
b
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
f32s
:=
make
([]
float32
,
mul
(
tt
.
Shape
))
if
err
:=
binary
.
Read
(
&
b
,
binary
.
LittleEndian
,
&
f32s
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
f32s
,
[]
float32
{
6
,
7
,
14
,
15
,
22
,
23
});
diff
!=
""
{
t
.
Errorf
(
"unexpected data (-want +got):
\n
%s"
,
diff
)
}
}
})
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment