Debian Codegraph @

dense_compat_test.go

raw ◀ ▶
2 Debian patches touch this file
1 // Code generated by genlib2. DO NOT EDIT.
2
3 package tensor
4
5 import (
6 "testing"
7
•8 arrow "github.com/apache/arrow-go/v18/arrow"
9 arrowArray "github.com/apache/arrow-go/v18/arrow/array"
10 "github.com/apache/arrow-go/v18/arrow/memory"
11 arrowTensor "github.com/apache/arrow-go/v18/arrow/tensor"
12 "github.com/stretchr/testify/assert"
13 "gonum.org/v1/gonum/mat"
14 )
15
16 var toMat64Tests = []struct {
17 data interface{}
18 sliced interface{}
19 shape Shape
20 dt Dtype
21 }{
22 {Range(Int, 0, 6), []int{0, 1, 3, 4}, Shape{2, 3}, Int},
23 {Range(Int8, 0, 6), []int8{0, 1, 3, 4}, Shape{2, 3}, Int8},
24 {Range(Int16, 0, 6), []int16{0, 1, 3, 4}, Shape{2, 3}, Int16},
25 {Range(Int32, 0, 6), []int32{0, 1, 3, 4}, Shape{2, 3}, Int32},
26 {Range(Int64, 0, 6), []int64{0, 1, 3, 4}, Shape{2, 3}, Int64},
27 {Range(Uint, 0, 6), []uint{0, 1, 3, 4}, Shape{2, 3}, Uint},
28 {Range(Uint8, 0, 6), []uint8{0, 1, 3, 4}, Shape{2, 3}, Uint8},
29 {Range(Uint16, 0, 6), []uint16{0, 1, 3, 4}, Shape{2, 3}, Uint16},
30 {Range(Uint32, 0, 6), []uint32{0, 1, 3, 4}, Shape{2, 3}, Uint32},
31 {Range(Uint64, 0, 6), []uint64{0, 1, 3, 4}, Shape{2, 3}, Uint64},
32 {Range(Float32, 0, 6), []float32{0, 1, 3, 4}, Shape{2, 3}, Float32},
33 {Range(Float64, 0, 6), []float64{0, 1, 3, 4}, Shape{2, 3}, Float64},
34 {Range(Complex64, 0, 6), []complex64{0, 1, 3, 4}, Shape{2, 3}, Complex64},
35 {Range(Complex128, 0, 6), []complex128{0, 1, 3, 4}, Shape{2, 3}, Complex128},
36 }
37
38 func TestToMat64(t *testing.T) {
39 assert := assert.New(t)
40 for i, tmt := range toMat64Tests {
41 T := New(WithBacking(tmt.data), WithShape(tmt.shape...))
42 var m *mat.Dense
43 var err error
44 if m, err = ToMat64(T); err != nil {
45 t.Errorf("ToMat basic test %d failed : %v", i, err)
46 continue
47 }
48 conv := anyToFloat64s(tmt.data)
49 assert.Equal(conv, m.RawMatrix().Data, "i %d from %v", i, tmt.dt)
50
51 if T, err = sliceDense(T, nil, makeRS(0, 2)); err != nil {
52 t.Errorf("Slice failed %v", err)
53 continue
54 }
55 if m, err = ToMat64(T); err != nil {
56 t.Errorf("ToMat of slice test %d failed : %v", i, err)
57 continue
58 }
59 conv = anyToFloat64s(tmt.sliced)
60 assert.Equal(conv, m.RawMatrix().Data, "sliced test %d from %v", i, tmt.dt)
61 t.Logf("Done")
62
63 if tmt.dt == Float64 {
64 T = New(WithBacking(tmt.data), WithShape(tmt.shape...))
65 if m, err = ToMat64(T, UseUnsafe()); err != nil {
66 t.Errorf("ToMat64 unsafe test %d failed: %v", i, err)
67 }
68 conv = anyToFloat64s(tmt.data)
69 assert.Equal(conv, m.RawMatrix().Data, "float64 unsafe i %d from %v", i, tmt.dt)
70 conv[0] = 1000
71 assert.Equal(conv, m.RawMatrix().Data, "float64 unsafe i %d from %v", i, tmt.dt)
72 conv[0] = 0 // reset for future tests that use the same backing
73 }
74 }
75 // idiocy test
76 T := New(Of(Float64), WithShape(2, 3, 4))
77 _, err := ToMat64(T)
78 if err == nil {
79 t.Error("Expected an error when trying to convert a 3-T to *mat.Dense")
80 }
81 }
82
83 func TestFromMat64(t *testing.T) {
84 assert := assert.New(t)
85 var m *mat.Dense
86 var T *Dense
87 var backing []float64
88
89 for i, tmt := range toMat64Tests {
90 backing = Range(Float64, 0, 6).([]float64)
91 m = mat.NewDense(2, 3, backing)
92 T = FromMat64(m)
93 conv := anyToFloat64s(tmt.data)
94 assert.Equal(conv, T.Float64s(), "test %d: []float64 from %v", i, tmt.dt)
95 assert.True(T.Shape().Eq(tmt.shape))
96
97 T = FromMat64(m, As(tmt.dt))
98 assert.Equal(tmt.data, T.Data())
99 assert.True(T.Shape().Eq(tmt.shape))
100
101 if tmt.dt == Float64 {
102 backing = Range(Float64, 0, 6).([]float64)
103 m = mat.NewDense(2, 3, backing)
104 T = FromMat64(m, UseUnsafe())
105 assert.Equal(backing, T.Float64s())
106 assert.True(T.Shape().Eq(tmt.shape))
107 backing[0] = 1000
108 assert.Equal(backing, T.Float64s(), "test %d - unsafe float64", i)
109 }
110 }
111 }
112
113 var toArrowArrayTests = []struct {
114 data interface{}
115 valid []bool
116 dt arrow.DataType
117 shape Shape
118 }{
119 {
120 data: Range(Int8, 0, 6),
121 valid: []bool{true, true, true, false, true, true},
122 dt: arrow.PrimitiveTypes.Int8,
123 shape: Shape{6, 1},
124 },
125 {
126 data: Range(Int16, 0, 6),
127 valid: []bool{true, true, true, false, true, true},
128 dt: arrow.PrimitiveTypes.Int16,
129 shape: Shape{6, 1},
130 },
131 {
132 data: Range(Int32, 0, 6),
133 valid: []bool{true, true, true, false, true, true},
134 dt: arrow.PrimitiveTypes.Int32,
135 shape: Shape{6, 1},
136 },
137 {
138 data: Range(Int64, 0, 6),
139 valid: []bool{true, true, true, false, true, true},
140 dt: arrow.PrimitiveTypes.Int64,
141 shape: Shape{6, 1},
142 },
143 {
144 data: Range(Uint8, 0, 6),
145 valid: []bool{true, true, true, false, true, true},
146 dt: arrow.PrimitiveTypes.Uint8,
147 shape: Shape{6, 1},
148 },
149 {
150 data: Range(Uint16, 0, 6),
151 valid: []bool{true, true, true, false, true, true},
152 dt: arrow.PrimitiveTypes.Uint16,
153 shape: Shape{6, 1},
154 },
155 {
156 data: Range(Uint32, 0, 6),
157 valid: []bool{true, true, true, false, true, true},
158 dt: arrow.PrimitiveTypes.Uint32,
159 shape: Shape{6, 1},
160 },
161 {
162 data: Range(Uint64, 0, 6),
163 valid: []bool{true, true, true, false, true, true},
164 dt: arrow.PrimitiveTypes.Uint64,
165 shape: Shape{6, 1},
166 },
167 {
168 data: Range(Float32, 0, 6),
169 valid: []bool{true, true, true, false, true, true},
170 dt: arrow.PrimitiveTypes.Float32,
171 shape: Shape{6, 1},
172 },
173 {
174 data: Range(Float64, 0, 6),
175 valid: []bool{true, true, true, false, true, true},
176 dt: arrow.PrimitiveTypes.Float64,
177 shape: Shape{6, 1},
178 },
179 }
180
181 func TestFromArrowArray(t *testing.T) {
182 assert := assert.New(t)
183 var T *Dense
184 pool := memory.NewGoAllocator()
185
186 for i, taat := range toArrowArrayTests {
•187 var m arrow.Array
188
189 switch taat.dt {
190 case arrow.BinaryTypes.String:
191 b := arrowArray.NewStringBuilder(pool)
192 defer b.Release()
193 b.AppendValues(
194 []string{"0", "1", "2", "3", "4", "5"},
195 taat.valid,
196 )
197 m = b.NewArray()
198 defer m.Release()
199 case arrow.FixedWidthTypes.Boolean:
200 b := arrowArray.NewBooleanBuilder(pool)
201 defer b.Release()
202 b.AppendValues(
203 []bool{true, false, true, false, true, false},
204 taat.valid,
205 )
206 m = b.NewArray()
207 defer m.Release()
208 case arrow.PrimitiveTypes.Int8:
209 b := arrowArray.NewInt8Builder(pool)
210 defer b.Release()
211 b.AppendValues(
212 Range(Int8, 0, 6).([]int8),
213 taat.valid,
214 )
215 m = b.NewArray()
216 defer m.Release()
217 case arrow.PrimitiveTypes.Int16:
218 b := arrowArray.NewInt16Builder(pool)
219 defer b.Release()
220 b.AppendValues(
221 Range(Int16, 0, 6).([]int16),
222 taat.valid,
223 )
224 m = b.NewArray()
225 defer m.Release()
226 case arrow.PrimitiveTypes.Int32:
227 b := arrowArray.NewInt32Builder(pool)
228 defer b.Release()
229 b.AppendValues(
230 Range(Int32, 0, 6).([]int32),
231 taat.valid,
232 )
233 m = b.NewArray()
234 defer m.Release()
235 case arrow.PrimitiveTypes.Int64:
236 b := arrowArray.NewInt64Builder(pool)
237 defer b.Release()
238 b.AppendValues(
239 Range(Int64, 0, 6).([]int64),
240 taat.valid,
241 )
242 m = b.NewArray()
243 defer m.Release()
244 case arrow.PrimitiveTypes.Uint8:
245 b := arrowArray.NewUint8Builder(pool)
246 defer b.Release()
247 b.AppendValues(
248 Range(Uint8, 0, 6).([]uint8),
249 taat.valid,
250 )
251 m = b.NewArray()
252 defer m.Release()
253 case arrow.PrimitiveTypes.Uint16:
254 b := arrowArray.NewUint16Builder(pool)
255 defer b.Release()
256 b.AppendValues(
257 Range(Uint16, 0, 6).([]uint16),
258 taat.valid,
259 )
260 m = b.NewArray()
261 defer m.Release()
262 case arrow.PrimitiveTypes.Uint32:
263 b := arrowArray.NewUint32Builder(pool)
264 defer b.Release()
265 b.AppendValues(
266 Range(Uint32, 0, 6).([]uint32),
267 taat.valid,
268 )
269 m = b.NewArray()
270 defer m.Release()
271 case arrow.PrimitiveTypes.Uint64:
272 b := arrowArray.NewUint64Builder(pool)
273 defer b.Release()
274 b.AppendValues(
275 Range(Uint64, 0, 6).([]uint64),
276 taat.valid,
277 )
278 m = b.NewArray()
279 defer m.Release()
280 case arrow.PrimitiveTypes.Float32:
281 b := arrowArray.NewFloat32Builder(pool)
282 defer b.Release()
283 b.AppendValues(
284 Range(Float32, 0, 6).([]float32),
285 taat.valid,
286 )
287 m = b.NewArray()
288 defer m.Release()
289 case arrow.PrimitiveTypes.Float64:
290 b := arrowArray.NewFloat64Builder(pool)
291 defer b.Release()
292 b.AppendValues(
293 Range(Float64, 0, 6).([]float64),
294 taat.valid,
295 )
296 m = b.NewArray()
297 defer m.Release()
298 default:
299 t.Errorf("DataType not supported in tests: %v", taat.dt)
300 }
301
302 T = FromArrowArray(m)
303 switch taat.dt {
304 case arrow.PrimitiveTypes.Int8:
305 conv := taat.data.([]int8)
306 assert.Equal(conv, T.Int8s(), "test %d: []int8 from %v", i, taat.dt)
307 case arrow.PrimitiveTypes.Int16:
308 conv := taat.data.([]int16)
309 assert.Equal(conv, T.Int16s(), "test %d: []int16 from %v", i, taat.dt)
310 case arrow.PrimitiveTypes.Int32:
311 conv := taat.data.([]int32)
312 assert.Equal(conv, T.Int32s(), "test %d: []int32 from %v", i, taat.dt)
313 case arrow.PrimitiveTypes.Int64:
314 conv := taat.data.([]int64)
315 assert.Equal(conv, T.Int64s(), "test %d: []int64 from %v", i, taat.dt)
316 case arrow.PrimitiveTypes.Uint8:
317 conv := taat.data.([]uint8)
318 assert.Equal(conv, T.Uint8s(), "test %d: []uint8 from %v", i, taat.dt)
319 case arrow.PrimitiveTypes.Uint16:
320 conv := taat.data.([]uint16)
321 assert.Equal(conv, T.Uint16s(), "test %d: []uint16 from %v", i, taat.dt)
322 case arrow.PrimitiveTypes.Uint32:
323 conv := taat.data.([]uint32)
324 assert.Equal(conv, T.Uint32s(), "test %d: []uint32 from %v", i, taat.dt)
325 case arrow.PrimitiveTypes.Uint64:
326 conv := taat.data.([]uint64)
327 assert.Equal(conv, T.Uint64s(), "test %d: []uint64 from %v", i, taat.dt)
328 case arrow.PrimitiveTypes.Float32:
329 conv := taat.data.([]float32)
330 assert.Equal(conv, T.Float32s(), "test %d: []float32 from %v", i, taat.dt)
331 case arrow.PrimitiveTypes.Float64:
332 conv := taat.data.([]float64)
333 assert.Equal(conv, T.Float64s(), "test %d: []float64 from %v", i, taat.dt)
334 default:
335 t.Errorf("DataType not supported in tests: %v", taat.dt)
336 }
337 for i, invalid := range T.Mask() {
338 assert.Equal(taat.valid[i], !invalid)
339 }
340 assert.True(T.Shape().Eq(taat.shape))
341 }
342 }
343
344 var toArrowTensorTests = []struct {
345 rowMajorData interface{}
346 colMajorData interface{}
347 rowMajorValid []bool
348 colMajorValid []bool
349 dt arrow.DataType
350 shape Shape
351 }{
352 {
353 rowMajorData: []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
354 colMajorData: []int8{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
355 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
356 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
357 dt: arrow.PrimitiveTypes.Int8,
358 shape: Shape{2, 5},
359 },
360 {
361 rowMajorData: []int16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
362 colMajorData: []int16{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
363 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
364 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
365 dt: arrow.PrimitiveTypes.Int16,
366 shape: Shape{2, 5},
367 },
368 {
369 rowMajorData: []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
370 colMajorData: []int32{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
371 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
372 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
373 dt: arrow.PrimitiveTypes.Int32,
374 shape: Shape{2, 5},
375 },
376 {
377 rowMajorData: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
378 colMajorData: []int64{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
379 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
380 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
381 dt: arrow.PrimitiveTypes.Int64,
382 shape: Shape{2, 5},
383 },
384 {
385 rowMajorData: []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
386 colMajorData: []uint8{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
387 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
388 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
389 dt: arrow.PrimitiveTypes.Uint8,
390 shape: Shape{2, 5},
391 },
392 {
393 rowMajorData: []uint16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
394 colMajorData: []uint16{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
395 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
396 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
397 dt: arrow.PrimitiveTypes.Uint16,
398 shape: Shape{2, 5},
399 },
400 {
401 rowMajorData: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
402 colMajorData: []uint32{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
403 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
404 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
405 dt: arrow.PrimitiveTypes.Uint32,
406 shape: Shape{2, 5},
407 },
408 {
409 rowMajorData: []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
410 colMajorData: []uint64{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
411 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
412 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
413 dt: arrow.PrimitiveTypes.Uint64,
414 shape: Shape{2, 5},
415 },
416 {
417 rowMajorData: []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
418 colMajorData: []float32{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
419 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
420 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
421 dt: arrow.PrimitiveTypes.Float32,
422 shape: Shape{2, 5},
423 },
424 {
425 rowMajorData: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
426 colMajorData: []float64{1, 6, 2, 7, 3, 8, 4, 9, 5, 10},
427 rowMajorValid: []bool{true, false, true, false, true, false, true, false, true, false},
428 colMajorValid: []bool{true, false, false, true, true, false, false, true, true, false},
429 dt: arrow.PrimitiveTypes.Float64,
430 shape: Shape{2, 5},
431 },
432 }
433
434 func TestFromArrowTensor(t *testing.T) {
435 assert := assert.New(t)
436 var rowMajorT *Dense
437 var colMajorT *Dense
438 pool := memory.NewGoAllocator()
439
440 for i, taat := range toArrowTensorTests {
•441 var rowMajorArr arrow.Array
442 var colMajorArr arrow.Array
443 var rowMajor arrowTensor.Interface
444 var colMajor arrowTensor.Interface
445
446 switch taat.dt {
447 case arrow.PrimitiveTypes.Int8:
448 b := arrowArray.NewInt8Builder(pool)
449 defer b.Release()
450 b.AppendValues(
451 []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
452 taat.rowMajorValid,
453 )
454 rowMajorArr = b.NewArray()
455 defer rowMajorArr.Release()
456
457 b.AppendValues(
458 []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
459 taat.rowMajorValid,
460 )
461 colMajorArr = b.NewArray()
462 defer colMajorArr.Release()
463
464 rowMajor = arrowTensor.NewInt8(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
465 defer rowMajor.Release()
466 colMajor = arrowTensor.NewInt8(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Int8SizeBytes), int64(arrow.Int8SizeBytes * 2)}, []string{"x", "y"})
467 defer colMajor.Release()
468 case arrow.PrimitiveTypes.Int16:
469 b := arrowArray.NewInt16Builder(pool)
470 defer b.Release()
471 b.AppendValues(
472 []int16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
473 taat.rowMajorValid,
474 )
475 rowMajorArr = b.NewArray()
476 defer rowMajorArr.Release()
477
478 b.AppendValues(
479 []int16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
480 taat.rowMajorValid,
481 )
482 colMajorArr = b.NewArray()
483 defer colMajorArr.Release()
484
485 rowMajor = arrowTensor.NewInt16(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
486 defer rowMajor.Release()
487 colMajor = arrowTensor.NewInt16(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Int16SizeBytes), int64(arrow.Int16SizeBytes * 2)}, []string{"x", "y"})
488 defer colMajor.Release()
489 case arrow.PrimitiveTypes.Int32:
490 b := arrowArray.NewInt32Builder(pool)
491 defer b.Release()
492 b.AppendValues(
493 []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
494 taat.rowMajorValid,
495 )
496 rowMajorArr = b.NewArray()
497 defer rowMajorArr.Release()
498
499 b.AppendValues(
500 []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
501 taat.rowMajorValid,
502 )
503 colMajorArr = b.NewArray()
504 defer colMajorArr.Release()
505
506 rowMajor = arrowTensor.NewInt32(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
507 defer rowMajor.Release()
508 colMajor = arrowTensor.NewInt32(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Int32SizeBytes), int64(arrow.Int32SizeBytes * 2)}, []string{"x", "y"})
509 defer colMajor.Release()
510 case arrow.PrimitiveTypes.Int64:
511 b := arrowArray.NewInt64Builder(pool)
512 defer b.Release()
513 b.AppendValues(
514 []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
515 taat.rowMajorValid,
516 )
517 rowMajorArr = b.NewArray()
518 defer rowMajorArr.Release()
519
520 b.AppendValues(
521 []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
522 taat.rowMajorValid,
523 )
524 colMajorArr = b.NewArray()
525 defer colMajorArr.Release()
526
527 rowMajor = arrowTensor.NewInt64(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
528 defer rowMajor.Release()
529 colMajor = arrowTensor.NewInt64(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Int64SizeBytes), int64(arrow.Int64SizeBytes * 2)}, []string{"x", "y"})
530 defer colMajor.Release()
531 case arrow.PrimitiveTypes.Uint8:
532 b := arrowArray.NewUint8Builder(pool)
533 defer b.Release()
534 b.AppendValues(
535 []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
536 taat.rowMajorValid,
537 )
538 rowMajorArr = b.NewArray()
539 defer rowMajorArr.Release()
540
541 b.AppendValues(
542 []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
543 taat.rowMajorValid,
544 )
545 colMajorArr = b.NewArray()
546 defer colMajorArr.Release()
547
548 rowMajor = arrowTensor.NewUint8(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
549 defer rowMajor.Release()
550 colMajor = arrowTensor.NewUint8(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Uint8SizeBytes), int64(arrow.Uint8SizeBytes * 2)}, []string{"x", "y"})
551 defer colMajor.Release()
552 case arrow.PrimitiveTypes.Uint16:
553 b := arrowArray.NewUint16Builder(pool)
554 defer b.Release()
555 b.AppendValues(
556 []uint16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
557 taat.rowMajorValid,
558 )
559 rowMajorArr = b.NewArray()
560 defer rowMajorArr.Release()
561
562 b.AppendValues(
563 []uint16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
564 taat.rowMajorValid,
565 )
566 colMajorArr = b.NewArray()
567 defer colMajorArr.Release()
568
569 rowMajor = arrowTensor.NewUint16(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
570 defer rowMajor.Release()
571 colMajor = arrowTensor.NewUint16(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Uint16SizeBytes), int64(arrow.Uint16SizeBytes * 2)}, []string{"x", "y"})
572 defer colMajor.Release()
573 case arrow.PrimitiveTypes.Uint32:
574 b := arrowArray.NewUint32Builder(pool)
575 defer b.Release()
576 b.AppendValues(
577 []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
578 taat.rowMajorValid,
579 )
580 rowMajorArr = b.NewArray()
581 defer rowMajorArr.Release()
582
583 b.AppendValues(
584 []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
585 taat.rowMajorValid,
586 )
587 colMajorArr = b.NewArray()
588 defer colMajorArr.Release()
589
590 rowMajor = arrowTensor.NewUint32(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
591 defer rowMajor.Release()
592 colMajor = arrowTensor.NewUint32(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Uint32SizeBytes), int64(arrow.Uint32SizeBytes * 2)}, []string{"x", "y"})
593 defer colMajor.Release()
594 case arrow.PrimitiveTypes.Uint64:
595 b := arrowArray.NewUint64Builder(pool)
596 defer b.Release()
597 b.AppendValues(
598 []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
599 taat.rowMajorValid,
600 )
601 rowMajorArr = b.NewArray()
602 defer rowMajorArr.Release()
603
604 b.AppendValues(
605 []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
606 taat.rowMajorValid,
607 )
608 colMajorArr = b.NewArray()
609 defer colMajorArr.Release()
610
611 rowMajor = arrowTensor.NewUint64(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
612 defer rowMajor.Release()
613 colMajor = arrowTensor.NewUint64(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Uint64SizeBytes), int64(arrow.Uint64SizeBytes * 2)}, []string{"x", "y"})
614 defer colMajor.Release()
615 case arrow.PrimitiveTypes.Float32:
616 b := arrowArray.NewFloat32Builder(pool)
617 defer b.Release()
618 b.AppendValues(
619 []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
620 taat.rowMajorValid,
621 )
622 rowMajorArr = b.NewArray()
623 defer rowMajorArr.Release()
624
625 b.AppendValues(
626 []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
627 taat.rowMajorValid,
628 )
629 colMajorArr = b.NewArray()
630 defer colMajorArr.Release()
631
632 rowMajor = arrowTensor.NewFloat32(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
633 defer rowMajor.Release()
634 colMajor = arrowTensor.NewFloat32(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Float32SizeBytes), int64(arrow.Float32SizeBytes * 2)}, []string{"x", "y"})
635 defer colMajor.Release()
636 case arrow.PrimitiveTypes.Float64:
637 b := arrowArray.NewFloat64Builder(pool)
638 defer b.Release()
639 b.AppendValues(
640 []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
641 taat.rowMajorValid,
642 )
643 rowMajorArr = b.NewArray()
644 defer rowMajorArr.Release()
645
646 b.AppendValues(
647 []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
648 taat.rowMajorValid,
649 )
650 colMajorArr = b.NewArray()
651 defer colMajorArr.Release()
652
653 rowMajor = arrowTensor.NewFloat64(rowMajorArr.Data(), []int64{2, 5}, nil, []string{"x", "y"})
654 defer rowMajor.Release()
655 colMajor = arrowTensor.NewFloat64(colMajorArr.Data(), []int64{2, 5}, []int64{int64(arrow.Float64SizeBytes), int64(arrow.Float64SizeBytes * 2)}, []string{"x", "y"})
656 defer colMajor.Release()
657 default:
658 t.Errorf("DataType not supported in tests: %v", taat.dt)
659 }
660
661 rowMajorT = FromArrowTensor(rowMajor)
662 colMajorT = FromArrowTensor(colMajor)
663
664 assert.Equal(taat.rowMajorData, rowMajorT.Data(), "test %d: row major %v", i, taat.dt)
665 assert.Equal(len(taat.rowMajorValid), len(rowMajorT.Mask()), "test %d: row major %v mask length incorrect", i, taat.dt)
666 for i, invalid := range rowMajorT.Mask() {
667 assert.Equal(taat.rowMajorValid[i], !invalid, "test %d: row major %v mask value incorrect", i, taat.dt)
668 }
669 assert.True(colMajorT.Shape().Eq(taat.shape))
670
671 assert.Equal(taat.colMajorData, colMajorT.Data(), "test %d: column major %v", i, taat.dt)
672 assert.Equal(len(taat.colMajorValid), len(colMajorT.Mask()), "test %d: column major %v mask length incorrect", i, taat.dt)
673 for i, invalid := range colMajorT.Mask() {
674 assert.Equal(taat.colMajorValid[i], !invalid, "test %d: column major %v mask value incorrect", i, taat.dt)
675 }
676 assert.True(rowMajorT.Shape().Eq(taat.shape))
677 }
678 }