-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.go
More file actions
88 lines (78 loc) · 1.78 KB
/
Copy pathindex.go
File metadata and controls
88 lines (78 loc) · 1.78 KB
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
package apl
import (
"fmt"
"strings"
)
// IdxSpec is the value of an index specification.
// For an axis specification this must be a length 1 slice
// and the value is an apl.Float.
// For an index specification this is an array and each value
// is either an EmptyArray or an IntArray.
// IdxSpec is origin dependend.
type IdxSpec []Value
func (x IdxSpec) String(f Format) string {
if x == nil {
return "[nil]"
}
v := make([]string, len(x))
for i, e := range x {
v[i] = e.String(f)
}
return "[" + strings.Join(v, ";") + "]"
}
func (x IdxSpec) Copy() Value {
r := make(IdxSpec, len(x))
for i := range r {
r[i] = x[i].Copy()
}
return r
}
func (x IdxSpec) Eval(a *Apl) (Value, error) {
return x, nil
}
// Shape returns the result shape of the index specification applied to an array with shape src.
func (x IdxSpec) Shape(src []int) ([]int, error) {
return nil, fmt.Errorf("TODO apl.IdxSpec.Shape")
}
// IdxSpec represents an expression of an index specification.
// That is what is in square brackets following an array.
type idxSpec []expr
func (x idxSpec) String(f Format) string {
if x == nil {
return "[nil]"
}
v := make([]string, len(x))
for i, e := range x {
v[i] = e.String(f)
}
return "[" + strings.Join(v, ";") + "]"
}
func (x idxSpec) Eval(a *Apl) (Value, error) {
idx := make(IdxSpec, len(x))
for i, e := range x {
if v, err := e.Eval(a); err != nil {
return nil, err
} else {
idx[i] = v
}
}
return idx, nil
}
// Axis combines the right argument with an axis specification.
type Axis struct {
R Value
A Value
}
func (ax Axis) String(f Format) string {
return fmt.Sprintf("[%s]%s", ax.A.String(f), ax.R.String(f))
}
func (ax Axis) Copy() Value {
r := Axis{}
if ax.R != nil {
r.R = ax.R.Copy()
}
if ax.A != nil {
r.A = ax.A.Copy()
}
return r
}