-
Notifications
You must be signed in to change notification settings - Fork 24
/
shuffle.go
34 lines (31 loc) · 1017 Bytes
/
shuffle.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
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package patgen
import (
"cogentcore.org/lab/base/randx"
"cogentcore.org/lab/table"
)
// Shuffle shuffles rows in specified columns in the table independently
func Shuffle(dt *table.Table, rows []int, colNames []string, colIndependent bool) {
cl := dt.Clone()
if colIndependent { // independent
for _, colNm := range colNames {
sfrows := make([]int, len(rows))
copy(sfrows, rows)
randx.PermuteInts(sfrows, RandSource)
for i, row := range rows {
dt.Column(colNm).RowTensor(row).CopyFrom(cl.Column(colNm).RowTensor(sfrows[i]))
}
}
} else { // shuffle together
sfrows := make([]int, len(rows))
copy(sfrows, rows)
randx.PermuteInts(sfrows, RandSource)
for _, colNm := range colNames {
for i, row := range rows {
dt.Column(colNm).RowTensor(row).CopyFrom(cl.Column(colNm).RowTensor(sfrows[i]))
}
}
}
}