Skip to content

Commit 8a4ff43

Browse files
fix: update documentation and benchmarks to use double for order parameter
1 parent a9cfe13 commit 8a4ff43

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The function has the following parameters:
5050
- **x**: input [`Float64Array`][@stdlib/array/float64].
5151
- **strideX**: stride length.
5252

53-
The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to sort every other element
53+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to sort every other element:
5454

5555
```javascript
5656
var Float64Array = require( '@stdlib/array/float64' );
@@ -94,7 +94,7 @@ The function has the following additional parameters:
9494

9595
- **offsetX**: starting index.
9696

97-
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:
97+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on starting a index. For example, to access only the last three elements:
9898

9999
```javascript
100100
var Float64Array = require( '@stdlib/array/float64' );
@@ -178,7 +178,7 @@ Sorts a double-precision floating-point strided array using heapsort.
178178
```c
179179
double x[] = { 1.0, -2.0, 3.0, -4.0 };
180180

181-
stdlib_strided_dsorthp( 2, -1, x, 1 );
181+
stdlib_strided_dsorthp( 2, -1.0, x, 1 );
182182
```
183183
184184
The function accepts the following arguments:
@@ -189,7 +189,7 @@ The function accepts the following arguments:
189189
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
190190
191191
```c
192-
stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX );
192+
stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX );
193193
```
194194

195195
<!--lint disable maximum-heading-length-->
@@ -203,19 +203,19 @@ Sorts a double-precision floating-point strided array using heapsort and alterna
203203
```c
204204
double x[] = { 1.0, -2.0, 3.0, -4.0 };
205205

206-
stdlib_strided_dsorthp_ndarray( 4, 1, x, 1, 0 );
206+
stdlib_strided_dsorthp_ndarray( 4, 1.0, x, 1, 0 );
207207
```
208208
209209
The function accepts the following arguments:
210210
211211
- **N**: `[in] CBLAS_INT` number of indexed elements.
212-
- **order**: `[in] CBLAS_INT` sort order.
212+
- **order**: `[in] double` sort order.
213213
- **X**: `[inout] double*` input array. 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.
214-
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
215-
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
214+
- **strideX**: `[in] CBLAS_INT` stride length.
215+
- **offsetX**: `[in] CBLAS_INT` starting index.
216216
217217
```c
218-
stdlib_strided_dsorthp_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX );
218+
stdlib_strided_dsorthp_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
219219
```
220220

221221
</section>

lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static double benchmark1( int iterations, int len ) {
105105
}
106106
t = tic();
107107
for ( i = 0; i < iterations; i++ ) {
108-
stdlib_strided_dsorthp( len, 1, x, 1 );
108+
stdlib_strided_dsorthp( len, 1.0, x, 1 );
109109
if ( x[ 0 ] != x[ 0 ] ) {
110110
printf( "should not return NaN\n" );
111111
break;
@@ -136,7 +136,7 @@ static double benchmark2( int iterations, int len ) {
136136
}
137137
t = tic();
138138
for ( i = 0; i < iterations; i++ ) {
139-
stdlib_strided_dsorthp_ndarray( len, 1, x, 1, 0);
139+
stdlib_strided_dsorthp_ndarray( len, 1.0, x, 1, 0);
140140
if ( x[ 0 ] != x[ 0 ] ) {
141141
printf( "should not return NaN\n" );
142142
break;

lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{{alias}}( N, order, x, strideX )
33
Sorts a double-precision floating-point strided array using heapsort.
44

5-
The `N` and stride parameters determine which elements in `x` are accessed
6-
at runtime.
5+
The `N` and stride parameters determine which elements in the strided array
6+
are accessed at runtime.
77

88
Indexing is relative to the first index. To introduce an offset, use typed
99
array views.
@@ -73,8 +73,8 @@
7373
alternative indexing semantics.
7474

7575
While typed array views mandate a view offset based on the underlying
76-
buffer, the `offsetX` parameter supports indexing semantics based on a
77-
starting index.
76+
buffer, the offset parameter supports indexing semantics based on a starting
77+
index.
7878

7979
Parameters
8080
----------
@@ -92,7 +92,7 @@
9292
Stride length.
9393

9494
offsetX: integer
95-
Starting index of `x`.
95+
Starting index.
9696

9797
Returns
9898
-------

lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ extern "C" {
3131
/**
3232
* Sorts a double-precision floating-point strided array using heapsort.
3333
*/
34-
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX );
34+
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX );
3535

3636
/**
3737
* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
3838
*/
39-
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX );
39+
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
4040

4141
#ifdef __cplusplus
4242
}

lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ var ndarray = require( './ndarray.js' );
5353
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
5454
*/
5555
function dsorthp( N, order, x, strideX ) {
56-
var offsetX;
57-
offsetX = stride2offset( N, strideX );
58-
return ndarray( N, order, x, strideX, offsetX );
56+
return ndarray( N, order, x, strideX, stride2offset( N, strideX ) );
5957
}
6058

6159

lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var addon = require( './../src/addon.node' );
4343
* dsorthp( x.length, 1.0, x, 1, 0 );
4444
*/
4545
function dsorthp( N, order, x, strideX, offsetX ) {
46-
addon.ndarray( N, order, x, strideX, offsetX);
46+
addon.ndarray( N, order, x, strideX, offsetX );
4747
return x;
4848
}
4949

lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* @param X input array
4141
* @param strideX stride length
4242
*/
43-
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX) {
43+
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX) {
4444
CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
4545
return API_SUFFIX(stdlib_strided_dsorthp_ndarray)( N, order, X, strideX, ox );
4646
}
@@ -63,9 +63,11 @@ void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order,
6363
* @param strideX stride length
6464
* @param offsetX starting index
6565
*/
66-
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ) {
66+
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
6767
CBLAS_INT parent;
6868
CBLAS_INT child;
69+
CBLAS_INT ox;
70+
CBLAS_INT sx;
6971
CBLAS_INT n;
7072
CBLAS_INT i;
7173
CBLAS_INT j;
@@ -79,8 +81,8 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double
7981
}
8082
// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...
8183
if ( order < 0.0 ) {
82-
strideX *= -1;
83-
offsetX -= (N-1) * strideX;
84+
sx = -strideX;
85+
ox = offsetX - ( (N-1)*sx );
8486
}
8587
// Set the initial heap size:
8688
n = N;
@@ -93,7 +95,7 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double
9395
if ( parent > 0 ) {
9496
// We need to build the heap...
9597
parent -= 1;
96-
t = X[ offsetX+(parent*strideX) ];
98+
t = X[ ox+(parent*sx) ];
9799
} else {
98100
// Reduce the heap size:
99101
n -= 1;
@@ -103,11 +105,11 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double
103105
return;
104106
}
105107
// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
106-
i = offsetX + (n*strideX);
108+
i = ox + (n*sx);
107109
t = X[ i ];
108110

109111
// Move the heap root to its sorted position:
110-
X[ i ] = X[ offsetX ];
112+
X[ i ] = X[ ox ];
111113
}
112114
// We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
113115

@@ -121,19 +123,19 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double
121123
// Find the largest child...
122124
k = child + 1;
123125
if ( k < n ) {
124-
v1 = X[ offsetX+(k*strideX) ];
125-
v2 = X[ offsetX+(child*strideX) ];
126+
v1 = X[ ox+(k*sx) ];
127+
v2 = X[ ox+(child*sx) ];
126128

127129
// Check if a "right" child exists and is "bigger"...
128130
if ( v1 > v2 || stdlib_base_is_nan( v1 ) || (v1 == v2 && stdlib_base_is_positive_zero( v1 ) ) ) {
129131
child += 1;
130132
}
131133
}
132134
// Check if the largest child is bigger than `t`...
133-
v1 = X[ offsetX+(child*strideX) ];
135+
v1 = X[ ox+(child*sx) ];
134136
if ( v1 > t || stdlib_base_is_nan( v1 ) || ( v1 == t && stdlib_base_is_positive_zero( v1 ) ) ) {
135137
// Insert the larger child value:
136-
X[ offsetX+(j*strideX) ] = v1;
138+
X[ ox+(j*sx) ] = v1;
137139

138140
// Update `j` to point to the child index:
139141
j = child;
@@ -146,6 +148,6 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double
146148
}
147149
}
148150
// Insert `t` into the heap:
149-
X[ offsetX+(j*strideX) ] = t;
151+
X[ ox+(j*sx) ] = t;
150152
}
151153
}

0 commit comments

Comments
 (0)