simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

variance.transform.js (1150B)


      1 import { factory } from '../../utils/factory.js';
      2 import { errorTransform } from './utils/errorTransform.js';
      3 import { createVariance } from '../../function/statistics/variance.js';
      4 import { lastDimToZeroBase } from './utils/lastDimToZeroBase.js';
      5 var name = 'variance';
      6 var dependencies = ['typed', 'add', 'subtract', 'multiply', 'divide', 'apply', 'isNaN'];
      7 /**
      8  * Attach a transform function to math.var
      9  * Adds a property transform containing the transform function.
     10  *
     11  * This transform changed the `dim` parameter of function var
     12  * from one-based to zero based
     13  */
     14 
     15 export var createVarianceTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
     16   var {
     17     typed,
     18     add,
     19     subtract,
     20     multiply,
     21     divide,
     22     apply,
     23     isNaN
     24   } = _ref;
     25   var variance = createVariance({
     26     typed,
     27     add,
     28     subtract,
     29     multiply,
     30     divide,
     31     apply,
     32     isNaN
     33   });
     34   return typed(name, {
     35     '...any': function any(args) {
     36       args = lastDimToZeroBase(args);
     37 
     38       try {
     39         return variance.apply(null, args);
     40       } catch (err) {
     41         throw errorTransform(err);
     42       }
     43     }
     44   });
     45 }, {
     46   isTransformFunction: true
     47 });