Skip to content

Commit 04bc39b

Browse files
committed
feat: add benchmarks, examples, docs
--- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 8416f53 commit 04bc39b

File tree

13 files changed

+91
-269
lines changed

13 files changed

+91
-269
lines changed

lib/node_modules/@stdlib/math/base/special/kernel-cosf/README.md

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,40 @@ limitations under the License.
1818
1919
-->
2020

21-
# kernelCos
21+
# kernelCosf
2222

23-
> Compute the [cosine][cosine] of a double-precision floating-point number on `[-π/4, π/4]`.
23+
> Compute the [cosine][cosine] of a single-precision floating-point number on `[-π/4, π/4]`.
2424
2525
<section class="usage">
2626

2727
## Usage
2828

2929
```javascript
30-
var kernelCos = require( '@stdlib/math/base/special/kernel-cos' );
30+
var kernelCosf = require( '@stdlib/math/base/special/kernel-cosf' );
3131
```
3232

33-
#### kernelCos( x, y )
33+
#### kernelCosf( x )
3434

35-
Computes the [cosine][cosine] of a double-precision floating-point number on `[-π/4, π/4]`.
35+
Computes the [cosine][cosine] of a single-precision floating-point number on `[-π/4, π/4]`.
3636

3737
```javascript
38-
var v = kernelCos( 0.0, 0.0 );
38+
var v = kernelCosf( 0.0 );
3939
// returns ~1.0
4040

41-
v = kernelCos( 3.141592653589793/6.0, 0.0 );
41+
v = kernelCosf( 3.141592653589793/6.0 );
4242
// returns ~0.866
4343

44-
v = kernelCos( 0.785, -1.144e-17 );
44+
v = kernelCosf( 0.785 );
4545
// returns ~0.707
4646

47-
v = kernelCos( NaN, 0.0 );
47+
v = kernelCosf( NaN );
4848
// returns NaN
4949
```
5050

5151
</section>
5252

5353
<!-- /.usage -->
5454

55-
<section class="notes">
56-
57-
## Notes
58-
59-
- For increased accuracy, the number for which the [cosine][cosine] should be evaluated can be supplied as a [double-double number][double-double-arithmetic] (i.e., a non-evaluated sum of two [double-precision floating-point numbers][ieee754] `x` and `y`).
60-
61-
- As components of a [double-double number][double-double-arithmetic], the two [double-precision floating-point numbers][ieee754] `x` and `y` must satisfy
62-
63-
<!-- <equation class="equation" label="eq:double_double_inequality" align="center" raw="|y| \leq \frac{1}{2} \operatorname{ulp}(x)" alt="Inequality for the two components of a double-double number."> -->
64-
65-
<div class="equation" align="center" data-raw-text="|y| \leq \frac{1}{2} \operatorname{ulp}(x)" data-equation="eq:double_double_inequality">
66-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/kernel-cos/docs/img/equation_double_double_inequality.svg" alt="Inequality for the two components of a double-double number.">
67-
<br>
68-
</div>
69-
70-
<!-- </equation> -->
71-
72-
where `ulp` stands for [units in the last place][ulp].
73-
74-
</section>
75-
76-
<!-- /.notes -->
77-
7855
<section class="examples">
7956

8057
## Examples
@@ -84,13 +61,13 @@ v = kernelCos( NaN, 0.0 );
8461
```javascript
8562
var linspace = require( '@stdlib/array/base/linspace' );
8663
var PI = require( '@stdlib/constants/float64/pi' );
87-
var kernelCos = require( '@stdlib/math/base/special/kernel-cos' );
64+
var kernelCosf = require( '@stdlib/math/base/special/kernel-cosf' );
8865

8966
var x = linspace( -PI/4.0, PI/4.0, 100 );
9067

9168
var i;
9269
for ( i = 0; i < x.length; i++ ) {
93-
console.log( 'kernelCos(%d) = %d', x[ i ], kernelCos( x[ i ], 0.0 ) );
70+
console.log( 'kernelCosf(%d) = %d', x[ i ], kernelCosf( x[ i ] ) );
9471
}
9572
```
9673

@@ -121,28 +98,27 @@ for ( i = 0; i < x.length; i++ ) {
12198
### Usage
12299

123100
```c
124-
#include "stdlib/math/base/special/kernel_cos.h"
101+
#include "stdlib/math/base/special/kernel_cosf.h"
125102
```
126103

127-
#### stdlib_base_kernel_cos( x, y )
104+
#### stdlib_base_kernel_cosf( x )
128105

129-
Computes the [cosine][cosine] of a double-precision floating-point number on `[-π/4, π/4]`.
106+
Computes the [cosine][cosine] of a single-precision floating-point number on `[-π/4, π/4]`.
130107

131108
```c
132-
var v = stdlib_base_kernel_cos( 0.0, 0.0 );
133-
// returns ~0.0
109+
float v = stdlib_base_kernel_cosf( 0.0f );
110+
// returns ~0.0f
134111

135-
v = stdlib_base_kernel_cos( 3.141592653589793/6.0, 0.0 );
136-
// returns ~0.866
112+
v = stdlib_base_kernel_cosf( 3.141592653589793/6.0f );
113+
// returns ~0.866f
137114
```
138115

139116
The function accepts the following arguments:
140117

141-
- **x**: `[in] double` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
142-
- **y**: `[in] double` tail of `x`.
118+
- **x**: `[in] float` input value (in radians, assumed to be bounded by `~pi/4` in magnitude).
143119

144120
```c
145-
double stdlib_base_kernel_cos( const double x, const double y );
121+
float stdlib_base_kernel_cosf( const float x );
146122
```
147123
148124
</section>
@@ -153,10 +129,6 @@ double stdlib_base_kernel_cos( const double x, const double y );
153129
154130
<section class="notes">
155131
156-
### Notes
157-
158-
- For increased accuracy, the number for which the [cosine][cosine] should be evaluated can be supplied as a [double-double number][double-double-arithmetic] (i.e., a non-evaluated sum of two [double-precision floating-point numbers][ieee754] `x` and `y`).
159-
160132
</section>
161133
162134
<!-- /.notes -->
@@ -168,17 +140,17 @@ double stdlib_base_kernel_cos( const double x, const double y );
168140
### Examples
169141
170142
```c
171-
#include "stdlib/math/base/special/kernel_cos.h"
143+
#include "stdlib/math/base/special/kernel_cosf.h"
172144
#include <stdio.h>
173145
174146
int main( void ) {
175-
const double x[] = { -0.7853981633974483, -0.6108652381980153, -0.4363323129985824, -0.26179938779914946, -0.08726646259971649, 0.08726646259971649, 0.26179938779914935, 0.43633231299858233, 0.6108652381980153, 0.7853981633974483 };
147+
const float x[] = { -0.7853981633974483f, -0.6108652381980153f, -0.4363323129985824f, -0.26179938779914946f, -0.08726646259971649f, 0.08726646259971649f, 0.26179938779914935f, 0.43633231299858233f, 0.6108652381980153f, 0.7853981633974483f };
176148
177-
double out;
149+
float v;
178150
int i;
179151
for ( i = 0; i < 10; i++ ) {
180-
out = stdlib_base_kernel_cos( x[ i ], 0.0 );
181-
printf ( "x[ i ]: %lf, y: %lf, out: %lf\n", x[ i ], 0.0, out );
152+
v = stdlib_base_kernel_cosf( x[ i ] );
153+
printf( "kernelCosf(%f) = %f\n", x[ i ], v );
182154
}
183155
}
184156
```
@@ -195,14 +167,6 @@ int main( void ) {
195167

196168
<section class="related">
197169

198-
* * *
199-
200-
## See Also
201-
202-
- <span class="package-name">[`@stdlib/math/base/special/cos`][@stdlib/math/base/special/cos]</span><span class="delimiter">: </span><span class="description">compute the cosine of a number.</span>
203-
- <span class="package-name">[`@stdlib/math/base/special/kernel-sin`][@stdlib/math/base/special/kernel-sin]</span><span class="delimiter">: </span><span class="description">compute the sine of a double-precision floating-point number on \[-π/4, π/4].</span>
204-
- <span class="package-name">[`@stdlib/math/base/special/kernel-tan`][@stdlib/math/base/special/kernel-tan]</span><span class="delimiter">: </span><span class="description">compute the tangent of a double-precision floating-point number on \[-π/4, π/4].</span>
205-
206170
</section>
207171

208172
<!-- /.related -->
@@ -213,20 +177,8 @@ int main( void ) {
213177

214178
[cosine]: https://en.wikipedia.org/wiki/Cosine
215179

216-
[double-double-arithmetic]: https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#Double-double_arithmetic
217-
218-
[ieee754]: https://en.wikipedia.org/wiki/IEEE_floating_point
219-
220-
[ulp]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
221-
222180
<!-- <related-links> -->
223181

224-
[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos
225-
226-
[@stdlib/math/base/special/kernel-sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kernel-sin
227-
228-
[@stdlib/math/base/special/kernel-tan]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kernel-tan
229-
230182
<!-- </related-links> -->
231183

232184
</section>

lib/node_modules/@stdlib/math/base/special/kernel-cosf/benchmark/benchmark.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var PI = require( '@stdlib/constants/float64/pi' );
2727
var pkg = require( './../package.json' ).name;
28-
var kernelCos = require( './../lib' );
28+
var kernelCosf = require( './../lib' );
2929

3030

3131
// MAIN //
@@ -35,10 +35,13 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38+
x = uniform( 100, -PI/4.0, PI/4.0, {
39+
'dtype': 'float32'
40+
});
41+
3842
b.tic();
3943
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu() * PI / 2 ) - ( PI / 4.0 );
41-
y = kernelCos( x, 0.0 );
44+
y = kernelCosf( x[ i % x.length ] );
4245
if ( isnan( y ) ) {
4346
b.fail( 'should not return NaN' );
4447
}

lib/node_modules/@stdlib/math/base/special/kernel-cosf/benchmark/benchmark.native.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var PI = require( '@stdlib/constants/float64/pi' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -31,9 +31,9 @@ var pkg = require( './../package.json' ).name;
3131

3232
// VARIABLES //
3333

34-
var kernelCos = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var kernelCosf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3535
var opts = {
36-
'skip': ( kernelCos instanceof Error )
36+
'skip': ( kernelCosf instanceof Error )
3737
};
3838

3939

@@ -44,10 +44,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var y;
4545
var i;
4646

47+
x = uniform( 100, -PI/4.0, PI/4.0, {
48+
'dtype': 'float32'
49+
});
50+
4751
b.tic();
4852
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu() * PI/2.0 ) - ( PI/4.0 );
50-
y = kernelCos( x, 0.0 );
53+
y = kernelCosf( x[ i % x.length ] );
5154
if ( isnan( y ) ) {
5255
b.fail( 'should not return NaN' );
5356
}

lib/node_modules/@stdlib/math/base/special/kernel-cosf/benchmark/c/native/benchmark.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/kernel_cos.h"
19+
#include "stdlib/math/base/special/kernel_cosf.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222
#include <math.h>
2323
#include <time.h>
2424
#include <sys/time.h>
2525

26-
#define NAME "kernel_cos"
26+
#define NAME "kernel_cosf"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -79,9 +79,9 @@ static double tic( void ) {
7979
*
8080
* @return random number
8181
*/
82-
static double rand_double( void ) {
82+
static float rand_float( void ) {
8383
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
return (float)r / ( (float)RAND_MAX + 1.0f );
8585
}
8686

8787
/**
@@ -90,16 +90,19 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93+
float x[ 100 ];
9394
double elapsed;
94-
double x;
9595
double z;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( ( rand_float()*2.0f ) - 1.0f ) * 0.7853981633974483f;
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( ( rand_double() * 2.0 ) - 1.0 ) * 0.7853981633974483;
102-
z = stdlib_base_kernel_cos( x, 0.0 );
105+
z = stdlib_base_kernel_cosf( x[ i%100 ] );
103106
if ( z != z ) {
104107
printf( "should not return NaN\n" );
105108
break;

lib/node_modules/@stdlib/math/base/special/kernel-cosf/docs/img/equation_double_double_inequality.svg

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/node_modules/@stdlib/math/base/special/kernel-cosf/examples/c/example.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
*/
1818

1919

20-
#include "stdlib/math/base/special/kernel_cos.h"
20+
#include "stdlib/math/base/special/kernel_cosf.h"
2121
#include <stdio.h>
2222

2323
int main( void ) {
24-
const double x[] = { -0.7853981633974483, -0.6108652381980153, -0.4363323129985824, -0.26179938779914946, -0.08726646259971649, 0.08726646259971649, 0.26179938779914935, 0.43633231299858233, 0.6108652381980153, 0.7853981633974483 };
24+
const float x[] = { -0.7853981633974483f, -0.6108652381980153f, -0.4363323129985824f, -0.26179938779914946f, -0.08726646259971649f, 0.08726646259971649f, 0.26179938779914935f, 0.43633231299858233f, 0.6108652381980153f, 0.7853981633974483f };
2525

26-
double out;
26+
float v;
2727
int i;
2828
for ( i = 0; i < 10; i++ ) {
29-
out = stdlib_base_kernel_cos( x[ i ], 0.0 );
30-
printf ( "x[ i ]: %lf, y: %lf, out: %lf\n", x[ i ], 0.0, out );
29+
v = stdlib_base_kernel_cosf( x[ i ] );
30+
printf( "kernelCosf(%f) = %f\n", x[ i ], v );
3131
}
3232
}

lib/node_modules/@stdlib/math/base/special/kernel-cosf/examples/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
var linspace = require( '@stdlib/array/base/linspace' );
2222
var PI = require( '@stdlib/constants/float64/pi' );
23-
var kernelCos = require( './../lib' );
23+
var kernelCosf = require( './../lib' );
2424

2525
var x = linspace( -PI/4.0, PI/4.0, 100 );
2626

2727
var i;
2828
for ( i = 0; i < x.length; i++ ) {
29-
console.log( 'kernelCos(%d) = %d', x[ i ], kernelCos( x[ i ], 0.0 ) );
29+
console.log( 'kernelCosf(%d) = %d', x[ i ], kernelCosf( x[ i ] ) );
3030
}

0 commit comments

Comments
 (0)