-
Notifications
You must be signed in to change notification settings - Fork 3
/
class_test.go
343 lines (325 loc) · 21.4 KB
/
class_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package qol
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
T "gorgonia.org/tensor"
)
func TestToClass(t *testing.T) {
// Panic Tests
// TODO: panic without an iterator
// Test panic on non vector
assert.Panics(t, func() { ToClass(T.New(T.Of(T.Float32), T.WithShape(10, 10)), 0) })
// Panic on unsupported T dtype
assert.Panics(t, func() { ToClass(T.New(T.Of(T.Complex64), T.WithShape(10)), 0) })
// Panic on Unreachable
assert.Panics(t, func() { ToClass(T.New(T.WithBacking([]float32{0, 0, 1, 0, 0})), 999) })
// Value Tests
// only specifying vectors of length 5 varying values, type, and threshold
// Float32
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]float32{0, 0, 1, 0, 0})), 0))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]float32{0.1, 0.1, 0.6, 0.7, 0.1})), 0))
assert.Equal(t, Class(3), ToClass(T.New(T.WithBacking([]float32{0.1, 0.1, 0.6, 0.7, 0.1})), 0.65))
assert.Equal(t, Class(0), ToClass(T.New(T.WithBacking([]float32{1, 1, 1, 1, 1})), 0))
// lFat64
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]float64{0, 0, 1, 0, 0})), 0))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]float64{0.1, 0.1, 0.6, 0.7, 0.1})), 0))
assert.Equal(t, Class(3), ToClass(T.New(T.WithBacking([]float64{0.1, 0.1, 0.6, 0.7, 0.1})), 0.65))
assert.Equal(t, Class(0), ToClass(T.New(T.WithBacking([]float64{1, 1, 1, 1, 1})), 0))
// nI
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]int{0, 0, 1, 0, 0})), 0))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]int{0, 0, 1, 0, 0})), 999))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]int{0, 0, 2, 0, 0})), 0))
assert.Equal(t, Class(1), ToClass(T.New(T.WithBacking([]int{0, 1, 2, 0, 0})), 0))
assert.Equal(t, Class(0), ToClass(T.New(T.WithBacking([]int{1, 1, 1, 1, 1})), 0))
assert.Equal(t, Class(4), ToClass(T.New(T.WithBacking([]int{-1, -2, -3, 0, 1})), 0))
// iut
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]uint{0, 0, 1, 0, 0})), 0))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]uint{0, 0, 1, 0, 0})), 999))
assert.Equal(t, Class(2), ToClass(T.New(T.WithBacking([]uint{0, 0, 2, 0, 0})), 0))
assert.Equal(t, Class(1), ToClass(T.New(T.WithBacking([]uint{0, 1, 2, 0, 0})), 0))
assert.Equal(t, Class(0), ToClass(T.New(T.WithBacking([]uint{1, 1, 1, 1, 1})), 0))
}
func TestToClasses(t *testing.T) {
// Panic Tests
// TODO: panic without an iterator
// Test panic on non matrix
assert.Panics(t, func() { ToClasses(T.New(T.Of(T.Float32), T.WithShape(10)), 0) })
assert.Panics(t, func() { ToClasses(T.New(T.Of(T.Float32), T.WithShape(10, 10, 10)), 0) })
// Panic on unsupported T dtype
assert.Panics(t, func() { ToClasses(T.New(T.Of(T.Complex64), T.WithShape(10)), 0) })
// Panic on Unreachable
assert.Panics(t, func() { ToClasses(T.New(T.WithBacking([]float32{0, 0, 1, 0, 0, 1}), T.WithShape(2, 3)), 999) })
// Value Tests
// only specifying matracies of length 2x3 varying values, type, and threshold
shp := T.WithShape(2, 3)
// Float32
// chewxy testcase
assert.Equal(t, []Class{2, 0}, ToClasses(T.New(T.WithBacking([]float32{0.1, 0.1, 0.6, 0.7, 0.1, 0.6, 0.1, 0.1, 0.7, 0.1}), T.WithShape(2, 5)), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]float32{0, 0, 1, 0, 1, 0}), shp), 0))
assert.Equal(t, []Class{1, 1}, ToClasses(T.New(T.WithBacking([]float32{0.1, 0.6, 0.7, 0.1, 0.7, 0.6}), shp), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]float32{0.1, 0.6, 0.7, 0.1, 0.7, 0.6}), shp), 0.65))
assert.Equal(t, []Class{2, 2}, ToClasses(T.New(T.WithBacking([]float32{0.1, -1, 0.7, -1.0, 0.2, 0.6}), shp), 0))
assert.Equal(t, []Class{0, 0}, ToClasses(T.New(T.WithBacking([]float32{1, 1, 1, 1, 1, 1}), shp), 0))
// Float64
// chewxy testcase
assert.Equal(t, []Class{2, 0}, ToClasses(T.New(T.WithBacking([]float64{0.1, 0.1, 0.6, 0.7, 0.1, 0.6, 0.1, 0.1, 0.7, 0.1}), T.WithShape(2, 5)), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]float64{0, 0, 1, 0, 1, 0}), shp), 0))
assert.Equal(t, []Class{1, 1}, ToClasses(T.New(T.WithBacking([]float64{0.1, 0.6, 0.7, 0.1, 0.7, 0.6}), shp), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]float64{0.1, 0.6, 0.7, 0.1, 0.7, 0.6}), shp), 0.65))
assert.Equal(t, []Class{2, 2}, ToClasses(T.New(T.WithBacking([]float64{0.1, -1, 0.7, -1.0, 0.2, 0.6}), shp), 0))
assert.Equal(t, []Class{0, 0}, ToClasses(T.New(T.WithBacking([]float64{1, 1, 1, 1, 1, 1}), shp), 0))
// Int
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]int{0, 0, 1, 0, 1, 0}), shp), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]int{0, 0, 1, 0, 1, 0}), shp), 999))
assert.Equal(t, []Class{2, 0}, ToClasses(T.New(T.WithBacking([]int{0, 0, 2, 1, 2, 0}), shp), 0))
assert.Equal(t, []Class{0, 0}, ToClasses(T.New(T.WithBacking([]int{1, 1, 1, 1, 1, 1}), shp), 0))
assert.Equal(t, []Class{1, 2}, ToClasses(T.New(T.WithBacking([]int{-1, 1, -2, -3, 0, 1}), shp), 0))
// Uint
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]uint{0, 0, 1, 0, 1, 0}), shp), 0))
assert.Equal(t, []Class{2, 1}, ToClasses(T.New(T.WithBacking([]uint{0, 0, 1, 0, 1, 0}), shp), 999))
assert.Equal(t, []Class{2, 0}, ToClasses(T.New(T.WithBacking([]uint{0, 0, 2, 1, 2, 0}), shp), 0))
assert.Equal(t, []Class{0, 0}, ToClasses(T.New(T.WithBacking([]uint{1, 1, 1, 1, 1, 1}), shp), 0))
}
func NewToOneHotVectorSuite(unsafe bool, a Class, numClasses uint, backingActual, backingExpected interface{}) *ToOneHotVectorSuite {
shp := T.WithShape(int(numClasses))
return &ToOneHotVectorSuite{
unsafe: unsafe,
a: a,
numClasses: numClasses,
reuse: T.New(T.WithBacking(backingActual), shp),
expected: T.New(T.WithBacking(backingExpected), shp),
}
}
// ToOneHotVectorSuite test both the safe and unsafe version and the
// ToOneHotVector by specifying the `unsafe` boolean flag
type ToOneHotVectorSuite struct {
suite.Suite
unsafe bool
a Class
numClasses uint
reuse, expected *T.Dense
}
func (suite *ToOneHotVectorSuite) Test() {
// Safe or unsafe function
var oh *T.Dense
if suite.unsafe {
oh = UnsafeToOneHotVector(suite.a, suite.numClasses, suite.reuse)
} else {
oh = ToOneHotVector(suite.a, suite.numClasses, suite.reuse.Dtype())
}
// Check data and shape between expected and resulting of UnsafeToOneHotVector
assert.Equal(suite.T(), suite.expected.Data(), oh.Data())
assert.Equal(suite.T(), suite.expected.Shape(), oh.Shape())
if suite.unsafe {
// Check if the operation is infact unsafe
assert.Equal(suite.T(), suite.expected.Data(), suite.reuse.Data())
assert.Equal(suite.T(), suite.expected.Shape(), suite.reuse.Shape())
assert.Equal(suite.T(), &suite.reuse, &oh)
}
}
func TestToOneHotVectorSuite(t *testing.T) {
// Panics
// n classes not the same as vector length
assert.Panics(t, func() { UnsafeToOneHotVector(0, 999, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(0, 2, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.NotPanics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
// Class is out of range
assert.Panics(t, func() { UnsafeToOneHotVector(10, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(5, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.NotPanics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
// Non Vector
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(1, 5))) })
// Unsupported type
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Complex64), T.WithShape(5))) })
// Value tests
// Float32
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []float32{1, 1, 1, 1, 1}, []float32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 3, []float32{0, 0, 0}, []float32{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 3, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 0, 0, 1, 0}))
// Float64
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []float64{1, 1, 1, 1, 1}, []float64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 3, []float64{0, 0, 0}, []float64{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 3, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 0, 0, 1, 0}))
// Int32
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int32{1, 1, 1, 1, 1}, []int32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 3, []int32{0, 0, 0}, []int32{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 3, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 0, 0, 1, 0}))
// Int64
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int64{1, 1, 1, 1, 1}, []int64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 3, []int64{0, 0, 0}, []int64{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 3, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 0, 0, 1, 0}))
// Int
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int{0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 5, []int{1, 1, 1, 1, 1}, []int{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 1, 3, []int{0, 0, 0}, []int{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(false, 3, 5, []int{0, 0, 0, 0, 0}, []int{0, 0, 0, 1, 0}))
}
func TestUnsafeToOneHotVectorSuite(t *testing.T) {
// Panics
// n classes not the same as vector length
assert.Panics(t, func() { UnsafeToOneHotVector(0, 999, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(0, 2, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.NotPanics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
// Class is out of range
assert.Panics(t, func() { UnsafeToOneHotVector(10, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(5, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.NotPanics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
// Non Vector
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Float32), T.WithShape(1, 5))) })
// Unsupported type
assert.Panics(t, func() { UnsafeToOneHotVector(0, 5, T.New(T.Of(T.Complex64), T.WithShape(5))) })
// Value tests
// Float32
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float32{1, 1, 1, 1, 1}, []float32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float32{1, 1, 1, 1, 1}, []float32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 3, []float32{0, 0, 0}, []float32{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 3, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 0, 0, 1, 0}))
// Float64
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float64{1, 1, 1, 1, 1}, []float64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []float64{1, 1, 1, 1, 1}, []float64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 3, []float64{0, 0, 0}, []float64{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 3, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 0, 0, 1, 0}))
// Int32
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int32{1, 1, 1, 1, 1}, []int32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int32{1, 1, 1, 1, 1}, []int32{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 3, []int32{0, 0, 0}, []int32{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 3, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 0, 0, 1, 0}))
// Int64
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int64{1, 1, 1, 1, 1}, []int64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int64{1, 1, 1, 1, 1}, []int64{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 3, []int64{0, 0, 0}, []int64{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 3, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 0, 0, 1, 0}))
// Int
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int{0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int{1, 1, 1, 1, 1}, []int{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 5, []int{1, 1, 1, 1, 1}, []int{0, 1, 0, 0, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 1, 3, []int{0, 0, 0}, []int{0, 1, 0}))
suite.Run(t, NewToOneHotVectorSuite(true, 3, 5, []int{0, 0, 0, 0, 0}, []int{0, 0, 0, 1, 0}))
}
func NewToOneHotMatrixSuite(unsafe bool, a []Class, numClasses uint, backingActual, backingExpected interface{}, shp T.Shape) *ToOneHotMatrixSuite {
return &ToOneHotMatrixSuite{
unsafe: unsafe,
a: a,
numClasses: numClasses,
reuse: T.New(T.WithBacking(backingActual), T.WithShape(shp...)),
expected: T.New(T.WithBacking(backingExpected), T.WithShape(shp...)),
}
}
// ToOneHotMatrixSuite test both the safe and unsafe version and the
// ToOneHotMatrix by specifying the `unsafe` boolean flag
type ToOneHotMatrixSuite struct {
suite.Suite
unsafe bool
a []Class
numClasses uint
reuse, expected *T.Dense
}
func (suite *ToOneHotMatrixSuite) Test() {
// Safe or unsafe function
var oh *T.Dense
if suite.unsafe {
oh = UnsafeToOneHotMatrix(suite.a, suite.numClasses, suite.reuse)
} else {
oh = ToOneHotMatrix(suite.a, suite.numClasses, suite.reuse.Dtype())
}
// Check data and shape between expected and resulting of UnsafeToOneHotMatrix
assert.Equal(suite.T(), suite.expected.Data(), oh.Data())
assert.Equal(suite.T(), suite.expected.Shape(), oh.Shape())
if suite.unsafe {
// Check if the operation is infact unsafe
assert.Equal(suite.T(), suite.reuse.Data(), suite.expected.Data())
assert.Equal(suite.T(), suite.reuse.Shape(), suite.expected.Shape())
assert.Equal(suite.T(), &oh, &suite.reuse)
}
}
func TestToOneHotMatrix(t *testing.T) {
// Panic tests
// Unsupported type
assert.Panics(t, func() { ToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.Complex64) })
assert.NotPanics(t, func() { ToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.Float32) })
// Value tests
// Float32
// Row Vector
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1}, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 0}, []int{1, 5}))
// Col Vector
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{0, 0, 0, 0, 0}, 1, []float32{0, 0, 0, 0, 0}, []float32{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1, 1}, 3, []float32{0, 0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{2, 0}, 3, []float32{0, 0, 0, 0, 0, 0}, []float32{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Float64
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1}, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{0, 0, 0, 0, 0}, 1, []float64{0, 0, 0, 0, 0}, []float64{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1, 1}, 3, []float64{0, 0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{2, 0}, 3, []float64{0, 0, 0, 0, 0, 0}, []float64{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1}, 5, []int{0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{0, 0, 0, 0, 0}, 1, []int{0, 0, 0, 0, 0}, []int{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1, 1}, 3, []int{0, 0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{2, 0}, 3, []int{0, 0, 0, 0, 0, 0}, []int{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int64
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1}, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{0, 0, 0, 0, 0}, 1, []int64{0, 0, 0, 0, 0}, []int64{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1, 1}, 3, []int64{0, 0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{2, 0}, 3, []int64{0, 0, 0, 0, 0, 0}, []int64{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int32
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1}, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{0, 0, 0, 0, 0}, 1, []int32{0, 0, 0, 0, 0}, []int32{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{1, 1}, 3, []int32{0, 0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(false, []Class{2, 0}, 3, []int32{0, 0, 0, 0, 0, 0}, []int32{0, 0, 1, 1, 0, 0}, []int{2, 3}))
}
func TestUnsafeToOneHotMatrix(t *testing.T) {
// Panic tests
// Non Matrix
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1}, 5, T.New(T.Of(T.Float32), T.WithShape(5))) })
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5, 5))) })
assert.NotPanics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
// Wrong number of classes (rows)
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.NotPanics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
// Wrong number of classes (cols)
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 4, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 6, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
assert.NotPanics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
// Unsupported type
assert.Panics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Complex64), T.WithShape(5, 5))) })
assert.NotPanics(t, func() { UnsafeToOneHotMatrix([]Class{1, 1, 1, 1, 1}, 5, T.New(T.Of(T.Float32), T.WithShape(5, 5))) })
// Value tests
// Float32
// Row Vector
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1}, 5, []float32{0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 0}, []int{1, 5}))
// Col Vector
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{0, 0, 0, 0, 0}, 1, []float32{0, 0, 0, 0, 0}, []float32{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1, 1}, 3, []float32{0, 0, 0, 0, 0, 0}, []float32{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{2, 0}, 3, []float32{0, 0, 0, 0, 0, 0}, []float32{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Float64
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1}, 5, []float64{0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{0, 0, 0, 0, 0}, 1, []float64{0, 0, 0, 0, 0}, []float64{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1, 1}, 3, []float64{0, 0, 0, 0, 0, 0}, []float64{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{2, 0}, 3, []float64{0, 0, 0, 0, 0, 0}, []float64{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1}, 5, []int{0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{0, 0, 0, 0, 0}, 1, []int{0, 0, 0, 0, 0}, []int{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1, 1}, 3, []int{0, 0, 0, 0, 0, 0}, []int{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{2, 0}, 3, []int{0, 0, 0, 0, 0, 0}, []int{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int64
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1}, 5, []int64{0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{0, 0, 0, 0, 0}, 1, []int64{0, 0, 0, 0, 0}, []int64{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1, 1}, 3, []int64{0, 0, 0, 0, 0, 0}, []int64{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{2, 0}, 3, []int64{0, 0, 0, 0, 0, 0}, []int64{0, 0, 1, 1, 0, 0}, []int{2, 3}))
// Int32
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1}, 5, []int32{0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 0}, []int{1, 5}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{0, 0, 0, 0, 0}, 1, []int32{0, 0, 0, 0, 0}, []int32{1, 1, 1, 1, 1}, []int{5, 1}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{1, 1}, 3, []int32{0, 0, 0, 0, 0, 0}, []int32{0, 1, 0, 0, 1, 0}, []int{2, 3}))
suite.Run(t, NewToOneHotMatrixSuite(true, []Class{2, 0}, 3, []int32{0, 0, 0, 0, 0, 0}, []int32{0, 0, 1, 1, 0, 0}, []int{2, 3}))
}