You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -54,11 +54,11 @@ The function has the following parameters:
54
54
-**N**: number of indexed elements.
55
55
-**order**: sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
56
56
-**x**: first input [`Float32Array`][@stdlib/array/float32].
57
-
-**strideX**: `x` index increment.
57
+
-**strideX**: stride length for `x`.
58
58
-**y**: second input [`Float32Array`][@stdlib/array/float32].
59
-
-**strideY**: `y` index increment.
59
+
-**strideY**: stride length for `y`.
60
60
61
-
The `N` and `stride` parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element
61
+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element:
The function has the following additional parameters:
120
120
121
-
-**offsetX**: `x`starting index.
122
-
-**offsetY**: `y`starting index.
121
+
-**offsetX**: starting index for `x`.
122
+
-**offsetY**: starting index for `y`.
123
123
124
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`.
124
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements:
var discreteUniform =require( '@stdlib/random/array/discrete-uniform' );
171
169
var ssort2ins =require( '@stdlib/blas/ext/base/ssort2ins' );
172
170
173
-
var rand;
174
-
var sign;
175
-
var x;
176
-
var y;
177
-
var i;
178
-
179
-
x =newFloat32Array( 10 );
180
-
y =newFloat32Array( 10 ); // index array
181
-
for ( i =0; i <x.length; i++ ) {
182
-
rand =round( randu()*100.0 );
183
-
sign =randu();
184
-
if ( sign <0.5 ) {
185
-
sign =-1.0;
186
-
} else {
187
-
sign =1.0;
188
-
}
189
-
x[ i ] = sign * rand;
190
-
y[ i ] = i;
191
-
}
171
+
var x =discreteUniform( 10, -100, 100, {
172
+
'dtype':'float32'
173
+
});
174
+
var y =discreteUniform( 10, -100, 100, {
175
+
'dtype':'float32'
176
+
});
177
+
192
178
console.log( x );
193
179
console.log( y );
194
180
@@ -207,6 +193,137 @@ console.log( y );
207
193
208
194
* * *
209
195
196
+
<!-- C interface documentation. -->
197
+
198
+
<sectionclass="c">
199
+
200
+
## C APIs
201
+
202
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
203
+
204
+
<sectionclass="intro">
205
+
206
+
</section>
207
+
208
+
<!-- /.intro -->
209
+
210
+
<!-- C usage documentation. -->
211
+
212
+
<sectionclass="usage">
213
+
214
+
### Usage
215
+
216
+
```c
217
+
#include"stdlib/blas/ext/base/ssort2ins.h"
218
+
```
219
+
220
+
#### stdlib_strided_ssort2ins( N, order, \*X, strideX, \*Y, strideY )
221
+
222
+
Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using insertion sort.
223
+
224
+
```c
225
+
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f };
226
+
float y[] = { 0.0f, 1.0f, 2.0f, 3.0f };
227
+
228
+
stdlib_strided_ssort2ins( 4, 1.0f, x, 1, y, 1 );
229
+
```
230
+
231
+
The function accepts the following arguments:
232
+
233
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
234
+
- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
235
+
- **X**: `[inout] float*` first input array.
236
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
237
+
- **Y**: `[inout] float*` second input array.
238
+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using insertion sort and alternative indexing semantics.
251
+
252
+
```c
253
+
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f };
254
+
float y[] = { 0.0f, 1.0f, 2.0f, 3.0f };
255
+
256
+
stdlib_strided_ssort2ins_ndarray( 4, 1.0f, x, 1, 0, y, 1, 0 );
257
+
```
258
+
259
+
The function accepts the following arguments:
260
+
261
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
262
+
- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
263
+
- **X**: `[inout] float*` first input array.
264
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
265
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
266
+
- **Y**: `[inout] float*` second input array.
267
+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
268
+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
stdlib_strided_ssort2ins( N, 1.0f, x, strideX, y, strideY );
310
+
311
+
// Print the result:
312
+
for ( int i = 0; i < 8; i++ ) {
313
+
printf( "x[ %i ] = %f\n", i, x[ i ] );
314
+
printf( "y[ %i ] = %f\n", i, y[ i ] );
315
+
}
316
+
}
317
+
```
318
+
319
+
</section>
320
+
321
+
<!-- /.examples -->
322
+
323
+
</section>
324
+
325
+
<!-- /.c -->
326
+
210
327
## See Also
211
328
212
329
- <span class="package-name">[`@stdlib/blas/ext/base/dsort2ins`][@stdlib/blas/ext/base/dsort2ins]</span><span class="delimiter">: </span><span class="description">simultaneously sort two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort.</span>
0 commit comments