time-to-botec

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

README.md (7803B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 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 # dabs
     22 
     23 > Compute the [absolute value][@stdlib/math/base/special/abs] for each element in a double-precision floating-point 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 dabs = require( '@stdlib/math/strided/special/dabs' );
     37 ```
     38 
     39 #### dabs( N, x, strideX, y, strideY )
     40 
     41 Computes the [absolute value][@stdlib/math/base/special/abs] for each element in a double-precision floating-point strided array `x` and assigns the results to elements in a double-precision floating-point strided array `y`.
     42 
     43 ```javascript
     44 var Float64Array = require( '@stdlib/array/float64' );
     45 
     46 var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
     47 
     48 // Compute the absolute values in-place:
     49 dabs( x.length, x, 1, x, 1 );
     50 // x => <Float64Array>[ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ]
     51 ```
     52 
     53 The function accepts the following arguments:
     54 
     55 -   **N**: number of indexed elements.
     56 -   **x**: input [`Float64Array`][@stdlib/array/float64].
     57 -   **strideX**: index increment for `x`.
     58 -   **y**: output [`Float64Array`][@stdlib/array/float64].
     59 -   **strideY**: index increment for `y`.
     60 
     61 The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to index every other value in `x` and to index the first `N` elements of `y` in reverse order,
     62 
     63 ```javascript
     64 var Float64Array = require( '@stdlib/array/float64' );
     65 var floor = require( '@stdlib/math/base/special/floor' );
     66 
     67 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
     68 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
     69 
     70 var N = floor( x.length / 2 );
     71 
     72 dabs( N, x, 2, y, -1 );
     73 // y => <Float64Array>[ 5.0, 3.0, 1.0, 0.0, 0.0, 0.0 ]
     74 ```
     75 
     76 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][@stdlib/array/float64] views.
     77 
     78 ```javascript
     79 var Float64Array = require( '@stdlib/array/float64' );
     80 var floor = require( '@stdlib/math/base/special/floor' );
     81 
     82 // Initial arrays...
     83 var x0 = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
     84 var y0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
     85 
     86 // Create offset views...
     87 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
     88 var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
     89 
     90 var N = floor( x0.length / 2 );
     91 
     92 dabs( N, x1, -2, y1, 1 );
     93 // y0 => <Float64Array>[ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ]
     94 ```
     95 
     96 #### dabs.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
     97 
     98 Computes the [absolute value][@stdlib/math/base/special/abs] for each element in a double-precision floating-point strided array `x` and assigns the results to elements in a double-precision floating-point strided array `y` using alternative indexing semantics.
     99 
    100 ```javascript
    101 var Float64Array = require( '@stdlib/array/float64' );
    102 
    103 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );
    104 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
    105 
    106 dabs.ndarray( x.length, x, 1, 0, y, 1, 0 );
    107 // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
    108 ```
    109 
    110 The function accepts the following additional arguments:
    111 
    112 -   **offsetX**: starting index for `x`.
    113 -   **offsetY**: starting index for `y`.
    114 
    115 While [`typed array`][@stdlib/array/float64] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to index every other value in `x` starting from the second value and to index the last `N` elements in `y`,
    116 
    117 ```javascript
    118 var Float64Array = require( '@stdlib/array/float64' );
    119 var floor = require( '@stdlib/math/base/special/floor' );
    120 
    121 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
    122 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
    123 
    124 var N = floor( x.length / 2 );
    125 
    126 dabs.ndarray( N, x, 2, 1, y, -1, y.length-1 );
    127 // y => <Float64Array>[ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ]
    128 ```
    129 
    130 </section>
    131 
    132 <!-- /.usage -->
    133 
    134 <section class="notes">
    135 
    136 </section>
    137 
    138 <!-- /.notes -->
    139 
    140 <section class="examples">
    141 
    142 ## Examples
    143 
    144 <!-- eslint no-undef: "error" -->
    145 
    146 ```javascript
    147 var round = require( '@stdlib/math/base/special/round' );
    148 var randu = require( '@stdlib/random/base/randu' );
    149 var Float64Array = require( '@stdlib/array/float64' );
    150 var dabs = require( '@stdlib/math/strided/special/dabs' );
    151 
    152 var x = new Float64Array( 10 );
    153 var y = new Float64Array( 10 );
    154 
    155 var i;
    156 for ( i = 0; i < x.length; i++ ) {
    157     x[ i ] = round( (randu()*200.0) - 100.0 );
    158 }
    159 console.log( x );
    160 console.log( y );
    161 
    162 dabs.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
    163 console.log( y );
    164 ```
    165 
    166 </section>
    167 
    168 <!-- /.examples -->
    169 
    170 <!-- C interface documentation. -->
    171 
    172 * * *
    173 
    174 <section class="c">
    175 
    176 ## C APIs
    177 
    178 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
    179 
    180 <section class="intro">
    181 
    182 </section>
    183 
    184 <!-- /.intro -->
    185 
    186 <!-- C usage documentation. -->
    187 
    188 <section class="usage">
    189 
    190 ### Usage
    191 
    192 ```c
    193 #include "stdlib/math/strided/special/dabs.h"
    194 ```
    195 
    196 #### stdlib_strided_dabs( N, \*X, strideX, \*Y, strideY )
    197 
    198 Computes the absolute value for each element in a double-precision floating-point strided array `X` and assigns the results to elements in a double-precision floating-point strided array `Y`.
    199 
    200 ```c
    201 #include <stdint.h>
    202 
    203 double X[] = { -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 };
    204 double Y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
    205 
    206 int64_t N = 4;
    207 
    208 stdlib_strided_dabs( N, X, 2, Y, 2 );
    209 ```
    210 
    211 The function accepts the following arguments:
    212 
    213 -   **N**: `[in] int64_t` number of indexed elements.
    214 -   **X**: `[in] double*` input array.
    215 -   **strideX**: `[in] int64_t` index increment for `X`.
    216 -   **Y**: `[out] double*` output array.
    217 -   **strideY**: `[in] int64_t` index increment for `Y`.
    218 
    219 ```c
    220 void stdlib_strided_dabs( const int64_t N, const double *X, const int64_t strideX, double *Y, const int64_t strideY );
    221 ```
    222 
    223 </section>
    224 
    225 <!-- /.usage -->
    226 
    227 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    228 
    229 <section class="notes">
    230 
    231 </section>
    232 
    233 <!-- /.notes -->
    234 
    235 <!-- C API usage examples. -->
    236 
    237 <section class="examples">
    238 
    239 ### Examples
    240 
    241 ```c
    242 #include "stdlib/math/strided/special/dabs.h"
    243 #include <stdint.h>
    244 #include <stdio.h>
    245 
    246 int main() {
    247     // Create an input strided array:
    248     double X[] = { -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 };
    249 
    250     // Create an output strided array:
    251     double Y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
    252 
    253     // Specify the number of elements:
    254     int64_t N = 4;
    255 
    256     // Specify the stride lengths:
    257     int64_t strideX = 2;
    258     int64_t strideY = 2;
    259 
    260     // Compute the absolute value element-wise:
    261     stdlib_strided_dabs( N, X, strideX, Y, strideY );
    262 
    263     // Print the result:
    264     for ( int i = 0; i < 8; i++ ) {
    265         printf( "Y[ %i ] = %lf\n", i, Y[ i ] );
    266     }
    267 }
    268 ```
    269 
    270 </section>
    271 
    272 <!-- /.examples -->
    273 
    274 </section>
    275 
    276 <!-- /.c -->
    277 
    278 <section class="links">
    279 
    280 [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64
    281 
    282 [@stdlib/math/base/special/abs]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/abs
    283 
    284 </section>
    285 
    286 <!-- /.links -->