forked from hail-is/hail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Children.scala
257 lines (254 loc) · 8.58 KB
/
Children.scala
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package is.hail.expr.ir
import is.hail.utils._
object Children {
private val none: IndexedSeq[BaseIR] = Array.empty[BaseIR]
def apply(x: IR): IndexedSeq[BaseIR] = x match {
case I32(x) => none
case I64(x) => none
case F32(x) => none
case F64(x) => none
case Str(x) => none
case UUID4(_) => none
case True() => none
case False() => none
case Literal(_, _) => none
case EncodedLiteral(_, _) => none
case Void() => none
case Cast(v, typ) =>
Array(v)
case CastRename(v, typ) =>
Array(v)
case NA(typ) => none
case IsNA(value) =>
Array(value)
case Coalesce(values) => values.toFastIndexedSeq
case Consume(value) => FastIndexedSeq(value)
case If(cond, cnsq, altr) =>
Array(cond, cnsq, altr)
case Let(name, value, body) =>
Array(value, body)
case RelationalLet(name, value, body) =>
Array(value, body)
case AggLet(name, value, body, _) =>
Array(value, body)
case TailLoop(_, args, body) =>
args.map(_._2).toFastIndexedSeq :+ body
case Recur(_, args, _) =>
args.toFastIndexedSeq
case Ref(name, typ) =>
none
case RelationalRef(_, _) =>
none
case ApplyBinaryPrimOp(op, l, r) =>
Array(l, r)
case ApplyUnaryPrimOp(op, x) =>
Array(x)
case ApplyComparisonOp(op, l, r) =>
Array(l, r)
case MakeArray(args, typ) =>
args.toFastIndexedSeq
case MakeStream(args, _, _) =>
args.toFastIndexedSeq
case ArrayRef(a, i, _) =>
Array(a, i)
case ArraySlice(a, start, stop, step, _) =>
if (stop.isEmpty)
Array(a, start, step)
else
Array(a, start, stop.get, step)
case ArrayLen(a) =>
Array(a)
case StreamIota(start, step, _) =>
Array(start, step)
case StreamRange(start, stop, step, _, _) =>
Array(start, stop, step)
case SeqSample(totalRange, numToSample, rngState, _) =>
Array(totalRange, numToSample, rngState)
case StreamDistribute(child, pivots, path, _, _) =>
Array(child, pivots, path)
case StreamWhiten(stream, _, _, _, _, _, _, _) =>
Array(stream)
case ArrayZeros(length) =>
Array(length)
case MakeNDArray(data, shape, rowMajor, _) =>
Array(data, shape, rowMajor)
case NDArrayShape(nd) =>
Array(nd)
case NDArrayReshape(nd, shape, _) =>
Array(nd, shape)
case NDArrayConcat(nds, _) =>
Array(nds)
case ArraySort(a, _, _, lessThan) =>
Array(a, lessThan)
case ArrayMaximalIndependentSet(a, tieBreaker) =>
Array(a) ++ tieBreaker.map { case (_, _, tb) => tb }
case ToSet(a) =>
Array(a)
case ToDict(a) =>
Array(a)
case ToArray(a) =>
Array(a)
case CastToArray(a) =>
Array(a)
case ToStream(a, _) =>
Array(a)
case LowerBoundOnOrderedCollection(orderedCollection, elem, _) =>
Array(orderedCollection, elem)
case GroupByKey(collection) =>
Array(collection)
case RNGStateLiteral() => none
case RNGSplit(state, split) =>
Array(state, split)
case StreamLen(a) =>
Array(a)
case StreamTake(a, len) =>
Array(a, len)
case StreamDrop(a, len) =>
Array(a, len)
case StreamGrouped(a, size) =>
Array(a, size)
case StreamGroupByKey(a, _, _) =>
Array(a)
case StreamMap(a, name, body) =>
Array(a, body)
case StreamZip(as, names, body, _, _) =>
as :+ body
case StreamZipJoin(as, _, _, _, joinF) =>
as :+ joinF
case StreamMultiMerge(as, _) =>
as
case StreamFilter(a, name, cond) =>
Array(a, cond)
case StreamTakeWhile(a, name, cond) =>
Array(a, cond)
case StreamDropWhile(a, name, cond) =>
Array(a, cond)
case StreamFlatMap(a, name, body) =>
Array(a, body)
case StreamFold(a, zero, accumName, valueName, body) =>
Array(a, zero, body)
case StreamFold2(a, accum, valueName, seq, result) =>
Array(a) ++ accum.map(_._2) ++ seq ++ Array(result)
case StreamScan(a, zero, accumName, valueName, body) =>
Array(a, zero, body)
case StreamJoinRightDistinct(left, right, lKey, rKey, l, r, join, joinType) =>
Array(left, right, join)
case StreamFor(a, valueName, body) =>
Array(a, body)
case StreamAgg(a, name, query) =>
Array(a, query)
case StreamAggScan(a, name, query) =>
Array(a, query)
case StreamBufferedAggregate(streamChild, initAggs, newKey, seqOps, _, _, _) =>
Array(streamChild, initAggs, newKey, seqOps)
case StreamLocalLDPrune(streamChild, r2Threshold, windowSize, maxQueueSize, nSamples) =>
Array(streamChild, r2Threshold, windowSize, maxQueueSize, nSamples)
case RunAggScan(array, _, init, seq, result, _) =>
Array(array, init, seq, result)
case RunAgg(body, result, _) =>
Array(body, result)
case NDArrayRef(nd, idxs, _) =>
nd +: idxs
case NDArraySlice(nd, slices) =>
Array(nd, slices)
case NDArrayFilter(nd, keep) =>
nd +: keep
case NDArrayMap(nd, _, body) =>
Array(nd, body)
case NDArrayMap2(l, r, _, _, body, _) =>
Array(l, r, body)
case NDArrayReindex(nd, _) =>
Array(nd)
case NDArrayAgg(nd, _) =>
Array(nd)
case NDArrayMatMul(l, r, _) =>
Array(l, r)
case NDArrayQR(nd, _, _) =>
Array(nd)
case NDArraySVD(nd, _, _, _) =>
Array(nd)
case NDArrayEigh(nd, _, _) =>
Array(nd)
case NDArrayInv(nd, errorID) =>
Array(nd)
case NDArrayWrite(nd, path) =>
Array(nd, path)
case AggFilter(cond, aggIR, _) =>
Array(cond, aggIR)
case AggExplode(array, _, aggBody, _) =>
Array(array, aggBody)
case AggGroupBy(key, aggIR, _) =>
Array(key, aggIR)
case AggArrayPerElement(a, _, _, aggBody, knownLength, _) => Array(a, aggBody) ++ knownLength.toArray[IR]
case MakeStruct(fields) =>
fields.map(_._2).toFastIndexedSeq
case SelectFields(old, fields) =>
Array(old)
case InsertFields(old, fields, _) =>
(old +: fields.map(_._2)).toFastIndexedSeq
case InitOp(_, args, _) => args
case SeqOp(_, args, _) => args
case _: ResultOp => none
case _: AggStateValue => none
case _: CombOp => none
case CombOpValue(_, value, _) => Array(value)
case InitFromSerializedValue(_, value, _) => Array(value)
case SerializeAggs(_, _, _, _) => none
case DeserializeAggs(_, _, _, _) => none
case Begin(xs) =>
xs
case ApplyAggOp(initOpArgs, seqOpArgs, aggSig) =>
initOpArgs ++ seqOpArgs
case ApplyScanOp(initOpArgs, seqOpArgs, aggSig) =>
initOpArgs ++ seqOpArgs
case AggFold(zero, seqOp, combOp, elementName, accumName, _) =>
Array(zero, seqOp, combOp)
case GetField(o, name) =>
Array(o)
case MakeTuple(fields) =>
fields.map(_._2).toFastIndexedSeq
case GetTupleElement(o, idx) =>
Array(o)
case In(i, typ) =>
none
case Die(message, typ, errorId) =>
Array(message)
case Trap(child) => Array(child)
case ConsoleLog(message, result) =>
Array(message, result)
case ApplyIR(_, _, args, _) =>
args.toFastIndexedSeq
case Apply(_, _, args, _, _) =>
args.toFastIndexedSeq
case ApplySeeded(_, args, rngState, _, _) =>
args.toFastIndexedSeq :+ rngState
case ApplySpecial(_, _, args, _, _) =>
args.toFastIndexedSeq
// from MatrixIR
case MatrixWrite(child, _) => Array(child)
case MatrixMultiWrite(children, _) => children
// from TableIR
case TableCount(child) => Array(child)
case MatrixCount(child) => Array(child)
case TableGetGlobals(child) => Array(child)
case TableCollect(child) => Array(child)
case TableAggregate(child, query) => Array(child, query)
case MatrixAggregate(child, query) => Array(child, query)
case TableWrite(child, _) => Array(child)
case TableMultiWrite(children, _) => children
case TableToValueApply(child, _) => Array(child)
case MatrixToValueApply(child, _) => Array(child)
// from BlockMatrixIR
case BlockMatrixToValueApply(child, _) => Array(child)
case BlockMatrixCollect(child) => Array(child)
case BlockMatrixWrite(child, _) => Array(child)
case BlockMatrixMultiWrite(blockMatrices, _) => blockMatrices
case CollectDistributedArray(ctxs, globals, _, _, body, dynamicID, _, _) => Array(ctxs, globals, body, dynamicID)
case ReadPartition(path, _, _) => Array(path)
case WritePartition(stream, ctx, _) => Array(stream, ctx)
case WriteMetadata(writeAnnotations, _) => Array(writeAnnotations)
case ReadValue(path, _, _) => Array(path)
case WriteValue(value, path, _, staged) => Array(value, path) ++ staged.toArray[IR]
case LiftMeOut(child) => Array(child)
}
}