time-to-botec

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

README.md (5074B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2020 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 # iterBeta
     22 
     23 > Create an [iterator][mdn-iterator-protocol] which iteratively evaluates the [beta function][@stdlib/math/base/special/beta].
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var iterBeta = require( '@stdlib/math/iter/special/beta' );
     41 ```
     42 
     43 #### iterBeta( x, y )
     44 
     45 Returns an [iterator][mdn-iterator-protocol] which iteratively evaluates the [beta function][@stdlib/math/base/special/beta].
     46 
     47 ```javascript
     48 var array2iterator = require( '@stdlib/array/to-iterator' );
     49 
     50 var x = array2iterator( [ 1.0, 5.0, 4.0 ] );
     51 var y = array2iterator( [ 1.0, 0.2, 1.0 ] );
     52 
     53 var it = iterBeta( x, y );
     54 // returns <Object>
     55 
     56 var r = it.next().value;
     57 // returns 1.0
     58 
     59 r = it.next().value;
     60 // returns ~3.382
     61 
     62 r = it.next().value;
     63 // returns 0.25
     64 
     65 // ...
     66 ```
     67 
     68 The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties:
     69 
     70 -   **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished.
     71 -   **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object.
     72 
     73 If provided a numeric value as an [`iterator`][mdn-iterator-protocol] argument, the value is broadcast as an **infinite** [iterator][mdn-iterator-protocol] which **always** returns the provided value.
     74 
     75 ```javascript
     76 var array2iterator = require( '@stdlib/array/to-iterator' );
     77 
     78 var x = array2iterator( [ 1.0, 5.0 ] );
     79 
     80 var it = iterBeta( x, 2.0 );
     81 // returns <Object>
     82 
     83 var v = it.next().value;
     84 // returns 0.5
     85 
     86 v = it.next().value;
     87 // returns ~0.0333
     88 
     89 var bool = it.next().done;
     90 // returns true
     91 ```
     92 
     93 </section>
     94 
     95 <!-- /.usage -->
     96 
     97 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     98 
     99 <section class="notes">
    100 
    101 ## Notes
    102 
    103 -   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.
    104 -   The length of the returned [iterator][mdn-iterator-protocol] is equal to the length of the shortest provided [iterator][mdn-iterator-protocol]. In other words, the returned [iterator][mdn-iterator-protocol] ends once **one** of the provided [iterators][mdn-iterator-protocol] ends.
    105 -   If an environment supports `Symbol.iterator` **and** a provided [iterator][mdn-iterator-protocol] is iterable, the returned [iterator][mdn-iterator-protocol] is iterable.
    106 
    107 </section>
    108 
    109 <!-- /.notes -->
    110 
    111 <!-- Package usage examples. -->
    112 
    113 <section class="examples">
    114 
    115 ## Examples
    116 
    117 <!-- eslint no-undef: "error" -->
    118 
    119 ```javascript
    120 var uniform = require( '@stdlib/random/iter/uniform' );
    121 var iterBeta = require( '@stdlib/math/iter/special/beta' );
    122 
    123 // Create seeded iterators for generating pseudorandom numbers:
    124 var x = uniform( 0.0, 2.0, {
    125     'seed': 1234,
    126     'iter': 10
    127 });
    128 
    129 var y = uniform( 0.0, 2.0, {
    130     'seed': 4567,
    131     'iter': 10
    132 });
    133 
    134 // Create an iterator which consumes the pseudorandom number iterators:
    135 var it = iterBeta( x, y );
    136 
    137 // Perform manual iteration...
    138 var r;
    139 while ( true ) {
    140     r = it.next();
    141     if ( r.done ) {
    142         break;
    143     }
    144     console.log( r.value );
    145 }
    146 ```
    147 
    148 </section>
    149 
    150 <!-- /.examples -->
    151 
    152 <!-- 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. -->
    153 
    154 <section class="references">
    155 
    156 </section>
    157 
    158 <!-- /.references -->
    159 
    160 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    161 
    162 <section class="links">
    163 
    164 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    165 
    166 [@stdlib/math/base/special/beta]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/beta
    167 
    168 </section>
    169 
    170 <!-- /.links -->