Skip to content

Commit 501ef98

Browse files
add math/base/special/logitf
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 33ea60a commit 501ef98

File tree

10 files changed

+85
-58
lines changed

10 files changed

+85
-58
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The [logit][logit] function is defined as the logarithm of the odds `p / (1-p)`;
3939

4040
<!-- </equation> -->
4141

42-
The [logit][logit] function is the inverse of the [standard logistic][standard-logistic] function, sometimes also called the sigmoid function.
42+
The [logit][logit] function is the inverse of the [standard logistic][standard-logistic] function, sometimes also called the sigmoid function.
4343

4444
</section>
4545

@@ -86,15 +86,18 @@ v = logitf( -0.2 );
8686
<!-- eslint no-undef: "error" -->
8787

8888
```javascript
89-
var randu = require( '@stdlib/random/base/randu' );
89+
var uniform = require( '@stdlib/random/array/uniform' );
9090
var logitf = require( '@stdlib/math/base/special/logitf' );
9191

92-
var p;
92+
var len = 100;
93+
var opts = {
94+
'dtype': 'float32'
95+
};
96+
var p = uniform( len, 0, 1, opts );
9397
var i;
9498

9599
for ( i = 0; i < 100; i++ ) {
96-
p = randu();
97-
console.log( 'logitf(%d) = %f', p, logitf( p ) );
100+
console.log( 'logitf(%f) = %f', p[ i ], logitf( p[ i ] ) );
98101
}
99102
```
100103

@@ -145,7 +148,7 @@ The function accepts the following arguments:
145148
- **p**: `[in] float` input value.
146149

147150
```c
148-
float stdlib_base_logitf( const float p );
151+
float stdlib_base_logitf( const float p );
149152
```
150153
151154
</section>

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,37 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var logitf = require( './../lib' );
2828

2929

3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var opts;
34+
var len;
3335
var x;
3436
var y;
3537
var i;
3638

39+
opts = {
40+
'dtype': 'float32'
41+
};
42+
43+
len = 100;
44+
x = uniform( len, 0, 1, opts );
45+
3746
b.tic();
3847
for ( i = 0; i < b.iterations; i++ ) {
39-
x = randu();
40-
y = logitf( x );
41-
if ( isnan( y ) ) {
48+
y = logitf( x[ i % len ] );
49+
if ( isnanf( y ) ) {
4250
b.fail( 'should not return NaN' );
4351
}
4452
}
4553
b.toc();
46-
if ( isnan( y ) ) {
54+
if ( isnanf( y ) ) {
4755
b.fail( 'should not return NaN' );
4856
}
4957
b.pass( 'benchmark finished' );

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

@@ -39,20 +39,28 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
43+
var len;
4244
var x;
4345
var y;
4446
var i;
4547

48+
opts = {
49+
'dtype': 'float32'
50+
};
51+
52+
len = 100;
53+
x = uniform( len, 0, 1, opts );
54+
4655
b.tic();
4756
for ( i = 0; i < b.iterations; i++ ) {
48-
x = randu();
49-
y = logitf( x );
50-
if ( isnan( y ) ) {
57+
y = logitf( x[ i % len ] );
58+
if ( isnanf( y ) ) {
5159
b.fail( 'should not return NaN' );
5260
}
5361
}
5462
b.toc();
55-
if ( isnan( y ) ) {
63+
if ( isnanf( y ) ) {
5664
b.fail( 'should not return NaN' );
5765
}
5866
b.pass( 'benchmark finished' );

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,18 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94+
float x[ 100 ];
9495
float y;
9596
double t;
9697
int i;
9798

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = rand_float();
101+
}
102+
98103
t = tic();
99104
for ( i = 0; i < ITERATIONS; i++ ) {
100-
y = stdlib_base_logitf( rand_float() );
105+
y = stdlib_base_logitf( x[ i % 100 ] );
101106
if ( y != y ) {
102107
printf( "should not return NaN\n" );
103108
break;

lib/node_modules/@stdlib/math/base/special/logitf/examples/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
2222
var logitf = require( './../lib' );
2323

24-
var p;
24+
var len = 100;
25+
var opts = {
26+
'dtype': 'float32'
27+
};
28+
var p = uniform( len, 0, 1, opts );
2529
var i;
2630

2731
for ( i = 0; i < 100; i++ ) {
28-
p = randu();
29-
console.log( 'logitf(%d) = %f', p, logitf( p ) );
32+
console.log( 'logitf(%f) = %f', p[ i ], logitf( p[ i ] ) );
3033
}

lib/node_modules/@stdlib/math/base/special/logitf/lib/main.js

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

2121
// MODULES //
2222

23-
var isProbability = require( '@stdlib/math/base/assert/is-probability' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
23+
var isProbabilityf = require( '@stdlib/math/base/assert/is-probabilityf' );
24+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2525
var lnf = require( '@stdlib/math/base/special/lnf' );
2626
var PINF = require( '@stdlib/constants/float32/pinf' );
2727
var NINF = require( '@stdlib/constants/float32/ninf' );
@@ -56,10 +56,10 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
5656
* // returns NaN
5757
*/
5858
function logitf( p ) {
59-
if ( isnan( p ) ) {
59+
if ( isnanf( p ) ) {
6060
return p;
6161
}
62-
if ( !isProbability( p ) ) {
62+
if ( !isProbabilityf( p ) ) {
6363
return NaN;
6464
}
6565
if ( p === 0.0 ) {

lib/node_modules/@stdlib/math/base/special/logitf/manifest.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
4040
"@stdlib/math/base/special/lnf",
41-
"@stdlib/math/base/assert/is-nan",
42-
"@stdlib/math/base/assert/is-probability",
41+
"@stdlib/math/base/assert/is-nanf",
42+
"@stdlib/math/base/assert/is-probabilityf",
4343
"@stdlib/constants/float32/pinf",
4444
"@stdlib/constants/float32/ninf"
4545
]
@@ -56,8 +56,8 @@
5656
"libpath": [],
5757
"dependencies": [
5858
"@stdlib/math/base/special/lnf",
59-
"@stdlib/math/base/assert/is-nan",
60-
"@stdlib/math/base/assert/is-probability",
59+
"@stdlib/math/base/assert/is-nanf",
60+
"@stdlib/math/base/assert/is-probabilityf",
6161
"@stdlib/constants/float32/pinf",
6262
"@stdlib/constants/float32/ninf"
6363
]
@@ -74,8 +74,8 @@
7474
"libpath": [],
7575
"dependencies": [
7676
"@stdlib/math/base/special/lnf",
77-
"@stdlib/math/base/assert/is-nan",
78-
"@stdlib/math/base/assert/is-probability",
77+
"@stdlib/math/base/assert/is-nanf",
78+
"@stdlib/math/base/assert/is-probabilityf",
7979
"@stdlib/constants/float32/pinf",
8080
"@stdlib/constants/float32/ninf"
8181
]

lib/node_modules/@stdlib/math/base/special/logitf/src/main.c

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

1919
#include "stdlib/math/base/special/logitf.h"
20-
#include "stdlib/math/base/assert/is_probability.h"
21-
#include "stdlib/math/base/assert/is_nan.h"
20+
#include "stdlib/math/base/assert/is_probabilityf.h"
21+
#include "stdlib/math/base/assert/is_nanf.h"
2222
#include "stdlib/math/base/special/lnf.h"
2323
#include "stdlib/constants/float32/pinf.h"
2424
#include "stdlib/constants/float32/ninf.h"
@@ -34,10 +34,10 @@
3434
* // returns ~-1.386
3535
*/
3636
float stdlib_base_logitf( const float p ) {
37-
if ( stdlib_base_is_nan( p ) ) {
37+
if ( stdlib_base_is_nanf( p ) ) {
3838
return 0.0 / 0.0; // NaN
3939
}
40-
if ( !stdlib_base_is_probability( p ) ) {
40+
if ( !stdlib_base_is_probabilityf( p ) ) {
4141
return 0.0 / 0.0; // NaN
4242
}
4343
if ( p == 0.0 ) {

lib/node_modules/@stdlib/math/base/special/logitf/test/test.js

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

2323
var tape = require( 'tape' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2525
var PINF = require( '@stdlib/constants/float32/pinf' );
2626
var NINF = require( '@stdlib/constants/float32/ninf' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
@@ -47,27 +47,27 @@ tape( 'main export is a function', function test( t ) {
4747

4848
tape( 'the function returns `NaN` when provided `NaN`', function test( t ) {
4949
var y = logitf( NaN );
50-
t.equal( isnan( y ), true, 'returns NaN' );
50+
t.equal( isnanf( y ), true, 'returns expected value' );
5151
t.end();
5252
});
5353

5454
tape( 'the function returns `NaN` when provided a number outside `[0,1]`', function test( t ) {
5555
var y = logitf( 1.2 );
56-
t.equal( isnan( y ), true, 'returns NaN' );
56+
t.equal( isnanf( y ), true, 'returns expected value' );
5757
y = logitf( -0.1 );
58-
t.equal( isnan( y ), true, 'returns NaN' );
58+
t.equal( isnanf( y ), true, 'returns expected value' );
5959
t.end();
6060
});
6161

6262
tape( 'the function returns `-Infinity` when provided `0`', function test( t ) {
6363
var y = logitf( 0.0 );
64-
t.equal( y, NINF, 'returns -Infinity' );
64+
t.equal( y, NINF, 'returns expected value' );
6565
t.end();
6666
});
6767

6868
tape( 'the function returns `+Infinity` when provided `1`', function test( t ) {
6969
var y = logitf( 1.0 );
70-
t.equal( y, PINF, 'returns +Infinity' );
70+
t.equal( y, PINF, 'returns expected value' );
7171
t.end();
7272
});
7373

lib/node_modules/@stdlib/math/base/special/logitf/test/test.native.js

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

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var PINF = require( '@stdlib/constants/float32/pinf' );
2727
var NINF = require( '@stdlib/constants/float32/ninf' );
2828
var EPS = require( '@stdlib/constants/float32/eps' );
@@ -48,39 +48,39 @@ var opts = {
4848

4949
// TESTS //
5050

51-
tape( 'main export is a function', function test( t ) {
51+
tape( 'main export is a function', opts, function test( t ) {
5252
t.ok( true, __filename );
5353
t.strictEqual( typeof logitf, 'function', 'main export is a function' );
5454
t.end();
5555
});
5656

57-
tape( 'the function returns `NaN` when provided `NaN`', function test( t ) {
57+
tape( 'the function returns `NaN` when provided `NaN`', opts, function test( t ) {
5858
var y = logitf( NaN );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnanf( y ), true, 'returns expected value' );
6060
t.end();
6161
});
6262

63-
tape( 'the function returns `NaN` when provided a number outside `[0,1]`', function test( t ) {
63+
tape( 'the function returns `NaN` when provided a number outside `[0,1]`', opts, function test( t ) {
6464
var y = logitf( 1.2 );
65-
t.equal( isnan( y ), true, 'returns NaN' );
65+
t.equal( isnanf( y ), true, 'returns expected value' );
6666
y = logitf( -0.1 );
67-
t.equal( isnan( y ), true, 'returns NaN' );
67+
t.equal( isnanf( y ), true, 'returns expected value' );
6868
t.end();
6969
});
7070

71-
tape( 'the function returns `-Infinity` when provided `0`', function test( t ) {
71+
tape( 'the function returns `-Infinity` when provided `0`', opts, function test( t ) {
7272
var y = logitf( 0.0 );
73-
t.equal( y, NINF, 'returns -Infinity' );
73+
t.equal( y, NINF, 'returns expected value' );
7474
t.end();
7575
});
7676

77-
tape( 'the function returns `+Infinity` when provided `1`', function test( t ) {
77+
tape( 'the function returns `+Infinity` when provided `1`', opts, function test( t ) {
7878
var y = logitf( 1.0 );
79-
t.equal( y, PINF, 'returns +Infinity' );
79+
t.equal( y, PINF, 'returns expected value' );
8080
t.end();
8181
});
8282

83-
tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', function test( t ) {
83+
tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', opts, function test( t ) {
8484
var expected;
8585
var delta;
8686
var tol;
@@ -103,7 +103,7 @@ tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', fu
103103
t.end();
104104
});
105105

106-
tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`', function test( t ) {
106+
tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`', opts, function test( t ) {
107107
var expected;
108108
var delta;
109109
var tol;
@@ -126,7 +126,7 @@ tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`',
126126
t.end();
127127
});
128128

129-
tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`', function test( t ) {
129+
tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`', opts, function test( t ) {
130130
var expected;
131131
var delta;
132132
var tol;
@@ -149,7 +149,7 @@ tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`',
149149
t.end();
150150
});
151151

152-
tape( 'the function evaluates the logitf of `x` for the interval `[0.75,1)`', function test( t ) {
152+
tape( 'the function evaluates the logitf of `x` for the interval `[0.75,1)`', opts, function test( t ) {
153153
var expected;
154154
var delta;
155155
var tol;

0 commit comments

Comments
 (0)