time-to-botec

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

README.md (4018B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2019 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # itercusum
     22 
     23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative sum.
     24 
     25 <section class="intro">
     26 
     27 The cumulative sum is defined as
     28 
     29 <!-- <equation class="equation" label="eq:cumulative_sum" align="center" raw="\begin{align*} s_0 &= x_0 \\ s_1 &= x_1 + s_0 \\ s_2 &= x_2 + s_1 \\ s_n &= x_n + s_{n-1} = x_n + \sum_{i=0}^{n-1} x_i \end{align*}" alt="Equation for the cumulative sum."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\begin{align*} s_0 &amp;= x_0 \\ s_1 &amp;= x_1 + s_0 \\ s_2 &amp;= x_2 + s_1 \\ s_n &amp;= x_n + s_{n-1} = x_n + \sum_{i=0}^{n-1} x_i \end{align*}" data-equation="eq:cumulative_sum">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@755a26b39bb6429f6d0b6dd8d13bd0bd1ec5ba35/lib/node_modules/@stdlib/stats/iter/cusum/docs/img/equation_cumulative_sum.svg" alt="Equation for the cumulative sum.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 </section>
     39 
     40 <!-- /.intro -->
     41 
     42 <!-- Package usage documentation. -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var itercusum = require( '@stdlib/stats/iter/cusum' );
     50 ```
     51 
     52 #### itercusum( iterator )
     53 
     54 Returns an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative sum.
     55 
     56 ```javascript
     57 var array2iterator = require( '@stdlib/array/to-iterator' );
     58 
     59 var arr = array2iterator( [ 2.0, 1.0, 3.0, -7.0, -5.0 ] );
     60 var it = itercusum( arr );
     61 
     62 var s = it.next().value;
     63 // returns 2.0
     64 
     65 s = it.next().value;
     66 // returns 3.0
     67 
     68 s = it.next().value;
     69 // returns 6.0
     70 
     71 s = it.next().value;
     72 // returns -1.0
     73 
     74 s = it.next().value;
     75 // returns -6.0
     76 ```
     77 
     78 </section>
     79 
     80 <!-- /.usage -->
     81 
     82 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     83 
     84 <section class="notes">
     85 
     86 ## Notes
     87 
     88 -   If an iterated value is non-numeric (including `NaN`), the function returns `NaN` for **all** future iterations. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly.
     89 
     90 </section>
     91 
     92 <!-- /.notes -->
     93 
     94 <!-- Package usage examples. -->
     95 
     96 <section class="examples">
     97 
     98 ## Examples
     99 
    100 <!-- eslint no-undef: "error" -->
    101 
    102 ```javascript
    103 var runif = require( '@stdlib/random/iter/uniform' );
    104 var itercusum = require( '@stdlib/stats/iter/cusum' );
    105 
    106 // Create an iterator for generating uniformly distributed pseudorandom numbers:
    107 var rand = runif( -10.0, 10.0, {
    108     'seed': 1234,
    109     'iter': 100
    110 });
    111 
    112 // Create an iterator for iteratively computing a cumulative sum:
    113 var it = itercusum( rand );
    114 
    115 // Perform manual iteration...
    116 var v;
    117 while ( true ) {
    118     v = it.next();
    119     if ( typeof v.value === 'number' ) {
    120         console.log( 'sum: %d', v.value );
    121     }
    122     if ( v.done ) {
    123         break;
    124     }
    125 }
    126 ```
    127 
    128 </section>
    129 
    130 <!-- /.examples -->
    131 
    132 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    133 
    134 <section class="references">
    135 
    136 </section>
    137 
    138 <!-- /.references -->
    139 
    140 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    141 
    142 <section class="links">
    143 
    144 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    145 
    146 </section>
    147 
    148 <!-- /.links -->