time-to-botec

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

README.md (5063B)


      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 # cumaxabs
     22 
     23 > Calculate the cumulative maximum absolute value of a strided array.
     24 
     25 <section class="intro">
     26 
     27 </section>
     28 
     29 <!-- /.intro -->
     30 
     31 <section class="usage">
     32 
     33 ## Usage
     34 
     35 ```javascript
     36 var cumaxabs = require( '@stdlib/stats/base/cumaxabs' );
     37 ```
     38 
     39 #### cumaxabs( N, x, strideX, y, strideY )
     40 
     41 Computes the cumulative maximum absolute value of a strided array.
     42 
     43 ```javascript
     44 var x = [ 1.0, -2.0, 2.0 ];
     45 var y = [ 0.0, 0.0, 0.0 ];
     46 
     47 cumaxabs( x.length, x, 1, y, 1 );
     48 // y => [ 1.0, 2.0, 2.0 ]
     49 ```
     50 
     51 The function has the following parameters:
     52 
     53 -   **N**: number of indexed elements.
     54 -   **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
     55 -   **strideX**: index increment for `x`.
     56 -   **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
     57 -   **strideY**: index increment for `y`.
     58 
     59 The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative maximum absolute value of every other element in `x`,
     60 
     61 ```javascript
     62 var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
     63 var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
     64 
     65 var v = cumaxabs( 4, x, 2, y, 1 );
     66 // y => [ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
     67 ```
     68 
     69 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
     70 
     71 <!-- eslint-disable stdlib/capitalized-comments -->
     72 
     73 ```javascript
     74 var Float64Array = require( '@stdlib/array/float64' );
     75 
     76 // Initial arrays...
     77 var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
     78 var y0 = new Float64Array( x0.length );
     79 
     80 // Create offset views...
     81 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
     82 var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
     83 
     84 cumaxabs( 4, x1, -2, y1, 1 );
     85 // y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0, 0.0 ]
     86 ```
     87 
     88 #### cumaxabs.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
     89 
     90 Computes the cumulative maximum absolute value of a strided array using alternative indexing semantics.
     91 
     92 ```javascript
     93 var x = [ 1.0, -2.0, 2.0 ];
     94 var y = [ 0.0, 0.0, 0.0 ];
     95 
     96 cumaxabs.ndarray( x.length, x, 1, 0, y, 1, 0 );
     97 // y => [ 1.0, 2.0, 2.0 ]
     98 ```
     99 
    100 The function has the following additional parameters:
    101 
    102 -   **offsetX**: starting index for `x`.
    103 -   **offsetY**: starting index for `y`.
    104 
    105 While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative maximum absolute value of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element
    106 
    107 ```javascript
    108 var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
    109 var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
    110 
    111 cumaxabs.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
    112 // y => [ 0.0, 0.0, 0.0, 0.0, 4.0, 2.0, 2.0, 1.0 ]
    113 ```
    114 
    115 </section>
    116 
    117 <!-- /.usage -->
    118 
    119 <section class="notes">
    120 
    121 ## Notes
    122 
    123 -   If `N <= 0`, both functions return `y` unchanged.
    124 -   Depending on the environment, the typed versions ([`dcumaxabs`][@stdlib/stats/base/dcumaxabs], [`scumaxabs`][@stdlib/stats/base/scumaxabs], etc.) are likely to be significantly more performant.
    125 
    126 </section>
    127 
    128 <!-- /.notes -->
    129 
    130 <section class="examples">
    131 
    132 ## Examples
    133 
    134 <!-- eslint no-undef: "error" -->
    135 
    136 ```javascript
    137 var randu = require( '@stdlib/random/base/randu' );
    138 var round = require( '@stdlib/math/base/special/round' );
    139 var Float64Array = require( '@stdlib/array/float64' );
    140 var cumaxabs = require( '@stdlib/stats/base/cumaxabs' );
    141 
    142 var y;
    143 var x;
    144 var i;
    145 
    146 x = new Float64Array( 10 );
    147 y = new Float64Array( x.length );
    148 for ( i = 0; i < x.length; i++ ) {
    149     x[ i ] = round( randu()*100.0 );
    150 }
    151 console.log( x );
    152 console.log( y );
    153 
    154 cumaxabs( x.length, x, 1, y, -1 );
    155 console.log( y );
    156 ```
    157 
    158 </section>
    159 
    160 <!-- /.examples -->
    161 
    162 <section class="references">
    163 
    164 </section>
    165 
    166 <!-- /.references -->
    167 
    168 <section class="links">
    169 
    170 [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
    171 
    172 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
    173 
    174 [@stdlib/stats/base/dcumaxabs]: https://www.npmjs.com/package/@stdlib/stats/tree/main/base/dcumaxabs
    175 
    176 [@stdlib/stats/base/scumaxabs]: https://www.npmjs.com/package/@stdlib/stats/tree/main/base/scumaxabs
    177 
    178 </section>
    179 
    180 <!-- /.links -->