Skip to content

feat: add support for computing the derivative of cardinal sine (cosc) #3122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
3bd783f
cosc
RiyaChy072 Nov 16, 2024
a00350f
basic index.js file
RiyaChy072 Nov 16, 2024
9e4fb42
added example file
RiyaChy072 Nov 16, 2024
ec5adcb
added makefile inside example folder
RiyaChy072 Nov 16, 2024
a9b0dca
git commit -m "added benchmark folder"
RiyaChy072 Nov 16, 2024
61bdb50
"deleted benchmark"
RiyaChy072 Nov 16, 2024
4dbbcbd
added benchmark.native.js file
RiyaChy072 Nov 16, 2024
df17998
added benchmark.c file
RiyaChy072 Nov 16, 2024
281b664
added makefile inside native folder
RiyaChy072 Nov 16, 2024
383a46d
Markfile
RiyaChy072 Nov 16, 2024
b2262e3
added cosc.h file
RiyaChy072 Nov 16, 2024
e71fa67
added cosc.h file
RiyaChy072 Nov 16, 2024
8094f83
added src file
RiyaChy072 Nov 16, 2024
435f5d4
added addon.c file
RiyaChy072 Nov 16, 2024
ac8d206
added makefile inside src
RiyaChy072 Nov 16, 2024
3a5ce44
added main.c and Makefile
RiyaChy072 Nov 16, 2024
8f43f70
added test file
RiyaChy072 Nov 16, 2024
8063c8c
added test.native.js
RiyaChy072 Nov 16, 2024
bff2f49
added binding.gyp file
RiyaChy072 Nov 16, 2024
61326c6
added binding.gyp file
RiyaChy072 Nov 16, 2024
1244639
added include.gypi file
RiyaChy072 Nov 16, 2024
3577eed
added include.gypi
RiyaChy072 Nov 16, 2024
f16cdd5
"added manifest.json file"
RiyaChy072 Nov 16, 2024
637b54f
Merge branch 'stdlib-js:develop' into derivative-of-cardinal-sine
RiyaChy072 Nov 17, 2024
a7e1419
Merge remote-tracking branch 'upstream/develop' into derivative-of-ca…
stdlib-bot Nov 18, 2024
3d6fbfb
"added README file"
RiyaChy072 Nov 18, 2024
e7ce6a0
Merge branch 'derivative-of-cardinal-sine' of https://github.com/Riya…
RiyaChy072 Nov 18, 2024
8911d84
"added benchmark.js"
RiyaChy072 Nov 18, 2024
4212a00
"added index.js inside examples"
RiyaChy072 Nov 18, 2024
9c5c475
"added test.js"
RiyaChy072 Nov 18, 2024
a52bf3c
"added data.json"
RiyaChy072 Nov 18, 2024
12a250d
added large negative json
RiyaChy072 Nov 18, 2024
b8c0821
added json file
RiyaChy072 Nov 18, 2024
ac9e19c
added json
RiyaChy072 Nov 18, 2024
b1d4355
added require
RiyaChy072 Nov 18, 2024
8a823b2
"added require"
RiyaChy072 Nov 18, 2024
8ca19ed
"added runner.jl"
RiyaChy072 Nov 18, 2024
fd554fe
"added tiny negative json"
RiyaChy072 Nov 18, 2024
56d93d8
"added tiny positive json"
RiyaChy072 Nov 18, 2024
68a161f
"added package.json"
RiyaChy072 Nov 18, 2024
3b85eec
"added repl.txt"
RiyaChy072 Nov 18, 2024
c2c97d1
"added package"
RiyaChy072 Nov 18, 2024
86d0eee
"added index.d.ts"
RiyaChy072 Nov 18, 2024
c0ba73e
"added test.ts"
RiyaChy072 Nov 18, 2024
224c819
"added benchmark.py"
RiyaChy072 Nov 18, 2024
ffdc830
"fixed spacing conventions"
RiyaChy072 Nov 22, 2024
2aa082b
"rectified mistake"
RiyaChy072 Nov 22, 2024
fb22f5d
"added space"
RiyaChy072 Nov 22, 2024
865c8c3
chore: update copyright years
stdlib-bot Nov 22, 2024
ea11a36
"added space"
RiyaChy072 Nov 22, 2024
3e2e301
Merge branch 'derivative-of-cardinal-sine' of https://github.com/Riya…
RiyaChy072 Nov 22, 2024
d6ecae7
Merge branch 'stdlib-js:develop' into derivative-of-cardinal-sine
RiyaChy072 Nov 22, 2024
f8b10ff
"fixed some issues"
RiyaChy072 Nov 23, 2024
520ce51
Merge branch 'derivative-of-cardinal-sine' of https://github.com/Riya…
RiyaChy072 Nov 23, 2024
6fba45c
"made changes"
RiyaChy072 Nov 23, 2024
7d4d17b
"added change"
RiyaChy072 Nov 28, 2024
ec814c0
"updated fixture"
RiyaChy072 Nov 29, 2024
d4ee9c4
"updated json data"
RiyaChy072 Nov 29, 2024
ea93a54
"updated large positive"
RiyaChy072 Nov 30, 2024
19883d7
"fixed large positive"
RiyaChy072 Nov 30, 2024
c87b701
"updated data"
RiyaChy072 Nov 30, 2024
383889c
"added changes"
RiyaChy072 Nov 30, 2024
3aeae28
"added changes"
RiyaChy072 Nov 30, 2024
d90a967
"added changes"
RiyaChy072 Dec 11, 2024
e0e03fa
"added changes"
RiyaChy072 Dec 11, 2024
b824901
"added changes"
RiyaChy072 Dec 11, 2024
e1d2d50
"added changes"
RiyaChy072 Dec 11, 2024
98258a0
"fixed issues"
RiyaChy072 Dec 27, 2024
f808932
"fixed benchmark"
RiyaChy072 Dec 27, 2024
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
213 changes: 213 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cosc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<!--

@license Apache-2.0

Copyright (c) 2024 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.

-->

# cosc

> Compute the [derivative of cardinal sine][cosc] of a number.

<section class="intro">

The normalized [derivative of cardinal sine][cosc] function is defined as

<!-- <equation class="equation" label="eq:cosc_function" align="center" raw="\operatorname{cosc}(x) := \begin{cases} \frac{{\operatorname{cos}(\pi x)}-\frac{\operatorname{sin}(\pi x)}{\pi x}}{x} & \textrm{if}\ x \neq 0 \\ 0 & \textrm{if}\ x = 0 \end{cases}" alt="Cosc function"> -->

```math
\mathop{\mathrm{cosc}}(x) := \begin{cases} \frac {{\operatorname{cos}(\pi x)}-\frac{\operatorname{sin}(\pi x)}{\pi x}}{x} & \textrm{if}\ x \neq 0 \\ 0 & \textrm{if}\ x = 0 \end{cases}
```

<!-- <div class="equation" align="center" data-raw-text="\operatorname{cosc}(x) := \begin{cases} \frac {{\operatorname{cos}(\pi x)}-\frac{\operatorname{sin}(\pi x)}{\pi x}}{x} &amp; \textrm{if}\ x \neq 0 \\ 0 &amp; \textrm{if}\ x = 0 \end{cases}" data-equation="eq:cosc_function">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/cosc/docs/img/equation_cosc_function.svg" alt="Cosc function">
<br>
</div> -->

<!-- </equation> -->

for any real number `x`.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var cosc = require( '@stdlib/math/base/special/cosc' );
```

#### cosc( x )

Computes the normalized [derivative of cardinal sine][cosc] of a `number`.

```javascript
var v = cosc( 0.5 );
// returns ~-1.273

v = cosc( -1.2 );
// returns ~0.544

v = cosc( 0.0 );
// returns 0.0

v = cosc( NaN );
// returns NaN
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var linspace = require( '@stdlib/array/base/linspace' );
var cosc = require( '@stdlib/math/base/special/cosc' );

var x = linspace( -5.0, 5.0, 100 );

var i;
for ( i = 0; i < x.length; i++ ) {
console.log( cosc( x[ i ] ) );
}
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/math/base/special/cosc.h"
```

#### stdlib_base_cosc( x )

Computes the normalized [derivative of cardinal sine][cosc] of a `number`.

```c
double y = stdlib_base_cosc( 0.5 );
// returns ~-1.273
```

The function accepts the following arguments:

- **x**: `[in] double` input value.

```c
double stdlib_base_cosc( const double x );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/math/base/special/cosc.h"
#include <stdio.h>

int main( void ) {
const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 };

double y;
int i;
for ( i = 0; i < 5; i++ ) {
y = stdlib_base_cosc( x[ i ] );
printf( "cosc(%lf) = %lf\n", x[ i ], y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/math/base/special/cos`][@stdlib/math/base/special/cos]</span><span class="delimiter">: </span><span class="description">compute the cos of a number.</span>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[cosc]: https://en.wikipedia.org/wiki/cosc_function

<!-- <related-links> -->

[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cosc = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 2.0 ) - 2.0;
y = cosc( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var cosc = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( cosc instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 2.0 ) - 2.0;
y = cosc( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading