Skip to content

Commit fe25ba3

Browse files
committed
refactor!: remove support for non-ndarray arguments
This commit refactors the API to be more in line with recent work for reduction dispatch (e.g., see `ndarray/base/unary-strided1d-dispatch`. As such, non-ndarray argument support has been dropped. If such generalized support is still desired, users should create a wrapper which performs dispatch to specialized array and scalar implementations. BREAKING CHANGE: remove support for non-ndarray arguments To migrate, users will need to create higher-level wrappers which perform argument dispatch. --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent fb46eb4 commit fe25ba3

File tree

61 files changed

+1400
-5514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1400
-5514
lines changed

lib/node_modules/@stdlib/math/tools/unary/README.md

Lines changed: 209 additions & 184 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
24+
var uniform = require( '@stdlib/random/uniform' );
25+
var zeros = require( '@stdlib/ndarray/zeros' );
26+
var getData = require( '@stdlib/ndarray/data-buffer' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
28-
var ndarray = require( '@stdlib/ndarray/ctor' );
29+
var format = require( '@stdlib/string/format' );
2930
var pkg = require( './../package.json' ).name;
3031
var abs = require( './fixtures/dispatcher.js' );
3132

3233

3334
// VARIABLES //
3435

35-
var rand = uniform( -100.0, 100.0 );
36+
var DTYPES = [
37+
'float64',
38+
'float32',
39+
'generic'
40+
];
3641

3742

3843
// FUNCTIONS //
@@ -41,21 +46,20 @@ var rand = uniform( -100.0, 100.0 );
4146
* Creates a benchmark function.
4247
*
4348
* @private
44-
* @param {PositiveInteger} len - array length
49+
* @param {PositiveInteger} size - array size
50+
* @param {string} dtype - data type
4551
* @returns {Function} benchmark function
4652
*/
47-
function createBenchmark( len ) {
48-
var buf;
53+
function createBenchmark( size, dtype ) {
54+
var options;
4955
var x;
5056
var y;
51-
var i;
5257

53-
buf = new Float32Array( len );
54-
for ( i = 0; i < len; i++ ) {
55-
buf[ i ] = rand();
56-
}
57-
x = ndarray( 'float32', buf, [ len ], [ 1 ], 0, 'row-major' );
58-
y = ndarray( x.dtype, new Float32Array( len ), x.shape, x.strides, x.offset, x.order ); // eslint-disable-line max-len
58+
options = {
59+
'dtype': dtype
60+
};
61+
x = uniform( [], -10.0, 10.0, options );
62+
y = zeros( [ size ], options );
5963

6064
return benchmark;
6165

@@ -66,17 +70,18 @@ function createBenchmark( len ) {
6670
* @param {Benchmark} b - benchmark instance
6771
*/
6872
function benchmark( b ) {
73+
var out;
6974
var i;
7075

7176
b.tic();
7277
for ( i = 0; i < b.iterations; i++ ) {
73-
abs.assign( x, y );
74-
if ( isnan( y.data[ i%len ] ) ) {
75-
b.fail( 'should not return NaN' );
78+
out = abs.assign( x, y );
79+
if ( typeof out !== 'object' ) {
80+
b.fail( 'should return an ndarray' );
7681
}
7782
}
7883
b.toc();
79-
if ( isnan( y.data[ i%len ] ) ) {
84+
if ( isnan( getData( out )[ i%size ] ) ) {
8085
b.fail( 'should not return NaN' );
8186
}
8287
b.pass( 'benchmark finished' );
@@ -93,19 +98,24 @@ function createBenchmark( len ) {
9398
* @private
9499
*/
95100
function main() {
96-
var len;
101+
var size;
97102
var min;
98103
var max;
104+
var dt;
99105
var f;
100106
var i;
107+
var j;
101108

102109
min = 1; // 10^min
103110
max = 6; // 10^max
104111

105-
for ( i = min; i <= max; i++ ) {
106-
len = pow( 10, i );
107-
f = createBenchmark( len );
108-
bench( pkg+'::ndarray:assign:contiguous=true,ndims=1,dtype=float32,len='+len, f );
112+
for ( j = 0; j < DTYPES.length; j++ ) {
113+
dt = DTYPES[ j ];
114+
for ( i = min; i <= max; i++ ) {
115+
size = pow( 10, i );
116+
f = createBenchmark( size, dt );
117+
bench( format( '%s::broadcast:assign:contiguous=true,ndims=0,dtype=%s,size=%d', pkg, dt, size ), f );
118+
}
109119
}
110120
}
111121

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/uniform' );
25+
var zeros = require( '@stdlib/ndarray/zeros' );
26+
var getData = require( '@stdlib/ndarray/data-buffer' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
var abs = require( './fixtures/dispatcher.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var DTYPES = [
37+
'float64',
38+
'float32',
39+
'generic'
40+
];
41+
42+
43+
// FUNCTIONS //
44+
45+
/**
46+
* Creates a benchmark function.
47+
*
48+
* @private
49+
* @param {PositiveInteger} size - array size
50+
* @param {string} dtype - data type
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( size, dtype ) {
54+
var options;
55+
var x;
56+
var y;
57+
58+
options = {
59+
'dtype': dtype
60+
};
61+
x = uniform( [ size ], -10.0, 10.0, options );
62+
y = zeros( [ size ], options );
63+
64+
return benchmark;
65+
66+
/**
67+
* Benchmark function.
68+
*
69+
* @private
70+
* @param {Benchmark} b - benchmark instance
71+
*/
72+
function benchmark( b ) {
73+
var out;
74+
var i;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
out = abs.assign( x, y );
79+
if ( typeof out !== 'object' ) {
80+
b.fail( 'should return an ndarray' );
81+
}
82+
}
83+
b.toc();
84+
if ( isnan( getData( out )[ i%size ] ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
b.pass( 'benchmark finished' );
88+
b.end();
89+
}
90+
}
91+
92+
93+
// MAIN //
94+
95+
/**
96+
* Main execution sequence.
97+
*
98+
* @private
99+
*/
100+
function main() {
101+
var size;
102+
var min;
103+
var max;
104+
var dt;
105+
var f;
106+
var i;
107+
var j;
108+
109+
min = 1; // 10^min
110+
max = 6; // 10^max
111+
112+
for ( j = 0; j < DTYPES.length; j++ ) {
113+
dt = DTYPES[ j ];
114+
for ( i = min; i <= max; i++ ) {
115+
size = pow( 10, i );
116+
f = createBenchmark( size, dt );
117+
bench( format( '%s::broadcast:assign:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f );
118+
}
119+
}
120+
}
121+
122+
main();
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
24+
var uniform = require( '@stdlib/random/uniform' );
25+
var getData = require( '@stdlib/ndarray/data-buffer' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
28-
var ndarray = require( '@stdlib/ndarray/ctor' );
28+
var format = require( '@stdlib/string/format' );
2929
var pkg = require( './../package.json' ).name;
3030
var abs = require( './fixtures/dispatcher.js' );
3131

3232

3333
// VARIABLES //
3434

35-
var rand = uniform( -100.0, -1.0 );
35+
var DTYPES = [
36+
'float64',
37+
'float32',
38+
'generic'
39+
];
3640

3741

3842
// FUNCTIONS //
@@ -41,17 +45,18 @@ var rand = uniform( -100.0, -1.0 );
4145
* Creates a benchmark function.
4246
*
4347
* @private
44-
* @param {PositiveInteger} len - array length
48+
* @param {PositiveInteger} size - array size
49+
* @param {string} dtype - data type
4550
* @returns {Function} benchmark function
4651
*/
47-
function createBenchmark( len ) {
48-
var buf;
52+
function createBenchmark( size, dtype ) {
53+
var options;
4954
var x;
50-
var y;
5155

52-
buf = new Float32Array( [ rand() ] );
53-
x = ndarray( 'float32', buf, [], [ 0 ], 0, 'row-major' );
54-
y = ndarray( x.dtype, new Float32Array( len ), [ len ], [ 1 ], 0, 'row-major' );
56+
options = {
57+
'dtype': dtype
58+
};
59+
x = uniform( [ size ], -10.0, 10.0, options );
5560

5661
return benchmark;
5762

@@ -62,17 +67,18 @@ function createBenchmark( len ) {
6267
* @param {Benchmark} b - benchmark instance
6368
*/
6469
function benchmark( b ) {
70+
var out;
6571
var i;
6672

6773
b.tic();
6874
for ( i = 0; i < b.iterations; i++ ) {
69-
abs.assign( x, y );
70-
if ( isnan( y.data[ i%len ] ) ) {
71-
b.fail( 'should not return NaN' );
75+
out = abs( x );
76+
if ( typeof out !== 'object' ) {
77+
b.fail( 'should return an ndarray' );
7278
}
7379
}
7480
b.toc();
75-
if ( isnan( y.data[ i%len ] ) ) {
81+
if ( isnan( getData( out )[ i%size ] ) ) {
7682
b.fail( 'should not return NaN' );
7783
}
7884
b.pass( 'benchmark finished' );
@@ -89,19 +95,24 @@ function createBenchmark( len ) {
8995
* @private
9096
*/
9197
function main() {
92-
var len;
98+
var size;
9399
var min;
94100
var max;
101+
var dt;
95102
var f;
96103
var i;
104+
var j;
97105

98106
min = 1; // 10^min
99107
max = 6; // 10^max
100108

101-
for ( i = min; i <= max; i++ ) {
102-
len = pow( 10, i );
103-
f = createBenchmark( len );
104-
bench( pkg+'::ndarray,broadcast:contiguous=true,ndims=1,dtype=float32,len='+len, f );
109+
for ( j = 0; j < DTYPES.length; j++ ) {
110+
dt = DTYPES[ j ];
111+
for ( i = min; i <= max; i++ ) {
112+
size = pow( 10, i );
113+
f = createBenchmark( size, dt );
114+
bench( format( '%s:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f );
115+
}
105116
}
106117
}
107118

0 commit comments

Comments
 (0)