Skip to content

Commit 7507be0

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 f0602e3 commit 7507be0

File tree

10 files changed

+239
-88
lines changed

10 files changed

+239
-88
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-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-strided1d-dispatch-factory' );
3333
```
3434

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

3737
Returns a function for applying a strided function 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

@@ -84,9 +90,12 @@ var table = {
8490
};
8591

8692
var dtypes = [ 'float64', 'float32', 'generic' ];
87-
var policy = 'same';
93+
var policies = {
94+
'output': 'same',
95+
'casting': 'none'
96+
};
8897

89-
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
98+
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policies );
9099

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

126135
var dtypes = [ 'float64', 'float32', 'generic' ];
127-
var policy = 'same';
136+
var policies = {
137+
'output': 'same',
138+
'casting': 'none'
139+
};
128140

129-
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
141+
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policies );
130142

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

155167
var idt = dtypes( 'real_and_generic' );
156168
var odt = idt;
157-
var policy = 'same';
169+
var policies = {
170+
'output': 'same',
171+
'casting': 'none'
172+
};
158173

159174
var table = {
160175
'default': base
161176
};
162-
var unary = unaryStrided1dDispatchFactory( table, [ idt ], odt, policy );
177+
var unary = unaryStrided1dDispatchFactory( table, [ idt ], odt, policies );
163178

164179
var xbuf = [ -1.0, 2.0, -3.0 ];
165180
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -235,8 +250,11 @@ var unaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/unary-strided
235250
var idt = dtypes( 'real_and_generic' );
236251
var odt = dtypes( 'real_and_generic' );
237252
238-
// Define the policy mapping an input data type to an output data type:
239-
var policy = 'same';
253+
// Define dispatch policies:
254+
var policies = {
255+
'output': 'same',
256+
'casting': 'none'
257+
};
240258
241259
// Define a dispatch table:
242260
var table = {
@@ -252,7 +270,7 @@ var table = {
252270
};
253271
254272
// Create an interface for performing an operation:
255-
var cumax = unaryStrided1dDispatchFactory( table, [ idt ], odt, policy );
273+
var cumax = unaryStrided1dDispatchFactory( table, [ idt ], odt, policies );
256274
257275
// Generate an array of random numbers:
258276
var xbuf = discreteUniform( 25, -10, 10, {
@@ -292,6 +310,10 @@ console.log( ndarray2array( y ) );
292310

293311
<section class="links">
294312

313+
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies
314+
315+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/input-casting-policies
316+
295317
</section>
296318

297319
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/unary-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': cumax
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-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-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': cumax
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-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 applying a strided function to 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/cumax}} };
50-
> var f = {{alias}}( t, [ dt ], dt, 'same' );
54+
> var f = {{alias}}( t, [ dt ], dt, p );
5155

5256

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

8185
Examples
8286
--------
83-
> var dtypes = [ 'float64', 'float32', 'generic' ];
87+
> var dts = [ 'float64', 'float32', 'generic' ];
88+
> var p = { 'output': 'same', 'casting': 'none' };
8489
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/cumax}} };
85-
> var f = {{alias}}( t, [ dtypes ], dtypes, 'same' );
90+
> var f = {{alias}}( t, [ dts ], dts, p );
8691
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
8792
> var dt = 'generic';
8893
> var sh = [ buf.length ];
@@ -125,9 +130,10 @@ fcn.assign( x[, ...args], out[, options] )
125130

126131
Examples
127132
--------
128-
> var dtypes = [ 'float64', 'float32', 'generic' ];
133+
> var dts = [ 'float64', 'float32', 'generic' ];
134+
> var p = { 'output': 'same', 'casting': 'none' };
129135
> var t = { 'default': {{alias:@stdlib/stats/base/ndarray/cumax}} };
130-
> var f = {{alias}}( t, [ dtypes ], dtypes, 'same' );
136+
> var f = {{alias}}( t, [ dts ], dts, p );
131137
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
132138
> var dt = 'generic';
133139
> var sh = [ buf.length ];

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

Lines changed: 34 additions & 7 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.
@@ -96,6 +96,21 @@ interface DispatchTable<T, U> extends BaseDispatchTable<T, U> {
9696
fcns: ArrayLike<Unary<T, U> | UnaryWithAdditionalArrays<T, U>>;
9797
}
9898

99+
/**
100+
* Dispatch policies.
101+
*/
102+
interface Policies {
103+
/**
104+
* Output data type policy.
105+
*/
106+
output: OutputPolicy;
107+
108+
/**
109+
* Input ndarray casting policy.
110+
*/
111+
casting: InputCastingPolicy;
112+
}
113+
99114
/**
100115
* Interface for applying an operation to an ndarray.
101116
*/
@@ -115,7 +130,10 @@ interface UnaryFunction<T, U> {
115130
*
116131
* var idt = dtypes( 'real_and_generic' );
117132
* var odt = idt;
118-
* var policy = 'same';
133+
* var policies = {
134+
* 'output': 'same',
135+
* 'casting': 'none'
136+
* };
119137
*
120138
* var table = {
121139
* 'default': base
@@ -149,7 +167,10 @@ interface UnaryFunction<T, U> {
149167
*
150168
* var idt = dtypes( 'real_and_generic' );
151169
* var odt = idt;
152-
* var policy = 'same';
170+
* var policies = {
171+
* 'output': 'same',
172+
* 'casting': 'none'
173+
* };
153174
*
154175
* var table = {
155176
* 'default': base
@@ -189,7 +210,10 @@ interface UnaryFunction<T, U> {
189210
*
190211
* var idt = dtypes( 'real_and_generic' );
191212
* var odt = idt;
192-
* var policy = 'same';
213+
* var policies = {
214+
* 'output': 'same',
215+
* 'casting': 'none'
216+
* };
193217
*
194218
* var table = {
195219
* 'default': base
@@ -220,7 +244,7 @@ interface UnaryFunction<T, U> {
220244
* @param table - dispatch table
221245
* @param idtypes - list containing lists of supported input data types for each ndarray argument
222246
* @param odtypes - list of supported output data types
223-
* @param policy - output data type policy
247+
* @param policies - dispatch policies
224248
* @returns function for applying a unary function
225249
*
226250
* @example
@@ -231,7 +255,10 @@ interface UnaryFunction<T, U> {
231255
*
232256
* var idt = dtypes( 'real_and_generic' );
233257
* var odt = idt;
234-
* var policy = 'same';
258+
* var policies = {
259+
* 'output': 'same',
260+
* 'casting': 'none'
261+
* };
235262
*
236263
* var table = {
237264
* 'default': base
@@ -247,7 +274,7 @@ interface UnaryFunction<T, U> {
247274
* var arr = ndarray2array( y );
248275
* // returns [ -1.0, 2.0, 2.0 ]
249276
*/
250-
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>;
277+
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>;
251278

252279

253280
// EXPORTS //

0 commit comments

Comments
 (0)