time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

SqPointSet.js (2453B)


      1 import zipWith from "lodash/zipWith.js";
      2 import { PointSetDist } from "../../../dist/PointSetDist.js";
      3 import { ContinuousShape } from "../../../PointSet/Continuous.js";
      4 import { DiscreteShape } from "../../../PointSet/Discrete.js";
      5 import { MixedShape } from "../../../PointSet/Mixed.js";
      6 import { SqPointSetDistribution } from "./index.js";
      7 var Tag;
      8 (function (Tag) {
      9     Tag["Mixed"] = "Mixed";
     10     Tag["Discrete"] = "Discrete";
     11     Tag["Continuous"] = "Continuous";
     12 })(Tag || (Tag = {}));
     13 function shapePoints(x) {
     14     const xs = x.xyShape.xs;
     15     const ys = x.xyShape.ys;
     16     return zipWith(xs, ys, (x, y) => ({ x, y }));
     17 }
     18 export function wrapPointSet(value) {
     19     if (value instanceof ContinuousShape) {
     20         return new SqContinuousPointSet(value);
     21     }
     22     else if (value instanceof DiscreteShape) {
     23         return new SqDiscretePointSet(value);
     24     }
     25     else if (value instanceof MixedShape) {
     26         return new SqMixedPointSet(value);
     27     }
     28     throw new Error(`Unknown PointSet shape ${value}`);
     29 }
     30 class SqAbstractPointSet {
     31     constructor(_value) { }
     32 }
     33 export class SqMixedPointSet {
     34     constructor(_value) {
     35         this._value = _value;
     36         this.tag = Tag.Mixed;
     37     }
     38     get value() {
     39         return this._value;
     40     }
     41     asShape() {
     42         const v = this.value;
     43         return {
     44             discrete: shapePoints(v.discrete),
     45             continuous: shapePoints(v.continuous),
     46         };
     47     }
     48     asDistribution() {
     49         return new SqPointSetDistribution(new PointSetDist(this.value));
     50     }
     51 }
     52 export class SqDiscretePointSet {
     53     constructor(_value) {
     54         this._value = _value;
     55         this.tag = Tag.Discrete;
     56     }
     57     get value() {
     58         return this._value;
     59     }
     60     asShape() {
     61         const v = this.value;
     62         return {
     63             discrete: shapePoints(v),
     64             continuous: [],
     65         };
     66     }
     67     asDistribution() {
     68         return new SqPointSetDistribution(new PointSetDist(this.value.toMixed()));
     69     }
     70 }
     71 export class SqContinuousPointSet {
     72     constructor(_value) {
     73         this._value = _value;
     74         this.tag = Tag.Continuous;
     75     }
     76     get value() {
     77         return this._value;
     78     }
     79     asShape() {
     80         const v = this.value;
     81         return {
     82             discrete: [],
     83             continuous: shapePoints(v),
     84         };
     85     }
     86     asDistribution() {
     87         return new SqPointSetDistribution(new PointSetDist(this.value.toMixed()));
     88     }
     89 }
     90 //# sourceMappingURL=SqPointSet.js.map