-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat_batching.go
43 lines (39 loc) · 1.1 KB
/
float_batching.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
package dataframe
import (
"fmt"
)
type FloatBatching struct {
bColumns []int
iColumns []int
fColumns []int
columns []string
initialized bool
}
func imin(x, y int) int {
if x < y {
return x
}
return y
}
func (bat *FloatBatching) initialize(df *DataFrame, columns []string) {
if !bat.initialized {
bat.initialized = true
bat.columns = columns
bat.fColumns = make([]int, 0, imin(len(df.floats), len(bat.columns)))
bat.bColumns = make([]int, 0, imin(len(df.bools), len(bat.columns)))
bat.iColumns = make([]int, 0, imin(len(df.ints), len(bat.columns)))
for i, col := range bat.columns {
if _, ok := df.floats[col]; ok {
bat.fColumns = append(bat.fColumns, i)
} else if _, ok := df.bools[col]; ok {
bat.bColumns = append(bat.bColumns, i)
} else if _, ok := df.ints[col]; ok {
bat.iColumns = append(bat.iColumns, i)
} else if _, ok := df.objects[col]; ok {
panic(fmt.Sprintf("%s cannot be converted to floats", col))
} else {
panic(fmt.Sprintf("column %s does not exist", col))
}
}
}
}