README.md (7406B)
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 # dramp 22 23 > Evaluate the [ramp function][@stdlib/math/base/special/ramp] 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 dramp = require( '@stdlib/math/strided/special/dramp' ); 37 ``` 38 39 #### dramp( N, x, strideX, y, strideY ) 40 41 Evaluates the [ramp function][@stdlib/math/base/special/ramp] 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( [ 1.1, 2.5, -3.5, 4.0, -5.9 ] ); 47 48 // Perform operation in-place: 49 dramp( x.length, x, 1, x, 1 ); 50 // x => <Float64Array>[ 1.1, 2.5, 0.0, 4.0, 0.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 66 var x = new Float64Array( [ 1.1, 2.5, -3.5, 4.0, -5.9, 6.4 ] ); 67 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 68 69 dramp( 3, x, 2, y, -1 ); 70 // y => <Float64Array>[ 0.0, 0.0, 1.1, 0.0, 0.0, 0.0 ] 71 ``` 72 73 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][@stdlib/array/float64] views. 74 75 ```javascript 76 var Float64Array = require( '@stdlib/array/float64' ); 77 78 // Initial arrays... 79 var x0 = new Float64Array( [ 1.1, 2.5, -3.5, 4.0, -5.9, 6.4 ] ); 80 var y0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 81 82 // Create offset views... 83 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 84 var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element 85 86 dramp( 3, x1, -2, y1, 1 ); 87 // y0 => <Float64Array>[ 0.0, 0.0, 0.0, 6.4, 4.0, 2.5 ] 88 ``` 89 90 #### dramp.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) 91 92 Evaluates the [ramp function][@stdlib/math/base/special/ramp] 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. 93 94 ```javascript 95 var Float64Array = require( '@stdlib/array/float64' ); 96 97 var x = new Float64Array( [ 1.1, 2.5, -3.5, 4.0, -5.9 ] ); 98 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 99 100 dramp.ndarray( x.length, x, 1, 0, y, 1, 0 ); 101 // y => <Float64Array>[ 1.1, 2.5, 0.0, 4.0, 0.0 ] 102 ``` 103 104 The function accepts the following additional arguments: 105 106 - **offsetX**: starting index for `x`. 107 - **offsetY**: starting index for `y`. 108 109 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`, 110 111 ```javascript 112 var Float64Array = require( '@stdlib/array/float64' ); 113 114 var x = new Float64Array( [ 1.1, 2.5, -3.5, 4.0, -5.9, 6.4 ] ); 115 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 116 117 dramp.ndarray( 3, x, 2, 1, y, -1, y.length-1 ); 118 // y => <Float64Array>[ 0.0, 0.0, 0.0, 6.4, 4.0, 2.5 ] 119 ``` 120 121 </section> 122 123 <!-- /.usage --> 124 125 <section class="notes"> 126 127 </section> 128 129 <!-- /.notes --> 130 131 <section class="examples"> 132 133 ## Examples 134 135 <!-- eslint no-undef: "error" --> 136 137 ```javascript 138 var uniform = require( '@stdlib/random/base/uniform' ); 139 var Float64Array = require( '@stdlib/array/float64' ); 140 var dramp = require( '@stdlib/math/strided/special/dramp' ); 141 142 var x = new Float64Array( 10 ); 143 var y = new Float64Array( 10 ); 144 145 var i; 146 for ( i = 0; i < x.length; i++ ) { 147 x[ i ] = uniform( -10.0, 10.0 ); 148 } 149 console.log( x ); 150 console.log( y ); 151 152 dramp.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); 153 console.log( y ); 154 ``` 155 156 </section> 157 158 <!-- /.examples --> 159 160 <!-- C interface documentation. --> 161 162 * * * 163 164 <section class="c"> 165 166 ## C APIs 167 168 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 169 170 <section class="intro"> 171 172 </section> 173 174 <!-- /.intro --> 175 176 <!-- C usage documentation. --> 177 178 <section class="usage"> 179 180 ### Usage 181 182 ```c 183 #include "stdlib/math/strided/special/dramp.h" 184 ``` 185 186 #### stdlib_strided_dramp( N, \*X, strideX, \*Y, strideY ) 187 188 Evaluates the ramp function for each element in a double-precision floating-point strided array `X` and assigns the results to elements in a single-precision floating-point strided array `Y`. 189 190 ```c 191 #include <stdint.h> 192 193 double X[] = { 1.1, 2.5, -3.5, 4.0, -5.9, 6.4, -7.0, 8.2 }; 194 double Y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; 195 196 int64_t N = 4; 197 198 stdlib_strided_dramp( N, X, 2, Y, 2 ); 199 ``` 200 201 The function accepts the following arguments: 202 203 - **N**: `[in] int64_t` number of indexed elements. 204 - **X**: `[in] double*` input array. 205 - **strideX**: `[in] int64_t` index increment for `X`. 206 - **Y**: `[out] double*` output array. 207 - **strideY**: `[in] int64_t` index increment for `Y`. 208 209 ```c 210 void stdlib_strided_dramp( const int64_t N, const double *X, const int64_t strideX, double *Y, const int64_t strideY ); 211 ``` 212 213 </section> 214 215 <!-- /.usage --> 216 217 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 218 219 <section class="notes"> 220 221 </section> 222 223 <!-- /.notes --> 224 225 <!-- C API usage examples. --> 226 227 <section class="examples"> 228 229 ### Examples 230 231 ```c 232 #include "stdlib/math/strided/special/dramp.h" 233 #include <stdint.h> 234 #include <stdio.h> 235 236 int main() { 237 // Create an input strided array: 238 double X[] = { 1.1, 2.5, -3.5, 4.0, -5.9, 6.4, -7.0, 8.2 }; 239 240 // Create an output strided array: 241 double Y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; 242 243 // Specify the number of elements: 244 int64_t N = 4; 245 246 // Specify the stride lengths: 247 int64_t strideX = 2; 248 int64_t strideY = 2; 249 250 // Compute the results: 251 stdlib_strided_dramp( N, X, strideX, Y, strideY ); 252 253 // Print the results: 254 for ( int i = 0; i < 8; i++ ) { 255 printf( "Y[ %i ] = %lf\n", i, Y[ i ] ); 256 } 257 } 258 ``` 259 260 </section> 261 262 <!-- /.examples --> 263 264 </section> 265 266 <!-- /.c --> 267 268 <section class="links"> 269 270 [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64 271 272 [@stdlib/math/base/special/ramp]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/ramp 273 274 </section> 275 276 <!-- /.links -->