Skip to content

Commit f0602e3

Browse files
committed
refactor!: replace policy string argument with a policy object
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: skipped - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent e41167e commit f0602e3

File tree

10 files changed

+351
-149
lines changed

10 files changed

+351
-149
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-strided1d-dispatch' );
3131
```
3232

33-
#### UnaryStrided1dDispatch( table, idtypes, odtypes, policy )
33+
#### UnaryStrided1dDispatch( table, idtypes, odtypes, policies )
3434

3535
Returns an interface for applying a strided function to an input ndarray.
3636

@@ -42,9 +42,12 @@ var table = {
4242
};
4343

4444
var dtypes = [ 'float64', 'float32', 'generic' ];
45-
var policy = 'same';
45+
var policies = {
46+
'output': 'same',
47+
'casting': 'none'
48+
};
4649

47-
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policy );
50+
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
4851
```
4952

5053
The constructor has the following parameters:
@@ -62,7 +65,10 @@ The constructor has the following parameters:
6265

6366
- **odtypes**: list of supported output data types.
6467

65-
- **policy**: output data type policy.
68+
- **policies**: dispatch policies. Must have the following properties:
69+
70+
- **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
71+
- **casting**: input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
6672

6773
#### UnaryStrided1dDispatch.prototype.apply( x\[, ...args]\[, options] )
6874

@@ -78,9 +84,12 @@ var table = {
7884
};
7985

8086
var dtypes = [ 'float64', 'float32', 'generic' ];
81-
var policy = 'same';
87+
var policies = {
88+
'output': 'same',
89+
'casting': 'none'
90+
};
8291

83-
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policy );
92+
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
8493

8594
var xbuf = [ -1.0, 2.0, -3.0 ];
8695
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -116,9 +125,12 @@ var table = {
116125
};
117126

118127
var dtypes = [ 'float64', 'float32', 'generic' ];
119-
var policy = 'same';
128+
var policies = {
129+
'output': 'same',
130+
'casting': 'none'
131+
};
120132

121-
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policy );
133+
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
122134

123135
var xbuf = [ -1.0, 2.0, -3.0 ];
124136
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -144,12 +156,15 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' );
144156

145157
var idt = dtypes( 'real_and_generic' );
146158
var odt = idt;
147-
var policy = 'same';
159+
var policies = {
160+
'output': 'same',
161+
'casting': 'none'
162+
};
148163

149164
var table = {
150165
'default': base
151166
};
152-
var unary = new UnaryStrided1dDispatch( table, [ idt ], odt, policy );
167+
var unary = new UnaryStrided1dDispatch( table, [ idt ], odt, policies );
153168

154169
var xbuf = [ -1.0, 2.0, -3.0 ];
155170
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -225,8 +240,11 @@ var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-strided1d-disp
225240
var idt = dtypes( 'real_and_generic' );
226241
var odt = dtypes( 'real_and_generic' );
227242
228-
// Define the policy mapping an input data type to an output data type:
229-
var policy = 'same';
243+
// Define dispatch policies:
244+
var policies = {
245+
'output': 'same',
246+
'casting': 'none'
247+
};
230248
231249
// Define a dispatch table:
232250
var table = {
@@ -242,7 +260,7 @@ var table = {
242260
};
243261
244262
// Create an interface for performing a reduction:
245-
var cumax = new UnaryStrided1dDispatch( table, [ idt ], odt, policy );
263+
var cumax = new UnaryStrided1dDispatch( table, [ idt ], odt, policies );
246264
247265
// Generate an array of random numbers:
248266
var xbuf = discreteUniform( 25, -10, 10, {
@@ -282,6 +300,10 @@ console.log( ndarray2array( y ) );
282300

283301
<section class="links">
284302

303+
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies
304+
305+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/input-casting-policies
306+
285307
</section>
286308

287309
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/benchmark/benchmark.apply.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var UnaryStrided1dDispatch = require( './../lib' );
4141
* @returns {Function} benchmark function
4242
*/
4343
function createBenchmark( len ) {
44+
var policies;
4445
var unary;
4546
var table;
4647
var dt;
@@ -50,7 +51,11 @@ function createBenchmark( len ) {
5051
'default': cumax
5152
};
5253
dt = dtypes( 'real_floating_point' );
53-
unary = new UnaryStrided1dDispatch( table, [ dt ], dt, 'same' );
54+
policies = {
55+
'output': 'same',
56+
'casting': 'none'
57+
};
58+
unary = new UnaryStrided1dDispatch( table, [ dt ], dt, policies );
5459

5560
x = uniform( len, -50.0, 50.0, {
5661
'dtype': 'float64'

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/benchmark/benchmark.assign.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var UnaryStrided1dDispatch = require( './../lib' );
4242
* @returns {Function} benchmark function
4343
*/
4444
function createBenchmark( len ) {
45+
var policies;
4546
var unary;
4647
var table;
4748
var out;
@@ -52,7 +53,11 @@ function createBenchmark( len ) {
5253
'default': cumax
5354
};
5455
dt = dtypes( 'real_floating_point' );
55-
unary = new UnaryStrided1dDispatch( table, [ dt ], dt, 'same' );
56+
policies = {
57+
'output': 'same',
58+
'casting': 'none'
59+
};
60+
unary = new UnaryStrided1dDispatch( table, [ dt ], dt, policies );
5661

5762
x = uniform( len, -50.0, 50.0, {
5863
'dtype': 'float64'

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/benchmark/benchmark.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var UnaryStrided1dDispatch = require( './../lib' );
2929
// MAIN //
3030

3131
bench( pkg+'::new', function benchmark( b ) {
32+
var policies;
3233
var dtypes;
3334
var table;
3435
var v;
@@ -41,10 +42,14 @@ bench( pkg+'::new', function benchmark( b ) {
4142
'float64',
4243
'float32'
4344
];
45+
policies = {
46+
'output': 'same',
47+
'casting': 'none'
48+
};
4449

4550
b.tic();
4651
for ( i = 0; i < b.iterations; i++ ) {
47-
v = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, 'same' );
52+
v = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
4853
if ( typeof v !== 'object' ) {
4954
b.fail( 'should return an object' );
5055
}
@@ -58,6 +63,7 @@ bench( pkg+'::new', function benchmark( b ) {
5863
});
5964

6065
bench( pkg+'::no_new', function benchmark( b ) {
66+
var policies;
6167
var dtypes;
6268
var table;
6369
var fcn;
@@ -71,12 +77,16 @@ bench( pkg+'::no_new', function benchmark( b ) {
7177
'float64',
7278
'float32'
7379
];
80+
policies = {
81+
'output': 'same',
82+
'casting': 'none'
83+
};
7484

7585
fcn = UnaryStrided1dDispatch;
7686

7787
b.tic();
7888
for ( i = 0; i < b.iterations; i++ ) {
79-
v = fcn( table, [ dtypes ], dtypes, 'same' );
89+
v = fcn( table, [ dtypes ], dtypes, policies );
8090
if ( typeof v !== 'object' ) {
8191
b.fail( 'should return an object' );
8292
}

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/docs/repl.txt

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

2-
{{alias}}( table, idtypes, odtypes, policy )
2+
{{alias}}( table, idtypes, odtypes, policies )
33
Returns an ndarray function interface for applying a strided function to an
44
input ndarray.
55

@@ -36,8 +36,11 @@
3636
odtypes: Array<string>
3737
List of supported output array data types.
3838

39-
policy: string
40-
Output data type policy.
39+
policies: Object
40+
Dispatch policies. Must have the following properties:
41+
42+
- output: output data type policy.
43+
- casting: input ndarray casting policy.
4144

4245
Returns
4346
-------
@@ -46,9 +49,10 @@
4649

4750
Examples
4851
--------
49-
> var dtypes = [ 'float64', 'float32', 'generic' ];
52+
> var dts = [ 'float64', 'float32', 'generic' ];
53+
> var p = { 'output': 'same', 'casting': 'none' };
5054
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/cumax}} };
51-
> var out = new {{alias}}( t, [ dtypes ], dtypes, 'same' );
55+
> var out = new {{alias}}( t, [ dts ], dts, p );
5256

5357

5458
{{alias}}.prototype.apply( x[, ...args][, options] )
@@ -81,9 +85,10 @@
8185

8286
Examples
8387
--------
84-
> var dtypes = [ 'float64', 'float32', 'generic' ];
88+
> var dts = [ 'float64', 'float32', 'generic' ];
89+
> var p = { 'output': 'same', 'casting': 'none' };
8590
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/cumax}} };
86-
> var f = new {{alias}}( t, [ dtypes ], dtypes, 'same' );
91+
> var f = new {{alias}}( t, [ dts ], dts, p );
8792
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
8893
> var dt = 'generic';
8994
> var sh = [ buf.length ];
@@ -126,9 +131,10 @@
126131

127132
Examples
128133
--------
129-
> var dtypes = [ 'float64', 'float32', 'generic' ];
134+
> var dts = [ 'float64', 'float32', 'generic' ];
135+
> var p = { 'output': 'same', 'casting': 'none' };
130136
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/cumax}} };
131-
> var f = new {{alias}}( t, [ dtypes ], dtypes, 'same' );
137+
> var f = new {{alias}}( t, [ dts ], dts, p );
132138
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
133139
> var dt = 'generic';
134140
> var sh = [ buf.length ];

0 commit comments

Comments
 (0)