simple-squiggle

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

sum.transform.js (1015B)


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