Skip to content

Commit 478b35b

Browse files
committed
feat: add math/base/special/trigammaf
--- 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: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 5be5220 commit 478b35b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+502
-1786
lines changed

lib/node_modules/@stdlib/math/base/special/trigammaf/README.md

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2018 The Stdlib Authors.
5+
Copyright (c) 2025 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -20,23 +20,18 @@ limitations under the License.
2020

2121
# Trigamma
2222

23-
> [Trigamma][trigamma-function] function.
23+
> [Trigamma][trigamma-function] function for a single-precision floating-point number.
2424
2525
<section class="intro">
2626

27-
The [trigamma function][trigamma-function] `ψ^(1)` is the derivative of the [digamma function][@stdlib/math/base/special/digamma].
27+
The [trigamma function][trigamma-function] `ψ^(1)` is the derivative of the [digamma function][digamma-function].
2828

2929
<!-- <equation class="equation" label="eq:trigamma_function" align="center" raw="\psi^{(1)}(x) =\frac{d}{dx} \Psi(x) = \sum_{k=0}^\infty \frac{1}{(k+x)^2}" alt="Trigamma function"> -->
3030

3131
```math
3232
\psi^{(1)}(x) =\frac{d}{dx} \Psi(x) = \sum_{k=0}^\infty \frac{1}{(k+x)^2}
3333
```
3434

35-
<!-- <div class="equation" align="center" data-raw-text="\psi^{(1)}(x) =\frac{d}{dx} \Psi(x) = \sum_{k=0}^\infty \frac{1}{(k+x)^2}" data-equation="eq:trigamma_function">
36-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/trigamma/docs/img/equation_trigamma_function.svg" alt="Trigamma function">
37-
<br>
38-
</div> -->
39-
4035
<!-- </equation> -->
4136

4237
</section>
@@ -48,41 +43,41 @@ The [trigamma function][trigamma-function] `ψ^(1)` is the derivative of the [di
4843
## Usage
4944

5045
```javascript
51-
var trigamma = require( '@stdlib/math/base/special/trigamma' );
46+
var trigammaf = require( '@stdlib/math/base/special/trigammaf' );
5247
```
5348

54-
#### trigamma( x )
49+
#### trigammaf( x )
5550

56-
Evaluates the [trigamma function][trigamma-function].
51+
Evaluates the [trigamma function][trigamma-function] for a single-precision floating-point number.
5752

5853
```javascript
59-
var v = trigamma( -2.5 );
54+
var v = trigammaf( -2.5 );
6055
// returns ~9.539
6156

62-
v = trigamma( 1.0 );
57+
v = trigammaf( 1.0 );
6358
// returns ~1.645
6459

65-
v = trigamma( 10.0 );
60+
v = trigammaf( 10.0 );
6661
// returns ~0.105
6762
```
6863

6964
If `x` is `0` or a negative `integer`, the function returns `NaN`.
7065

7166
```javascript
72-
var v = trigamma( 0.0 );
67+
var v = trigammaf( 0.0 );
7368
// returns NaN
7469

75-
v = trigamma( -1.0 );
70+
v = trigammaf( -1.0 );
7671
// returns NaN
7772

78-
v = trigamma( -2.0 );
73+
v = trigammaf( -2.0 );
7974
// returns NaN
8075
```
8176

8277
If provided `NaN`, the function returns `NaN`.
8378

8479
```javascript
85-
var v = trigamma( NaN );
80+
var v = trigammaf( NaN );
8681
// returns NaN
8782
```
8883

@@ -99,14 +94,14 @@ var v = trigamma( NaN );
9994
```javascript
10095
var uniform = require( '@stdlib/random/array/uniform' );
10196
var logEachMap = require( '@stdlib/console/log-each-map' );
102-
var trigamma = require( '@stdlib/math/base/special/trigamma' );
97+
var trigammaf = require( '@stdlib/math/base/special/trigammaf' );
10398

10499
var opts = {
105-
'dtype': 'float64'
100+
'dtype': 'float32'
106101
};
107102
var x = uniform( 100, -50.0, 50.0, opts );
108103

109-
logEachMap( 'x: %0.4f, ψ^(1)(x): %0.4f', x, trigamma );
104+
logEachMap( 'x: %0.4f, ψ^(1)(x): %0.4f', x, trigammaf );
110105
```
111106

112107
</section>
@@ -136,27 +131,27 @@ logEachMap( 'x: %0.4f, ψ^(1)(x): %0.4f', x, trigamma );
136131
### Usage
137132

138133
```c
139-
#include "stdlib/math/base/special/trigamma.h"
134+
#include "stdlib/math/base/special/trigammaf.h"
140135
```
141136

142-
#### stdlib_base_trigamma( x )
137+
#### stdlib_base_trigammaf( x )
143138

144-
Evaluates the [trigamma function][trigamma-function].
139+
Evaluates the [trigamma function][trigamma-function] for a single-precision floating-point number.
145140

146141
```c
147-
double out = stdlib_base_trigamma( -2.5 );
148-
// returns ~9.539
142+
float out = stdlib_base_trigammaf( -2.5f );
143+
// returns ~9.539f
149144

150-
out = stdlib_base_trigamma( 1.0 );
151-
// returns ~1.645
145+
out = stdlib_base_trigammaf( 1.0f );
146+
// returns ~1.645f
152147
```
153148

154149
The function accepts the following arguments:
155150

156-
- **x**: `[in] double` input value.
151+
- **x**: `[in] float` input value.
157152

158153
```c
159-
double stdlib_base_trigamma( const double x );
154+
float stdlib_base_trigammaf( const float x );
160155
```
161156
162157
</section>
@@ -178,17 +173,17 @@ double stdlib_base_trigamma( const double x );
178173
### Examples
179174
180175
```c
181-
#include "stdlib/math/base/special/trigamma.h"
176+
#include "stdlib/math/base/special/trigammaf.h"
182177
#include <stdio.h>
183178
184179
int main( void ) {
185-
const double x[] = { 4.0, -1.5, -0.5, 0.5 };
180+
const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f };
186181
187-
double y;
182+
float y;
188183
int i;
189184
for ( i = 0; i < 4; i++ ) {
190-
y = stdlib_base_trigamma( x[ i ] );
191-
printf( "trigamma(%lf) = %lf\n", x[ i ], y );
185+
y = stdlib_base_trigammaf( x[ i ] );
186+
printf( "x: %f, ψ^(1)(x): %f\n", x[ i ], y );
192187
}
193188
}
194189
```
@@ -205,13 +200,6 @@ int main( void ) {
205200

206201
<section class="related">
207202

208-
* * *
209-
210-
## See Also
211-
212-
- <span class="package-name">[`@stdlib/math/base/special/digamma`][@stdlib/math/base/special/digamma]</span><span class="delimiter">: </span><span class="description">digamma function.</span>
213-
- <span class="package-name">[`@stdlib/math/base/special/gamma`][@stdlib/math/base/special/gamma]</span><span class="delimiter">: </span><span class="description">gamma function.</span>
214-
215203
</section>
216204

217205
<!-- /.related -->
@@ -222,11 +210,9 @@ int main( void ) {
222210

223211
[trigamma-function]: https://en.wikipedia.org/wiki/Trigamma_function
224212

225-
<!-- <related-links> -->
213+
[digamma-function]: https://en.wikipedia.org/wiki/Digamma_function
226214

227-
[@stdlib/math/base/special/digamma]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/digamma
228-
229-
[@stdlib/math/base/special/gamma]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma
215+
<!-- <related-links> -->
230216

231217
<!-- </related-links> -->
232218

lib/node_modules/@stdlib/math/base/special/trigammaf/benchmark/benchmark.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var uniform = require( '@stdlib/random/array/uniform' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var EPS = require( '@stdlib/constants/float64/eps' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var EPS = require( '@stdlib/constants/float32/eps' );
2727
var pkg = require( './../package.json' ).name;
28-
var trigamma = require( './../lib' );
28+
var trigammaf = require( './../lib' );
2929

3030

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

38-
x = uniform( 100, EPS, 100.0 );
38+
x = uniform( 100, EPS, 100.0, {
39+
'dtype': 'float32'
40+
});
3941

4042
b.tic();
4143
for ( i = 0; i < b.iterations; i++ ) {
42-
y = trigamma( x[ i % x.length ] );
43-
if ( isnan( y ) ) {
44+
y = trigammaf( x[ i%x.length ] );
45+
if ( isnanf( y ) ) {
4446
b.fail( 'should not return NaN' );
4547
}
4648
}
4749
b.toc();
48-
if ( isnan( y ) ) {
50+
if ( isnanf( y ) ) {
4951
b.fail( 'should not return NaN' );
5052
}
5153
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/trigammaf/benchmark/benchmark.native.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -23,17 +23,17 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/array/uniform' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27-
var EPS = require( '@stdlib/constants/float64/eps' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var EPS = require( '@stdlib/constants/float32/eps' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
3030

3131

3232
// VARIABLES //
3333

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

3939

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

47-
x = uniform( 100, EPS, 100.0 );
47+
x = uniform( 100, EPS, 100.0, {
48+
'dtype': 'float32'
49+
});
4850

4951
b.tic();
5052
for ( i = 0; i < b.iterations; i++ ) {
51-
y = trigamma( x[ i % x.length ] );
52-
if ( isnan( y ) ) {
53+
y = trigammaf( x[ i%x.length ] );
54+
if ( isnanf( y ) ) {
5355
b.fail( 'should not return NaN' );
5456
}
5557
}
5658
b.toc();
57-
if ( isnan( y ) ) {
59+
if ( isnanf( y ) ) {
5860
b.fail( 'should not return NaN' );
5961
}
6062
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/math/base/special/trigammaf/benchmark/c/native/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/math/base/special/trigammaf/benchmark/c/native/benchmark.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -16,14 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/trigamma.h"
19+
#include "stdlib/math/base/special/trigammaf.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 "trigamma"
26+
#define NAME "trigammaf"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -75,13 +75,15 @@ static double tic( void ) {
7575
}
7676

7777
/**
78-
* Generates a random number on the interval [0,1).
78+
* Generates a random number on the interval [min,max).
7979
*
80-
* @return random number
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
8183
*/
82-
static double rand_double( void ) {
83-
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
static float random_uniform( const float min, const float max ) {
85+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -90,19 +92,19 @@ static double rand_double( void ) {
9092
* @return elapsed time in seconds
9193
*/
9294
static double benchmark( void ) {
93-
double x[ 100 ];
95+
float x[ 100 ];
9496
double elapsed;
95-
double y;
9697
double t;
98+
float y;
9799
int i;
98100

99101
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 100.0 * rand_double() );
102+
x[ i ] = random_uniform( -50.0f, 50.0f );
101103
}
102104

103105
t = tic();
104106
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_trigamma( x[ i%100 ] );
107+
y = stdlib_base_trigammaf( x[ i%100 ] );
106108
if ( y != y ) {
107109
printf( "should not return NaN\n" );
108110
break;

0 commit comments

Comments
 (0)