Skip to content

Commit a044e35

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 19a94ba commit a044e35

File tree

10 files changed

+340
-165
lines changed

10 files changed

+340
-165
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-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-reduce-strided1d-dispatch' );
3131
```
3232

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

3535
Constructor for performing a reduction on 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

@@ -77,9 +83,12 @@ var table = {
7783
};
7884

7985
var dtypes = [ 'float64', 'float32', 'generic' ];
80-
var policy = 'same';
86+
var policies = {
87+
'output': 'same',
88+
'casting': 'none'
89+
};
8190

82-
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policy );
91+
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
8392

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

117126
var dtypes = [ 'float64', 'float32', 'generic' ];
118-
var policy = 'same';
127+
var policies = {
128+
'output': 'same',
129+
'casting': 'none'
130+
};
119131

120-
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policy );
132+
var unary = new UnaryStrided1dDispatch( table, [ dtypes ], dtypes, policies );
121133

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

143155
var idt = dtypes( 'real_and_generic' );
144156
var odt = idt;
145-
var policy = 'same';
157+
var policies = {
158+
'output': 'same',
159+
'casting': 'none'
160+
};
146161

147162
var table = {
148163
'default': base
149164
};
150-
var unary = new UnaryStrided1dDispatch( table, [ idt ], odt, policy );
165+
var unary = new UnaryStrided1dDispatch( table, [ idt ], odt, policies );
151166

152167
var xbuf = [ -1.0, 2.0, -3.0 ];
153168
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -221,8 +236,11 @@ var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-reduce-strided
221236
var idt = dtypes( 'real_and_generic' );
222237
var odt = dtypes( 'real_and_generic' );
223238
224-
// Define the policy mapping an input data type to an output data type:
225-
var policy = 'same';
239+
// Define dispatch policies:
240+
var policies = {
241+
'output': 'same',
242+
'casting': 'none'
243+
};
226244
227245
// Define a dispatch table:
228246
var table = {
@@ -238,7 +256,7 @@ var table = {
238256
};
239257
240258
// Create an interface for performing a reduction:
241-
var max = new UnaryStrided1dDispatch( table, [ idt ], odt, policy );
259+
var max = new UnaryStrided1dDispatch( table, [ idt ], odt, policies );
242260
243261
// Generate an array of random numbers:
244262
var xbuf = uniform( 100, -1.0, 1.0, {
@@ -277,6 +295,10 @@ console.log( ndarray2array( y ) );
277295

278296
<section class="links">
279297

298+
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies
299+
300+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/input-casting-policies
301+
280302
</section>
281303

282304
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/unary-reduce-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': max
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-reduce-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': max
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-reduce-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-reduce-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 performing a reduction on an input
44
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/max}} };
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] )
@@ -85,9 +89,10 @@
8589

8690
Examples
8791
--------
88-
> var dtypes = [ 'float64', 'float32', 'generic' ];
92+
> var dts = [ 'float64', 'float32', 'generic' ];
93+
> var p = { 'output': 'same', 'casting': 'none' };
8994
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/max}} };
90-
> var f = new {{alias}}( t, [ dtypes ], dtypes, 'same' );
95+
> var f = new {{alias}}( t, [ dts ], dts, p );
9196
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
9297
> var dt = 'generic';
9398
> var sh = [ buf.length ];
@@ -130,9 +135,10 @@
130135

131136
Examples
132137
--------
133-
> var dtypes = [ 'float64', 'float32', 'generic' ];
138+
> var dts = [ 'float64', 'float32', 'generic' ];
139+
> var p = { 'output': 'same', 'casting': 'none' };
134140
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/max}} };
135-
> var f = new {{alias}}( t, [ dtypes ], dtypes, 'same' );
141+
> var f = new {{alias}}( t, [ dts ], dts, 'same' );
136142
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
137143
> var dt = 'generic';
138144
> var sh = [ buf.length ];

0 commit comments

Comments
 (0)