Skip to content

Commit 835392c

Browse files
committed
2021/09/19-08:26:30 (Linux cray unknown)
1 parent 5909fbd commit 835392c

File tree

1 file changed

+62
-50
lines changed

1 file changed

+62
-50
lines changed

scoresLr_expand.go

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,41 @@ import "github.com/pborman/getopt"
3030

3131
/* -------------------------------------------------------------------------- */
3232

33-
type AbstractOperation interface {
34-
Apply(columns, incomplete_columns [][]float64, names, incomplete_names []string, from, to, max_features int) ([][]float64, [][]float64, []string, []string)
35-
}
36-
37-
/* -------------------------------------------------------------------------- */
38-
39-
type Operation struct {
40-
Final bool
41-
Incompatible []*Operation
33+
type Desk struct {
34+
columns [][]float64
35+
names []string
36+
incomplete_columns [][]float64
37+
incomplete_names []string
4238
}
4339

44-
func (op Operation) Append(columns, incomplete_columns [][]float64, names, incomplete_names []string, column []float64, name string) ([][]float64, [][]float64, []string, []string) {
40+
func (obj Desk) Append(column []float64, name string, final bool) Desk {
4541
if column != nil {
46-
if op.Final {
47-
columns = append(columns, column)
48-
if len(names) > 0 {
49-
names = append(names, name)
42+
if final {
43+
obj.columns = append(obj.columns, column)
44+
if len(obj.names) > 0 {
45+
obj.names = append(obj.names, name)
5046
}
5147
} else {
52-
incomplete_columns = append(incomplete_columns, column)
53-
if len(names) > 0 {
54-
incomplete_names = append(incomplete_names, name)
48+
obj.incomplete_columns = append(obj.incomplete_columns, column)
49+
if len(obj.names) > 0 {
50+
obj.incomplete_names = append(obj.incomplete_names, name)
5551
}
5652
}
5753
}
58-
return columns, incomplete_columns, names, incomplete_names
54+
return obj
55+
}
56+
57+
/* -------------------------------------------------------------------------- */
58+
59+
type AbstractOperation interface {
60+
Apply(desk Desk, from, to, max_features int) Desk
61+
}
62+
63+
/* -------------------------------------------------------------------------- */
64+
65+
type Operation struct {
66+
Final bool
67+
Incompatible []*Operation
5968
}
6069

6170
func (op *Operation) AddIncompatible(op_a *Operation) {
@@ -95,24 +104,24 @@ func (op OperationUnary) apply(column_in []float64, name_in string) ([]float64,
95104
return column, name
96105
}
97106

98-
func (op OperationUnary) Apply(columns, incomplete_columns [][]float64, names, incomplete_names []string, from, to, max_features int) ([][]float64, [][]float64, []string, []string) {
99-
tmp_columns := columns[from:to]
100-
tmp_names := names[from:to]
107+
func (op OperationUnary) Apply(desk Desk, from, to, max_features int) Desk {
108+
tmp_columns := desk.columns[from:to]
109+
tmp_names := desk. names[from:to]
101110
if op.Final {
102-
tmp_columns = append(tmp_columns, incomplete_columns...)
103-
tmp_names = append(tmp_names , incomplete_names ...)
104-
incomplete_columns = nil
105-
incomplete_names = nil
111+
tmp_columns = append(tmp_columns, desk.incomplete_columns...)
112+
tmp_names = append(tmp_names , desk.incomplete_names ...)
113+
desk.incomplete_columns = nil
114+
desk.incomplete_names = nil
106115
}
107116
// apply to complete
108117
for j := 0; j < len(tmp_columns); j++ {
109-
if max_features > 0 && len(columns) >= max_features {
118+
if max_features > 0 && len(desk.columns) >= max_features {
110119
break
111120
}
112121
column, name := op.apply(tmp_columns[j], tmp_names[j])
113-
columns, incomplete_columns, names, incomplete_names = op.Append(columns, incomplete_columns, names, incomplete_names, column, name)
122+
desk = desk.Append(column, name, op.Final)
114123
}
115-
return columns, incomplete_columns, names, incomplete_names
124+
return desk
116125
}
117126

118127
/* -------------------------------------------------------------------------- */
@@ -140,26 +149,26 @@ func (op OperationBinary) apply(column_a, column_b []float64, name_a, name_b str
140149
return column, name
141150
}
142151

143-
func (op OperationBinary) Apply(columns, incomplete_columns [][]float64, names, incomplete_names []string, from, to, max_features int) ([][]float64, [][]float64, []string, []string) {
144-
tmp_columns := columns[from:to]
145-
tmp_names := names[from:to]
152+
func (op OperationBinary) Apply(desk Desk, from, to, max_features int) Desk {
153+
tmp_columns := desk.columns[from:to]
154+
tmp_names := desk. names[from:to]
146155
if op.Final {
147-
tmp_columns = append(tmp_columns, incomplete_columns...)
148-
tmp_names = append(tmp_names , incomplete_names ...)
149-
incomplete_columns = nil
150-
incomplete_names = nil
156+
tmp_columns = append(tmp_columns, desk.incomplete_columns...)
157+
tmp_names = append(tmp_names , desk.incomplete_names ...)
158+
desk.incomplete_columns = nil
159+
desk.incomplete_names = nil
151160
}
152161
for j1 := 0; j1 < len(tmp_columns); j1++ {
153162
for j2 := j1+1; j2 < len(tmp_columns); j2++ {
154-
if max_features > 0 && len(columns) >= max_features {
163+
if max_features > 0 && len(desk.columns) >= max_features {
155164
goto ret
156165
}
157166
column, name := op.apply(tmp_columns[j1], tmp_columns[j2], tmp_names[j1], tmp_names[j2])
158-
columns, incomplete_columns, names, incomplete_names = op.Append(columns, incomplete_columns, names, incomplete_names, column, name)
167+
desk = desk.Append(column, name, op.Final)
159168
}
160169
}
161170
ret:
162-
return columns, incomplete_columns, names, incomplete_names
171+
return desk
163172
}
164173

165174
/* -------------------------------------------------------------------------- */
@@ -336,26 +345,29 @@ func expand_parse_operations(allowed_operations string) []AbstractOperation {
336345

337346
/* -------------------------------------------------------------------------- */
338347

339-
func expand_scores(config Config, filenames_in []string, basename_out string, max_d, max_features int, allowed_operations string) {
340-
operations := expand_parse_operations(allowed_operations)
341-
columns, lengths, names := expand_import(config, filenames_in)
342-
incomplete_columns := [][]float64{}
343-
incomplete_names := []string{}
344-
348+
func expand_scores(config Config, filenames_in []string, basename_out string, max_d, max_features int, operations []AbstractOperation) {
349+
desk := Desk{}
350+
lengths := []int{}
351+
// import data
352+
if columns, lengths_, names := expand_import(config, filenames_in); true {
353+
desk.columns = columns
354+
desk.names = names
355+
lengths = lengths_
356+
}
345357
from := 0
346-
to := len(columns)
358+
to := len(desk.columns)
347359
for d := 0; max_d == 0 || d < max_d; d++ {
348360
for _, op := range operations {
349-
columns, incomplete_columns, names, incomplete_names = op.Apply(columns, incomplete_columns, names, incomplete_names, from, to, max_features)
361+
desk = op.Apply(desk, from, to, max_features)
350362
}
351-
if max_features > 0 && len(columns) >= max_features {
363+
if max_features > 0 && len(desk.columns) >= max_features {
352364
break
353365
}
354366
// update range
355367
from = to
356-
to = len(columns)
368+
to = len(desk.columns)
357369
}
358-
expand_export(config, columns, lengths, names, basename_out)
370+
expand_export(config, desk.columns, lengths, desk.names, basename_out)
359371
}
360372

361373
/* -------------------------------------------------------------------------- */
@@ -399,5 +411,5 @@ func main_expand_scores(config Config, args []string) {
399411
filenames_in := strings.Split(options.Args()[0], ",")
400412
basename_out := options.Args()[1]
401413

402-
expand_scores(config, filenames_in, basename_out, *optMaxDepth, *optMaxFeatures, *optOperations)
414+
expand_scores(config, filenames_in, basename_out, *optMaxDepth, *optMaxFeatures, expand_parse_operations(*optOperations))
403415
}

0 commit comments

Comments
 (0)