Skip to content

Commit b087d7b

Browse files
committed
feat: add support for enforcing traversal order
--- 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: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 d1bc036 commit b087d7b

File tree

5 files changed

+101
-7
lines changed

5 files changed

+101
-7
lines changed

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

Lines changed: 7 additions & 1 deletion
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, policies )
35+
#### unaryStrided1dDispatchFactory( table, idtypes, odtypes, policies\[, options] )
3636

3737
Returns a function for applying a strided function an input ndarray.
3838

@@ -74,6 +74,12 @@ The function has the following parameters:
7474
- **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
7575
- **casting**: input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
7676

77+
- **options**: function options (_optional_).
78+
79+
The function supports the following options:
80+
81+
- **strictTraversalOrder**: boolean specifying whether the order of element traversal must match the memory layout order of an input ndarray. Default: `false`.
82+
7783
#### unary( x\[, ...args]\[, options] )
7884

7985
Applies a strided function to a provided input ndarray.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

55
Parameters
@@ -41,6 +41,13 @@
4141
- output: output data type policy.
4242
- casting: input ndarray casting policy.
4343

44+
options: Object (optional)
45+
Function options.
46+
47+
options.strictTraversalOrder: boolean (optional)
48+
Boolean specifying whether the order of element traversal must match the
49+
memory layout order of an input ndarray.
50+
4451
Returns
4552
-------
4653
fcn: Function

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ interface Options extends BaseOptions {
5353
dtype?: DataType;
5454
}
5555

56+
/**
57+
* Interface defining factory options.
58+
*/
59+
interface FactoryOptions {
60+
/**
61+
* Boolean specifying whether the order of element traversal must match the memory layout of an input ndarray.
62+
*/
63+
strictTraversalOrder?: boolean;
64+
}
65+
5666
/**
5767
* Strided function.
5868
*
@@ -245,6 +255,7 @@ interface UnaryFunction<T, U> {
245255
* @param idtypes - list containing lists of supported input data types for each ndarray argument
246256
* @param odtypes - list of supported output data types
247257
* @param policies - dispatch policies
258+
* @param options - function options
248259
* @returns function for applying a unary function
249260
*
250261
* @example
@@ -274,7 +285,7 @@ interface UnaryFunction<T, U> {
274285
* var arr = ndarray2array( y );
275286
* // returns [ -1.0, 2.0, 2.0 ]
276287
*/
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>;
288+
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies, options?: FactoryOptions ): UnaryFunction<T, U>;
278289

279290

280291
// EXPORTS //

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

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import factory = require( './index' );
4040
};
4141

4242
factory<number, number>( table, [ dtypes ], dtypes, policies ); // $ExpectType UnaryFunction<number, number>
43+
factory<number, number>( table, [ dtypes ], dtypes, policies, {} ); // $ExpectType UnaryFunction<number, number>
4344
}
4445

4546
// The compiler throws an error if the function is provided a first argument which is not a dispatch table...
@@ -59,6 +60,16 @@ import factory = require( './index' );
5960
factory( 'abc', [ dtypes ], dtypes, policies ); // $ExpectError
6061
factory( {}, [ dtypes ], dtypes, policies ); // $ExpectError
6162
factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes, policies ); // $ExpectError
63+
64+
factory( '5', [ dtypes ], dtypes, policies, {} ); // $ExpectError
65+
factory( 5, [ dtypes ], dtypes, policies, {} ); // $ExpectError
66+
factory( true, [ dtypes ], dtypes, policies, {} ); // $ExpectError
67+
factory( false, [ dtypes ], dtypes, policies, {} ); // $ExpectError
68+
factory( null, [ dtypes ], dtypes, policies, {} ); // $ExpectError
69+
factory( void 0, [ dtypes ], dtypes, policies, {} ); // $ExpectError
70+
factory( 'abc', [ dtypes ], dtypes, policies, {} ); // $ExpectError
71+
factory( {}, [ dtypes ], dtypes, policies, {} ); // $ExpectError
72+
factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes, policies, {} ); // $ExpectError
6273
}
6374

6475
// The compiler throws an error if the function is provided a second argument which is not a list of data type lists...
@@ -81,6 +92,16 @@ import factory = require( './index' );
8192
factory<number, number>( table, 'abc', dtypes, policies ); // $ExpectError
8293
factory<number, number>( table, {}, dtypes, policies ); // $ExpectError
8394
factory<number, number>( table, ( x: number ): number => x, dtypes, policies ); // $ExpectError
95+
96+
factory<number, number>( table, '5', dtypes, policies, {} ); // $ExpectError
97+
factory<number, number>( table, 5, dtypes, policies, {} ); // $ExpectError
98+
factory<number, number>( table, true, dtypes, policies, {} ); // $ExpectError
99+
factory<number, number>( table, false, dtypes, policies, {} ); // $ExpectError
100+
factory<number, number>( table, null, dtypes, policies, {} ); // $ExpectError
101+
factory<number, number>( table, void 0, dtypes, policies, {} ); // $ExpectError
102+
factory<number, number>( table, 'abc', dtypes, policies, {} ); // $ExpectError
103+
factory<number, number>( table, {}, dtypes, policies, {} ); // $ExpectError
104+
factory<number, number>( table, ( x: number ): number => x, dtypes, policies, {} ); // $ExpectError
84105
}
85106

86107
// The compiler throws an error if the function is provided a third argument which is not a list of data types...
@@ -103,6 +124,16 @@ import factory = require( './index' );
103124
factory<number, number>( table, [ dtypes ], 'abc', policies ); // $ExpectError
104125
factory<number, number>( table, [ dtypes ], {}, policies ); // $ExpectError
105126
factory<number, number>( table, [ dtypes ], ( x: number ): number => x, policies ); // $ExpectError
127+
128+
factory<number, number>( table, [ dtypes ], '5', policies, {} ); // $ExpectError
129+
factory<number, number>( table, [ dtypes ], 5, policies, {} ); // $ExpectError
130+
factory<number, number>( table, [ dtypes ], true, policies, {} ); // $ExpectError
131+
factory<number, number>( table, [ dtypes ], false, policies, {} ); // $ExpectError
132+
factory<number, number>( table, [ dtypes ], null, policies, {} ); // $ExpectError
133+
factory<number, number>( table, [ dtypes ], void 0, policies, {} ); // $ExpectError
134+
factory<number, number>( table, [ dtypes ], 'abc', policies, {} ); // $ExpectError
135+
factory<number, number>( table, [ dtypes ], {}, policies, {} ); // $ExpectError
136+
factory<number, number>( table, [ dtypes ], ( x: number ): number => x, policies, {} ); // $ExpectError
106137
}
107138

108139
// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object...
@@ -121,6 +152,36 @@ import factory = require( './index' );
121152
factory<number, number>( table, [ dtypes ], dtypes, 'abc' ); // $ExpectError
122153
factory<number, number>( table, [ dtypes ], dtypes, {} ); // $ExpectError
123154
factory<number, number>( table, [ dtypes ], dtypes, ( x: number ): number => x ); // $ExpectError
155+
156+
factory<number, number>( table, [ dtypes ], dtypes, '5', {} ); // $ExpectError
157+
factory<number, number>( table, [ dtypes ], dtypes, 5, {} ); // $ExpectError
158+
factory<number, number>( table, [ dtypes ], dtypes, true, {} ); // $ExpectError
159+
factory<number, number>( table, [ dtypes ], dtypes, false, {} ); // $ExpectError
160+
factory<number, number>( table, [ dtypes ], dtypes, null, {} ); // $ExpectError
161+
factory<number, number>( table, [ dtypes ], dtypes, void 0, {} ); // $ExpectError
162+
factory<number, number>( table, [ dtypes ], dtypes, 'abc', {} ); // $ExpectError
163+
factory<number, number>( table, [ dtypes ], dtypes, {}, {} ); // $ExpectError
164+
factory<number, number>( table, [ dtypes ], dtypes, ( x: number ): number => x, {} ); // $ExpectError
165+
}
166+
167+
// The compiler throws an error if the function is provided a fifth argument which is not an object...
168+
{
169+
const dtypes: Array<DataType> = [ 'float64', 'float32' ];
170+
const table = {
171+
'default': cumax
172+
};
173+
const policies = {
174+
'output': 'same' as OutputPolicy,
175+
'casting': 'none' as InputCastingPolicy
176+
};
177+
178+
factory<number, number>( table, [ dtypes ], dtypes, policies, '5' ); // $ExpectError
179+
factory<number, number>( table, [ dtypes ], dtypes, policies, 5 ); // $ExpectError
180+
factory<number, number>( table, [ dtypes ], dtypes, policies, true ); // $ExpectError
181+
factory<number, number>( table, [ dtypes ], dtypes, policies, false ); // $ExpectError
182+
factory<number, number>( table, [ dtypes ], dtypes, policies, null ); // $ExpectError
183+
factory<number, number>( table, [ dtypes ], dtypes, policies, 'abc' ); // $ExpectError
184+
factory<number, number>( table, [ dtypes ], dtypes, policies, ( x: number ): number => x ); // $ExpectError
124185
}
125186

126187
// The compiler throws an error if the function is provided an unsupported number of arguments...
@@ -137,7 +198,7 @@ import factory = require( './index' );
137198
factory(); // $ExpectError
138199
factory<number, number>( abs ); // $ExpectError
139200
factory<number, number>( table, [ dtypes ] ); // $ExpectError
140-
factory<number, number>( table, [ dtypes ], dtypes, policies, {} ); // $ExpectError
201+
factory<number, number>( table, [ dtypes ], dtypes, policies, {}, {} ); // $ExpectError
141202
}
142203

143204
// The function returns a function which returns an ndarray...

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-strided1d-disp
3838
* @param {Object} policies - policies
3939
* @param {string} policies.output - output data type policy
4040
* @param {string} policies.casting - input ndarray casting policy
41+
* @param {Options} [options] - function options
42+
* @param {boolean} [options.strictTraversalOrder=false] - boolean specifying whether to require that element traversal match the memory layout of an input ndarray
4143
* @throws {TypeError} first argument must be an object having valid properties
44+
* @throws {Error} first argument must be an object having valid properties
4245
* @throws {TypeError} second argument must be an array containing arrays of supported data types
4346
* @throws {TypeError} third argument must be an array of supported data types
4447
* @throws {TypeError} fourth argument must be an object having supported policies
45-
* @throws {Error} first argument must be an object having valid properties
48+
* @throws {TypeError} options argument must be an object
49+
* @throws {TypeError} must provide valid options
4650
* @returns {Function} function for applying a strided function an ndarray
4751
*
4852
* @example
@@ -105,8 +109,13 @@ var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-strided1d-disp
105109
* var bool = ( out === y );
106110
* // returns true
107111
*/
108-
function factory( table, idtypes, odtypes, policies ) {
109-
var f = new UnaryStrided1dDispatch( table, idtypes, odtypes, policies );
112+
function factory( table, idtypes, odtypes, policies, options ) {
113+
var f;
114+
if ( arguments.length > 4 ) {
115+
f = new UnaryStrided1dDispatch( table, idtypes, odtypes, policies, options ); // eslint-disable-line max-len
116+
} else {
117+
f = new UnaryStrided1dDispatch( table, idtypes, odtypes, policies );
118+
}
110119
setReadOnly( main, 'assign', assign );
111120
return main;
112121

0 commit comments

Comments
 (0)