Skip to content

Commit aa7edbf

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: na - task: lint_package_json status: na - task: lint_repl_help status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent ccba75e commit aa7edbf

File tree

6 files changed

+703
-251
lines changed

6 files changed

+703
-251
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Returns default options.
25+
*
26+
* @private
27+
* @returns {Object} default options
28+
*
29+
* @example
30+
* var o = defaults();
31+
* // returns {...}
32+
*/
33+
function defaults() {
34+
return {
35+
// Require that the order of element traversal match the memory layout of an input ndarray:
36+
'strictTraversalOrder': false
37+
};
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = defaults;

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

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var isFunction = require( '@stdlib/assert/is-function' );
24-
var format = require( '@stdlib/string/format' );
24+
var mainFactory = require( './main_factory.js' );
2525
var main = require( './main.js' );
2626

2727

@@ -30,8 +30,11 @@ var main = require( './main.js' );
3030
/**
3131
* Return a function for applying a one-dimensional strided array function to a list of specified dimensions in an input ndarray and assigning results to a provided output ndarray.
3232
*
33-
* @param {Function} fcn - wrapper for a one-dimensional strided array function
34-
* @throws {TypeError} first argument must be a function
33+
* @param {Function} [fcn] - wrapper for a one-dimensional strided array function
34+
* @param {Options} [options] - function options
35+
* @param {boolean} [options.strictTraversalOrder=false] - boolean specifying whether to require that element traversal match the memory layout of an input ndarray
36+
* @throws {TypeError} options argument must be an object
37+
* @throws {TypeError} must provide valid options
3538
* @returns {Function} function for applying a strided array function
3639
*
3740
* @example
@@ -106,11 +109,37 @@ var main = require( './main.js' );
106109
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
107110
* // returns [ [ [ [ 1.0, 3.0 ], [ 6.0, 10.0 ] ], [ [ 5.0, 11.0 ], [ 18.0, 26.0 ] ], [ [ 9.0, 19.0 ], [ 30.0, 42.0 ] ] ] ]
108111
*/
109-
function factory( fcn ) {
110-
if ( !isFunction( fcn ) ) {
111-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
112+
function factory() {
113+
var nargs;
114+
var unary;
115+
var fcn;
116+
var f;
117+
118+
nargs = arguments.length;
119+
120+
// Case: factory()
121+
if ( nargs === 0 ) {
122+
unary = main;
123+
f = wrap;
124+
}
125+
// Case: factory( fcn, opts )
126+
else if ( nargs > 1 ) {
127+
unary = mainFactory( arguments[ 1 ] );
128+
fcn = arguments[ 0 ];
129+
f = apply;
112130
}
113-
return apply;
131+
// Case: factory( fcn )
132+
else if ( isFunction( arguments[ 0 ] ) ) {
133+
unary = main;
134+
fcn = arguments[ 0 ];
135+
f = apply;
136+
}
137+
// Case: factory( opts )
138+
else {
139+
unary = mainFactory( arguments[ 0 ] );
140+
f = wrap;
141+
}
142+
return f;
114143

115144
/**
116145
* Applies a one-dimensional strided array function to a list of specified dimensions in an input ndarray and assigns results to a provided output ndarray.
@@ -128,7 +157,27 @@ function factory( fcn ) {
128157
} else {
129158
opts = {};
130159
}
131-
return main( fcn, arrays, dims, opts );
160+
return unary( fcn, arrays, dims, opts );
161+
}
162+
163+
/**
164+
* Applies a one-dimensional strided array function to a list of specified dimensions in an input ndarray and assigns results to a provided output ndarray.
165+
*
166+
* @private
167+
* @param {Function} fcn - wrapper for a one-dimensional strided array function
168+
* @param {ArrayLikeObject<Object>} arrays - array-like object containing ndarrays
169+
* @param {IntegerArray} dims - list of dimensions to which to apply a strided array function
170+
* @param {Options} [options] - function options
171+
* @returns {void}
172+
*/
173+
function wrap( fcn, arrays, dims, options ) {
174+
var opts;
175+
if ( arguments.length > 3 ) {
176+
opts = options;
177+
} else {
178+
opts = {};
179+
}
180+
return unary( fcn, arrays, dims, opts );
132181
}
133182
}
134183

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,16 @@
168168

169169
// MODULES //
170170

171+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
172+
var factory = require( './factory.js' );
171173
var main = require( './main.js' );
172174

173175

176+
// MAIN //
177+
178+
setReadOnly( main, 'factory', factory );
179+
180+
174181
// EXPORTS //
175182

176183
module.exports = main;

0 commit comments

Comments
 (0)