@elaraai/east 1.0.65 → 1.0.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
4
  */
5
5
  import type { AST } from "../ast.js";
6
- import { IntegerType, VectorType, FunctionType, type NeverType } from "../types.js";
6
+ import { BooleanType, FloatType, IntegerType, VectorType, FunctionType, type NeverType } from "../types.js";
7
7
  import type { IntegerExpr } from "./integer.js";
8
8
  import { Expr, type ToExpr } from "./expr.js";
9
9
  import type { SubtypeExprOrValue, ExprType, TypeOf } from "./types.js";
@@ -97,5 +97,221 @@ export declare class VectorExpr<T extends any> extends Expr<VectorType<T>> {
97
97
  * @returns The final accumulated value
98
98
  */
99
99
  reduce<T2>(combineFn: SubtypeExprOrValue<FunctionType<[previous: TypeOf<NoInfer<T2>>, value: T, key: IntegerType], TypeOf<NoInfer<T2>>>>, init: T2): ExprType<TypeOf<T2>>;
100
+ /** Requires a Float or Integer element type for the arithmetic builtins. */
101
+ private numericElem;
102
+ /** Requires a Boolean element type for the mask builtins. */
103
+ private maskElem;
104
+ /** Builds a unary/binary elementwise builtin returning a vector of this element type. */
105
+ private elementwise;
106
+ /**
107
+ * Multiplies every element by a scalar, producing a new vector.
108
+ *
109
+ * @param alpha - The scalar factor (same type as the elements)
110
+ * @returns A new VectorExpr with every element scaled by alpha
111
+ */
112
+ scale(alpha: SubtypeExprOrValue<T>): VectorExpr<T>;
113
+ /**
114
+ * Sums the elements in index order, left to right.
115
+ *
116
+ * The accumulation order is part of the cross-runtime contract: a
117
+ * reassociated float sum gives a different last bit. An empty vector sums
118
+ * to zero.
119
+ *
120
+ * @returns An expression of the element type holding the sum
121
+ */
122
+ sum(): ExprType<T>;
123
+ /**
124
+ * Adds a scaled vector elementwise: `this + alpha * other`.
125
+ *
126
+ * Add and subtract fall out at `alpha` of one and minus one.
127
+ *
128
+ * @param other - The vector to scale and add (same length and element type)
129
+ * @param alpha - The scalar factor applied to other
130
+ * @returns A new VectorExpr holding the combined elements
131
+ *
132
+ * @throws East runtime error if the vector lengths differ
133
+ */
134
+ addScaled(other: SubtypeExprOrValue<VectorType<T>>, alpha: SubtypeExprOrValue<T>): VectorExpr<T>;
135
+ /**
136
+ * Multiplies two vectors elementwise.
137
+ *
138
+ * @param other - The vector to multiply with (same length and element type)
139
+ * @returns A new VectorExpr holding the elementwise products
140
+ *
141
+ * @throws East runtime error if the vector lengths differ
142
+ */
143
+ mul(other: SubtypeExprOrValue<VectorType<T>>): VectorExpr<T>;
144
+ /**
145
+ * Adds a scalar to every element, producing a new vector.
146
+ *
147
+ * @param value - The scalar addend (same type as the elements)
148
+ * @returns A new VectorExpr with value added to every element
149
+ */
150
+ addScalar(value: SubtypeExprOrValue<T>): VectorExpr<T>;
151
+ /**
152
+ * Computes the dot product, accumulating in index order, left to right.
153
+ *
154
+ * @param other - The vector to multiply with (same length and element type)
155
+ * @returns An expression of the element type holding the dot product
156
+ *
157
+ * @throws East runtime error if the vector lengths differ
158
+ */
159
+ dot(other: SubtypeExprOrValue<VectorType<T>>): ExprType<T>;
160
+ /**
161
+ * Returns the largest element under East's total order (NaN is greatest).
162
+ * Ties resolve to the earliest occurrence.
163
+ *
164
+ * @returns An expression of the element type holding the maximum
165
+ *
166
+ * @throws East runtime error if the vector is empty
167
+ */
168
+ max(): ExprType<T>;
169
+ /**
170
+ * Returns the smallest element under East's total order.
171
+ * Ties resolve to the earliest occurrence.
172
+ *
173
+ * @returns An expression of the element type holding the minimum
174
+ *
175
+ * @throws East runtime error if the vector is empty
176
+ */
177
+ min(): ExprType<T>;
178
+ /**
179
+ * Returns the index of the largest element under East's total order.
180
+ * Ties resolve to the earliest occurrence.
181
+ *
182
+ * @returns An IntegerExpr holding the index of the maximum
183
+ *
184
+ * @throws East runtime error if the vector is empty
185
+ */
186
+ argMax(): IntegerExpr;
187
+ /**
188
+ * Returns the index of the smallest element under East's total order.
189
+ * Ties resolve to the earliest occurrence.
190
+ *
191
+ * @returns An IntegerExpr holding the index of the minimum
192
+ *
193
+ * @throws East runtime error if the vector is empty
194
+ */
195
+ argMin(): IntegerExpr;
196
+ /**
197
+ * Computes the arithmetic mean as a Float, accumulating in index order.
198
+ * Integer elements widen to Float per element; an empty vector yields NaN.
199
+ *
200
+ * @returns A FloatExpr holding the mean
201
+ */
202
+ mean(): ExprType<FloatType>;
203
+ /**
204
+ * Computes the running sum in index order, left to right.
205
+ * Element i of the result is the sum of elements 0 through i.
206
+ *
207
+ * @returns A new VectorExpr of the running sums
208
+ */
209
+ cumSum(): VectorExpr<T>;
210
+ /**
211
+ * Takes the absolute value of every element.
212
+ *
213
+ * @returns A new VectorExpr with every element replaced by its magnitude
214
+ */
215
+ abs(): VectorExpr<T>;
216
+ /**
217
+ * Clamps every element between lo and hi under East's total order:
218
+ * an element below lo becomes lo, one above hi becomes hi.
219
+ *
220
+ * @param lo - The lower bound (same type as the elements)
221
+ * @param hi - The upper bound (same type as the elements)
222
+ * @returns A new VectorExpr with every element clamped
223
+ */
224
+ clamp(lo: SubtypeExprOrValue<T>, hi: SubtypeExprOrValue<T>): VectorExpr<T>;
225
+ /**
226
+ * Gathers elements at the given indices: element j of the result is
227
+ * `this[indices[j]]`.
228
+ *
229
+ * @param indices - The indices to read, as a Vector of Integers
230
+ * @returns A new VectorExpr with one element per index
231
+ *
232
+ * @throws East runtime error if any index is out of bounds
233
+ */
234
+ gather(indices: SubtypeExprOrValue<VectorType<IntegerType>>): VectorExpr<T>;
235
+ /**
236
+ * Returns a copy of this vector with `src[j]` added at `indices[j]` for
237
+ * each j in order. Duplicate indices accumulate in input order.
238
+ *
239
+ * @param indices - The target index for each source element
240
+ * @param src - The values to add (same length as indices)
241
+ * @returns A new VectorExpr with the additions applied
242
+ *
243
+ * @throws East runtime error if the index and source lengths differ, or any index is out of bounds
244
+ */
245
+ scatterAdd(indices: SubtypeExprOrValue<VectorType<IntegerType>>, src: SubtypeExprOrValue<VectorType<T>>): VectorExpr<T>;
246
+ /**
247
+ * Finds, for each needle, the leftmost insertion index that keeps this
248
+ * (sorted) vector sorted under East's total order — numpy's
249
+ * `searchsorted` with side "left". Assumes this vector is sorted; the
250
+ * result is unspecified otherwise.
251
+ *
252
+ * @param needles - The values to locate
253
+ * @returns A VectorExpr of Integers holding one insertion index per needle
254
+ */
255
+ searchSorted(needles: SubtypeExprOrValue<VectorType<T>>): VectorExpr<IntegerType>;
256
+ /** Builds an elementwise comparison builtin returning a Boolean mask. */
257
+ private comparison;
258
+ /**
259
+ * Compares elementwise for equality under East's equality (NaN equals NaN,
260
+ * negative zero differs from positive zero), producing a Boolean mask.
261
+ *
262
+ * @param other - The vector to compare with (same length and element type)
263
+ * @returns A VectorExpr of Booleans, true where elements are equal
264
+ *
265
+ * @throws East runtime error if the vector lengths differ
266
+ */
267
+ eq(other: SubtypeExprOrValue<VectorType<T>>): VectorExpr<BooleanType>;
268
+ /**
269
+ * Compares elementwise with less-than under East's total order,
270
+ * producing a Boolean mask.
271
+ *
272
+ * @param other - The vector to compare with (same length and element type)
273
+ * @returns A VectorExpr of Booleans, true where this element is less
274
+ *
275
+ * @throws East runtime error if the vector lengths differ
276
+ */
277
+ lt(other: SubtypeExprOrValue<VectorType<T>>): VectorExpr<BooleanType>;
278
+ /**
279
+ * Compares elementwise with greater-than under East's total order,
280
+ * producing a Boolean mask.
281
+ *
282
+ * @param other - The vector to compare with (same length and element type)
283
+ * @returns A VectorExpr of Booleans, true where this element is greater
284
+ *
285
+ * @throws East runtime error if the vector lengths differ
286
+ */
287
+ gt(other: SubtypeExprOrValue<VectorType<T>>): VectorExpr<BooleanType>;
288
+ /**
289
+ * Selects elementwise from two vectors using this Boolean vector as the
290
+ * mask: element i of the result is `a[i]` where this mask is true, else
291
+ * `b[i]`.
292
+ *
293
+ * @param a - The vector supplying elements where the mask is true
294
+ * @param b - The vector supplying elements where the mask is false
295
+ * @returns A new VectorExpr of the selected elements
296
+ *
297
+ * @throws East runtime error if the vector lengths differ
298
+ */
299
+ select<T2>(a: Expr<VectorType<T2>>, b: SubtypeExprOrValue<VectorType<T2>>): VectorExpr<T2>;
300
+ /**
301
+ * Keeps the elements where the mask is true, in order — the dense
302
+ * analogue of the sparse noise-floor filter.
303
+ *
304
+ * @param mask - The Boolean vector deciding which elements survive
305
+ * @returns A new VectorExpr holding the surviving elements
306
+ *
307
+ * @throws East runtime error if the mask and vector lengths differ
308
+ */
309
+ compress(mask: SubtypeExprOrValue<VectorType<BooleanType>>): VectorExpr<T>;
310
+ /**
311
+ * Counts the true elements of this Boolean vector.
312
+ *
313
+ * @returns An IntegerExpr holding the number of true elements
314
+ */
315
+ countTrue(): IntegerExpr;
100
316
  }
101
317
  //# sourceMappingURL=vector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vector.d.ts","sourceRoot":"","sources":["../../../src/expr/vector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAc,YAAY,EAA4B,KAAK,SAAS,EAAqC,MAAM,aAAa,CAAC;AAE7J,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAa,IAAI,EAA6B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;GAQG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,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EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;IAIrE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC;IAa1F;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAW1E;;;;OAIG;IACH,SAAS,IAAI,WAAW;CAWzB"}
@@ -1,5 +1,6 @@
1
+ import {} from "../builtins.js";
1
2
  import { get_location_id } from "../location.js";
2
- import { IntegerType, VectorType, MatrixType, FunctionType, ArrayType, isSubtype, printType, isTypeEqual } from "../types.js";
3
+ import { BooleanType, FloatType, IntegerType, VectorType, MatrixType, FunctionType, ArrayType, isSubtype, printType, isTypeEqual } from "../types.js";
3
4
  import { valueOrExprToAst, valueOrExprToAstTyped } from "./ast.js";
4
5
  import { AstSymbol, Expr, FactorySymbol, TypeSymbol } from "./expr.js";
5
6
  /**
@@ -198,5 +199,399 @@ export class VectorExpr extends Expr {
198
199
  arguments: [this[AstSymbol], initAst, combineAst],
199
200
  });
200
201
  }
202
+ /** Requires a Float or Integer element type for the arithmetic builtins. */
203
+ numericElem(method) {
204
+ const t = this.element_type;
205
+ if (t.type !== "Float" && t.type !== "Integer") {
206
+ throw new Error(`Vector.${method} requires a Float or Integer element type, got ${printType(t)}`);
207
+ }
208
+ return t;
209
+ }
210
+ /** Requires a Boolean element type for the mask builtins. */
211
+ maskElem(method) {
212
+ if (this.element_type.type !== "Boolean") {
213
+ throw new Error(`Vector.${method} requires a Boolean element type, got ${printType(this.element_type)}`);
214
+ }
215
+ }
216
+ /** Builds a unary/binary elementwise builtin returning a vector of this element type. */
217
+ elementwise(builtin, args) {
218
+ return this[FactorySymbol]({
219
+ ast_type: "Builtin",
220
+ type: VectorType(this.element_type),
221
+ loc_id: get_location_id(),
222
+ builtin,
223
+ type_parameters: [this.element_type],
224
+ arguments: [this[AstSymbol], ...args],
225
+ });
226
+ }
227
+ /**
228
+ * Multiplies every element by a scalar, producing a new vector.
229
+ *
230
+ * @param alpha - The scalar factor (same type as the elements)
231
+ * @returns A new VectorExpr with every element scaled by alpha
232
+ */
233
+ scale(alpha) {
234
+ const elem = this.numericElem("scale");
235
+ return this.elementwise("VectorScale", [valueOrExprToAstTyped(alpha, elem)]);
236
+ }
237
+ /**
238
+ * Sums the elements in index order, left to right.
239
+ *
240
+ * The accumulation order is part of the cross-runtime contract: a
241
+ * reassociated float sum gives a different last bit. An empty vector sums
242
+ * to zero.
243
+ *
244
+ * @returns An expression of the element type holding the sum
245
+ */
246
+ sum() {
247
+ const elem = this.numericElem("sum");
248
+ return this[FactorySymbol]({
249
+ ast_type: "Builtin",
250
+ type: elem,
251
+ loc_id: get_location_id(),
252
+ builtin: "VectorSum",
253
+ type_parameters: [elem],
254
+ arguments: [this[AstSymbol]],
255
+ });
256
+ }
257
+ /**
258
+ * Adds a scaled vector elementwise: `this + alpha * other`.
259
+ *
260
+ * Add and subtract fall out at `alpha` of one and minus one.
261
+ *
262
+ * @param other - The vector to scale and add (same length and element type)
263
+ * @param alpha - The scalar factor applied to other
264
+ * @returns A new VectorExpr holding the combined elements
265
+ *
266
+ * @throws East runtime error if the vector lengths differ
267
+ */
268
+ addScaled(other, alpha) {
269
+ const elem = this.numericElem("addScaled");
270
+ return this.elementwise("VectorAddScaled", [
271
+ valueOrExprToAstTyped(other, VectorType(elem)),
272
+ valueOrExprToAstTyped(alpha, elem),
273
+ ]);
274
+ }
275
+ /**
276
+ * Multiplies two vectors elementwise.
277
+ *
278
+ * @param other - The vector to multiply with (same length and element type)
279
+ * @returns A new VectorExpr holding the elementwise products
280
+ *
281
+ * @throws East runtime error if the vector lengths differ
282
+ */
283
+ mul(other) {
284
+ const elem = this.numericElem("mul");
285
+ return this.elementwise("VectorMul", [valueOrExprToAstTyped(other, VectorType(elem))]);
286
+ }
287
+ /**
288
+ * Adds a scalar to every element, producing a new vector.
289
+ *
290
+ * @param value - The scalar addend (same type as the elements)
291
+ * @returns A new VectorExpr with value added to every element
292
+ */
293
+ addScalar(value) {
294
+ const elem = this.numericElem("addScalar");
295
+ return this.elementwise("VectorAddScalar", [valueOrExprToAstTyped(value, elem)]);
296
+ }
297
+ /**
298
+ * Computes the dot product, accumulating in index order, left to right.
299
+ *
300
+ * @param other - The vector to multiply with (same length and element type)
301
+ * @returns An expression of the element type holding the dot product
302
+ *
303
+ * @throws East runtime error if the vector lengths differ
304
+ */
305
+ dot(other) {
306
+ const elem = this.numericElem("dot");
307
+ return this[FactorySymbol]({
308
+ ast_type: "Builtin",
309
+ type: elem,
310
+ loc_id: get_location_id(),
311
+ builtin: "VectorDot",
312
+ type_parameters: [elem],
313
+ arguments: [this[AstSymbol], valueOrExprToAstTyped(other, VectorType(elem))],
314
+ });
315
+ }
316
+ /**
317
+ * Returns the largest element under East's total order (NaN is greatest).
318
+ * Ties resolve to the earliest occurrence.
319
+ *
320
+ * @returns An expression of the element type holding the maximum
321
+ *
322
+ * @throws East runtime error if the vector is empty
323
+ */
324
+ max() {
325
+ const elem = this.numericElem("max");
326
+ return this[FactorySymbol]({
327
+ ast_type: "Builtin",
328
+ type: elem,
329
+ loc_id: get_location_id(),
330
+ builtin: "VectorMax",
331
+ type_parameters: [elem],
332
+ arguments: [this[AstSymbol]],
333
+ });
334
+ }
335
+ /**
336
+ * Returns the smallest element under East's total order.
337
+ * Ties resolve to the earliest occurrence.
338
+ *
339
+ * @returns An expression of the element type holding the minimum
340
+ *
341
+ * @throws East runtime error if the vector is empty
342
+ */
343
+ min() {
344
+ const elem = this.numericElem("min");
345
+ return this[FactorySymbol]({
346
+ ast_type: "Builtin",
347
+ type: elem,
348
+ loc_id: get_location_id(),
349
+ builtin: "VectorMin",
350
+ type_parameters: [elem],
351
+ arguments: [this[AstSymbol]],
352
+ });
353
+ }
354
+ /**
355
+ * Returns the index of the largest element under East's total order.
356
+ * Ties resolve to the earliest occurrence.
357
+ *
358
+ * @returns An IntegerExpr holding the index of the maximum
359
+ *
360
+ * @throws East runtime error if the vector is empty
361
+ */
362
+ argMax() {
363
+ const elem = this.numericElem("argMax");
364
+ return this[FactorySymbol]({
365
+ ast_type: "Builtin",
366
+ type: IntegerType,
367
+ loc_id: get_location_id(),
368
+ builtin: "VectorArgMax",
369
+ type_parameters: [elem],
370
+ arguments: [this[AstSymbol]],
371
+ });
372
+ }
373
+ /**
374
+ * Returns the index of the smallest element under East's total order.
375
+ * Ties resolve to the earliest occurrence.
376
+ *
377
+ * @returns An IntegerExpr holding the index of the minimum
378
+ *
379
+ * @throws East runtime error if the vector is empty
380
+ */
381
+ argMin() {
382
+ const elem = this.numericElem("argMin");
383
+ return this[FactorySymbol]({
384
+ ast_type: "Builtin",
385
+ type: IntegerType,
386
+ loc_id: get_location_id(),
387
+ builtin: "VectorArgMin",
388
+ type_parameters: [elem],
389
+ arguments: [this[AstSymbol]],
390
+ });
391
+ }
392
+ /**
393
+ * Computes the arithmetic mean as a Float, accumulating in index order.
394
+ * Integer elements widen to Float per element; an empty vector yields NaN.
395
+ *
396
+ * @returns A FloatExpr holding the mean
397
+ */
398
+ mean() {
399
+ const elem = this.numericElem("mean");
400
+ return this[FactorySymbol]({
401
+ ast_type: "Builtin",
402
+ type: FloatType,
403
+ loc_id: get_location_id(),
404
+ builtin: "VectorMean",
405
+ type_parameters: [elem],
406
+ arguments: [this[AstSymbol]],
407
+ });
408
+ }
409
+ /**
410
+ * Computes the running sum in index order, left to right.
411
+ * Element i of the result is the sum of elements 0 through i.
412
+ *
413
+ * @returns A new VectorExpr of the running sums
414
+ */
415
+ cumSum() {
416
+ this.numericElem("cumSum");
417
+ return this.elementwise("VectorCumSum", []);
418
+ }
419
+ /**
420
+ * Takes the absolute value of every element.
421
+ *
422
+ * @returns A new VectorExpr with every element replaced by its magnitude
423
+ */
424
+ abs() {
425
+ this.numericElem("abs");
426
+ return this.elementwise("VectorAbs", []);
427
+ }
428
+ /**
429
+ * Clamps every element between lo and hi under East's total order:
430
+ * an element below lo becomes lo, one above hi becomes hi.
431
+ *
432
+ * @param lo - The lower bound (same type as the elements)
433
+ * @param hi - The upper bound (same type as the elements)
434
+ * @returns A new VectorExpr with every element clamped
435
+ */
436
+ clamp(lo, hi) {
437
+ const elem = this.numericElem("clamp");
438
+ return this.elementwise("VectorClamp", [
439
+ valueOrExprToAstTyped(lo, elem),
440
+ valueOrExprToAstTyped(hi, elem),
441
+ ]);
442
+ }
443
+ /**
444
+ * Gathers elements at the given indices: element j of the result is
445
+ * `this[indices[j]]`.
446
+ *
447
+ * @param indices - The indices to read, as a Vector of Integers
448
+ * @returns A new VectorExpr with one element per index
449
+ *
450
+ * @throws East runtime error if any index is out of bounds
451
+ */
452
+ gather(indices) {
453
+ return this.elementwise("VectorGather", [valueOrExprToAstTyped(indices, VectorType(IntegerType))]);
454
+ }
455
+ /**
456
+ * Returns a copy of this vector with `src[j]` added at `indices[j]` for
457
+ * each j in order. Duplicate indices accumulate in input order.
458
+ *
459
+ * @param indices - The target index for each source element
460
+ * @param src - The values to add (same length as indices)
461
+ * @returns A new VectorExpr with the additions applied
462
+ *
463
+ * @throws East runtime error if the index and source lengths differ, or any index is out of bounds
464
+ */
465
+ scatterAdd(indices, src) {
466
+ const elem = this.numericElem("scatterAdd");
467
+ return this.elementwise("VectorScatterAdd", [
468
+ valueOrExprToAstTyped(indices, VectorType(IntegerType)),
469
+ valueOrExprToAstTyped(src, VectorType(elem)),
470
+ ]);
471
+ }
472
+ /**
473
+ * Finds, for each needle, the leftmost insertion index that keeps this
474
+ * (sorted) vector sorted under East's total order — numpy's
475
+ * `searchsorted` with side "left". Assumes this vector is sorted; the
476
+ * result is unspecified otherwise.
477
+ *
478
+ * @param needles - The values to locate
479
+ * @returns A VectorExpr of Integers holding one insertion index per needle
480
+ */
481
+ searchSorted(needles) {
482
+ return this[FactorySymbol]({
483
+ ast_type: "Builtin",
484
+ type: VectorType(IntegerType),
485
+ loc_id: get_location_id(),
486
+ builtin: "VectorSearchSorted",
487
+ type_parameters: [this.element_type],
488
+ arguments: [this[AstSymbol], valueOrExprToAstTyped(needles, VectorType(this.element_type))],
489
+ });
490
+ }
491
+ /** Builds an elementwise comparison builtin returning a Boolean mask. */
492
+ comparison(builtin, other) {
493
+ return this[FactorySymbol]({
494
+ ast_type: "Builtin",
495
+ type: VectorType(BooleanType),
496
+ loc_id: get_location_id(),
497
+ builtin,
498
+ type_parameters: [this.element_type],
499
+ arguments: [this[AstSymbol], valueOrExprToAstTyped(other, VectorType(this.element_type))],
500
+ });
501
+ }
502
+ /**
503
+ * Compares elementwise for equality under East's equality (NaN equals NaN,
504
+ * negative zero differs from positive zero), producing a Boolean mask.
505
+ *
506
+ * @param other - The vector to compare with (same length and element type)
507
+ * @returns A VectorExpr of Booleans, true where elements are equal
508
+ *
509
+ * @throws East runtime error if the vector lengths differ
510
+ */
511
+ eq(other) {
512
+ return this.comparison("VectorEq", other);
513
+ }
514
+ /**
515
+ * Compares elementwise with less-than under East's total order,
516
+ * producing a Boolean mask.
517
+ *
518
+ * @param other - The vector to compare with (same length and element type)
519
+ * @returns A VectorExpr of Booleans, true where this element is less
520
+ *
521
+ * @throws East runtime error if the vector lengths differ
522
+ */
523
+ lt(other) {
524
+ return this.comparison("VectorLt", other);
525
+ }
526
+ /**
527
+ * Compares elementwise with greater-than under East's total order,
528
+ * producing a Boolean mask.
529
+ *
530
+ * @param other - The vector to compare with (same length and element type)
531
+ * @returns A VectorExpr of Booleans, true where this element is greater
532
+ *
533
+ * @throws East runtime error if the vector lengths differ
534
+ */
535
+ gt(other) {
536
+ return this.comparison("VectorGt", other);
537
+ }
538
+ /**
539
+ * Selects elementwise from two vectors using this Boolean vector as the
540
+ * mask: element i of the result is `a[i]` where this mask is true, else
541
+ * `b[i]`.
542
+ *
543
+ * @param a - The vector supplying elements where the mask is true
544
+ * @param b - The vector supplying elements where the mask is false
545
+ * @returns A new VectorExpr of the selected elements
546
+ *
547
+ * @throws East runtime error if the vector lengths differ
548
+ */
549
+ select(a, b) {
550
+ this.maskElem("select");
551
+ const elem = Expr.type(a).element;
552
+ return this[FactorySymbol]({
553
+ ast_type: "Builtin",
554
+ type: VectorType(elem),
555
+ loc_id: get_location_id(),
556
+ builtin: "VectorSelect",
557
+ type_parameters: [elem],
558
+ arguments: [this[AstSymbol], Expr.ast(a), valueOrExprToAstTyped(b, VectorType(elem))],
559
+ });
560
+ }
561
+ /**
562
+ * Keeps the elements where the mask is true, in order — the dense
563
+ * analogue of the sparse noise-floor filter.
564
+ *
565
+ * @param mask - The Boolean vector deciding which elements survive
566
+ * @returns A new VectorExpr holding the surviving elements
567
+ *
568
+ * @throws East runtime error if the mask and vector lengths differ
569
+ */
570
+ compress(mask) {
571
+ return this[FactorySymbol]({
572
+ ast_type: "Builtin",
573
+ type: VectorType(this.element_type),
574
+ loc_id: get_location_id(),
575
+ builtin: "VectorCompress",
576
+ type_parameters: [this.element_type],
577
+ arguments: [valueOrExprToAstTyped(mask, VectorType(BooleanType)), this[AstSymbol]],
578
+ });
579
+ }
580
+ /**
581
+ * Counts the true elements of this Boolean vector.
582
+ *
583
+ * @returns An IntegerExpr holding the number of true elements
584
+ */
585
+ countTrue() {
586
+ this.maskElem("countTrue");
587
+ return this[FactorySymbol]({
588
+ ast_type: "Builtin",
589
+ type: IntegerType,
590
+ loc_id: get_location_id(),
591
+ builtin: "VectorCountTrue",
592
+ type_parameters: [],
593
+ arguments: [this[AstSymbol]],
594
+ });
595
+ }
201
596
  }
202
597
  //# sourceMappingURL=vector.js.map