From c7e0f03f90914d087beab7c09bc0361da88676a7 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 24 Sep 2025 10:14:19 +0530 Subject: [PATCH 1/9] chore: initial scaffold setup --- .../math-special-unary/data/README__md.txt | 227 +++++++++++++ .../benchmark__1d_contiguous__js.txt | 116 +++++++ .../benchmark__1d_contiguous__native__js.txt | 121 +++++++ .../benchmark__1d_contiguous_assign__js.txt | 123 +++++++ ...mark__1d_contiguous_assign__native__js.txt | 128 +++++++ .../benchmark__nd_contiguous__js.txt | 116 +++++++ .../benchmark__nd_contiguous__native__js.txt | 121 +++++++ .../benchmark__nd_noncontiguous__js.txt | 122 +++++++ ...enchmark__nd_noncontiguous__native__js.txt | 127 +++++++ .../benchmark__nd_singleton_dims__js.txt | 116 +++++++ ...nchmark__nd_singleton_dims__native__js.txt | 121 +++++++ .../math-special-unary/data/binding__gyp.txt | 170 ++++++++++ .../data/docs/repl__txt.txt | 67 ++++ .../data/docs/types/index__d__ts.txt | 146 ++++++++ .../data/docs/types/test__ts.txt | 154 +++++++++ .../data/examples/index__js.txt | 31 ++ .../math-special-unary/data/include__gypi.txt | 53 +++ .../data/lib/config__js.txt | 59 ++++ .../math-special-unary/data/lib/index__js.txt | 65 ++++ .../math-special-unary/data/lib/main__js.txt | 72 ++++ .../data/lib/native__js.txt | 72 ++++ .../data/manifest__json.txt | 42 +++ .../math-special-unary/data/package__json.txt | 66 ++++ .../math-special-unary/data/src/Makefile.txt | 70 ++++ .../data/test/test__assign__js.txt | 136 ++++++++ .../data/test/test__assign__native__js.txt | 145 ++++++++ .../math-special-unary/data/test/test__js.txt | 129 ++++++++ .../data/test/test__main__js.txt | 284 ++++++++++++++++ .../data/test/test__main__native__js.txt | 293 ++++++++++++++++ .../math-special-unary/scripts/runner.js | 276 ++++++++++++++++ .../math-special-unary/scripts/scaffold.sh | 312 ++++++++++++++++++ 31 files changed, 4080 insertions(+) create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/binding__gyp.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/repl__txt.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/index__d__ts.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/test__ts.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/examples/index__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/include__gypi.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/config__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/index__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/main__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/manifest__json.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/package__json.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/src/Makefile.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__native__js.txt create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js create mode 100755 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt new file mode 100644 index 000000000000..7ebc3a3feaa5 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt @@ -0,0 +1,227 @@ + + +# {{ALIAS}} + +> {{PKG_DESC}} + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var {{ALIAS}} = require( '@{{PKG}}' ); +``` + +#### {{ALIAS}}( x\[, options] ) + +{{MAIN_DESC}} + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( {{EXAMPLE_VALUES_2X2}} ); +var y = {{ALIAS}}( x ); +// returns + +var arr = ndarray2array( y ); +// returns {{EXAMPLE_RESULTS_2X2}} +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a real-valued or generic [data type][@stdlib/ndarray/dtypes]. +- **order**: output ndarray [order][@stdlib/ndarray/orders] (i.e., memory layout). + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); + +var x = array( {{EXAMPLE_VALUES_2X2}} ); +var y = {{ALIAS}}( x, { + 'dtype': 'generic' +}); +// returns + +var dt = getDType( y ); +// returns 'generic' + +var arr = ndarray2array( y ); +// returns {{EXAMPLE_RESULTS_2X2}} +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [order][@stdlib/ndarray/orders] as the input [ndarray][@stdlib/ndarray/ctor]. To return an [ndarray][@stdlib/ndarray/ctor] having a specific memory layout irrespective of the memory layout of the input [ndarray][@stdlib/ndarray/ctor], set the `order` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); +var getOrder = require( '@stdlib/ndarray/order' ); + +var x = array( {{EXAMPLE_VALUES_2X2}} ); +var y = {{ALIAS}}( x, { + 'order': 'column-major' +}); +// returns + +var ord = getOrder( y ); +// returns 'column-major' + +var arr = ndarray2array( y ); +// returns {{EXAMPLE_RESULTS_2X2}} +``` + +#### {{ALIAS}}.assign( x, y ) + +{{ASSIGN_DESC}} + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( {{EXAMPLE_VALUES_2X2}} ); +var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); + +var out = {{ALIAS}}.assign( x, y ); +// returns + +var bool = ( out === y ); +// returns true + +var arr = ndarray2array( out ); +// returns {{EXAMPLE_RESULTS_2X2}} +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the output [ndarray][@stdlib/ndarray/ctor]. +- **y**: output [ndarray][@stdlib/ndarray/ctor]. + +The function supports broadcasting an input [ndarray][@stdlib/ndarray/ctor] to the shape of the output [ndarray][@stdlib/ndarray/ctor] without performing a physical copy of the input [ndarray][@stdlib/ndarray/ctor]'s underlying data. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var array = require( '@stdlib/ndarray/array' ); + +// Create a 2x2 input ndarray: +var x = array( {{EXAMPLE_VALUES_2X2}} ); + +// Create a 2x2x2 output ndarray: +var y = zeros( [ 2, 2, 2 ] ); + +var out = {{ALIAS}}.assign( x, y ); +// returns + +var arr = ndarray2array( out ); +// returns [ {{EXAMPLE_RESULTS_2X2}}, {{EXAMPLE_RESULTS_2X2}} ] +``` + +
+ + + + + +
+ +## Notes + +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + + + +
+ +## Examples + + + +```javascript +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var {{ALIAS}} = require( '@{{PKG}}' ); + +var x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}} ); +console.log( ndarray2array( x ) ); + +var y = {{ALIAS}}( x ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__js.txt new file mode 100644 index 000000000000..1f02ebfdea05 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__js.txt @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var {{ALIAS}} = require( './../lib/main.js' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__native__js.txt new file mode 100644 index 000000000000..6093ff417fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous__native__js.txt @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s::native:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__js.txt new file mode 100644 index 000000000000..853e5933a9cf --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__js.txt @@ -0,0 +1,123 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var {{ALIAS}} = require( './../lib/main.js' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var options; + var x; + var y; + + options = { + 'dtype': dtype + }; + x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, options ); + y = zeros( [ size ], options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = {{ALIAS}}.assign( x, y ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( z )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s:assign:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__native__js.txt new file mode 100644 index 000000000000..a546c7e4e3ef --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__1d_contiguous_assign__native__js.txt @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var options; + var x; + var y; + + options = { + 'dtype': dtype + }; + x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, options ); + y = zeros( [ size ], options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = {{ALIAS}}.assign( x, y ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( z )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s::native:assign:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__js.txt new file mode 100644 index 000000000000..840c763ab0d1 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__js.txt @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var {{ALIAS}} = require( './../lib/main.js' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size/2, 2, 1 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s:contiguous=true,ndims=3,dtype=%s,size=%d', pkg, dt, size ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__native__js.txt new file mode 100644 index 000000000000..58f964a33342 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_contiguous__native__js.txt @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size/2, 2, 1 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s::native:contiguous=true,ndims=3,dtype=%s,size=%d', pkg, dt, size ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__js.txt new file mode 100644 index 000000000000..ff58562cd34a --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__js.txt @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/array/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var {{ALIAS}} = require( './../lib/main.js' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var buf; + var x; + + buf = random( size*2, {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + x = new ndarray( dtype, buf, [ size/2, 2, 1 ], [ 4, 1, 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s:contiguous=false,ndims=3,dtype=%s,size=%d', pkg, dt, size ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__native__js.txt new file mode 100644 index 000000000000..097733eed77b --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_noncontiguous__native__js.txt @@ -0,0 +1,127 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/array/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var buf; + var x; + + buf = random( size*2, {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + x = new ndarray( dtype, buf, [ size/2, 2, 1 ], [ 4, 1, 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s::native:contiguous=false,ndims=3,dtype=%s,size=%d', pkg, dt, size ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__js.txt new file mode 100644 index 000000000000..21dbf39b6365 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__js.txt @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var {{ALIAS}} = require( './../lib/main.js' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size, 1, 1 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s:contiguous=false,ndims=3,singleton_dims=2,dtype=%s,size=%d', pkg, dt, size ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__native__js.txt new file mode 100644 index 000000000000..9ac64481a6a1 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/benchmark/benchmark__nd_singleton_dims__native__js.txt @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var bench = require( '@stdlib/bench' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; +var DTYPES = [ + 'float64', + 'float32', + 'generic' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} size - array size +* @param {string} dtype - data type +* @returns {Function} benchmark function +*/ +function createBenchmark( size, dtype ) { + var x = random( [ size, 1, 1 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': dtype + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = {{ALIAS}}( x ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( getData( y )[ i%size ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var size; + var min; + var max; + var dt; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < DTYPES.length; j++ ) { + dt = DTYPES[ j ]; + for ( i = min; i <= max; i++ ) { + size = pow( 10, i ); + f = createBenchmark( size, dt ); + bench( format( '%s::native:contiguous=false,ndims=3,singleton_dims=2,dtype=%s,size=%d', pkg, dt, size ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/binding__gyp.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/binding__gyp.txt new file mode 100644 index 000000000000..f98b002d4798 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/binding__gyp.txt @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) {{YEAR}} {{COPYRIGHT}}. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99' + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11' + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/repl__txt.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/repl__txt.txt new file mode 100644 index 000000000000..4c90993f9f48 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/repl__txt.txt @@ -0,0 +1,67 @@ + +{{alias}}( x[, options] ) + {{REPL_TEXT_MAIN_DESC}} + + The function returns an ndarray having the same shape as the input ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a numeric or "generic" data type. + + options: Object (optional) + Options. + + options.dtype: string|DataType (optional) + Output array data type. Must be a real-valued or "generic" data type. + + options.order: string (optional) + Output array order. Must be either row-major (C-style) or column-major + (Fortran-style). By default, the order of the output array is the same + as the input array. + + Returns + ------- + y: ndarray + Output array containing element-wise results. + + Examples + -------- + > var arr = {{EXAMPLE_VALUES_2X2}}; + > var x = {{alias:@stdlib/ndarray/array}}( arr ); + > var y = {{alias}}( x ); + > {{alias:@stdlib/ndarray/to-array}}( y ) + {{EXAMPLE_RESULTS_2X2}} + + +{{alias}}.assign( x, y ) + {{REPL_TEXT_ASSIGN_DESC}} + + Parameters + ---------- + x: ndarray + Input array. Must have a numeric or "generic" data type. + + y: ndarray + Output array. + + Returns + ------- + y: ndarray + Output array. + + Examples + -------- + > var arr = {{EXAMPLE_VALUES_2X2}}; + > var x = {{alias:@stdlib/ndarray/array}}( arr ); + > var sh = {{alias:@stdlib/ndarray/shape}}( x ); + > var y = {{alias:@stdlib/ndarray/zeros}}( sh ); + > var out = {{alias}}.assign( x, y ); + > var bool = ( out === y ) + true + > {{alias:@stdlib/ndarray/to-array}}( y ) + {{EXAMPLE_RESULTS_2X2}} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/index__d__ts.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/index__d__ts.txt new file mode 100644 index 000000000000..9305a43d5184 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/index__d__ts.txt @@ -0,0 +1,146 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray, {{NDARRAY_IMPORT_TYPES}}, genericndarray, RealAndGenericDataType as DataType, Order } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = {{INPUT_NDARRAY_TYPE}} | genericndarray; + +/** +* Output array. +*/ +type OutputArray = {{OUTPUT_NDARRAY_TYPE}} | genericndarray; + +/** +* Interface describing options. +*/ +interface Options { + /** + * Output array order. + * + * ## Notes + * + * - By default, the order of the output array is the same as the input array. + */ + order?: Order; + + /** + * Output array data type. + */ + dtype?: DataType; +} + +/** +* Interface describing a unary element-wise function. +*/ +interface UnaryFunction { + /** + * {{MAIN_DESC}} + * + * @param x - input ndarray + * @param options - options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); + * // returns + * + * var y = {{ALIAS}}( x ); + * // returns + * + * var arr = ndarray2array( y ); + * // returns {{JS_EXAMPLE_RESULTS_2X2}} + */ + ( x: InputArray, options?: Options ): typedndarray; // FIXME: we lose type specificity here, as the output ndarray data type is determined according to the output data type policy in conjunction with the `dtype` option + + /** + * {{ASSIGN_DESC}} + * + * @param x - input ndarray + * @param y - output ndarray + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); + * var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); + * + * var z = {{ALIAS}}.assign( x, y ); + * // returns + * + * var bool = ( z === y ); + * // returns true + * + * var arr = ndarray2array( y ); + * // returns {{JS_EXAMPLE_RESULTS_2X2}} + */ + assign( x: InputArray, y: T ): T; +} + +/** +* {{MAIN_DESC}} +* +* @param x - input ndarray +* @param options - options +* @returns output ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); +* +* var y = {{ALIAS}}( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns {{JS_EXAMPLE_RESULTS_2X2}} +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); +* var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); +* +* var z = {{ALIAS}}.assign( x, y ); +* // returns +* +* var bool = ( z === y ); +* // returns true +* +* var arr = ndarray2array( y ); +* // returns {{JS_EXAMPLE_RESULTS_2X2}} +*/ +declare var {{ALIAS}}: UnaryFunction; + + +// EXPORTS // + +export = {{ALIAS}}; diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/test__ts.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/test__ts.txt new file mode 100644 index 000000000000..142379ddd00e --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/docs/types/test__ts.txt @@ -0,0 +1,154 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import {{ALIAS}} = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}( x ); // $ExpectType typedndarray + {{ALIAS}}( x, {} ); // $ExpectType typedndarray + {{ALIAS}}( x, { 'dtype': 'float32' } ); // $ExpectType typedndarray + {{ALIAS}}( x, { 'order': 'row-major' } ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + {{ALIAS}}( '5' ); // $ExpectError + {{ALIAS}}( 5 ); // $ExpectError + {{ALIAS}}( true ); // $ExpectError + {{ALIAS}}( false ); // $ExpectError + {{ALIAS}}( null ); // $ExpectError + {{ALIAS}}( void 0 ); // $ExpectError + {{ALIAS}}( [] ); // $ExpectError + {{ALIAS}}( {} ); // $ExpectError + {{ALIAS}}( [ '5' ] ); // $ExpectError + {{ALIAS}}( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a valid options object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}( x, '5' ); // $ExpectError + {{ALIAS}}( x, true ); // $ExpectError + {{ALIAS}}( x, false ); // $ExpectError + {{ALIAS}}( x, [ '5' ] ); // $ExpectError + {{ALIAS}}( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}( x, { 'dtype': '5' } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': true } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': false } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': null } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': {} } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': [ '5' ] } ); // $ExpectError + {{ALIAS}}( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `order` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}( x, { 'order': '5' } ); // $ExpectError + {{ALIAS}}( x, { 'order': true } ); // $ExpectError + {{ALIAS}}( x, { 'order': false } ); // $ExpectError + {{ALIAS}}( x, { 'order': null } ); // $ExpectError + {{ALIAS}}( x, { 'order': {} } ); // $ExpectError + {{ALIAS}}( x, { 'order': [ '5' ] } ); // $ExpectError + {{ALIAS}}( x, { 'order': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}(); // $ExpectError + {{ALIAS}}( x, {}, {} ); // $ExpectError +} + +// Attached to the main function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}.assign( x, x ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}.assign( '5', x ); // $ExpectError + {{ALIAS}}.assign( true, x ); // $ExpectError + {{ALIAS}}.assign( false, x ); // $ExpectError + {{ALIAS}}.assign( null, x ); // $ExpectError + {{ALIAS}}.assign( void 0, x ); // $ExpectError + {{ALIAS}}.assign( {}, x ); // $ExpectError + {{ALIAS}}.assign( ( x: number ): number => x, x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}.assign( x, '5' ); // $ExpectError + {{ALIAS}}.assign( x, true ); // $ExpectError + {{ALIAS}}.assign( x, false ); // $ExpectError + {{ALIAS}}.assign( x, null ); // $ExpectError + {{ALIAS}}.assign( x, void 0 ); // $ExpectError + {{ALIAS}}.assign( x, {} ); // $ExpectError + {{ALIAS}}.assign( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + {{ALIAS}}.assign(); // $ExpectError + {{ALIAS}}.assign( x ); // $ExpectError + {{ALIAS}}.assign( x, x, x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/examples/index__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/examples/index__js.txt new file mode 100644 index 000000000000..0af3a5623ea0 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/examples/index__js.txt @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var {{ALIAS}} = require( './../lib' ); + +var x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}} ); +console.log( ndarray2array( x ) ); + +var y = {{ALIAS}}( x ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/include__gypi.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/include__gypi.txt new file mode 100644 index 000000000000..9fad714bbcf4 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/include__gypi.txt @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) {{YEAR}} {{COPYRIGHT}}. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +* +* var y = {{ALIAS}}( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns {{JS_EXAMPLE_RESULTS_2X2}} +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var javascript = require( './main.js' ); + + +// MAIN // + +var main; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( tmp instanceof Error ) { + main = javascript; +} else { + main = tmp; +} + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/main__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/main__js.txt new file mode 100644 index 000000000000..f0b5e50131ed --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/main__js.txt @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var dispatch = require( '@stdlib/ndarray/dispatch' ); +var setProps = require( '@stdlib/ndarray/base/meta-data-props' ); +var ufunc = require( '@stdlib/math/tools/unary' ); +var unary = require( '@stdlib/ndarray/base/unary' ); +var data = require( './data.js' ); +var types = require( './types.json' ); +var config = require( './config.js' ); + + +// MAIN // + +/** +* {{MAIN_DESC}} +* +* @name {{ALIAS}} +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - options +* @param {string} [options.order] - output array order +* @param {*} [options.dtype] - output array dtype +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); +* // returns +* +* var y = {{ALIAS}}( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns {{JS_EXAMPLE_RESULTS_2X2}} +*/ +var {{ALIAS}} = ufunc( dispatch( unary, types, data, config.nargs, config.nin, config.nout ), [ config.idtypes ], config.odtypes, config.policies ); +setProps( config, types, {{ALIAS}} ); +setProps( config, types, {{ALIAS}}.assign ); + + +// EXPORTS // + +module.exports = {{ALIAS}}; diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/native__js.txt new file mode 100644 index 000000000000..20e083e0b2b3 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/lib/native__js.txt @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var dispatch = require( '@stdlib/ndarray/base/unary-addon-dispatch' ); +var setProps = require( '@stdlib/ndarray/base/meta-data-props' ); +var ufunc = require( '@stdlib/math/tools/unary' ); +var addon = require( './../src/addon.node' ); +var types = require( './types.json' ); +var config = require( './config.js' ); +var fallback = require( './main.js' ).assign; + + +// MAIN // + +/** +* {{MAIN_DESC}} +* +* @name {{ALIAS}} +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - options +* @param {string} [options.order] - output array order +* @param {*} [options.dtype] - output array dtype +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); +* // returns +* +* var y = {{ALIAS}}( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns {{JS_EXAMPLE_RESULTS_2X2}} +*/ +var {{ALIAS}} = ufunc( dispatch( addon, fallback ), [ config.idtypes ], config.odtypes, config.policies ); +setProps( config, types, {{ALIAS}} ); +setProps( config, types, {{ALIAS}}.assign ); + + +// EXPORTS // + +module.exports = {{ALIAS}}; diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/manifest__json.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/manifest__json.txt new file mode 100644 index 000000000000..a67eb638d11e --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/manifest__json.txt @@ -0,0 +1,42 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + {{PKG_DEPS}}, + "@stdlib/ndarray/base/function-object", + "@stdlib/ndarray/base/napi/unary", + "@stdlib/ndarray/base/unary", + "@stdlib/ndarray/dtypes" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/package__json.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/package__json.txt new file mode 100644 index 000000000000..71c56ea73207 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/package__json.txt @@ -0,0 +1,66 @@ +{ + "name": "@{{PKG}}", + "version": "0.0.0", + "description": "{{PKG_DESC}}", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "ndarray", + "elementwise", + "element-wise", + {{KEYWORDS}} + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/src/Makefile.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/src/Makefile.txt new file mode 100644 index 000000000000..a64cc31f1b68 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/src/Makefile.txt @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) {{YEAR}} {{COPYRIGHT}}. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__js.txt new file mode 100644 index 000000000000..b31e5abcaca5 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__js.txt @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var map = require( '@stdlib/ndarray/map' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var base = require( '@{{PKG}}' ); +var {{ALIAS}} = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof {{ALIAS}}, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( typeof {{ALIAS}}.assign, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var y; + var i; + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}.assign( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}.assign( x, value ); + }; + } +}); + +tape( 'the function {{TEST_DESC}} for each element in an ndarray and assigns the results to a provided output ndarray', function test( t ) { + var expected; + var out; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = zeros( getShape( x ), { + 'dtype': 'float64' + }); + out = {{ALIAS}}.assign( x, y ); + + expected = map( x, naryFunction( base, 1 ) ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( ndarray2array( out ), ndarray2array( expected ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__native__js.txt new file mode 100644 index 000000000000..74cda1b2c7fb --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__assign__native__js.txt @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var map = require( '@stdlib/ndarray/map' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var base = require( '@{{PKG}}' ); + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof {{ALIAS}}, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', opts, function test( t ) { + t.strictEqual( typeof {{ALIAS}}.assign, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', opts, function test( t ) { + var values; + var y; + var i; + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}.assign( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', opts, function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}.assign( x, value ); + }; + } +}); + +tape( 'the function {{TEST_DESC}} for each element in an ndarray and assigns the results to a provided output ndarray', opts, function test( t ) { + var expected; + var out; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = zeros( getShape( x ), { + 'dtype': 'float64' + }); + out = {{ALIAS}}.assign( x, y ); + + expected = map( x, naryFunction( base, 1 ) ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( ndarray2array( out ), ndarray2array( expected ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__js.txt new file mode 100644 index 000000000000..7762e5eb27ae --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__js.txt @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dtypes2signatures = require( '@stdlib/ndarray/base/dtypes2signatures' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var types = require( './../lib/types.json' ); +var config = require( './../lib/config.js' ); +var fcn = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fcn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var fcn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( fcn, mock, 'returns native implementation' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var main; + var fcn; + + main = require( './../lib/main.js' ); + + fcn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( fcn, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); + +tape( 'attached to the main export is a property for retrieving the number of input and output arrays', function test( t ) { + t.strictEqual( fcn.nargs, config.nargs, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a property for retrieving the number of input arrays', function test( t ) { + t.strictEqual( fcn.nin, config.nin, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a property for retrieving the number of output arrays', function test( t ) { + t.strictEqual( fcn.nout, config.nout, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a property for retrieving the list of supported array data types', function test( t ) { + t.deepEqual( fcn.types, dtypes2signatures( types, config.nin, config.nout ), 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method for assigning results to a provided output array', function test( t ) { + t.strictEqual( hasProp( fcn, 'assign' ), true, 'returns expected value' ); + t.strictEqual( typeof fcn.assign, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the `assign` method is a property for retrieving the number of input and output arrays', function test( t ) { + t.strictEqual( fcn.assign.nargs, config.nargs, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the `assign` method is a property for retrieving the number of input arrays', function test( t ) { + t.strictEqual( fcn.assign.nin, config.nin, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the `assign` method is a property for retrieving the number of output arrays', function test( t ) { + t.strictEqual( fcn.assign.nout, config.nout, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the `assign` method is a property for retrieving the list of supported array data types', function test( t ) { + t.deepEqual( fcn.assign.types, dtypes2signatures( types, config.nin, config.nout ), 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__js.txt new file mode 100644 index 000000000000..3da06ace03c0 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__js.txt @@ -0,0 +1,284 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var map = require( '@stdlib/ndarray/map' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var base = require( '@{{PKG}}' ); +var {{ALIAS}} = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof {{ALIAS}}, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an invalid `dtype` option', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an invalid `order` option', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, { + 'order': value + }); + }; + } +}); + +tape( 'the function {{TEST_DESC}} for each element in an ndarray', function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = {{ALIAS}}( x ); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), getOrder( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output ndarray data type', function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = {{ALIAS}}( x, { + 'dtype': 'generic' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.strictEqual( getDType( y ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), getOrder( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output ndarray order', function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64', + 'order': 'row-major' + }); + y = {{ALIAS}}( x, { + 'order': 'column-major' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64', + 'order': 'column-major' + }); + y = {{ALIAS}}( x, { + 'order': 'row-major' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__native__js.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__native__js.txt new file mode 100644 index 000000000000..3558426579ea --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__native__js.txt @@ -0,0 +1,293 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} {{COPYRIGHT}}. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var random = require( '@stdlib/random/{{BASE_PRNG}}' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var map = require( '@stdlib/ndarray/map' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var base = require( '@{{PKG}}' ); + + +// VARIABLES // + +var {{ALIAS}} = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( {{ALIAS}} instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof {{ALIAS}}, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', opts, function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', opts, function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', opts, function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an invalid `dtype` option', opts, function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an invalid `order` option', opts, function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + {{ALIAS}}( x, { + 'order': value + }); + }; + } +}); + +tape( 'the function {{TEST_DESC}} for each element in an ndarray', opts, function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = {{ALIAS}}( x ); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), getOrder( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output ndarray data type', opts, function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64' + }); + y = {{ALIAS}}( x, { + 'dtype': 'generic' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.strictEqual( getDType( y ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), getOrder( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output ndarray order', opts, function test( t ) { + var expected; + var x; + var y; + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64', + 'order': 'row-major' + }); + y = {{ALIAS}}( x, { + 'order': 'column-major' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}}, { + 'dtype': 'float64', + 'order': 'column-major' + }); + y = {{ALIAS}}( x, { + 'order': 'row-major' + }); + + expected = map( x, naryFunction( base, 1 ) ); + t.deepEqual( ndarray2array( y ), ndarray2array( expected ), 'returns expected value' ); + + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js new file mode 100644 index 000000000000..8f7f7023cfac --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js @@ -0,0 +1,276 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-lines */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var shell = require( 'child_process' ).execSync; // eslint-disable-line node/no-sync +var existsSync = require( '@stdlib/fs/exists' ).sync; +var objectKeys = require( '@stdlib/utils/keys' ); +var rootDir = require( '@stdlib/_tools/utils/root-dir' ); +var log = require( '@stdlib/console/log' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); +var isRealFloatingDataType = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); +var slice = require( '@stdlib/array/slice' ); +var join = require( '@stdlib/array/base/join' ); +var DATA = require( '@stdlib/math/special/data/unary.json' ); +var FUNCTION_DATABASE = require( '@stdlib/math/special/data/unary_function_database.json' ); + + +// VARIABLES // + +var CREATE_ONLY = 0; +var SCAFFOLD_SCRIPT = resolve( __dirname, 'scaffold.sh' ); +var ROOT_DIR = resolve( rootDir(), 'lib', 'node_modules' ); + + +// FUNCTIONS // + +/** +* Returns a string containing environment variable for generating pseudorandom numbers. +* +* @private +* @param {Object} obj - configuration object +* @returns {string} environment variable string +* +* @example +* var o = { +* 'prng': 'random/base/uniform', +* 'parameters': [ -10, 10 ] +* }; +* +* var s = prngEnvVars( o ); +* // returns 'BASE_PRNG=\'uniform\',RAND_MIN=-10,RAND_MAX=10' +*/ +function prngEnvVars( obj ) { + var base; + var min; + var max; + var p; + + p = obj.prng.split( '/' ); + base = p[ p.length-1 ]; + min = obj.parameters[ 0 ]; + max = obj.parameters[ 1 ]; + if ( base === 'uniform' ) { + if ( isInteger( min ) ) { + min = min.toString() + '.0'; + } + if ( isInteger( max ) ) { + max = max.toString() + '.0'; + } + } else { + min = min.toString(); + max = max.toString(); + } + return [ + 'BASE_PRNG=\'' + base + '\'', + 'RAND_MIN=' + min, + 'RAND_MAX=' + max + ].join( ' ' ); +} + +/** +* Returns an `ALIAS` environment variable string. +* +* @private +* @param {string} alias - package alias +* @returns {string} environment variable string +* +* @example +* var s = aliasEnvVar( 'abs' ); +* // returns 'ALIAS=abs' +* +* @example +* var s = aliasEnvVar( 'absf' ); +* // returns 'ALIAS=absf' +*/ +function aliasEnvVar( alias ) { + return 'ALIAS=' + alias; +} + +/** +* Returns the main export description environment variable. +* +* @private +* @param {string} desc - function description +* @returns {string} environment variable string +*/ +function mainDescEnvVar( desc ) { + return 'MAIN_DESC=\'' + desc + ' for each element in an ndarray.\''; +} + +/** +* Returns a string containing example values for a 2x2 array environment variable. +* +* @private +* @param {Array} values - example values +* @returns {string} environment variable string +* +* @example +* var exampleValues = [ 1.9, 4.8, 6.0, 8.1 ]; +* var out = jsExampleValues2x2EnvVar( exampleValues ); +* // returns "JS_EXAMPLE_VALUES_2X2='[ [ 1.9, 4.8 ], [ 6.0, 8.1 ] ]'" +* +* @example +* var exampleValues = [ { re: 1.9, im: 2.1 }, { re: 4.8, im: 3.2 }, { re: 6.0, im: 1.5 }, { re: 8.1, im: 2.7 } ]; +* var out = jsExampleValues2x2EnvVar( exampleValues ); +* // returns "JS_EXAMPLE_VALUES_2X2='[ [ { re: 1.9, im: 2.1 }, { re: 4.8, im: 3.2 } ], [ { re: 6.0, im: 1.5 }, { re: 8.1, im: 2.7 } ] ]'" +*/ +function jsExampleValues2x2EnvVar( values ) { + var bottomRow; + var topRow; + var matrix; + var vals; + var v; + var i; + + // Check if there are complex values in the array: + if ( values && values[ 0 ] && isComplexLike( values[ 0 ] ) ) { + matrix = []; + for ( i = 0; i < 4; i++ ) { + v = values[ i ]; + if ( v && isComplexLike( v ) ) { + matrix.push( '{ re: ' + v.re + ', im: ' + v.im + ' }' ); + } else { + matrix.push( '{ re: ' + v + ', im: 0 }' ); + } + } + topRow = join( slice( matrix, 0, 2 ), ', ' ); + bottomRow = join( slice( matrix, 2, 4 ), ', ' ); + return 'JS_EXAMPLE_VALUES_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; + } + + // For real values: + vals = []; + for ( i = 0; i < 4; i++ ) { + v = values[ i ]; + vals.push( v.toString() ); + } + topRow = join( slice( vals, 0, 2 ), ', ' ); + bottomRow = join( slice( vals, 2, 4 ), ', ' ); + return 'JS_EXAMPLE_VALUES_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; +} + +/** +* Returns a string containing example results for a 2x2 array environment variable. +* +* @private +* @param {Array} exampleValues - example input values +* @param {Function} fn - function to apply to each value +* @returns {string} environment variable string +* +* @example +* var abs = require( '@stdlib/math/base/special/abs' ); +* +* var exampleValues = [ 1.9, -4.8, -6.0, 8.1 ]; +* var out = jsExampleResults2x2EnvVar( exampleValues, abs ); +* // returns "JS_EXAMPLE_RESULTS_2X2='[ [ 1.9, 4.8 ], [ 6.0, 8.1 ] ]'" +*/ +function jsExampleResults2x2EnvVar( exampleValues, fn ) { + var bottomRow; + var results; + var topRow; + var v; + var r; + var i; + + // For complex values: + if ( exampleValues && exampleValues[ 0 ] && isComplexLike( exampleValues[ 0 ] ) ) { // eslint-disable-line max-len + results = []; + for ( i = 0; i < 4; i++ ) { + v = exampleValues[ i ]; + r = fn( v ); + results.push( r ); + } + topRow = join( slice( results, 0, 2 ), ', ' ); + bottomRow = join( slice( results, 2, 4 ), ', ' ); + return 'JS_EXAMPLE_RESULTS_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; + } + + // For real values: + results = []; + for ( i = 0; i < 4; i++ ) { + v = exampleValues[ i ]; + r = fn( v ); + results.push( r ); + } + topRow = join( slice( results, 0, 2 ), ', ' ); + bottomRow = join( slice( results, 2, 4 ), ', ' ); + return 'JS_EXAMPLE_RESULTS_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; +} + +/** +* Returns the assign export description environment variable. +* +* @private +* @param {string} desc - function description +* @returns {string} environment variable string +*/ +function assignDescEnvVar( desc ) { + return 'ASSIGN_DESC=\'' + desc + ' for each element in an ndarray and assigns results to a provided output ndarray.\''; +} + +/** +* Returns the input/output dtypes and policies environment variables. +* +* @private +* @param {Object} funcData - function data +* @returns {string} environment variable string +* +* @example +* var funcData = { +* "input_dtypes": "numeric_and_generic", +* "output_dtypes": "real_and_generic", +* "policies": { +* "output": "real_and_generic", +* "casting": "none" +* } +* }; +* var out = dtypesPoliciesEnvVars( funcData ); +* // returns 'INPUT_DTYPES=\'numeric_and_generic\' OUTPUT_DTYPES=\'real_and_generic\' OUTPUT_POLICY=\'real_and_generic\' CASTING_POLICY=\'none\'' +*/ +function dtypesPoliciesEnvVars( funcData ) { + return [ + 'INPUT_DTYPES=\'' + funcData.input_dtypes + '\'', + 'OUTPUT_DTYPES=\'' + funcData.output_dtypes + '\'', + 'OUTPUT_POLICY=\'' + funcData.policies.output + '\'', + 'CASTING_POLICY=\'' + funcData.policies.casting + '\'' + ].join( ' ' ); +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { // eslint-disable-line max-statements + +} + +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh new file mode 100755 index 000000000000..00235c6e0c96 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh @@ -0,0 +1,312 @@ +#!/usr/bin/env bash +# +# @license Apache-2.0 +# +# Copyright (c) 2020 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Script for scaffolding a package exposing an iterator which applies a unary mathematical function. +# +# Usage: scaffold.h +# +# Environment Variables: +# +# ALIAS Main export alias. +# DESC Default description. +# PKG_DESC Package description. +# MODULE_DESC Module description. +# MAIN_DESC Main export description. +# TEST_DESC Test description. +# DESC_LINK_TEXT README link text. +# KEYWORDS List of keywords. +# BASE_PRNG Base name of the package for generating pseudorandom numbers. +# RAND_MIN Minimum value for generated values. +# RAND_MAX Maximum value for generated values. +# VALUES_LEN_2 List of input values. +# JAVASCRIPT_RETURN_TYPE JavaScript return value data type. +# + +## USER-DEFINED VARIABLES ## + +# Define the main export alias: +alias=${ALIAS:-'iterTODO'} + +# Define the package description: +# shellcheck disable=SC2016 +pkg_desc=${PKG_DESC:-"Create an iterator which iteratively ${DESC:-'TODO'}."} + +# Define the module description: +# shellcheck disable=SC2016 +module_desc=${MODULE_DESC:-"Create an iterator which iteratively ${DESC:-'TODO'}."} + +# Define main export description: +# shellcheck disable=SC2016 +main_desc=${MAIN_DESC:-"Returns an iterator which iteratively ${DESC:-'TODO'}."} + +# Define the test description: +# shellcheck disable=SC2016 +test_desc=${TEST_DESC:-"${DESC:-'TODO'} for each iterated value"} + +# Define description text (found in the README) which should be a link to the unary package (NOTE: to not include a link, set to an empty string): +desc_link_text=${DESC_LINK_TEXT:-''} + +# Define a list of keywords: +if [[ -z "${KEYWORDS:-}" ]]; then +keywords=( + "stdmath" + "mathematics" + "math" +) +else + IFS=','; read -ra keywords <<< "${KEYWORDS}"; IFS=' '; +fi + +# Define the JavaScript return data type: +javascript_return_type=${JAVASCRIPT_RETURN_TYPE:-'number'} + +# Define a pseudorandom number generator for generating random values: +base_prng=${BASE_PRNG:-'uniform'} + +# Define the minimum value of generated values when benchmarking and testing the implementation: +rand_min=${RAND_MIN:-'-10.0'} + +# Define the maximum value of generated values when benchmarking and testing the implementation: +rand_max=${RAND_MAX:-'10.0'} + +# Define a list of input values: +if [[ -z "${VALUES_LEN_2:-}" ]]; then +values_len_2=( + '1.0' + '2.0' +) +else + IFS=','; read -ra values_len_2 <<< "${VALUES_LEN_2}"; IFS=' '; +fi + + +## COMPUTED VARIABLES ## + +# Converts from camel case to a underscored delineated string. +# +# $1 - string to convert +camelcase_to_snakecase() { + echo "$1" | sed 's/\([^A-Z]\)\([A-Z]\)/\1_\2/g' | sed 's/\([A-Z]\)\([A-Z]\)\([^A-Z]\)/\1_\2\3/g' | tr '[:upper:]' '[:lower:]' +} + +# Convert the alias to snakecase: +alias_snakecase=$(camelcase_to_snakecase "${alias:4}") + +# Define the destination package alias: +pkg_alias="${alias_snakecase//_/-}" + +# Define the destination package parent directory path: +pkg_path="${PKG_PATH:-'stdlib/math/iter/special'}" + +# Define the full destination package name: +pkg="${pkg_path}/${pkg_alias}" + +# Determine the root project directory: +root_dir="$(git rev-parse --show-toplevel)" + +# Define the project source code directory: +base_dir="${root_dir}/lib/node_modules" + +# Define the destination path: +dest_dir="${base_dir}/@${pkg}" + +# Define the location of this scaffold: +this_dir="${base_dir}/@stdlib/_tools/scaffold/math-iter-unary" + +# Define the location of a utility for wrapping REPL text descriptions: +wrap="${base_dir}/@stdlib/_tools/repl-txt/wrap-desc/bin/cli" + +# Define the unary function alias: +unary_alias=$(echo "${alias:4:1}" | tr '[:upper:]' '[:lower:]') +unary_alias="${unary_alias}${alias:5}" + +# Convert the unary function alias to snakecase: +unary_alias_snakecase=$(camelcase_to_snakecase "${unary_alias}") + +# Define the unary package "alias": +unary_pkg_alias="${UNARY_PKG_ALIAS:-${unary_alias_snakecase//_/-}}" + +# Define the unary package parent directory path: +unary_pkg_path="${UNARY_PKG_PATH:-'stdlib/math/base/special'}" + +# Define the package containing the unary function to apply: +unary_pkg="${unary_pkg_path}/${unary_pkg_alias}" + +# Define the REPL text main export description (note: 4 space indent and wrap at 80 characters): +repl_text_main_desc=$(printf "%s" "${main_desc}" | "${wrap}") +repl_text_main_desc="${repl_text_main_desc/ /}" + +# Define the copyright year: +year=$(date +'%Y') + +# Define the copyright holders: +copyright='The Stdlib Authors' + +# Define lists of expected values: +expected_script="var roundn = require( '${base_dir}/@stdlib/math/base/special/roundn' );var isInteger = require( '${base_dir}/@stdlib/assert/is-integer' ).isPrimitive;var f = require( '${base_dir}/@${unary_pkg}' );var arr = '${values_len_2[*]}'.split( ' ' );var expected = arr.slice();for ( var i = 0; i < arr.length; i++ ) {var v1 = f( parseFloat( arr[ i ] ) );var v2 = roundn( v1, -3 );if ( v1 == v2 ) {v = v1.toString();if ( isInteger( v1 ) ) {v += '.0';}} else {v = '~' + v2.toString();if ( isInteger( v2 ) ) {v += '.0';}}expected[ i ] = v;}console.log( expected.join( ',' ) );" + +tmp=$(node -e "${expected_script}") +IFS=','; read -ra expected_len_2 <<< "${tmp}"; IFS=' '; + + +## SCRIPT ## + +# Define the list of scaffold directories: +dirs=( + "benchmark" + "docs" + "docs/types" + "examples" + "lib" + "test" +) + +# Define the list of scaffold files: +files=( + "benchmark/benchmark.js" + "docs/types/index.d.ts" + "docs/types/test.ts" + "docs/repl.txt" + "examples/index.js" + "lib/index.js" + "lib/main.js" + "test/test.js" + "package.json" + "README.md" +) + +# Create the destination directories... +# shellcheck disable=SC2048 +for dir in ${dirs[*]}; do + mkdir -p "${dest_dir}/${dir}" +done + +# Copy the scaffold files to the destination directory... +# shellcheck disable=SC2048 +for file in ${files[*]}; do + cp "${this_dir}/data/${file//\./__}.txt" "${dest_dir}/${file}" +done + +# Performs a find and replace across the destination directory. +# +# $1 - regular expression +find_and_replace() { + find "${dest_dir}" -type f -print0 | xargs -0 perl -pi -w -e "$1" +} + +# Performs a find and replace across a specified file. +# +# $1 - file +# $2 - regular expression +file_find_and_replace() { + find "${dest_dir}/$1" -type f -print0 | xargs -0 perl -pi -w -e "$2" +} + +# Joins a list of strings. +# +# $1 - separator +# $* - list of strings to join +join() { + local d=$1; shift; local f=$1; shift; printf %s "$f" "${@/#/$d}"; +} + +# For each of the variables defined above, insert into the scaffold files... +regex="s/\\{\\{YEAR\\}\\}/${year}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{COPYRIGHT\\}\\}/${copyright}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{ALIAS\\}\\}/${alias}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{ALIAS_SNAKECASE\\}\\}/${alias_snakecase}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{PKG\\}\\}/${pkg//\//\\/}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{PKG_DESC\\}\\}/${pkg_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" +file_find_and_replace "README.md" "${regex}" + +regex="s/\\{\\{PKG_DESC\\}\\}/${pkg_desc}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{MODULE_DESC\\}\\}/${module_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" +file_find_and_replace "README.md" "${regex}" + +regex="s/\\{\\{MODULE_DESC\\}\\}/${module_desc}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{MAIN_DESC\\}\\}/${main_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" +file_find_and_replace "README.md" "${regex}" + +regex="s/\\{\\{MAIN_DESC\\}\\}/${main_desc}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{TEST_DESC\\}\\}/${test_desc}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{REPL_TEXT_MAIN_DESC\\}\\}/${repl_text_main_desc}/g;" +find_and_replace "${regex}" + +if [ -n "${desc_link_text}" ]; then + # WARNING: we assume that the description link text does *not* include any special regular expression characters... + regex="s/${desc_link_text}/[${desc_link_text}][\\@${unary_pkg//\//\\/}]/g;" + file_find_and_replace "README.md" "${regex}" +fi + +regex="s/\\{\\{UNARY_PKG\\}\\}/${unary_pkg//\//\\/}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{UNARY_ALIAS\\}\\}/${unary_alias}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{BASE_PRNG\\}\\}/${base_prng}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{RAND_MIN\\}\\}/${rand_min}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{RAND_MAX\\}\\}/${rand_max}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{JAVASCRIPT_RETURN_TYPE\\}\\}/${javascript_return_type}/g;" +find_and_replace "${regex}" + +keywords_sep='",\n "' +if [ "${#keywords[*]}" -eq 0 ]; then + words='' +else + words=$(join "${keywords_sep}" "${keywords[@]}") + words="\\n \"${words}\"," +fi +regex="s/\\{\\{KEYWORDS\\}\\}/${words}/g;" +find_and_replace "${regex}" + +expected_values_sep=', ' + +values=$(join "${expected_values_sep}" "${values_len_2[@]}") +regex="s/\\{\\{VALUES_LEN_2\\}\\}/${values}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{EXPECTED_1\\}\\}/${expected_len_2[0]}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{EXPECTED_2\\}\\}/${expected_len_2[1]}/g;" +find_and_replace "${regex}" From 32865abed93f2500044b8960f440695435cd537f Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 24 Sep 2025 21:55:40 +0530 Subject: [PATCH 2/9] chore: initial scripts --- .../scripts/generate_files.js | 494 ++++++++++++++++++ .../scripts/generate_matches_table.js | 237 +++++++++ .../math-special-unary/scripts/runner.js | 240 ++++++--- .../math-special-unary/scripts/scaffold.sh | 195 ++++--- 4 files changed, 1023 insertions(+), 143 deletions(-) create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js new file mode 100644 index 000000000000..4a249a276ccf --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js @@ -0,0 +1,494 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-lines */ + +'use strict'; + +// MODULES // + +var join = require( 'path' ).join; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var mkdirSync = require( 'fs' ).mkdirSync; +var licenseHeader = require( '@stdlib/_tools/licenses/header' ); +var currentYear = require( '@stdlib/time/current-year' ); +var capitalize = require( '@stdlib/string/capitalize' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var str2enum = require( '@stdlib/ndarray/base/dtype-str2enum' ); +var generateMatchesTable = require( './generate_matches_table.js' ); + + +// FUNCTIONS // + +/** +* Groups matches by input data type and returns grouped data, input types, and reordered matches. +* +* @private +* @param {Array} matches - array of match arrays +* @returns {Object} object containing grouped matches, input types, and reordered matches +*/ +function groupMatchesByInputType( matches ) { + var reorderedMatches = []; + var inputTypes = []; + var inputType; + var grouped = {}; + var i; + var j; + + for ( i = 0; i < matches.length; i++ ) { + inputType = matches[ i ][ 0 ]; + if ( !grouped[ inputType ] ) { + grouped[ inputType ] = []; + inputTypes.push( inputType ); + } + grouped[ inputType ].push( matches[ i ][ 1 ] ); + } + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + for ( j = 0; j < matches.length; j++ ) { + if ( matches[ j ][ 0 ] === inputType ) { + reorderedMatches.push( matches[ j ] ); + } + } + } + + return { + 'grouped': grouped, + 'inputTypes': inputTypes, + 'reorderedMatches': reorderedMatches + }; +} + +/** +* Generates the types.js file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @returns {string} types.js file content +*/ +function generateTypesFile( matches, header ) { + var outputTypes; + var inputTypes; + var inputType; + var grouped; + var result; + var jsOut; + var i; + var j; + + jsOut = header; + jsOut += '\n'; + jsOut += '/* eslint-disable array-element-newline */\n\n'; + jsOut += '\'use strict\';\n\n'; + jsOut += '// MODULES //\n\n'; + jsOut += 'var dtypes = require( \'@stdlib/ndarray/dtypes\' );\n\n\n'; + jsOut += '// MAIN //\n\n'; + jsOut += 'var types = [\n'; + + // Group matches by input dtype: + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + inputTypes = result.inputTypes; + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + jsOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + jsOut += '\tdtypes.' + inputType + ', dtypes.' + outputTypes[ j ]; + if ( i < inputTypes.length - 1 || j < outputTypes.length - 1 ) { + jsOut += ',\n'; + } else { + jsOut += '\n'; + } + } + + // Blank line between input type groups: + if ( i < inputTypes.length - 1 ) { + jsOut += '\n'; + } + } + + jsOut += '];\n\n\n'; + jsOut += '// EXPORTS //\n\n'; + jsOut += 'module.exports = types;\n'; + return jsOut; +} + +/** +* Generates the meta.json file content. +* +* @private +* @returns {string} meta.json file content +*/ +function generateMetaFile() { + var meta = { + 'nargs': 2, + 'nin': 1, + 'nout': 1 + }; + return JSON.stringify( meta, null, 2 ) + '\n'; +} + +/** +* Generates the types.json file content. +* +* @private +* @param {Array} matches - array of match entries +* @returns {string} types.json file content +*/ +function generateTypesJsonFile( matches ) { + var typeEnums; + var result; + var i; + + typeEnums = []; + for ( i = 0; i < matches.length; i++ ) { + typeEnums.push( str2enum( matches[ i ][ 0 ] ) ); + typeEnums.push( str2enum( matches[ i ][ 1 ] ) ); + } + + result = JSON.stringify( typeEnums ) + '\n'; + return result; +} + +/** +* Generates the data.js file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @returns {string} data.js file content +*/ +function generateDataFile( matches, header ) { + var uniquePackages; + var packageKeys; + var outputTypes; + var importName; + var inputTypes; + var matchIndex; + var packageMap; + var inputType; + var grouped; + var pkgPath; + var result; + var parts; + var dtype; + var jsOut; + var i; + var j; + var k; + + uniquePackages = {}; + packageMap = {}; + + for ( i = 0; i < matches.length; i++ ) { + pkgPath = matches[ i ][ 2 ]; + if ( !hasOwnProp( uniquePackages, pkgPath ) ) { + uniquePackages[ pkgPath ] = true; + if ( pkgPath.indexOf( '/identity' ) === -1 ) { + importName = pkgPath.split( '/' ).pop(); + } else { + // For identity functions, include dtype in the name: + parts = pkgPath.split( '/' ); + + // In future, we can get this dtype from the structured package data, once we have it: + dtype = parts[ parts.length - 3 ]; // For example, 'int32' from '@stdlib/number/int32/base/identity' + importName = 'identity' + capitalize( dtype ); + } + packageMap[ pkgPath ] = importName; + } + } + + jsOut = header; + jsOut += '\n/* eslint-disable stdlib/capitalized-comments */\n\n'; + jsOut += '\'use strict\';\n\n'; + jsOut += '// MODULES //\n\n'; + + // Add imports for all unique packages: + packageKeys = objectKeys( uniquePackages ); + for ( i = 0; i < packageKeys.length; i++ ) { + pkgPath = packageKeys[ i ]; + importName = packageMap[ pkgPath ]; + jsOut += 'var ' + importName + ' = require( \'' + pkgPath + '\' );\n'; + } + + jsOut += '\n\n// MAIN //\n\n'; + jsOut += 'var data = [\n'; + jsOut += '\t// NOTE: the following **must** match the order in `./types.js`. The order should be according to likelihood of use (e.g., if `float64` arrays are more likely, then `float64` types/data should come before `uint8`).\n\n'; + + // Group matches by input dtype: + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + inputTypes = result.inputTypes; + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + jsOut += '\t// ' + inputType + '\n'; + + for ( j = 0; j < outputTypes.length; j++ ) { + matchIndex = 0; + for ( k = 0; k < matches.length; k++ ) { + if ( matches[ k ][ 0 ] === inputType && + matches[ k ][ 1 ] === outputTypes[ j ] ) { + matchIndex = k; + break; + } + } + pkgPath = matches[ matchIndex ][ 2 ]; + importName = packageMap[ pkgPath ]; + jsOut += '\t' + importName; + if ( i < inputTypes.length - 1 || j < outputTypes.length - 1 ) { + jsOut += ',\n'; + } else { + jsOut += '\n'; + } + } + + // Blank line between input type groups: + if ( i < inputTypes.length - 1 ) { + jsOut += '\n'; + } + } + + jsOut += '];\n\n\n'; + jsOut += '// EXPORTS //\n\n'; + jsOut += 'module.exports = data;\n'; + return jsOut; +} + +/** +* Generates the addon.c file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @param {string} basePkg - base package name +* @returns {string} addon.c file content +*/ +function generateAddonFile( matches, header, basePkg ) { + var uniqueIncludes; + var functionIndex; + var outputTypes; + var includePath; + var kernelPath; + var inputType; + var grouped; + var result; + var cOut; + var i; + var j; + + // Generate unique includes... + uniqueIncludes = {}; + for ( i = 0; i < matches.length; i++ ) { + // Extract the full package path from the scalar kernel path: + kernelPath = matches[ i ][ 2 ]; + + includePath = kernelPath.replace( '@stdlib/', 'stdlib/' ) + '.h'; + uniqueIncludes[ '#include "' + includePath + '"' ] = true; + } + + // Group matches by input type: + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + matches = result.reorderedMatches; + + cOut = header; + cOut += Object.keys( uniqueIncludes ).join( '\n' ) + '\n'; + cOut += '#include "stdlib/ndarray/base/function_object.h"\n'; + cOut += '#include "stdlib/ndarray/base/napi/unary.h"\n'; + cOut += '#include "stdlib/ndarray/base/unary.h"\n'; + cOut += '#include "stdlib/ndarray/dtypes.h"\n'; + cOut += '#include \n\n'; + cOut += '// Define an interface name:\n'; + cOut += 'static const char name[] = "stdlib_ndarray_' + basePkg + '";\n\n'; + cOut += '// Define a list of ndarray functions:\n'; + cOut += 'static ndarrayFcn functions[] = {\n'; + + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t' + matches[ functionIndex ][ 7 ]; + functionIndex += 1; + if ( functionIndex < matches.length ) { + cOut += ',\n'; + } else { + cOut += '\n'; + } + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define the array of input and output ndarray types:\n'; + cOut += 'static int32_t types[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\tSTDLIB_NDARRAY_' + matches[ functionIndex ][ 0 ].toUpperCase() + ', STDLIB_NDARRAY_' + matches[ functionIndex ][ 1 ].toUpperCase(); + functionIndex += 1; + if ( functionIndex < matches.length ) { + cOut += ',\n'; + } else { + cOut += '\n'; + } + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define a list of ndarray function "data" (in this case, callbacks):\n'; + cOut += 'static void *data[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t(void *)' + matches[ functionIndex ][ 6 ]; + functionIndex += 1; + if ( functionIndex < matches.length ) { + cOut += ',\n'; + } else { + cOut += '\n'; + } + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Create an ndarray function object:\n'; + cOut += 'static const struct ndarrayFunctionObject obj = {\n'; + cOut += '\t// ndarray function name:\n'; + cOut += '\tname,\n\n'; + cOut += '\t// Number of input ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Number of output ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Total number of ndarray arguments (nin + nout):\n'; + cOut += '\t2,\n\n'; + cOut += '\t// Array containing ndarray functions:\n'; + cOut += '\tfunctions,\n\n'; + cOut += '\t// Number of ndarray functions:\n'; + cOut += '\t' + matches.length + ',\n\n'; + cOut += '\t// Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of ndarray argument types for a corresponding ndarray function:\n'; + cOut += '\ttypes,\n\n'; + cOut += '\t// Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions):\n'; + cOut += '\tdata\n'; + cOut += '};\n\n'; + cOut += 'STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj )\n'; + return cOut; +} + + +// MAIN // + +/** +* Main execution function. +* +* @private +* @param {string} destDir - destination directory +* @param {string} funcAlias - function alias +*/ +function main( destDir, funcAlias ) { + var filteredMatches; + var typesJsonOut; + var metaOut; + var dataOut; + var basePkg; + var matches; + var header; + var jsOut; + var cOut; + var i; + + // Ensure directories exist: + try { + mkdirSync( join( destDir, 'lib' ), { 'recursive': true } ); + mkdirSync( join( destDir, 'src' ), { 'recursive': true } ); + } catch ( err ) { + // Ignore errors if directories already exist + } + + // Generate and filter matches table: + matches = generateMatchesTable( funcAlias ); + + // Filter out generic types for addon.c: + filteredMatches = []; + for ( i = 0; i < matches.length; i++ ) { + if ( matches[ i ][ 0 ] !== 'generic' && matches[ i ][ 1 ] !== 'generic' ) { + filteredMatches.push( matches[ i ] ); + } + } + + // Extract package information: + basePkg = funcAlias; + + // Generate license header: + header = licenseHeader( 'Apache-2.0', 'js', { + 'year': currentYear(), + 'copyright': 'The Stdlib Authors' + }); + header += '\n/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */\n'; + + // Generate types.js: + jsOut = generateTypesFile( matches, header ); + writeFileSync( join( destDir, 'lib/types.js' ), jsOut, { + 'encoding': 'utf8' + }); + + // Generate types.json: + typesJsonOut = generateTypesJsonFile( matches ); + writeFileSync( join( destDir, 'lib/types.json' ), typesJsonOut, { + 'encoding': 'utf8' + }); + + // Generate meta.json: + metaOut = generateMetaFile(); + writeFileSync( join( destDir, 'lib/meta.json' ), metaOut, { + 'encoding': 'utf8' + }); + + // Generate data.js: + dataOut = generateDataFile( matches, header ); + writeFileSync( join( destDir, 'lib/data.js' ), dataOut, { + 'encoding': 'utf8' + }); + + // Generate addon.c: + cOut = generateAddonFile( filteredMatches, header, basePkg ); + writeFileSync( join( destDir, 'src/addon.c' ), cOut, { + 'encoding': 'utf8' + }); +} + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js new file mode 100644 index 000000000000..bc92b4c37d1c --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js @@ -0,0 +1,237 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var db = require( '@stdlib/math/special/data/unary_function_database.json' ); +var scaffoldDatabase = require( '@stdlib/math/special/data/unary.json' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); +var mostlySafeCasts = require( '@stdlib/ndarray/mostly-safe-casts' ); +var promotionRules = require( '@stdlib/ndarray/promotion-rules' ); +// Generate list of available ndarray kernels from source file names +var fs = require( 'fs' ); +var path = require( 'path' ); +var NDARRAY_KERNELS = (function() { + var srcDir = path.join( __dirname, '../../../../../../../lib/node_modules/@stdlib/ndarray/base/unary/src' ); + var files = fs.readdirSync( srcDir ); + var kernels = []; + + for ( var i = 0; i < files.length; i++ ) { + var file = files[ i ]; + if ( file.endsWith( '.c' ) && !file.startsWith( 'internal' ) ) { + // Extract function name from file name (e.g., 'd_d.c' -> 'stdlib_ndarray_d_d') + var baseName = file.replace( '.c', '' ); + kernels.push( 'stdlib_ndarray_' + baseName ); + } + } + return kernels; +})(); + + +// FUNCTIONS // + +/** +* Selects the appropriate scalar kernel based on input and output dtypes. +* +* @private +* @param {Object} scalarKernels - available scalar kernels +* @param {string} outputDtype - output dtype +* @param {string} inputDtype - input dtype +* @returns {string} scalar kernel name +*/ +function selectScalarKernel( scalarKernels, outputDtype, inputDtype ) { + var higherPrecisionDtype; + var scalarKernel; + + if ( inputDtype === 'generic' ) { + scalarKernel = scalarKernels[ outputDtype ] || scalarKernels.generic; + } else if ( outputDtype === 'generic' ) { + // Using the function appropriate for the input dtype, in case of generic output: + scalarKernel = scalarKernels[ inputDtype ] || scalarKernels.generic; + } else { + // Determine which dtype has higher priority using promotion rules: + higherPrecisionDtype = promotionRules( inputDtype, outputDtype ); + scalarKernel = scalarKernels[ higherPrecisionDtype ]; + if ( !scalarKernel ) { + scalarKernel = scalarKernels.generic; + } + } + + return scalarKernel; +} + +/** +* Selects the appropriate ndarray kernel name for dtype casting. +* +* @private +* @param {string} inputDtype - input dtype +* @param {string} outputDtype - output dtype +* @param {string} scalarKernel - scalar kernel name +* @param {Array} kernelList - list of available kernels +* @returns {string} kernel name +*/ +function selectKernelName( inputDtype, outputDtype, scalarKernel, kernelList ) { + var scalarKernelOutputDtype; + var scalarKernelInputDtype; + var ndarrayKernel; + var scaffoldEntry; + + // Check if the scalar kernel exists in the scaffold database + scaffoldEntry = scaffoldDatabase[ scalarKernel ]; + if ( !scaffoldEntry || !scaffoldEntry.parameters || scaffoldEntry.parameters.length === 0 ) { + // Fallback: use input and output dtypes directly + scalarKernelInputDtype = inputDtype; + scalarKernelOutputDtype = outputDtype; + } else { + scalarKernelInputDtype = scaffoldEntry.parameters[ 0 ].type.dtype; + scalarKernelOutputDtype = scaffoldEntry.returns.type.dtype; + } + + // Exact match: + if ( inputDtype === scalarKernelInputDtype && outputDtype === scalarKernelOutputDtype ) { + ndarrayKernel = 'stdlib_ndarray_' + dtypeChar( inputDtype ) + '_' + dtypeChar( outputDtype ); + } else { + // Not an exact match: + ndarrayKernel = 'stdlib_ndarray_'+dtypeChar(inputDtype)+'_'+dtypeChar(outputDtype)+'_as_'+dtypeChar(scalarKernelInputDtype)+'_'+dtypeChar(scalarKernelOutputDtype); + } + + if ( kernelList.indexOf( ndarrayKernel ) === -1 ) { + return; + } + + return ndarrayKernel; +} + + +// MAIN // + +/** +* Main function to generate dtype mappings. +* +* @private +* @param {string} funcAlias - function alias +* @returns {Array} array of mappings +*/ +function main( funcAlias ) { + var needsPromotion; + var cFunctionName; + var allowedCasts; + var scalarKernel; + var outputDtype; + var inputDtype; + var kernelName; + var mappings; + var filtered; + var obj; + var odt; + var idt; + var i; + var j; + var k; + + mappings = []; + + // Get scalar kernels and configuration for this function: + obj = db[ funcAlias ]; + if ( !obj ) { + throw new Error( 'Function alias not found in database: ' + funcAlias ); + } + + // Get input dtypes: + idt = dtypes( obj.input_dtypes ); + + // Get output dtypes: + odt = dtypes( obj.output_dtypes ); + + // Filter out excluded dtypes: + filtered = []; + for ( i = 0; i < idt.length; i++ ) { + if ( obj.excluded_dtypes.indexOf( idt[ i ] ) === -1 ) { + filtered.push( idt[ i ] ); + } + } + idt = filtered; + + // Generate all mostly-safe cast combinations: + for ( i = 0; i < idt.length; i++ ) { + inputDtype = idt[ i ]; + + if ( inputDtype === 'generic' ) { + allowedCasts = [ 'generic' ]; + } else { + // Get all dtypes this input can be mostly-safely cast to: + allowedCasts = mostlySafeCasts( inputDtype ); + } + + // Remove the dtypes which are not allowed for output, according to the output policy: + filtered = []; + for ( k = 0; k < allowedCasts.length; k++ ) { + if ( odt.indexOf( allowedCasts[ k ] ) !== -1 ) { + filtered.push( allowedCasts[ k ] ); + } + } + allowedCasts = filtered; + + for ( j = 0; j < allowedCasts.length; j++ ) { + outputDtype = allowedCasts[ j ]; + + if ( obj.excluded_dtypes.indexOf( outputDtype ) !== -1 ) { + continue; + } + + // Get scalar kernel for this dtype combination: + scalarKernel = selectScalarKernel( obj.scalar_kernels, outputDtype, inputDtype ); + + // Generate ndarray kernel name: + kernelName = selectKernelName( inputDtype, outputDtype, scalarKernel, NDARRAY_KERNELS ); + + // Skip if no kernel available: + if ( !kernelName ) { + continue; + } + + // Generate mapping: + needsPromotion = inputDtype !== outputDtype; + cFunctionName = scalarKernel.replace( '@stdlib/', 'stdlib_' ); + cFunctionName = cFunctionName.replace( /\//g, '_' ); + + mappings.push([ + inputDtype, + outputDtype, + scalarKernel, + needsPromotion, + ( needsPromotion ) ? outputDtype : null, + ( needsPromotion ) ? outputDtype : null, + cFunctionName, + kernelName + ]); + } + } + + return mappings; +} + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js index 8f7f7023cfac..5fcbe00fad06 100644 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js @@ -26,13 +26,10 @@ var resolve = require( 'path' ).resolve; var shell = require( 'child_process' ).execSync; // eslint-disable-line node/no-sync -var existsSync = require( '@stdlib/fs/exists' ).sync; var objectKeys = require( '@stdlib/utils/keys' ); -var rootDir = require( '@stdlib/_tools/utils/root-dir' ); var log = require( '@stdlib/console/log' ); var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var isComplexLike = require( '@stdlib/assert/is-complex-like' ); -var isRealFloatingDataType = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); var slice = require( '@stdlib/array/slice' ); var join = require( '@stdlib/array/base/join' ); var DATA = require( '@stdlib/math/special/data/unary.json' ); @@ -41,9 +38,7 @@ var FUNCTION_DATABASE = require( '@stdlib/math/special/data/unary_function_datab // VARIABLES // -var CREATE_ONLY = 0; var SCAFFOLD_SCRIPT = resolve( __dirname, 'scaffold.sh' ); -var ROOT_DIR = resolve( rootDir(), 'lib', 'node_modules' ); // FUNCTIONS // @@ -119,7 +114,7 @@ function aliasEnvVar( alias ) { * @returns {string} environment variable string */ function mainDescEnvVar( desc ) { - return 'MAIN_DESC=\'' + desc + ' for each element in an ndarray.\''; + return 'MAIN_DESC=\'' + escapeBashString( desc ) + ' for each element in an ndarray.\''; } /** @@ -175,90 +170,69 @@ function jsExampleValues2x2EnvVar( values ) { } /** -* Returns a string containing example results for a 2x2 array environment variable. +* Returns the assign export description environment variable. * * @private -* @param {Array} exampleValues - example input values -* @param {Function} fn - function to apply to each value +* @param {string} desc - function description * @returns {string} environment variable string -* -* @example -* var abs = require( '@stdlib/math/base/special/abs' ); -* -* var exampleValues = [ 1.9, -4.8, -6.0, 8.1 ]; -* var out = jsExampleResults2x2EnvVar( exampleValues, abs ); -* // returns "JS_EXAMPLE_RESULTS_2X2='[ [ 1.9, 4.8 ], [ 6.0, 8.1 ] ]'" */ -function jsExampleResults2x2EnvVar( exampleValues, fn ) { - var bottomRow; - var results; - var topRow; - var v; - var r; - var i; +function assignDescEnvVar( desc ) { + return 'ASSIGN_DESC=\'' + escapeBashString( desc ) + ' for each element in an ndarray and assigns results to a provided output ndarray.\''; +} - // For complex values: - if ( exampleValues && exampleValues[ 0 ] && isComplexLike( exampleValues[ 0 ] ) ) { // eslint-disable-line max-len - results = []; - for ( i = 0; i < 4; i++ ) { - v = exampleValues[ i ]; - r = fn( v ); - results.push( r ); - } - topRow = join( slice( results, 0, 2 ), ', ' ); - bottomRow = join( slice( results, 2, 4 ), ', ' ); - return 'JS_EXAMPLE_RESULTS_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; - } +/** +* Returns the input ndarray type environment variable. +* @private +* @param {string} dtypes - input dtypes +* @returns {string} environment variable string +*/ +function inputNdarrayTypeEnvVar( dtypes ) { + return 'INPUT_NDARRAY_TYPES=\'' + dtypes + '\''; +} - // For real values: - results = []; - for ( i = 0; i < 4; i++ ) { - v = exampleValues[ i ]; - r = fn( v ); - results.push( r ); - } - topRow = join( slice( results, 0, 2 ), ', ' ); - bottomRow = join( slice( results, 2, 4 ), ', ' ); - return 'JS_EXAMPLE_RESULTS_2X2=\'[ [ ' + topRow + ' ], [ ' + bottomRow + ' ] ]\''; +/** +* Returns the output ndarray type environment variable. +* +* @private +* @param {string} dtypes - output dtypes +* @returns {string} environment variable string +*/ +function outputNdarrayTypeEnvVar( dtypes ) { + return 'OUTPUT_NDARRAY_TYPES=\'' + dtypes + '\''; } /** -* Returns the assign export description environment variable. +* Returns the ndarray import types environment variable. * * @private -* @param {string} desc - function description +* @param {string} inputDtypes - input dtypes +* @param {string} outputDtypes - output dtypes * @returns {string} environment variable string */ -function assignDescEnvVar( desc ) { - return 'ASSIGN_DESC=\'' + desc + ' for each element in an ndarray and assigns results to a provided output ndarray.\''; +function ndarrayImportTypesEnvVar( inputDtypes, outputDtypes ) { + return 'NDARRAY_IMPORT_TYPES=\'' + inputDtypes + ',' + outputDtypes + '\''; } /** -* Returns the input/output dtypes and policies environment variables. +* Returns the package name environment variable. * * @private -* @param {Object} funcData - function data +* @param {string} pkg - package name * @returns {string} environment variable string +*/ +function pkgEnvVar( pkg ) { + return 'PKG=\'@stdlib/math/special/' + pkg + '\''; +} + +/** +* Escapes single quotes in a string for bash environment variables. * -* @example -* var funcData = { -* "input_dtypes": "numeric_and_generic", -* "output_dtypes": "real_and_generic", -* "policies": { -* "output": "real_and_generic", -* "casting": "none" -* } -* }; -* var out = dtypesPoliciesEnvVars( funcData ); -* // returns 'INPUT_DTYPES=\'numeric_and_generic\' OUTPUT_DTYPES=\'real_and_generic\' OUTPUT_POLICY=\'real_and_generic\' CASTING_POLICY=\'none\'' +* @private +* @param {string} str - input string +* @returns {string} escaped string */ -function dtypesPoliciesEnvVars( funcData ) { - return [ - 'INPUT_DTYPES=\'' + funcData.input_dtypes + '\'', - 'OUTPUT_DTYPES=\'' + funcData.output_dtypes + '\'', - 'OUTPUT_POLICY=\'' + funcData.policies.output + '\'', - 'CASTING_POLICY=\'' + funcData.policies.casting + '\'' - ].join( ' ' ); +function escapeBashString( str ) { + return str.replace( /'/g, "'\\''" ); } @@ -269,8 +243,134 @@ function dtypesPoliciesEnvVars( funcData ) { * * @private */ -function main() { // eslint-disable-line max-statements +function main() { + var scalarKernelPath; + var outputDtypes; + var inputDtypes; + var moduleDesc; + var baseAlias; + var testDesc; + var funcData; + var keywords; + var dataKeys; + var pkgDesc; + var dataKey; + var param; + var alias; + var desc; + var envs; + var cmd; + var o; + var i; + + // Get all function entries from unary.json database (these are the packages we want to generate)... + dataKeys = objectKeys( DATA ); + + // Process each function... + for ( i = 0; i < dataKeys.length; i++ ) { + dataKey = dataKeys[ i ]; + o = DATA[ dataKey ]; + + // Get the alias - either from the function entry or derive it from the package path + if ( o.alias ) { + alias = o.alias; + } else { + // Extract alias from package path (e.g., '@stdlib/math/base/special/abs' -> 'abs') + alias = dataKey.split( '/' ).pop(); + } + + log( 'Processing function: %s...', alias ); + + // Initialize environment variables array... + envs = []; + + // Basic package information... + envs.push( aliasEnvVar( o.alias ) ); + envs.push( pkgEnvVar( o.alias ) ); + envs.push( 'PKG_PATH=\'stdlib/math/special\'' ); + envs.push( 'UNARY_PKG_PATH=\'stdlib/math/base/special\'' ); + envs.push( 'UNARY_PKG_ALIAS=\'' + ( o.base_alias || o.alias ) + '\'' ); + + // Get the parameter information... + if ( !o.parameters || o.parameters.length === 0 ) { + log( 'Warning: function alias "%s" has no parameter information. Skipping...', alias ); + continue; + } + param = o.parameters[ 0 ]; + desc = param.desc; + pkgDesc = o.pkg_desc; + moduleDesc = 'Compute the ' + desc + ' for each element in an ndarray.'; + testDesc = desc + ' for each element in an ndarray'; + + // Description variables... + envs.push( 'DESC=\'' + escapeBashString( desc ) + '\'' ); + envs.push( 'PKG_DESC=\'' + escapeBashString( pkgDesc ) + '\'' ); + envs.push( 'MODULE_DESC=\'' + escapeBashString( moduleDesc ) + '\'' ); + envs.push( mainDescEnvVar( pkgDesc ) ); + envs.push( assignDescEnvVar( pkgDesc ) ); + envs.push( 'TEST_DESC=\'' + escapeBashString( testDesc ) + '\'' ); + envs.push( 'DESC_LINK_TEXT=\'' + escapeBashString( desc ) + '\'' ); + + // Type information... + envs.push( 'JAVASCRIPT_RETURN_TYPE=\'' + o.returns.type.javascript + '\'' ); + envs.push( 'C_OUTPUT_TYPE=\'' + o.returns.type.c + '\'' ); + envs.push( 'JSDOC_OUTPUT_TYPE=\'' + o.returns.type.jsdoc + '\'' ); + + // Example values and results... + envs.push( jsExampleValues2x2EnvVar( param.example_values ) ); + scalarKernelPath = '@stdlib/math/base/special/' + o.alias; + envs.push( 'SCALAR_KERNEL_PATH=\'' + scalarKernelPath + '\'' ); + + // PRNG information... + if ( param.rand ) { + envs.push( prngEnvVars( param.rand ) ); + } + + // Keywords... + keywords = o.keywords || []; + if ( o.extra_keywords ) { + keywords = keywords.concat( o.extra_keywords ); + } + envs.push( 'KEYWORDS=\'' + keywords.join( ',' ) + '\'' ); + // Year and copyright... + envs.push( 'YEAR=\'' + new Date().getFullYear() + '\'' ); + envs.push( 'COPYRIGHT=\'The Stdlib Authors\'' ); + + // Add TypeScript ndarray type variables... + baseAlias = o.base_alias || o.alias; + funcData = FUNCTION_DATABASE[ baseAlias ]; + inputDtypes = (funcData) ? funcData.input_dtypes : 'numeric_and_generic'; + outputDtypes = (funcData) ? funcData.output_dtypes : 'real_and_generic'; + + // Add input/output dtypes and policies environment variables... + if ( funcData ) { + envs.push( 'INPUT_DTYPES=\'' + funcData.input_dtypes + '\'' ); + envs.push( 'OUTPUT_DTYPES=\'' + funcData.output_dtypes + '\'' ); + envs.push( 'OUTPUT_POLICY=\'' + funcData.policies.output + '\'' ); + envs.push( 'CASTING_POLICY=\'' + funcData.policies.casting + '\'' ); + } + + // Add the TypeScript type variables (these functions need to be defined)... + envs.push( ndarrayImportTypesEnvVar( inputDtypes, outputDtypes ) ); + envs.push( inputNdarrayTypeEnvVar( inputDtypes ) ); + envs.push( outputNdarrayTypeEnvVar( outputDtypes ) ); + + // Add values for testing... + envs.push( 'VALUES_LEN_2=\'' + param.example_values.slice( 0, 2 ).join( ', ' ) + '\'' ); + envs.push( 'EXPECTED_1=\'' + param.example_values[ 0 ] + '\'' ); + envs.push( 'EXPECTED_2=\'' + param.example_values[ 1 ] + '\'' ); + + // Generate the command and execute... + log( 'Generated %d environment variables for %s', envs.length, alias ); + + // Use execSync with proper option handling + cmd = envs.join( ' ' ) + ' bash ' + SCAFFOLD_SCRIPT; + shell( cmd, { + 'encoding': 'utf8', + 'shell': '/bin/bash' + }); + } } main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh index 00235c6e0c96..2ffe3f797dcc 100755 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/scaffold.sh @@ -2,7 +2,7 @@ # # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Script for scaffolding a package exposing an iterator which applies a unary mathematical function. +# Script for scaffolding a package applying a unary mathematical function to each element in an ndarray. # # Usage: scaffold.h # @@ -35,28 +35,44 @@ # RAND_MAX Maximum value for generated values. # VALUES_LEN_2 List of input values. # JAVASCRIPT_RETURN_TYPE JavaScript return value data type. +# ASSIGN_DESC Assign function description. +# SCALAR_KERNEL_PATH Path to scalar kernel package. +# C_OUTPUT_TYPE C output type. +# JSDOC_OUTPUT_TYPE JSDoc output type. +# JS_EXAMPLE_VALUES_2X2 JavaScript example values for 2x2 array. +# INPUT_DTYPES Input data types. +# OUTPUT_DTYPES Output data types. +# OUTPUT_POLICY Output policy. +# CASTING_POLICY Casting policy. +# INPUT_NDARRAY_TYPES Input ndarray types. +# OUTPUT_NDARRAY_TYPES Output ndarray types. +# NDARRAY_IMPORT_TYPES Ndarray import types. # ## USER-DEFINED VARIABLES ## # Define the main export alias: -alias=${ALIAS:-'iterTODO'} +alias=${ALIAS:-'TODO'} # Define the package description: # shellcheck disable=SC2016 -pkg_desc=${PKG_DESC:-"Create an iterator which iteratively ${DESC:-'TODO'}."} +pkg_desc=${PKG_DESC:-"${DESC:-'TODO'} for each element in an ndarray."} # Define the module description: # shellcheck disable=SC2016 -module_desc=${MODULE_DESC:-"Create an iterator which iteratively ${DESC:-'TODO'}."} +module_desc=${MODULE_DESC:-"${DESC:-'TODO'} for each element in an ndarray."} # Define main export description: # shellcheck disable=SC2016 -main_desc=${MAIN_DESC:-"Returns an iterator which iteratively ${DESC:-'TODO'}."} +main_desc=${MAIN_DESC:-"${DESC:-'TODO'} for each element in an ndarray."} # Define the test description: # shellcheck disable=SC2016 -test_desc=${TEST_DESC:-"${DESC:-'TODO'} for each iterated value"} +test_desc=${TEST_DESC:-"the function ${DESC:-'TODO'} for each element in an ndarray."} + +# Define the assign description: +# shellcheck disable=SC2016 +assign_desc=${ASSIGN_DESC:-"${DESC:-'TODO'} for each element in an ndarray and assigns results to a provided output ndarray."} # Define description text (found in the README) which should be a link to the unary package (NOTE: to not include a link, set to an empty string): desc_link_text=${DESC_LINK_TEXT:-''} @@ -72,9 +88,6 @@ else IFS=','; read -ra keywords <<< "${KEYWORDS}"; IFS=' '; fi -# Define the JavaScript return data type: -javascript_return_type=${JAVASCRIPT_RETURN_TYPE:-'number'} - # Define a pseudorandom number generator for generating random values: base_prng=${BASE_PRNG:-'uniform'} @@ -84,14 +97,29 @@ rand_min=${RAND_MIN:-'-10.0'} # Define the maximum value of generated values when benchmarking and testing the implementation: rand_max=${RAND_MAX:-'10.0'} -# Define a list of input values: -if [[ -z "${VALUES_LEN_2:-}" ]]; then -values_len_2=( - '1.0' - '2.0' -) +# Define additional variables from runner.js: +scalar_kernel_path=${SCALAR_KERNEL_PATH:-'@stdlib/math/base/special/TODO'} +javascript_return_type=${JAVASCRIPT_RETURN_TYPE:-'number'} +c_output_type=${C_OUTPUT_TYPE:-'double'} +jsdoc_output_type=${JSDOC_OUTPUT_TYPE:-'number'} +js_example_values_2x2=${JS_EXAMPLE_VALUES_2X2:-'[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]'} +input_dtypes=${INPUT_DTYPES:-'numeric_and_generic'} +output_dtypes=${OUTPUT_DTYPES:-'real_and_generic'} +output_policy=${OUTPUT_POLICY:-'same'} +casting_policy=${CASTING_POLICY:-'safe'} +input_ndarray_types=${INPUT_NDARRAY_TYPES:-'RealArray'} +output_ndarray_types=${OUTPUT_NDARRAY_TYPES:-'RealArray'} +ndarray_import_types=${NDARRAY_IMPORT_TYPES:-'RealArray,RealArray'} + +# Define expected values (if not already provided): +expected_1=${EXPECTED_1:-'1.0'} +expected_2=${EXPECTED_2:-'2.0'} + +# Parse values_len_2 from VALUES_LEN_2 environment variable +if [[ -n "${VALUES_LEN_2:-}" ]]; then + IFS=',' read -ra values_len_2 <<< "${VALUES_LEN_2}" else - IFS=','; read -ra values_len_2 <<< "${VALUES_LEN_2}"; IFS=' '; + values_len_2=( '1.0' '2.0' ) fi @@ -105,13 +133,13 @@ camelcase_to_snakecase() { } # Convert the alias to snakecase: -alias_snakecase=$(camelcase_to_snakecase "${alias:4}") +alias_snakecase=$(camelcase_to_snakecase "${alias}") # Define the destination package alias: pkg_alias="${alias_snakecase//_/-}" # Define the destination package parent directory path: -pkg_path="${PKG_PATH:-'stdlib/math/iter/special'}" +pkg_path="${PKG_PATH:-'stdlib/math/special'}" # Define the full destination package name: pkg="${pkg_path}/${pkg_alias}" @@ -126,42 +154,19 @@ base_dir="${root_dir}/lib/node_modules" dest_dir="${base_dir}/@${pkg}" # Define the location of this scaffold: -this_dir="${base_dir}/@stdlib/_tools/scaffold/math-iter-unary" - -# Define the location of a utility for wrapping REPL text descriptions: -wrap="${base_dir}/@stdlib/_tools/repl-txt/wrap-desc/bin/cli" - -# Define the unary function alias: -unary_alias=$(echo "${alias:4:1}" | tr '[:upper:]' '[:lower:]') -unary_alias="${unary_alias}${alias:5}" - -# Convert the unary function alias to snakecase: -unary_alias_snakecase=$(camelcase_to_snakecase "${unary_alias}") - -# Define the unary package "alias": -unary_pkg_alias="${UNARY_PKG_ALIAS:-${unary_alias_snakecase//_/-}}" +this_dir="${base_dir}/@stdlib/_tools/scaffold/math-special-unary" # Define the unary package parent directory path: unary_pkg_path="${UNARY_PKG_PATH:-'stdlib/math/base/special'}" -# Define the package containing the unary function to apply: -unary_pkg="${unary_pkg_path}/${unary_pkg_alias}" - -# Define the REPL text main export description (note: 4 space indent and wrap at 80 characters): -repl_text_main_desc=$(printf "%s" "${main_desc}" | "${wrap}") -repl_text_main_desc="${repl_text_main_desc/ /}" +# Define the unary package alias: +unary_pkg_alias="${UNARY_PKG_ALIAS:-${alias}}" # Define the copyright year: -year=$(date +'%Y') +year=${YEAR:-$(date +'%Y')} # Define the copyright holders: -copyright='The Stdlib Authors' - -# Define lists of expected values: -expected_script="var roundn = require( '${base_dir}/@stdlib/math/base/special/roundn' );var isInteger = require( '${base_dir}/@stdlib/assert/is-integer' ).isPrimitive;var f = require( '${base_dir}/@${unary_pkg}' );var arr = '${values_len_2[*]}'.split( ' ' );var expected = arr.slice();for ( var i = 0; i < arr.length; i++ ) {var v1 = f( parseFloat( arr[ i ] ) );var v2 = roundn( v1, -3 );if ( v1 == v2 ) {v = v1.toString();if ( isInteger( v1 ) ) {v += '.0';}} else {v = '~' + v2.toString();if ( isInteger( v2 ) ) {v += '.0';}}expected[ i ] = v;}console.log( expected.join( ',' ) );" - -tmp=$(node -e "${expected_script}") -IFS=','; read -ra expected_len_2 <<< "${tmp}"; IFS=' '; +copyright=${COPYRIGHT:-'The Stdlib Authors'} ## SCRIPT ## @@ -173,21 +178,41 @@ dirs=( "docs/types" "examples" "lib" + "src" "test" ) # Define the list of scaffold files: files=( - "benchmark/benchmark.js" + "benchmark/benchmark_1d_contiguous_js.js" + "benchmark/benchmark_1d_contiguous_native_js.js" + "benchmark/benchmark_1d_contiguous_assign_js.js" + "benchmark/benchmark_1d_contiguous_assign_native_js.js" + "benchmark/benchmark_nd_contiguous_js.js" + "benchmark/benchmark_nd_contiguous_native_js.js" + "benchmark/benchmark_nd_noncontiguous_js.js" + "benchmark/benchmark_nd_noncontiguous_native_js.js" + "benchmark/benchmark_nd_singleton_dims_js.js" + "benchmark/benchmark_nd_singleton_dims_native_js.js" "docs/types/index.d.ts" "docs/types/test.ts" "docs/repl.txt" "examples/index.js" "lib/index.js" "lib/main.js" + "lib/native.js" + "lib/config.js" "test/test.js" + "test/test_assign_js.js" + "test/test_assign_native_js.js" + "test/test_main_js.js" + "test/test_main_native_js.js" "package.json" "README.md" + "binding.gyp" + "include.gypi" + "manifest.json" + "src/Makefile" ) # Create the destination directories... @@ -199,7 +224,12 @@ done # Copy the scaffold files to the destination directory... # shellcheck disable=SC2048 for file in ${files[*]}; do - cp "${this_dir}/data/${file//\./__}.txt" "${dest_dir}/${file}" + template_file="${this_dir}/data/${file//\./__}.txt" + if [ -f "${template_file}" ]; then + cp "${template_file}" "${dest_dir}/${file}" + else + echo "Warning: Template file ${template_file} not found. Skipping ${file}." + fi done # Performs a find and replace across the destination directory. @@ -235,58 +265,70 @@ find_and_replace "${regex}" regex="s/\\{\\{ALIAS\\}\\}/${alias}/g;" find_and_replace "${regex}" -regex="s/\\{\\{ALIAS_SNAKECASE\\}\\}/${alias_snakecase}/g;" -find_and_replace "${regex}" - regex="s/\\{\\{PKG\\}\\}/${pkg//\//\\/}/g;" find_and_replace "${regex}" -regex="s/\\{\\{PKG_DESC\\}\\}/${pkg_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" -file_find_and_replace "README.md" "${regex}" - regex="s/\\{\\{PKG_DESC\\}\\}/${pkg_desc}/g;" find_and_replace "${regex}" -regex="s/\\{\\{MODULE_DESC\\}\\}/${module_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" -file_find_and_replace "README.md" "${regex}" - regex="s/\\{\\{MODULE_DESC\\}\\}/${module_desc}/g;" find_and_replace "${regex}" -regex="s/\\{\\{MAIN_DESC\\}\\}/${main_desc//iterator/[iterator][mdn-iterator-protocol]}/g;" -file_find_and_replace "README.md" "${regex}" - regex="s/\\{\\{MAIN_DESC\\}\\}/${main_desc}/g;" find_and_replace "${regex}" -regex="s/\\{\\{TEST_DESC\\}\\}/${test_desc}/g;" +regex="s/\\{\\{ASSIGN_DESC\\}\\}/${assign_desc}/g;" find_and_replace "${regex}" -regex="s/\\{\\{REPL_TEXT_MAIN_DESC\\}\\}/${repl_text_main_desc}/g;" +regex="s/\\{\\{TEST_DESC\\}\\}/${test_desc}/g;" find_and_replace "${regex}" if [ -n "${desc_link_text}" ]; then # WARNING: we assume that the description link text does *not* include any special regular expression characters... - regex="s/${desc_link_text}/[${desc_link_text}][\\@${unary_pkg//\//\\/}]/g;" + regex="s/${desc_link_text}/[${desc_link_text}][\\@${unary_pkg_path//\//\\/}\\/${unary_pkg_alias}]/g;" file_find_and_replace "README.md" "${regex}" fi -regex="s/\\{\\{UNARY_PKG\\}\\}/${unary_pkg//\//\\/}/g;" +regex="s/\\{\\{UNARY_PKG\\}\\}/${unary_pkg_path//\//\\/}\\/${unary_pkg_alias}/g;" find_and_replace "${regex}" -regex="s/\\{\\{UNARY_ALIAS\\}\\}/${unary_alias}/g;" +regex="s/\\{\\{UNARY_PKG_ALIAS\\}\\}/${unary_pkg_alias}/g;" find_and_replace "${regex}" -regex="s/\\{\\{BASE_PRNG\\}\\}/${base_prng}/g;" +regex="s/\\{\\{SCALAR_KERNEL_PATH\\}\\}/${scalar_kernel_path//\//\\/}/g;" find_and_replace "${regex}" -regex="s/\\{\\{RAND_MIN\\}\\}/${rand_min}/g;" +regex="s/\\{\\{JAVASCRIPT_RETURN_TYPE\\}\\}/${javascript_return_type}/g;" find_and_replace "${regex}" -regex="s/\\{\\{RAND_MAX\\}\\}/${rand_max}/g;" +regex="s/\\{\\{C_OUTPUT_TYPE\\}\\}/${c_output_type}/g;" find_and_replace "${regex}" -regex="s/\\{\\{JAVASCRIPT_RETURN_TYPE\\}\\}/${javascript_return_type}/g;" +regex="s/\\{\\{JSDOC_OUTPUT_TYPE\\}\\}/${jsdoc_output_type}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{JS_EXAMPLE_VALUES_2X2\\}\\}/${js_example_values_2x2}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{INPUT_DTYPES\\}\\}/${input_dtypes}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{OUTPUT_DTYPES\\}\\}/${output_dtypes}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{OUTPUT_POLICY\\}\\}/${output_policy}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{CASTING_POLICY\\}\\}/${casting_policy}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{INPUT_NDARRAY_TYPES\\}\\}/${input_ndarray_types}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{OUTPUT_NDARRAY_TYPES\\}\\}/${output_ndarray_types}/g;" +find_and_replace "${regex}" + +regex="s/\\{\\{NDARRAY_IMPORT_TYPES\\}\\}/${ndarray_import_types}/g;" find_and_replace "${regex}" keywords_sep='",\n "' @@ -300,13 +342,20 @@ regex="s/\\{\\{KEYWORDS\\}\\}/${words}/g;" find_and_replace "${regex}" expected_values_sep=', ' - values=$(join "${expected_values_sep}" "${values_len_2[@]}") regex="s/\\{\\{VALUES_LEN_2\\}\\}/${values}/g;" find_and_replace "${regex}" -regex="s/\\{\\{EXPECTED_1\\}\\}/${expected_len_2[0]}/g;" +regex="s/\\{\\{EXPECTED_1\\}\\}/${expected_1}/g;" find_and_replace "${regex}" -regex="s/\\{\\{EXPECTED_2\\}\\}/${expected_len_2[1]}/g;" +regex="s/\\{\\{EXPECTED_2\\}\\}/${expected_2}/g;" find_and_replace "${regex}" + +# Generate the dynamic files (data.js, types.js, types.json, meta.json, addon.c) using the generation script +echo "Generating dynamic files for ${alias}..." +node "${this_dir}/scripts/generate_files.js" "${dest_dir}" "${alias}" +if [ $? -ne 0 ]; then + echo "Error: Failed to generate dynamic files for ${alias}" + exit 1 +fi From 39bf63df7a7a5dbc085d30230cd82cb54430aa69 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 24 Sep 2025 22:07:31 +0530 Subject: [PATCH 3/9] refactor: update scripts --- .../scripts/generate_files.js | 36 ++-- .../{generate_matches_table.js => script.js} | 186 +++++++++++++----- 2 files changed, 147 insertions(+), 75 deletions(-) rename lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/{generate_matches_table.js => script.js} (57%) diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js index 4a249a276ccf..d54a3da7601f 100644 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js @@ -24,14 +24,14 @@ var join = require( 'path' ).join; var writeFileSync = require( '@stdlib/fs/write-file' ).sync; -var mkdirSync = require( 'fs' ).mkdirSync; var licenseHeader = require( '@stdlib/_tools/licenses/header' ); var currentYear = require( '@stdlib/time/current-year' ); var capitalize = require( '@stdlib/string/capitalize' ); var objectKeys = require( '@stdlib/utils/keys' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var str2enum = require( '@stdlib/ndarray/base/dtype-str2enum' ); -var generateMatchesTable = require( './generate_matches_table.js' ); +var generateMatchesTable = require( './script.js' ); +var pkg = require( './../package.json' ); // FUNCTIONS // @@ -413,10 +413,8 @@ function generateAddonFile( matches, header, basePkg ) { * Main execution function. * * @private -* @param {string} destDir - destination directory -* @param {string} funcAlias - function alias */ -function main( destDir, funcAlias ) { +function main() { var filteredMatches; var typesJsonOut; var metaOut; @@ -428,16 +426,8 @@ function main( destDir, funcAlias ) { var cOut; var i; - // Ensure directories exist: - try { - mkdirSync( join( destDir, 'lib' ), { 'recursive': true } ); - mkdirSync( join( destDir, 'src' ), { 'recursive': true } ); - } catch ( err ) { - // Ignore errors if directories already exist - } - // Generate and filter matches table: - matches = generateMatchesTable( funcAlias ); + matches = generateMatchesTable(); // Filter out generic types for addon.c: filteredMatches = []; @@ -448,47 +438,47 @@ function main( destDir, funcAlias ) { } // Extract package information: - basePkg = funcAlias; + basePkg = pkg.name.split( '/' ).pop(); // Generate license header: header = licenseHeader( 'Apache-2.0', 'js', { 'year': currentYear(), 'copyright': 'The Stdlib Authors' }); - header += '\n/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */\n'; + header += '\n/* This is a generated file. Do not edit directly. */\n'; // Generate types.js: jsOut = generateTypesFile( matches, header ); - writeFileSync( join( destDir, 'lib/types.js' ), jsOut, { + writeFileSync( join( __dirname, '../lib/types.js' ), jsOut, { 'encoding': 'utf8' }); // Generate types.json: typesJsonOut = generateTypesJsonFile( matches ); - writeFileSync( join( destDir, 'lib/types.json' ), typesJsonOut, { + writeFileSync( join( __dirname, '../lib/types.json' ), typesJsonOut, { 'encoding': 'utf8' }); // Generate meta.json: metaOut = generateMetaFile(); - writeFileSync( join( destDir, 'lib/meta.json' ), metaOut, { + writeFileSync( join( __dirname, '../lib/meta.json' ), metaOut, { 'encoding': 'utf8' }); // Generate data.js: dataOut = generateDataFile( matches, header ); - writeFileSync( join( destDir, 'lib/data.js' ), dataOut, { + writeFileSync( join( __dirname, '../lib/data.js' ), dataOut, { 'encoding': 'utf8' }); // Generate addon.c: cOut = generateAddonFile( filteredMatches, header, basePkg ); - writeFileSync( join( destDir, 'src/addon.c' ), cOut, { + writeFileSync( join( __dirname, '../src/addon.c' ), cOut, { 'encoding': 'utf8' }); } -// EXPORTS // +// MAIN // -module.exports = main; +main(); diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/script.js similarity index 57% rename from lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js rename to lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/script.js index bc92b4c37d1c..3633530587e1 100644 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_matches_table.js +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/script.js @@ -22,30 +22,21 @@ // MODULES // +var join = require( 'path' ).join; +var readJSON = require( '@stdlib/fs/read-json' ).sync; var db = require( '@stdlib/math/special/data/unary_function_database.json' ); var scaffoldDatabase = require( '@stdlib/math/special/data/unary.json' ); var dtypes = require( '@stdlib/ndarray/dtypes' ); var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); var mostlySafeCasts = require( '@stdlib/ndarray/mostly-safe-casts' ); var promotionRules = require( '@stdlib/ndarray/promotion-rules' ); -// Generate list of available ndarray kernels from source file names -var fs = require( 'fs' ); -var path = require( 'path' ); -var NDARRAY_KERNELS = (function() { - var srcDir = path.join( __dirname, '../../../../../../../lib/node_modules/@stdlib/ndarray/base/unary/src' ); - var files = fs.readdirSync( srcDir ); - var kernels = []; - - for ( var i = 0; i < files.length; i++ ) { - var file = files[ i ]; - if ( file.endsWith( '.c' ) && !file.startsWith( 'internal' ) ) { - // Extract function name from file name (e.g., 'd_d.c' -> 'stdlib_ndarray_d_d') - var baseName = file.replace( '.c', '' ); - kernels.push( 'stdlib_ndarray_' + baseName ); - } - } - return kernels; -})(); + + +// VARIABLES // + +var pkgPath = join( __dirname, '..', 'package.json' ); +var pkg = readJSON( pkgPath ); +var basePkg = pkg.name.split( '/' ).pop(); // FUNCTIONS // @@ -58,11 +49,27 @@ var NDARRAY_KERNELS = (function() { * @param {string} outputDtype - output dtype * @param {string} inputDtype - input dtype * @returns {string} scalar kernel name +* +* @example +* var kernels = { +* 'float64': '@stdlib/math/base/special/floor', +* 'float32': '@stdlib/math/base/special/floorf', +* 'generic': '@stdlib/math/base/special/floor' +* }; +* var kernel = selectScalarKernel( kernels, 'float64', 'float32' ); +* // returns '@stdlib/math/base/special/floor' */ function selectScalarKernel( scalarKernels, outputDtype, inputDtype ) { var higherPrecisionDtype; var scalarKernel; + /* + * For example: + * + * inputDtype = 'complex64' + * outputDtype = 'float32' + */ + if ( inputDtype === 'generic' ) { scalarKernel = scalarKernels[ outputDtype ] || scalarKernels.generic; } else if ( outputDtype === 'generic' ) { @@ -70,8 +77,8 @@ function selectScalarKernel( scalarKernels, outputDtype, inputDtype ) { scalarKernel = scalarKernels[ inputDtype ] || scalarKernels.generic; } else { // Determine which dtype has higher priority using promotion rules: - higherPrecisionDtype = promotionRules( inputDtype, outputDtype ); - scalarKernel = scalarKernels[ higherPrecisionDtype ]; + higherPrecisionDtype = promotionRules( inputDtype, outputDtype ); // promotionRules( 'complex64', 'float32' ) => 'complex64' + scalarKernel = scalarKernels[ higherPrecisionDtype ]; // scalarKernels[ 'complex64' ] => '@stdlib/math/base/special/cfloorf' if ( !scalarKernel ) { scalarKernel = scalarKernels.generic; } @@ -87,36 +94,38 @@ function selectScalarKernel( scalarKernels, outputDtype, inputDtype ) { * @param {string} inputDtype - input dtype * @param {string} outputDtype - output dtype * @param {string} scalarKernel - scalar kernel name -* @param {Array} kernelList - list of available kernels * @returns {string} kernel name +* +* @example +* var kernel = selectKernelName( 'float32', 'float64', '@stdlib/math/base/special/abs' ); +* // returns 'stdlib_ndarray_f_d_as_d_d' +* +* @example +* var kernel = selectKernelName( 'float64', 'float32', '@stdlib/math/base/special/absf' ); +* // returns 'stdlib_ndarray_d_f_as_f_f' */ -function selectKernelName( inputDtype, outputDtype, scalarKernel, kernelList ) { +function selectKernelName( inputDtype, outputDtype, scalarKernel ) { var scalarKernelOutputDtype; var scalarKernelInputDtype; var ndarrayKernel; - var scaffoldEntry; - - // Check if the scalar kernel exists in the scaffold database - scaffoldEntry = scaffoldDatabase[ scalarKernel ]; - if ( !scaffoldEntry || !scaffoldEntry.parameters || scaffoldEntry.parameters.length === 0 ) { - // Fallback: use input and output dtypes directly - scalarKernelInputDtype = inputDtype; - scalarKernelOutputDtype = outputDtype; - } else { - scalarKernelInputDtype = scaffoldEntry.parameters[ 0 ].type.dtype; - scalarKernelOutputDtype = scaffoldEntry.returns.type.dtype; - } + + /* + * For example: + * + * inputDtype = 'complex64' + * outputDtype = 'float32' + * scalarKernel = '@stdlib/math/base/special/cfloorf' + */ + + scalarKernelInputDtype = scaffoldDatabase[ scalarKernel ].parameters[ 0 ].type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].parameters[ 0 ].type.dtype => 'complex64' + scalarKernelOutputDtype = scaffoldDatabase[ scalarKernel ].returns.type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].returns.type.dtype => 'complex64' // Exact match: if ( inputDtype === scalarKernelInputDtype && outputDtype === scalarKernelOutputDtype ) { ndarrayKernel = 'stdlib_ndarray_' + dtypeChar( inputDtype ) + '_' + dtypeChar( outputDtype ); } else { // Not an exact match: - ndarrayKernel = 'stdlib_ndarray_'+dtypeChar(inputDtype)+'_'+dtypeChar(outputDtype)+'_as_'+dtypeChar(scalarKernelInputDtype)+'_'+dtypeChar(scalarKernelOutputDtype); - } - - if ( kernelList.indexOf( ndarrayKernel ) === -1 ) { - return; + ndarrayKernel = 'stdlib_ndarray_'+dtypeChar(inputDtype)+'_'+dtypeChar(outputDtype)+'_as_'+dtypeChar(scalarKernelInputDtype)+'_'+dtypeChar(scalarKernelOutputDtype); // => 'stdlib_ndarray_c_f_as_c_c' } return ndarrayKernel; @@ -129,10 +138,9 @@ function selectKernelName( inputDtype, outputDtype, scalarKernel, kernelList ) { * Main function to generate dtype mappings. * * @private -* @param {string} funcAlias - function alias * @returns {Array} array of mappings */ -function main( funcAlias ) { +function main() { var needsPromotion; var cFunctionName; var allowedCasts; @@ -152,10 +160,29 @@ function main( funcAlias ) { mappings = []; // Get scalar kernels and configuration for this function: - obj = db[ funcAlias ]; - if ( !obj ) { - throw new Error( 'Function alias not found in database: ' + funcAlias ); - } + obj = db[ basePkg ]; + + /* + * obj = { + * "input_dtypes": "numeric_and_generic", + * "output_dtypes": "numeric_and_generic", + * "output_policy": "same", + * "excluded_dtypes": [ "float16", "uint8c", "complex32" ], + * "scalar_kernels": { + * "int8": "@stdlib/number/int8/base/identity", + * "int16": "@stdlib/number/int16/base/identity", + * "int32": "@stdlib/number/int32/base/identity", + * "uint8": "@stdlib/number/uint8/base/identity", + * "uint16": "@stdlib/number/uint16/base/identity", + * "uint32": "@stdlib/number/uint32/base/identity", + * "float32": "@stdlib/math/base/special/floorf", + * "float64": "@stdlib/math/base/special/floor", + * "complex64": "@stdlib/math/base/special/cfloorf", + * "complex128": "@stdlib/math/base/special/cfloor", + * "generic": "@stdlib/math/base/special/floor" + * } + * } + */ // Get input dtypes: idt = dtypes( obj.input_dtypes ); @@ -163,6 +190,25 @@ function main( funcAlias ) { // Get output dtypes: odt = dtypes( obj.output_dtypes ); + /* + * idt = [ + * 'complex32', + * 'complex64', + * 'complex128', + * 'float16', + * 'float32', + * 'float64', + * 'int16', + * 'int32', + * 'int8', + * 'uint16', + * 'uint32', + * 'uint8', + * 'uint8c', + * 'generic' + * ] + */ + // Filter out excluded dtypes: filtered = []; for ( i = 0; i < idt.length; i++ ) { @@ -172,15 +218,48 @@ function main( funcAlias ) { } idt = filtered; + /* + * idt = [ + * 'complex64', + * 'complex128', + * 'float32', + * 'float64', + * 'int16', + * 'int32', + * 'int8', + * 'uint16', + * 'uint32', + * 'uint8', + * 'generic' + * ] + */ + // Generate all mostly-safe cast combinations: for ( i = 0; i < idt.length; i++ ) { inputDtype = idt[ i ]; + /* + * For the first iteration: + * + * inputDtype = 'complex64' + */ + if ( inputDtype === 'generic' ) { allowedCasts = [ 'generic' ]; } else { // Get all dtypes this input can be mostly-safely cast to: allowedCasts = mostlySafeCasts( inputDtype ); + + /* + * For the first iteration: + * + * allowedCasts = [ + * 'complex64', + * 'complex128', + * 'float32', + * 'float64' + * ] + */ } // Remove the dtypes which are not allowed for output, according to the output policy: @@ -192,6 +271,8 @@ function main( funcAlias ) { } allowedCasts = filtered; + // console.log( 'allowedCasts for input dtype %s: %s', inputDtype, allowedCasts ); + for ( j = 0; j < allowedCasts.length; j++ ) { outputDtype = allowedCasts[ j ]; @@ -199,16 +280,17 @@ function main( funcAlias ) { continue; } + /* + * For example: + * + * outputDtype = 'float32' + */ + // Get scalar kernel for this dtype combination: - scalarKernel = selectScalarKernel( obj.scalar_kernels, outputDtype, inputDtype ); + scalarKernel = selectScalarKernel( obj.scalar_kernels, outputDtype, inputDtype ); // selectScalarKernel( kernels, 'float32', 'complex64' ) => '@stdlib/math/base/special/cfloorf' // Generate ndarray kernel name: - kernelName = selectKernelName( inputDtype, outputDtype, scalarKernel, NDARRAY_KERNELS ); - - // Skip if no kernel available: - if ( !kernelName ) { - continue; - } + kernelName = selectKernelName( inputDtype, outputDtype, scalarKernel ); // selectKernelName( 'complex64', 'float32', '@stdlib/math/base/special/cfloorf' ) => 'stdlib_ndarray_c_f_as_c_c' // Generate mapping: needsPromotion = inputDtype !== outputDtype; From ef93d507206e29104917f533aed943d0fd0bb47d Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 24 Sep 2025 22:12:32 +0530 Subject: [PATCH 4/9] refactor: update script --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math-special-unary/scripts/runner.js | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js index 5fcbe00fad06..8fcbb6a15135 100644 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js @@ -18,8 +18,6 @@ * limitations under the License. */ -/* eslint-disable max-lines */ - 'use strict'; // MODULES // @@ -311,11 +309,6 @@ function main() { envs.push( 'TEST_DESC=\'' + escapeBashString( testDesc ) + '\'' ); envs.push( 'DESC_LINK_TEXT=\'' + escapeBashString( desc ) + '\'' ); - // Type information... - envs.push( 'JAVASCRIPT_RETURN_TYPE=\'' + o.returns.type.javascript + '\'' ); - envs.push( 'C_OUTPUT_TYPE=\'' + o.returns.type.c + '\'' ); - envs.push( 'JSDOC_OUTPUT_TYPE=\'' + o.returns.type.jsdoc + '\'' ); - // Example values and results... envs.push( jsExampleValues2x2EnvVar( param.example_values ) ); scalarKernelPath = '@stdlib/math/base/special/' + o.alias; @@ -351,25 +344,13 @@ function main() { envs.push( 'CASTING_POLICY=\'' + funcData.policies.casting + '\'' ); } - // Add the TypeScript type variables (these functions need to be defined)... + // Add the TypeScript type variables... envs.push( ndarrayImportTypesEnvVar( inputDtypes, outputDtypes ) ); envs.push( inputNdarrayTypeEnvVar( inputDtypes ) ); envs.push( outputNdarrayTypeEnvVar( outputDtypes ) ); - // Add values for testing... - envs.push( 'VALUES_LEN_2=\'' + param.example_values.slice( 0, 2 ).join( ', ' ) + '\'' ); - envs.push( 'EXPECTED_1=\'' + param.example_values[ 0 ] + '\'' ); - envs.push( 'EXPECTED_2=\'' + param.example_values[ 1 ] + '\'' ); - - // Generate the command and execute... - log( 'Generated %d environment variables for %s', envs.length, alias ); - - // Use execSync with proper option handling - cmd = envs.join( ' ' ) + ' bash ' + SCAFFOLD_SCRIPT; - shell( cmd, { - 'encoding': 'utf8', - 'shell': '/bin/bash' - }); + cmd = envs.join( ' ' ) + ' . ' + SCAFFOLD_SCRIPT; + shell( cmd ); } } From 82c593920d9e9c63cc3f8f2ad447a596eba6a421 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Tue, 30 Sep 2025 22:27:29 +0530 Subject: [PATCH 5/9] refactor: update scripts and templates --- dtype_configurations.txt | 21 ++ extract_dtype_configs.js | 108 +++++++ .../math-special-unary/data/README__md.txt | 28 +- .../data/docs/repl__txt.txt | 8 +- .../math-special-unary/data/package__json.txt | 3 +- .../scripts/dtype_ndarray_mappings.json | 12 + .../scripts/generate_files.js | 57 +--- .../math-special-unary/scripts/runner.js | 287 ++++++++++++------ .../math-special-unary/scripts/scaffold.sh | 183 ++++++----- .../math-special-unary/scripts/script.js | 14 +- 10 files changed, 474 insertions(+), 247 deletions(-) create mode 100644 dtype_configurations.txt create mode 100644 extract_dtype_configs.js create mode 100644 lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/dtype_ndarray_mappings.json diff --git a/dtype_configurations.txt b/dtype_configurations.txt new file mode 100644 index 000000000000..2c5321a88812 --- /dev/null +++ b/dtype_configurations.txt @@ -0,0 +1,21 @@ +UNIQUE INPUT_DTYPES CONFIGURATIONS: +===================================== + +- numeric_and_generic: realcomplexndarray +- real_and_generic: realndarray + + +UNIQUE OUTPUT_DTYPES CONFIGURATIONS: +==================================== + +- floating_point_and_generic: floatcomplexndarray +- numeric_and_generic: realcomplexndarray +- real_and_generic: realndarray +- real_floating_point_and_generic: floatndarray + + +SUMMARY: +======== +Total unique input_dtypes configurations: 2 +Total unique output_dtypes configurations: 4 +Total functions analyzed: 132 diff --git a/extract_dtype_configs.js b/extract_dtype_configs.js new file mode 100644 index 000000000000..633790c11c3a --- /dev/null +++ b/extract_dtype_configs.js @@ -0,0 +1,108 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var fs = require( 'fs' ); +var db = require( './lib/node_modules/@stdlib/math/special/data/unary_function_database.json' ); + + +// MAIN // + +/** +* Extracts unique dtype configurations from the unary function database. +* +* @returns {void} +*/ +function main() { + var inputDtypesSet; + var outputDtypesSet; + var inputDtypes; + var outputDtypes; + var functions; + var results; + var func; + var obj; + var i; + + // Initialize sets to store unique values: + inputDtypesSet = new Set(); + outputDtypesSet = new Set(); + + // Get all function names: + functions = Object.keys( db ); + + // Iterate through each function: + for ( i = 0; i < functions.length; i++ ) { + func = functions[ i ]; + obj = db[ func ]; + + // Add input_dtypes if it exists: + if ( obj.input_dtypes ) { + inputDtypesSet.add( obj.input_dtypes ); + } + + // Add output_dtypes if it exists: + if ( obj.output_dtypes ) { + outputDtypesSet.add( obj.output_dtypes ); + } + } + + // Convert sets to sorted arrays: + inputDtypes = Array.from( inputDtypesSet ).sort(); + outputDtypes = Array.from( outputDtypesSet ).sort(); + + // Create results string: + results = 'UNIQUE INPUT_DTYPES CONFIGURATIONS:\n'; + results += '=====================================\n\n'; + for ( i = 0; i < inputDtypes.length; i++ ) { + results += '- ' + inputDtypes[ i ] + '\n'; + } + + results += '\n\nUNIQUE OUTPUT_DTYPES CONFIGURATIONS:\n'; + results += '====================================\n\n'; + for ( i = 0; i < outputDtypes.length; i++ ) { + results += '- ' + outputDtypes[ i ] + '\n'; + } + + results += '\n\nSUMMARY:\n'; + results += '========\n'; + results += 'Total unique input_dtypes configurations: ' + inputDtypes.length + '\n'; + results += 'Total unique output_dtypes configurations: ' + outputDtypes.length + '\n'; + results += 'Total functions analyzed: ' + functions.length + '\n'; + + // Write results to file: + fs.writeFileSync( 'dtype_configurations.txt', results, 'utf8' ); + + console.log( 'Dtype configurations extracted to dtype_configurations.txt' ); + console.log( 'Found ' + inputDtypes.length + ' unique input_dtypes and ' + outputDtypes.length + ' unique output_dtypes configurations' ); +} + + +// EXPORTS // + +module.exports = main; + +// If called directly from command line, execute the function +if ( require.main === module ) { + main(); +} diff --git a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt index 7ebc3a3feaa5..d7ee1d5e98ad 100644 --- a/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt +++ b/lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt @@ -20,7 +20,7 @@ limitations under the License. # {{ALIAS}} -> {{PKG_DESC}} +> {{README_PKG_DESC}} @@ -42,18 +42,18 @@ var {{ALIAS}} = require( '@{{PKG}}' ); #### {{ALIAS}}( x\[, options] ) -{{MAIN_DESC}} +{{README_MAIN_DESC}} ```javascript var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); -var x = array( {{EXAMPLE_VALUES_2X2}} ); +var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); var y = {{ALIAS}}( x ); // returns var arr = ndarray2array( y ); -// returns {{EXAMPLE_RESULTS_2X2}} +// returns {{JS_EXAMPLE_RESULTS_2X2}} ``` The function accepts the following arguments: @@ -73,7 +73,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var getDType = require( '@stdlib/ndarray/dtype' ); -var x = array( {{EXAMPLE_VALUES_2X2}} ); +var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); var y = {{ALIAS}}( x, { 'dtype': 'generic' }); @@ -83,7 +83,7 @@ var dt = getDType( y ); // returns 'generic' var arr = ndarray2array( y ); -// returns {{EXAMPLE_RESULTS_2X2}} +// returns {{JS_EXAMPLE_RESULTS_2X2}} ``` By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [order][@stdlib/ndarray/orders] as the input [ndarray][@stdlib/ndarray/ctor]. To return an [ndarray][@stdlib/ndarray/ctor] having a specific memory layout irrespective of the memory layout of the input [ndarray][@stdlib/ndarray/ctor], set the `order` option. @@ -93,7 +93,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var getOrder = require( '@stdlib/ndarray/order' ); -var x = array( {{EXAMPLE_VALUES_2X2}} ); +var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); var y = {{ALIAS}}( x, { 'order': 'column-major' }); @@ -103,18 +103,18 @@ var ord = getOrder( y ); // returns 'column-major' var arr = ndarray2array( y ); -// returns {{EXAMPLE_RESULTS_2X2}} +// returns {{JS_EXAMPLE_RESULTS_2X2}} ``` #### {{ALIAS}}.assign( x, y ) -{{ASSIGN_DESC}} +{{README_ASSIGN_DESC}} ```javascript var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); -var x = array( {{EXAMPLE_VALUES_2X2}} ); +var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); var out = {{ALIAS}}.assign( x, y ); @@ -124,7 +124,7 @@ var bool = ( out === y ); // returns true var arr = ndarray2array( out ); -// returns {{EXAMPLE_RESULTS_2X2}} +// returns {{JS_EXAMPLE_RESULTS_2X2}} ``` The function accepts the following arguments: @@ -140,7 +140,7 @@ var zeros = require( '@stdlib/ndarray/zeros' ); var array = require( '@stdlib/ndarray/array' ); // Create a 2x2 input ndarray: -var x = array( {{EXAMPLE_VALUES_2X2}} ); +var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); // Create a 2x2x2 output ndarray: var y = zeros( [ 2, 2, 2 ] ); @@ -149,7 +149,7 @@ var out = {{ALIAS}}.assign( x, y ); // returns var arr = ndarray2array( out ); -// returns [ {{EXAMPLE_RESULTS_2X2}}, {{EXAMPLE_RESULTS_2X2}} ] +// returns [ {{JS_EXAMPLE_RESULTS_2X2}}, {{JS_EXAMPLE_RESULTS_2X2}} ] ``` @@ -212,6 +212,8 @@ console.log( ndarray2array( y ) );