Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add evalrational.js
  • Loading branch information
Pranavchiku committed Dec 17, 2022
commit 529198e1ac010ddbe36e6d8524b2968191ca0102
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2022 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.
Expand All @@ -24,10 +24,15 @@
// MODULES //

var resolve = require( 'path' ).resolve;
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
var writeFileSync = require( '@stdlib/fs/write-file' ).sync;
var currentYear = require( '@stdlib/time/current-year' );
var substringBefore = require( '@stdlib/string/substring-before' );
var substringAfter = require( '@stdlib/string/substring-after' );
var format = require( '@stdlib/string/format' );
var licenseHeader = require( '@stdlib/_tools/licenses/header' );
var compile = require( '@stdlib/math/base/tools/evalrational-compile' );
var compileC = require( '@stdlib/math/base/tools/evalrational-compile-c' );


// VARIABLES //
Expand Down Expand Up @@ -166,6 +171,33 @@ var header = licenseHeader( 'Apache-2.0', 'js', {
header += '\n/* This is a generated file. Do not edit directly. */\n';


// FUNCTIONS //

/**
* Inserts a compiled function into file content.
*
* @private
* @param {string} text - source content
* @param {string} id - function identifier
* @param {string} str - function string
* @returns {string} updated content
*/
function insert( text, id, str ) {
var before;
var after;
var begin;
var end;

begin = '// BEGIN: '+id;
end = '// END: '+id;

before = substringBefore( text, begin );
after = substringAfter( text, end );

return format( '%s// BEGIN: %s\n\n%s\n%s%s', before, id, str, end, after );
}


// MAIN //

/**
Expand All @@ -175,7 +207,9 @@ header += '\n/* This is a generated file. Do not edit directly. */\n';
*/
function main() {
var fpath;
var copts;
var opts;
var file;
var str;

opts = {
Expand All @@ -201,6 +235,36 @@ function main() {
fpath = resolve( __dirname, '..', 'lib', 'rational_p5q5.js' );
str = header + compile( P5, Q5 );
writeFileSync( fpath, str, opts );

copts = {
'dtype': 'double',
'name': ''
};

fpath = resolve( __dirname, '..', 'src', 'main.c' );
file = readFileSync( fpath, opts );

copts.name = 'rational_p1q1';
str = compileC( P1, Q1, copts );
file = insert( file, copts.name, str );

copts.name = 'rational_p2q2';
str = compileC( P2, Q2, copts );
file = insert( file, copts.name, str );

copts.name = 'rational_p3q3';
str = compileC( P3, Q3, copts );
file = insert( file, copts.name, str );

copts.name = 'rational_p4q4';
str = compileC( P4, Q4, copts );
file = insert( file, copts.name, str );

copts.name = 'rational_p5q5';
str = compileC( P5, Q5, copts );
file = insert( file, copts.name, str );

writeFileSync( fpath, file, opts );
}

main();