Skip to content

Commit 1d26ae4

Browse files
committed
build: add loop generation scripts and refactor templates
--- 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 b71f305 commit 1d26ae4

File tree

20 files changed

+6480
-4682
lines changed

20 files changed

+6480
-4682
lines changed

lib/node_modules/@stdlib/ndarray/base/every/scripts/inline_loops.js

Lines changed: 557 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
// MODULES //
22+
23+
var numel = require( '@stdlib/ndarray/base/numel' );
24+
var filledarray = require( '@stdlib/array/filled' );
25+
var replace = require( '@stdlib/string/replace' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Defines byte arrays in a provided template string.
32+
*
33+
* @private
34+
* @param {string} tmpl - template string
35+
* @param {Array<Array>} shapes - array of shape arrays
36+
* @param {PositiveInteger} nb1 - bytes per element for output array
37+
* @returns {string} updated string
38+
*/
39+
function defineByteArrays( tmpl, shapes, nb1 ) {
40+
var bytes;
41+
var tmp;
42+
var N;
43+
var i;
44+
45+
bytes = filledarray( 0, nb1, 'generic' ).join( ', ' );
46+
tmpl = replace( tmpl, '{{INPUT_NDARRAY_1_BYTES_0D}}', bytes );
47+
48+
for ( i = 1; i < shapes.length; i++ ) {
49+
N = numel( shapes[ i ] );
50+
51+
tmp = '{{INPUT_NDARRAY_1_BYTES_'+i+'D}}';
52+
bytes = filledarray( 0, nb1*N, 'generic' ).join( ', ' );
53+
tmpl = replace( tmpl, tmp, bytes );
54+
}
55+
return tmpl;
56+
}
57+
58+
59+
// EXPORTS //
60+
61+
module.exports = defineByteArrays;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
// MODULES //
22+
23+
var replace = require( '@stdlib/string/replace' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Defines array shapes in a provided template string.
30+
*
31+
* @private
32+
* @param {string} tmpl - template string
33+
* @param {Array<Array>} shapes - array of shape arrays
34+
* @returns {string} updated string
35+
*/
36+
function defineShapes( tmpl, shapes ) {
37+
var i;
38+
for ( i = 1; i < shapes.length; i++ ) {
39+
tmpl = replace( tmpl, '{{NDARRAY_SHAPE_'+i+'D}}', shapes[ i ].join( ', ' ) );
40+
}
41+
return tmpl;
42+
}
43+
44+
45+
// EXPORTS //
46+
47+
module.exports = defineShapes;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// MODULES //
22+
23+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
24+
var gscal = require( '@stdlib/blas/base/gscal' );
25+
var replace = require( '@stdlib/string/replace' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Defines array strides in a provided template string.
32+
*
33+
* @private
34+
* @param {string} tmpl - template string
35+
* @param {Array<Array>} shapes - array of shape arrays
36+
* @param {PositiveInteger} nb1 - bytes per element for the first array
37+
* @param {string} order - memory layout order
38+
* @returns {string} updated string
39+
*/
40+
function defineStrides( tmpl, shapes, nb1, order ) {
41+
var strides;
42+
var tmp;
43+
var st;
44+
var i;
45+
46+
for ( i = 1; i < shapes.length; i++ ) {
47+
strides = shape2strides( shapes[ i ], order );
48+
49+
tmp = '{{INPUT_NDARRAY_1_STRIDES_'+i+'D}}';
50+
st = gscal( strides.length, nb1, strides.slice(), 1 );
51+
tmpl = replace( tmpl, tmp, st.join( ', ' ) );
52+
}
53+
return tmpl;
54+
}
55+
56+
57+
// EXPORTS //
58+
59+
module.exports = defineStrides;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
// MODULES //
22+
23+
var dtypes = require( '@stdlib/ndarray/dtypes' );
24+
var filter = require( './filter.js' );
25+
var EXCLUDE_DTYPES = require( './exclude_dtypes.js' );
26+
27+
28+
// MAIN //
29+
30+
// Resolve a list of dtypes for which we want to create loops:
31+
var DTYPES = filter( dtypes(), EXCLUDE_DTYPES ).sort();
32+
33+
34+
// EXPORTS //
35+
36+
module.exports = DTYPES;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
// Data types to exclude when generating loops:
24+
var EXCLUDE_DTYPES = [ 'binary', 'generic', 'uint8c' ];
25+
26+
27+
// EXPORTS //
28+
29+
module.exports = EXCLUDE_DTYPES;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* Removes a list of elements from a provided list.
25+
*
26+
* @private
27+
* @param {ArrayLikeObject} src - list to filter
28+
* @param {ArrayLikeObject} list - items to remove
29+
* @returns {ArrayLikeObject} filtered list
30+
*
31+
* @example
32+
* var src = [ 'a', 'b', 'c', 'd' ];
33+
* var list = [ 'b', 'd' ];
34+
*
35+
* var out = filter( src, list );
36+
* // returns [ 'a', 'c' ]
37+
*/
38+
function filter( src, list ) { // TODO: replace with a `@stdlib/array/base/*` utility performing the equivalent set operation
39+
var out;
40+
var M;
41+
var N;
42+
var v;
43+
var i;
44+
var j;
45+
46+
M = src.length;
47+
N = list.length;
48+
49+
out = [];
50+
for ( i = 0; i < M; i++ ) {
51+
v = src[ i ];
52+
for ( j = 0; j < N; j++ ) {
53+
if ( v === list[ j ] ) {
54+
break;
55+
}
56+
}
57+
if ( j === N ) {
58+
out.push( v );
59+
}
60+
}
61+
return out;
62+
}
63+
64+
65+
// EXPORTS //
66+
67+
module.exports = filter;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
* Tests whether a one-letter character abbreviation corresponds to a complex number data type.
25+
*
26+
* @private
27+
* @param {string} ch - one-letter character abbreviation
28+
* @returns {boolean} test result
29+
*
30+
* @example
31+
* var bool = isComplexChar( 'z' );
32+
* // returns true
33+
*/
34+
function isComplexChar( ch ) {
35+
return ( ch === 'c' || ch === 'z' );
36+
}
37+
38+
39+
// EXPORTS //
40+
41+
module.exports = isComplexChar;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
// MODULES //
22+
23+
var path = require( 'path' );
24+
var readDir = require( '@stdlib/fs/read-dir' ).sync;
25+
var unlink = require( '@stdlib/fs/unlink' ).sync;
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Removes files from a directory which match a provided regular expression.
32+
*
33+
* @private
34+
* @param {string} dir - directory
35+
* @param {RegExp} re - regular expression to test whether a file should be removed
36+
*/
37+
function removeFilesByRegExp( dir, re ) { // TODO: create a `@stdlib/fs/*` utility package for this
38+
var list;
39+
var i;
40+
41+
list = readDir( dir );
42+
for ( i = 0; i < list.length; i++ ) {
43+
if ( re.test( list[ i ] ) ) {
44+
unlink( path.join( dir, list[ i ] ) );
45+
}
46+
}
47+
}
48+
49+
50+
// EXPORTS //
51+
52+
module.exports = removeFilesByRegExp;

0 commit comments

Comments
 (0)