time-to-botec

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

README.md (8918B)


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