Skip to content

Commit 97fb507

Browse files
committed
fix: handle mostly safe casts and refactor loop generation
--- 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: passed - 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: na - task: lint_license_headers status: passed ---
1 parent 53a4c55 commit 97fb507

35 files changed

+1728
-994
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 isComplexChar = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type-char' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Returns a callback body based on callback input and output data types.
30+
*
31+
* @private
32+
* @param {string} ch1 - one-letter character abbreviation for input argument
33+
* @param {string} ch2 - one-letter character abbreviation for output value
34+
* @returns {string} callback body
35+
*/
36+
function callbackBody( ch1, ch2 ) {
37+
if ( isComplexChar( ch1 ) || isComplexChar( ch2 ) || ch1 !== ch2 ) {
38+
return '// ...';
39+
}
40+
return 'return x;';
41+
}
42+
43+
44+
// EXPORTS //
45+
46+
module.exports = callbackBody;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 logger = require( 'debug' );
25+
var readFile = require( '@stdlib/fs/read-file' ).sync;
26+
var writeFile = require( '@stdlib/fs/write-file' ).sync;
27+
var uppercase = require( '@stdlib/string/uppercase' );
28+
var currentYear = require( '@stdlib/time/current-year' );
29+
var replace = require( '@stdlib/string/replace' );
30+
var format = require( '@stdlib/string/format' );
31+
32+
33+
// VARIABLES //
34+
35+
var FOPTS = {
36+
'encoding': 'utf8'
37+
};
38+
39+
// Logger:
40+
var debug = logger( 'script:ndarray-unary-loops:create-header-files' );
41+
42+
// Templates:
43+
var TMPL_HEADER = readFile( path.resolve( __dirname, '..', 'templates', 'header.txt' ), FOPTS );
44+
45+
// Output directory:
46+
var INCLUDE_DIR = path.resolve( __dirname, '..', '..', 'include', 'stdlib', 'ndarray', 'base', 'unary' );
47+
48+
// Get the current year:
49+
var CURRENT_YEAR = currentYear().toString();
50+
51+
// Specify the copyright holder:
52+
var COPYRIGHT = 'The Stdlib Authors';
53+
54+
55+
// FUNCTIONS //
56+
57+
/**
58+
* Creates a header file for a provided loop signature.
59+
*
60+
* @private
61+
* @param {string} signature - loop signature
62+
* @throws {Error} unexpected error
63+
*/
64+
function createHeaderFile( signature ) {
65+
var fpath;
66+
var file;
67+
var err;
68+
69+
file = replace( TMPL_HEADER, '{{YEAR}}', CURRENT_YEAR );
70+
file = replace( file, '{{COPYRIGHT}}', COPYRIGHT );
71+
file = replace( file, '{{INCLUDE_GUARD}}', uppercase( signature ) );
72+
file = replace( file, '{{SIGNATURE}}', signature );
73+
74+
fpath = path.join( INCLUDE_DIR, format( '%s.h', signature ) );
75+
76+
debug( 'Creating header file: %s', fpath );
77+
err = writeFile( fpath, file, FOPTS );
78+
if ( err ) {
79+
throw err;
80+
}
81+
}
82+
83+
84+
// MAIN //
85+
86+
/**
87+
* Creates header files for a list of loop signatures.
88+
*
89+
* @private
90+
* @param {Array<string>} signatures - list of loop signatures
91+
*/
92+
function createHeaderFiles( signatures ) {
93+
var i;
94+
for ( i = 0; i < signatures.length; i++ ) {
95+
createHeaderFile( signatures[ i ] );
96+
}
97+
}
98+
99+
100+
// EXPORTS //
101+
102+
module.exports = createHeaderFiles;

0 commit comments

Comments
 (0)