Skip to content

Commit ccc1cd0

Browse files
committed
refactor
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: ---
1 parent c2ce045 commit ccc1cd0

File tree

11 files changed

+391
-133
lines changed

11 files changed

+391
-133
lines changed

lib/node_modules/@stdlib/stats/base/range/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var linspace = require( '@stdlib/array/linspace/docs/types/index' );
25+
var linspace = require( '@stdlib/array/base/linspace' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var pkg = require( './../package.json' ).name;
2828
var range = require( './../lib/range.js' );

lib/node_modules/@stdlib/stats/base/range/benchmark/benchmark.ndarray.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var randu = require( '@stdlib/random/base/randu' );
25+
var linspace = require( '@stdlib/array/linspace/docs/types/index' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
2728
var pkg = require( './../package.json' ).name;
@@ -39,12 +40,7 @@ var range = require( './../lib/ndarray.js' );
3940
*/
4041
function createBenchmark( len ) {
4142
var x;
42-
var i;
43-
44-
x = [];
45-
for ( i = 0; i < len; i++ ) {
46-
x.push( ( randu()*20.0 ) - 10.0 );
47-
}
43+
var x = linspace( 0.0, len, len );
4844
return benchmark;
4945

5046
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/range/docs/repl.txt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
{{alias}}( N, x, stride )
2+
{{alias}}( N, x, strideX )
33
Computes the range of a strided array.
44

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

88
Indexing is relative to the first index. To introduce an offset, use a typed
@@ -18,8 +18,8 @@
1818
x: Array<number>|TypedArray
1919
Input array.
2020

21-
stride: integer
22-
Index increment.
21+
strideX: integer
22+
Stride length.
2323

2424
Returns
2525
-------
@@ -33,22 +33,20 @@
3333
> {{alias}}( x.length, x, 1 )
3434
4.0
3535

36-
// Using `N` and `stride` parameters:
36+
// Using `N` and stride parameters:
3737
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ];
38-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
3938
> var stride = 2;
40-
> {{alias}}( N, x, stride )
39+
> {{alias}}( 3, x, stride )
4140
4.0
4241

4342
// Using view offsets:
4443
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
4544
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
46-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
4745
> stride = 2;
48-
> {{alias}}( N, x1, stride )
46+
> {{alias}}( 3, x1, stride )
4947
4.0
5048

51-
{{alias}}.ndarray( N, x, stride, offset )
49+
{{alias}}.ndarray( N, x, strideX, offsetX )
5250
Computes the range of a strided array using alternative indexing semantics.
5351

5452
While typed array views mandate a view offset based on the underlying
@@ -63,10 +61,10 @@
6361
x: Array<number>|TypedArray
6462
Input array.
6563

66-
stride: integer
67-
Index increment.
64+
strideX: integer
65+
Stride length.
6866

69-
offset: integer
67+
offsetX: integer
7068
Starting index.
7169

7270
Returns
@@ -83,8 +81,7 @@
8381

8482
// Using offset parameter:
8583
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ];
86-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
87-
> {{alias}}.ndarray( N, x, 2, 1 )
84+
> {{alias}}.ndarray( 3, x, 2, 1 )
8885
4.0
8986

9087
See Also

lib/node_modules/@stdlib/stats/base/range/docs/types/index.d.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { NumericArray } from '@stdlib/types/array';
23+
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
2424

2525
/**
2626
* Interface describing `range`.
2727
*/
28+
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
29+
2830
interface Routine {
2931
/**
3032
* Computes the range of a strided array.
3133
*
3234
* @param N - number of indexed elements
3335
* @param x - input array
34-
* @param stride - stride length
36+
* @param strideX - stride length
3537
* @returns range
3638
*
3739
* @example
@@ -40,15 +42,15 @@ interface Routine {
4042
* var v = range( x.length, x, 1 );
4143
* // returns 4.0
4244
*/
43-
( N: number, x: NumericArray, stride: number ): number;
45+
( N: number, x: InputArray, strideX: number ): number;
4446

4547
/**
4648
* Computes the range of a strided array using alternative indexing semantics.
4749
*
4850
* @param N - number of indexed elements
4951
* @param x - input array
50-
* @param stride - stride length
51-
* @param offset - starting index
52+
* @param strideX - stride length
53+
* @param offsetX - starting index
5254
* @returns range
5355
*
5456
* @example
@@ -57,15 +59,15 @@ interface Routine {
5759
* var v = range.ndarray( x.length, x, 1, 0 );
5860
* // returns 4.0
5961
*/
60-
ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
62+
ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number;
6163
}
6264

6365
/**
6466
* Computes the range of a strided array.
6567
*
6668
* @param N - number of indexed elements
6769
* @param x - input array
68-
* @param stride - stride length
70+
* @param strideX - stride length
6971
* @returns range
7072
*
7173
* @example

lib/node_modules/@stdlib/stats/base/range/docs/types/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import AccessorArray = require( '@stdlib/array/base/accessor' );
1920
import range = require( './index' );
2021

2122

@@ -26,6 +27,7 @@ import range = require( './index' );
2627
const x = new Float64Array( 10 );
2728

2829
range( x.length, x, 1 ); // $ExpectType number
30+
range( x.length, new AccessorArray( x ), 1 ); // $ExpectType number
2931
}
3032

3133
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -85,6 +87,7 @@ import range = require( './index' );
8587
const x = new Float64Array( 10 );
8688

8789
range.ndarray( x.length, x, 1, 0 ); // $ExpectType number
90+
range.ndarray( x.length, new AccessorArray( x ), 1, 0 ); // $ExpectType number
8891
}
8992

9093
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...

lib/node_modules/@stdlib/stats/base/range/examples/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var round = require( '@stdlib/math/base/special/round' );
23-
var Float64Array = require( '@stdlib/array/float64' );
21+
var linspace = require( '@stdlib/array/base/linspace' );
2422
var range = require( './../lib' );
2523

26-
var x;
27-
var i;
28-
29-
x = new Float64Array( 10 );
30-
for ( i = 0; i < x.length; i++ ) {
31-
x[ i ] = round( (randu()*100.0) - 50.0 );
32-
}
24+
var x = linspace(-50, 50, 10);
3325
console.log( x );
3426

3527
var v = range( x.length, x, 1 );
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
25+
26+
// MAIN //
27+
28+
/**
29+
* Computes the range of a strided array using the accessor protocol.
30+
*
31+
* @param {PositiveInteger} N - number of indexed elements
32+
* @param {Object} x - input array-like object supporting the accessor protocol
33+
* @param {Function} get - accessor function to retrieve array values
34+
* @param {integer} stride - stride length
35+
* @returns {number} range (max - min)
36+
*
37+
* @example
38+
* function accessor( arr, idx ) {
39+
* return arr.get( idx );
40+
* }
41+
*
42+
* var x = {
43+
* data: [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ],
44+
* get: function( i ) { return this.data[ i ]; }
45+
* };
46+
*
47+
* var v = range( 3, x, accessor, 2 );
48+
* // returns 4.0
49+
*/
50+
function range( N, x, get, stride ) {
51+
var max;
52+
var min;
53+
var ix;
54+
var v;
55+
var i;
56+
57+
if ( N <= 0 ) {
58+
return NaN;
59+
}
60+
if ( N === 1 || stride === 0 ) {
61+
v = get( x, 0 );
62+
if ( isnan( v ) ) {
63+
return NaN;
64+
}
65+
return 0.0;
66+
}
67+
if ( stride < 0 ) {
68+
ix = (1 - N) * stride;
69+
} else {
70+
ix = 0;
71+
}
72+
min = get( x, ix );
73+
max = min;
74+
for ( i = 1; i < N; i++ ) {
75+
ix += stride;
76+
v = get( x, ix );
77+
if ( isnan( v ) ) {
78+
return v;
79+
}
80+
if ( v < min ) {
81+
min = v;
82+
} else if ( v > max ) {
83+
max = v;
84+
}
85+
}
86+
return max - min;
87+
}
88+
89+
// EXPORTS //
90+
91+
module.exports = range;

0 commit comments

Comments
 (0)