README.md (3601B)
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 # itersumabs 22 23 > Compute the sum of absolute values for all [iterated][mdn-iterator-protocol] values. 24 25 <section class="intro"> 26 27 The sum of absolute values is defined as 28 29 <!-- <equation class="equation" label="eq:sum_absolute_values" align="center" raw="s = \sum_{i=0}^{n-1} |x_i|" alt="Equation for the sum of absolute values."> --> 30 31 <div class="equation" align="center" data-raw-text="s = \sum_{i=0}^{n-1} |x_i|" data-equation="eq:sum_absolute_values"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e7ac225deb396ee6d2b4d5fc1a2faa645582349f/lib/node_modules/@stdlib/stats/iter/sumabs/docs/img/equation_sum_absolute_values.svg" alt="Equation for the sum of absolute values."> 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 itersumabs = require( '@stdlib/stats/iter/sumabs' ); 50 ``` 51 52 #### itersumabs( iterator ) 53 54 Computes the sum of absolute values for 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 = itersumabs( arr ); 62 // returns 10.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 itersumabs = require( '@stdlib/stats/iter/sumabs' ); 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 of absolute values: 101 var s = itersumabs( rand ); 102 // returns <number> 103 104 console.log( 'sumabs: %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 -->