-
-
Notifications
You must be signed in to change notification settings - Fork 932
build: add scaffolding to generate math/special/* packages
#8139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
c7e0f03
32865ab
39bf63d
ef93d50
82c5939
bc812da
fe66127
d4db062
50ab32e
033dc3f
a6f8e92
af38a80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| <!-- | ||
|
|
||
| @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. --> | ||
|
|
||
| # {{ALIAS}} | ||
|
|
||
| > {{README_PKG_DESC}} | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- Package usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var {{ALIAS}} = require( '@{{PKG}}' ); | ||
| ``` | ||
|
|
||
| #### {{ALIAS}}( x\[, options] ) | ||
|
|
||
| {{README_MAIN_DESC}} | ||
|
|
||
| ```javascript | ||
| var ndarray2array = require( '@stdlib/ndarray/to-array' ); | ||
| var array = require( '@stdlib/ndarray/array' ); | ||
|
|
||
| var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little tricky, as it assumes that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you confirm that, for all ufuncs in math special, we will support float64, float32, and generic? |
||
| var y = {{ALIAS}}( x ); | ||
| // returns <ndarray> | ||
|
|
||
| var arr = ndarray2array( y ); | ||
| // returns {{JS_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 {{OUTPUT_POLICY_PHRASE}} [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( {{JS_EXAMPLE_VALUES_2X2}} ); | ||
| var y = {{ALIAS}}( x, { | ||
| 'dtype': 'generic' | ||
| }); | ||
| // returns <ndarray> | ||
|
|
||
| var dt = String( getDType( y ) ); | ||
| // returns 'generic' | ||
|
|
||
| var arr = ndarray2array( y ); | ||
| // 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. | ||
|
|
||
| ```javascript | ||
| var ndarray2array = require( '@stdlib/ndarray/to-array' ); | ||
| var array = require( '@stdlib/ndarray/array' ); | ||
| var getOrder = require( '@stdlib/ndarray/order' ); | ||
|
|
||
| var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); | ||
| var y = {{ALIAS}}( x, { | ||
| 'order': 'column-major' | ||
| }); | ||
| // returns <ndarray> | ||
|
|
||
| var ord = getOrder( y ); | ||
| // returns 'column-major' | ||
|
|
||
| var arr = ndarray2array( y ); | ||
| // returns {{JS_EXAMPLE_RESULTS_2X2}} | ||
| ``` | ||
|
|
||
| #### {{ALIAS}}.assign( x, y ) | ||
|
|
||
| {{README_ASSIGN_DESC}} | ||
|
|
||
| ```javascript | ||
| 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 out = {{ALIAS}}.assign( x, y ); | ||
| // returns <ndarray> | ||
|
|
||
| var bool = ( out === y ); | ||
| // returns true | ||
|
|
||
| var arr = ndarray2array( out ); | ||
| // returns {{JS_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( {{JS_EXAMPLE_VALUES_2X2}} ); | ||
|
|
||
| // Create a 2x2x2 output ndarray: | ||
| var y = zeros( [ 2, 2, 2 ] ); | ||
|
|
||
| var out = {{ALIAS}}.assign( x, y ); | ||
| // returns <ndarray> | ||
|
|
||
| var arr = ndarray2array( out ); | ||
| // returns [ {{JS_EXAMPLE_RESULTS_2X2}}, {{JS_EXAMPLE_RESULTS_2X2}} ] | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## 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 {{OUTPUT_POLICY_PHRASE}} [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]. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- Package usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```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 ) ); | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="references"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.references --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| [@stdlib/math/base/special/{{ALIAS}}]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40{{PKG_LINK_SUFFIX}} | ||
|
|
||
| [@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor | ||
|
|
||
| [@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders | ||
|
|
||
| [@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes | ||
|
|
||
| [@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies | ||
|
|
||
| [@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); |
Uh oh!
There was an error while loading. Please reload this page.