Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,2 @@
julia 1.5
JSON 0.21

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env julia
#
# @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.

import JSON

"""
gen( domain, name )
Generate fixture data and write to file.
# Arguments
* `domain`: domain
* `name::AbstractString`: output filename
# Examples
``` julia
julia> x = range( -1000.0, stop = 1000.0, length = 2001 );
julia> gen( x, \"data.json\" );
```
"""
function gen( domain, name )
x = collect( domain );
y = cos.( x );

# Store data to be written to file as a collection:
data = Dict([
("x", x),
("expected", y)
]);

# Based on the script directory, create an output filepath:
filepath = joinpath( dir, name );

# Write the data to the output filepath as JSON:
outfile = open( filepath, "w" );
write( outfile, JSON.json(data) );
write( outfile, "\n" );
close( outfile );
end

# Get the filename:
file = @__FILE__;

# Extract the directory in which this file resides:
dir = dirname( file );

# Values within the defined domain:
x = range( -pi/4.0, stop = pi/4.0, length = 1000 )
gen( x, "small_range.json" );

# Positive values outside the defined domain:
x = range( 40.0*pi/4.0, stop = 200*pi/4.0, length = 1000 )
gen( x, "large_positive.json" );

# Negative values outside the defined domain:
x = range( -200*pi/4.0, stop = -40*pi/4.0, length = 1000 )
gen( x, "large_negative.json" );

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/kernel-cos/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var linspace = require( '@stdlib/array/base/linspace' );
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
var PI = require( '@stdlib/constants/float64/pi' );
var cos = require( '@stdlib/math/base/special/cos' );
var kernelCos = require( './../lib' );


// FIXTURES //

var smallRange = require( './fixtures/julia/small_range.json' );
var largePositive = require( './fixtures/julia/large_positive.json' );
var largeNegative = require( './fixtures/julia/large_negative.json' );


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand All @@ -39,13 +44,13 @@

tape( 'the function returns `NaN` if provided `NaN` for either parameter', function test( t ) {
var v = kernelCos( NaN, 0.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = kernelCos( 4.0, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = kernelCos( NaN, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -55,7 +60,7 @@
var x;
var i;

values = linspace( -PI/4.0, PI/4.0, 1000 );
values = smallRange.x;
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
out = kernelCos( x, 0.0 );
Expand All @@ -72,8 +77,8 @@
var n;
var i;

values = linspace( 40.0*PI/4.0, 200*PI/4.0, 1000 );
values = largePositive.x;
y = new Array( 2 );

Check failure on line 81 in lib/node_modules/@stdlib/math/base/special/kernel-cos/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Using the `new Array()` constructor is not allowed; use an array literal with push instead
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
n = rempio2( x, y );
Expand Down Expand Up @@ -101,8 +106,8 @@
var n;
var i;

values = linspace( -200.0*PI/4.0, -40.0*PI/4.0, 1000 );
values = largeNegative.x;
y = new Array( 2 );

Check failure on line 110 in lib/node_modules/@stdlib/math/base/special/kernel-cos/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Using the `new Array()` constructor is not allowed; use an array literal with push instead
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
n = rempio2( x, y );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var linspace = require( '@stdlib/array/base/linspace' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
var PI = require( '@stdlib/constants/float64/pi' );
var cos = require( '@stdlib/math/base/special/cos' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand All @@ -38,6 +37,13 @@ var opts = {
};


// FIXTURES //

var smallRange = require( './fixtures/julia/small_range.json' );
var largePositive = require( './fixtures/julia/large_positive.json' );
var largeNegative = require( './fixtures/julia/large_negative.json' );


// TESTS //

tape( 'main export is a function', opts, function test( t ) {
Expand All @@ -48,52 +54,64 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'the function returns `NaN` if provided `NaN` for either parameter', opts, function test( t ) {
var v = kernelCos( NaN, 0.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = kernelCos( 4.0, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = kernelCos( NaN, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the cosine for input values on the interval `[-pi/4, pi/4]`', opts, function test( t ) {
var expected;
var values;
var out;
var x;
var i;

values = linspace( -PI/4.0, PI/4.0, 1000 );
values = smallRange.x;
expected = smallRange.expected;
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
out = kernelCos( x, 0.0 );
t.strictEqual( out, cos( x ), 'returns expected value' );
t.strictEqual( out, expected[ i ], 'returns expected value' );
}
t.end();
});

tape( 'the function can be used to compute the cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (positive)', opts, function test( t ) {
var expected;
var values;
var delta;
var tol;
var out;
var x;
var y;
var n;
var i;

values = linspace( 40.0*PI/4.0, 200*PI/4.0, 1000 );
values = largePositive.x;
expected = largePositive.expected;
y = new Array( 2 );
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
n = rempio2( x, y );
switch ( n & 3 ) {
case 0:
out = kernelCos( y[ 0 ], y[ 1 ] );
t.strictEqual( out, cos( x ), 'returns expected value' );
t.strictEqual( out, expected[ i ], 'returns expected value' );
break;
case 2:
out = -kernelCos( y[ 0 ], y[ 1 ] );
t.strictEqual( out, cos( x ), 'returns expected value' );
if ( out === expected[ i ] ) {
t.strictEqual( out, expected[ i ], 'returns expected value' );
} else {
delta = abs( out - expected[ i ] );
tol = EPS * abs( expected[ i ] );
Copy link
Contributor Author

@anandkaranubc anandkaranubc Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CFLAGS="-ffp-contract=off" is used while building the native add-on, I can confirm that adding this is not needed.

t.ok( delta <= tol, 'within tolerance. x: '+x+'. out: '+out+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
break;
default:
break;
Expand All @@ -103,26 +121,36 @@ tape( 'the function can be used to compute the cosine for input values outside o
});

tape( 'the function can be used to compute the cosine for input values outside of `[-pi/4, pi/4]` after argument reduction via `rempio2` (negative)', opts, function test( t ) {
var expected;
var values;
var delta;
var tol;
var out;
var x;
var y;
var n;
var i;

values = linspace( -200.0*PI/4.0, -40.0*PI/4.0, 1000 );
values = largeNegative.x;
expected = largeNegative.expected;
y = new Array( 2 );
for ( i = 0; i < values.length; i++ ) {
x = values[ i ];
n = rempio2( x, y );
switch ( n & 3 ) {
case 0:
out = kernelCos( y[ 0 ], y[ 1 ] );
t.strictEqual( out, cos( x ), 'returns expected value' );
t.strictEqual( out, expected[ i ], 'returns expected value' );
break;
case 2:
out = -kernelCos( y[ 0 ], y[ 1 ] );
t.strictEqual( out, cos( x ), 'returns expected value' );
if ( out === expected[ i ] ) {
t.strictEqual( out, expected[ i ], 'returns expected value' );
} else {
delta = abs( out - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x+'. out: '+out+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
break;
default:
break;
Expand Down
Loading