Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MAIN //

/**
* Returns a callback body based on an output data type.
*
* @private
* @param {string} ch1 - one-letter character abbreviation for output data type
* @returns {string} callback body
*/
function callbackBody( ch1 ) {
if ( ch1 === 'c' ) {
return 'return ( stdlib_complex64_real( x ) == 0.0f && stdlib_complex64_imag( x ) == 0.0f );';
}
if ( ch1 === 'z' ) {
return 'return ( stdlib_complex128_real( x ) == 0.0 && stdlib_complex128_imag( x ) == 0.0 );';
}
if ( ch1 === 'x' ) {
return 'return x;';
}
if ( ch1 === 'd' ) {
return 'return x == 0.0;';
}
if ( ch1 === 'f' ) {
return 'return x == 0.0f;';
}
return 'return x == 0;';
}


// EXPORTS //

module.exports = callbackBody;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env node

/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' );
var safeCasts = require( '@stdlib/ndarray/safe-casts' );
var filter = require( './filter.js' );
var EXCLUDE_DTYPES = require( './exclude_dtypes.js' );


// MAIN //

/**
* Generates a list of loop signatures from a list of data types.
*
* @private
* @param {StringArray} dtypes - list of data types
* @param {StringArray} specialLoops - list of special loop signatures
* @returns {StringArray} list of loop signatures
*/
function signatures( dtypes, specialLoops ) {
var casts;
var out;
var ch1;
var ch2;
var t1;
var t2;
var N;
var s;
var i;
var j;

N = dtypes.length;
out = [];
for ( i = 0; i < N; i++ ) {
t1 = dtypes[ i ];
ch1 = dtypeChar( t1 );
s = ch1 + '_x';
out.push( s );

casts = safeCasts( t1 );
casts = filter( casts, EXCLUDE_DTYPES );

for ( j = 0; j < casts.length; j++ ) {
t2 = casts[ j ];
if ( t2 === t1 ) {
continue;
}
ch2 = dtypeChar( t2 );
out.push( s + '_as_' + ch2 + '_x' );
}
}
for ( i = 0; i < specialLoops.length; i++ ) {
out.push( specialLoops[ i ] );
}
return out.sort();
}


// EXPORTS //

module.exports = signatures;
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env node

/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var readFile = require( '@stdlib/fs/read-file' ).sync;
var writeFile = require( '@stdlib/fs/write-file' ).sync;
var substringBefore = require( '@stdlib/string/substring-before' );
var substringAfter = require( '@stdlib/string/substring-after' );


// MAIN //

/**
* Updates the main header file.
*
* @private
* @param {string} mainHeaderPath - path to the main header file
* @param {Object} fopts - file options
* @param {StringArray} signatures - list of (sorted) loop signatures
* @throws {Error} unexpected error
*/
function updateMainHeader( mainHeaderPath, fopts, signatures ) {
var file;
var list;
var err;
var sig;
var ch;
var i;

file = readFile( mainHeaderPath, fopts );
if ( file instanceof Error ) {
throw file;
}
list = [];
ch = signatures[ 0 ].charAt( 0 );
for ( i = 0; i < signatures.length; i++ ) {
sig = signatures[ i ];
if ( sig.charAt( 0 ) !== ch ) {
ch = sig.charAt( 0 );
list.push( '' );
}
list.push( '#include "every/predicate/' + sig + '.h"' );
}
file = [
substringBefore( file, '\n// BEGIN PREDICATE LOOPS' ),
'// BEGIN PREDICATE LOOPS',
list.join( '\n' ),
'// END PREDICATE LOOPS',
substringAfter( file, '// END PREDICATE LOOPS\n' )
].join( '\n' );

err = writeFile( mainHeaderPath, file, fopts );
if ( err ) {
throw err;
}
}


// EXPORTS //

module.exports = updateMainHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var readJSON = require( '@stdlib/fs/read-json' ).sync;
var writeFile = require( '@stdlib/fs/write-file' ).sync;


// MAIN //

/**
* Updates the package manifest.
*
* @private
* @param {string} manifestPath - path to manifest file
* @param {Object} fopts - file options
* @param {RegExp} reLoopFile - regular expression to test for a loop file
* @param {StringArray} signatures - list of (sorted) loop signatures
* @throws {Error} unexpected error
*/
function updateManifest( manifestPath, fopts, reLoopFile, signatures ) {
var file;
var list;
var tmp;
var err;
var l;
var i;
var j;

file = readJSON( manifestPath, fopts );
if ( file instanceof Error ) {
throw file;
}
list = [];
for ( i = 0; i < signatures.length; i++ ) {
list.push( './src/predicate/' + signatures[ i ] + '.c' );
}
for ( j = 0; j < file.confs.length; j++ ) {
l = list.slice();
tmp = file.confs[ j ].src;
for ( i = 0; i < tmp.length; i++ ) {
if ( reLoopFile.test( tmp[ i ] ) === false ) {
l.push( tmp[ i ] );
}
}
l.sort();
file.confs[ j ].src = l;
}
err = writeFile( manifestPath, JSON.stringify( file, null, 2 ) + '\n', fopts );
if ( err ) {
throw err;
}
}


// EXPORTS //

module.exports = updateManifest;
Loading