Skip to content

Commit 9f35a29

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 a044e35 commit 9f35a29

File tree

10 files changed

+248
-93
lines changed

10 files changed

+248
-93
lines changed

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ limitations under the License.
3232
var unaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' );
3333
```
3434

35-
#### unaryStrided1dDispatchFactory( table, idtypes, odtypes, policy )
35+
#### unaryStrided1dDispatchFactory( table, idtypes, odtypes, policies )
3636

3737
Returns a function for performing a reduction on an input ndarray.
3838

@@ -46,9 +46,12 @@ var table = {
4646
};
4747

4848
var dtypes = [ 'float64', 'float32', 'generic' ];
49-
var policy = 'same';
49+
var policies = {
50+
'output': 'same',
51+
'casting': 'none'
52+
};
5053

51-
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
54+
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policies );
5255
```
5356

5457
The function has the following parameters:
@@ -66,7 +69,10 @@ The function has the following parameters:
6669

6770
- **odtypes**: list of supported output data types.
6871

69-
- **policy**: output data type policy.
72+
- **policies**: dispatch policies. Must have the following properties:
73+
74+
- **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
75+
- **casting**: input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
7076

7177
#### unary( x\[, ...args]\[, options] )
7278

@@ -83,9 +89,12 @@ var table = {
8389
};
8490

8591
var dtypes = [ 'float64', 'float32', 'generic' ];
86-
var policy = 'same';
92+
var policies = {
93+
'output': 'same',
94+
'casting': 'none'
95+
};
8796

88-
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
97+
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policies );
8998

9099
var xbuf = [ -1.0, 2.0, -3.0 ];
91100
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -123,9 +132,12 @@ var table = {
123132
};
124133

125134
var dtypes = [ 'float64', 'float32', 'generic' ];
126-
var policy = 'same';
135+
var policies = {
136+
'output': 'same',
137+
'casting': 'none'
138+
};
127139

128-
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
140+
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policies );
129141

130142
var xbuf = [ -1.0, 2.0, -3.0 ];
131143
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -152,12 +164,15 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' );
152164

153165
var idt = dtypes( 'real_and_generic' );
154166
var odt = idt;
155-
var policy = 'same';
167+
var policies = {
168+
'output': 'same',
169+
'casting': 'none'
170+
};
156171

157172
var table = {
158173
'default': base
159174
};
160-
var unary = unaryStrided1dDispatchFactory( table, [ idt ], odt, policy );
175+
var unary = unaryStrided1dDispatchFactory( table, [ idt ], odt, policies );
161176

162177
var xbuf = [ -1.0, 2.0, -3.0 ];
163178
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -233,8 +248,11 @@ var unaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/unary-reduce-
233248
var idt = dtypes( 'real_and_generic' );
234249
var odt = dtypes( 'real_and_generic' );
235250
236-
// Define the policy mapping an input data type to an output data type:
237-
var policy = 'same';
251+
// Define dispatch policies:
252+
var policies = {
253+
'output': 'same',
254+
'casting': 'none'
255+
};
238256
239257
// Define a dispatch table:
240258
var table = {
@@ -250,7 +268,7 @@ var table = {
250268
};
251269
252270
// Create an interface for performing a reduction:
253-
var max = unaryStrided1dDispatchFactory( table, [ idt ], odt, policy );
271+
var max = unaryStrided1dDispatchFactory( table, [ idt ], odt, policies );
254272
255273
// Generate an array of random numbers:
256274
var xbuf = uniform( 100, -1.0, 1.0, {
@@ -289,6 +307,10 @@ console.log( ndarray2array( y ) );
289307

290308
<section class="links">
291309

310+
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies
311+
312+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/input-casting-policies
313+
292314
</section>
293315

294316
<!-- /.links -->

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var factory = 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 = factory( table, [ dt ], dt, 'same' );
56+
policies = {
57+
'output': 'same',
58+
'casting': 'none'
59+
};
60+
unary = factory( 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-factory/benchmark/benchmark.js

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

3131
bench( pkg+'::factory', function benchmark( b ) {
32+
var policies;
3233
var dtypes;
3334
var table;
3435
var v;
@@ -41,10 +42,14 @@ bench( pkg+'::factory', 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 = factory( table, [ dtypes ], dtypes, 'same' );
52+
v = factory( table, [ dtypes ], dtypes, policies );
4853
if ( typeof v !== 'function' ) {
4954
b.fail( 'should return a function' );
5055
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var factory = 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 = factory( table, [ dt ], dt, 'same' );
54+
policies = {
55+
'output': 'same',
56+
'casting': 'none'
57+
};
58+
unary = factory( 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-factory/docs/repl.txt

Lines changed: 14 additions & 8 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 function for performing a reduction on an input ndarray.
44

55
Parameters
@@ -35,8 +35,11 @@
3535
odtypes: Array<string>
3636
List of supported output array data types.
3737

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

4144
Returns
4245
-------
@@ -46,8 +49,9 @@
4649
Examples
4750
--------
4851
> var dt = [ 'float64', 'float32', 'generic' ];
52+
> var p = { 'output': 'same', 'casting': 'none' };
4953
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/max}} };
50-
> var f = {{alias}}( t, [ dt ], dt, 'same' );
54+
> var f = {{alias}}( t, [ dt ], dt, p );
5155

5256

5357
fcn( x[, ...args][, options] )
@@ -84,9 +88,10 @@ fcn( x[, ...args][, options] )
8488

8589
Examples
8690
--------
87-
> var dtypes = [ 'float64', 'float32', 'generic' ];
91+
> var dts = [ 'float64', 'float32', 'generic' ];
92+
> var p = { 'output': 'same', 'casting': 'none' };
8893
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/max}} };
89-
> var f = {{alias}}( t, [ dtypes ], dtypes, 'same' );
94+
> var f = {{alias}}( t, [ dts ], dts, p );
9095
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
9196
> var dt = 'generic';
9297
> var sh = [ buf.length ];
@@ -129,9 +134,10 @@ fcn.assign( x[, ...args], out[, options] )
129134

130135
Examples
131136
--------
132-
> var dtypes = [ 'float64', 'float32', 'generic' ];
137+
> var dts = [ 'float64', 'float32', 'generic' ];
138+
> var p = { 'output': 'same', 'casting': 'none' };
133139
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/max}} };
134-
> var f = {{alias}}( t, [ dtypes ], dtypes, 'same' );
140+
> var f = {{alias}}( t, [ dts ], dts, p );
135141
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
136142
> var dt = 'generic';
137143
> var sh = [ buf.length ];

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/docs/types/index.d.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// <reference types="@stdlib/types"/>
2222

2323
import { ArrayLike } from '@stdlib/types/array';
24-
import { OutputPolicy, DataType, typedndarray } from '@stdlib/types/ndarray';
24+
import { OutputPolicy, InputCastingPolicy, DataType, typedndarray } from '@stdlib/types/ndarray';
2525

2626
/**
2727
* Input array.
@@ -101,6 +101,21 @@ interface DispatchTable<T, U> extends BaseDispatchTable<T, U> {
101101
fcns: ArrayLike<Unary<T, U> | UnaryWithAdditionalArrays<T, U>>;
102102
}
103103

104+
/**
105+
* Dispatch policies.
106+
*/
107+
interface Policies {
108+
/**
109+
* Output data type policy.
110+
*/
111+
output: OutputPolicy;
112+
113+
/**
114+
* Input ndarray casting policy.
115+
*/
116+
casting: InputCastingPolicy;
117+
}
118+
104119
/**
105120
* Interface for performing a reduction on an ndarray.
106121
*/
@@ -119,12 +134,15 @@ interface UnaryFunction<T, U> {
119134
*
120135
* var idt = dtypes( 'real_and_generic' );
121136
* var odt = idt;
122-
* var policy = 'same';
137+
* var policies = {
138+
* 'output': 'same',
139+
* 'casting': 'none'
140+
* };
123141
*
124142
* var table = {
125143
* 'default': base
126144
* };
127-
* var max = factory( table, [ idt ], odt, policy );
145+
* var max = factory( table, [ idt ], odt, policies );
128146
*
129147
* var xbuf = [ -1.0, 2.0, -3.0 ];
130148
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -152,12 +170,15 @@ interface UnaryFunction<T, U> {
152170
*
153171
* var idt = dtypes( 'real_and_generic' );
154172
* var odt = idt;
155-
* var policy = 'same';
173+
* var policies = {
174+
* 'output': 'same',
175+
* 'casting': 'none'
176+
* };
156177
*
157178
* var table = {
158179
* 'default': base
159180
* };
160-
* var max = factory( table, [ idt ], odt, policy );
181+
* var max = factory( table, [ idt ], odt, policies );
161182
*
162183
* var xbuf = [ -1.0, 2.0, -3.0 ];
163184
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -191,12 +212,15 @@ interface UnaryFunction<T, U> {
191212
*
192213
* var idt = dtypes( 'real_and_generic' );
193214
* var odt = idt;
194-
* var policy = 'same';
215+
* var policies = {
216+
* 'output': 'same',
217+
* 'casting': 'none'
218+
* };
195219
*
196220
* var table = {
197221
* 'default': base
198222
* };
199-
* var max = factory( table, [ idt ], odt, policy );
223+
* var max = factory( table, [ idt ], odt, policies );
200224
*
201225
* var xbuf = [ -1.0, 2.0, -3.0 ];
202226
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -222,7 +246,7 @@ interface UnaryFunction<T, U> {
222246
* @param table - dispatch table
223247
* @param idtypes - list containing lists of supported input data types for each ndarray argument
224248
* @param odtypes - list of supported output data types
225-
* @param policy - output data type policy
249+
* @param policies - dispatch policies
226250
* @returns function for applying a unary function
227251
*
228252
* @example
@@ -232,12 +256,15 @@ interface UnaryFunction<T, U> {
232256
*
233257
* var idt = dtypes( 'real_and_generic' );
234258
* var odt = idt;
235-
* var policy = 'same';
259+
* var policies = {
260+
* 'output': 'same',
261+
* 'casting': 'none'
262+
* };
236263
*
237264
* var table = {
238265
* 'default': base
239266
* };
240-
* var max = factory( table, [ idt ], odt, policy );
267+
* var max = factory( table, [ idt ], odt, policies );
241268
*
242269
* var xbuf = [ -1.0, 2.0, -3.0 ];
243270
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -248,7 +275,7 @@ interface UnaryFunction<T, U> {
248275
* var v = y.get();
249276
* // returns 2.0
250277
*/
251-
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policy: OutputPolicy ): UnaryFunction<T, U>;
278+
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies ): UnaryFunction<T, U>;
252279

253280

254281
// EXPORTS //

0 commit comments

Comments
 (0)