time-to-botec

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

README.md (3402B)


      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 # itersum
     22 
     23 > Compute the sum of all [iterated][mdn-iterator-protocol] values.
     24 
     25 <section class="intro">
     26 
     27 The sum is defined as
     28 
     29 <!-- <equation class="equation" label="eq:sum" align="center" raw="s = \sum_{i=0}^{n-1} x_i" alt="Equation for the sum."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="s = \sum_{i=0}^{n-1} x_i" data-equation="eq:sum">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e7ac225deb396ee6d2b4d5fc1a2faa645582349f/lib/node_modules/@stdlib/stats/iter/sum/docs/img/equation_sum.svg" alt="Equation for the 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 itersum = require( '@stdlib/stats/iter/sum' );
     50 ```
     51 
     52 #### itersum( iterator )
     53 
     54 Computes the sum of all [iterated][mdn-iterator-protocol] values.
     55 
     56 ```javascript
     57 var array2iterator = require( '@stdlib/array/to-iterator' );
     58 
     59 var arr = array2iterator( [ 1.0, 2.0, -3.5, 4.0 ] );
     60 
     61 var s = itersum( arr );
     62 // returns 3.5
     63 ```
     64 
     65 </section>
     66 
     67 <!-- /.usage -->
     68 
     69 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     70 
     71 <section class="notes">
     72 
     73 ## Notes
     74 
     75 -   If an iterated value is non-numeric (including `NaN`), the returned [`iterator`][mdn-iterator-protocol] returns `NaN`. 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.
     76 -   For iterators which can generate many values or which may output large numbers, care should be taken to prevent overflow.
     77 
     78 </section>
     79 
     80 <!-- /.notes -->
     81 
     82 <!-- Package usage examples. -->
     83 
     84 <section class="examples">
     85 
     86 ## Examples
     87 
     88 <!-- eslint no-undef: "error" -->
     89 
     90 ```javascript
     91 var runif = require( '@stdlib/random/iter/uniform' );
     92 var itersum = require( '@stdlib/stats/iter/sum' );
     93 
     94 // Create an iterator for generating uniformly distributed pseudorandom numbers:
     95 var rand = runif( -10.0, 10.0, {
     96     'seed': 1234,
     97     'iter': 100
     98 });
     99 
    100 // Compute the sum:
    101 var s = itersum( rand );
    102 // returns <number>
    103 
    104 console.log( 'Sum: %d.', s );
    105 ```
    106 
    107 </section>
    108 
    109 <!-- /.examples -->
    110 
    111 <!-- 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. -->
    112 
    113 <section class="references">
    114 
    115 </section>
    116 
    117 <!-- /.references -->
    118 
    119 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    120 
    121 <section class="links">
    122 
    123 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    124 
    125 </section>
    126 
    127 <!-- /.links -->