Skip to content

feat: add math/base/special/logitf #3367

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

Merged
merged 24 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
084c777
feat(math): add math/base/special/logitf
vivekmaurya001 Dec 7, 2024
fba8f2c
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 Dec 7, 2024
92cc9c6
chore: update copyright years
stdlib-bot Dec 7, 2024
33ea60a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Jan 18, 2025
501ef98
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
2e3dce0
chore: update copyright years
stdlib-bot Jan 18, 2025
1b0a660
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
30fe769
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 Jan 18, 2025
5a0da6c
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
b600358
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
41a7874
Apply suggestions from code review
gunjjoshi Mar 7, 2025
4348720
Update lib/node_modules/@stdlib/math/base/special/logitf/docs/types/i…
gunjjoshi Mar 7, 2025
d4d2a4a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Mar 7, 2025
04761f2
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Mar 8, 2025
7049e2f
feat: add math/base/special/logitf
vivekmaurya001 Mar 8, 2025
3327eed
chore: update copyright years
stdlib-bot Mar 8, 2025
a975a76
Merge remote-tracking branch 'upstream/develop' into logitf
stdlib-bot Apr 17, 2025
ae813a0
chore: clean-up
anandkaranubc Apr 17, 2025
abbfe91
docs: fix function descriptions
anandkaranubc Apr 17, 2025
cb908ea
bench: follow code conventions and fix function return types
anandkaranubc Apr 17, 2025
5c8a985
docs: replace manual for loop in examples
anandkaranubc Apr 17, 2025
ff84d08
chore: re-enable lint rule
anandkaranubc Apr 17, 2025
4d5d7aa
fix: use float64ToFloat32 to avoid elevated precision
anandkaranubc Apr 17, 2025
dc07f16
test: replace equal with strictEqual
anandkaranubc Apr 17, 2025
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
Prev Previous commit
Next Next commit
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
---
  • Loading branch information
vivekmaurya001 committed Jan 18, 2025
commit 501ef9887e601538113c6c98848a96a093d969fc
15 changes: 9 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/logitf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The [logit][logit] function is defined as the logarithm of the odds `p / (1-p)`;

<!-- </equation> -->

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

</section>

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

```javascript
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var logitf = require( '@stdlib/math/base/special/logitf' );

var p;
var len = 100;
var opts = {
'dtype': 'float32'
};
var p = uniform( len, 0, 1, opts );
var i;

for ( i = 0; i < 100; i++ ) {
p = randu();
console.log( 'logitf(%d) = %f', p, logitf( p ) );
console.log( 'logitf(%f) = %f', p[ i ], logitf( p[ i ] ) );
}
```

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

```c
float stdlib_base_logitf( const float p );
float stdlib_base_logitf( const float p );
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,37 @@
// MODULES //

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


// MAIN //

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

opts = {
'dtype': 'float32'
};

len = 100;
x = uniform( len, 0, 1, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu();
y = logitf( x );
if ( isnan( y ) ) {
y = logitf( x[ i % len ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

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 uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -39,20 +39,28 @@ var opts = {
// MAIN //

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

opts = {
'dtype': 'float32'
};

len = 100;
x = uniform( len, 0, 1, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu();
y = logitf( x );
if ( isnan( y ) ) {
y = logitf( x[ i % len ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ static float rand_float( void ) {
*/
static double benchmark( void ) {
double elapsed;
float x[ 100 ];
float y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = rand_float();
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
y = stdlib_base_logitf( rand_float() );
y = stdlib_base_logitf( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var logitf = require( './../lib' );

var p;
var len = 100;
var opts = {
'dtype': 'float32'
};
var p = uniform( len, 0, 1, opts );
var i;

for ( i = 0; i < 100; i++ ) {
p = randu();
console.log( 'logitf(%d) = %f', p, logitf( p ) );
console.log( 'logitf(%f) = %f', p[ i ], logitf( p[ i ] ) );
}
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/math/base/special/logitf/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

// MODULES //

var isProbability = require( '@stdlib/math/base/assert/is-probability' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isProbabilityf = require( '@stdlib/math/base/assert/is-probabilityf' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
Expand Down Expand Up @@ -56,10 +56,10 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
* // returns NaN
*/
function logitf( p ) {
if ( isnan( p ) ) {
if ( isnanf( p ) ) {
return p;
}
if ( !isProbability( p ) ) {
if ( !isProbabilityf( p ) ) {
return NaN;
}
if ( p === 0.0 ) {
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/logitf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-probability",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-probabilityf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/ninf"
]
Expand All @@ -56,8 +56,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-probability",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-probabilityf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/ninf"
]
Expand All @@ -74,8 +74,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/lnf",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-probability",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-probabilityf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/ninf"
]
Expand Down
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/math/base/special/logitf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

#include "stdlib/math/base/special/logitf.h"
#include "stdlib/math/base/assert/is_probability.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/assert/is_probabilityf.h"
#include "stdlib/math/base/assert/is_nanf.h"
#include "stdlib/math/base/special/lnf.h"
#include "stdlib/constants/float32/pinf.h"
#include "stdlib/constants/float32/ninf.h"
Expand All @@ -34,10 +34,10 @@
* // returns ~-1.386
*/
float stdlib_base_logitf( const float p ) {
if ( stdlib_base_is_nan( p ) ) {
if ( stdlib_base_is_nanf( p ) ) {
return 0.0 / 0.0; // NaN
}
if ( !stdlib_base_is_probability( p ) ) {
if ( !stdlib_base_is_probabilityf( p ) ) {
return 0.0 / 0.0; // NaN
}
if ( p == 0.0 ) {
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/logitf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var EPS = require( '@stdlib/constants/float32/eps' );
Expand All @@ -47,31 +47,31 @@

tape( 'the function returns `NaN` when provided `NaN`', function test( t ) {
var y = logitf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnanf( y ), true, 'returns expected value' );
t.end();
});

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

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

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

tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', function test( t ) {

Check warning on line 74 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -94,7 +94,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`', function test( t ) {

Check warning on line 97 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -117,7 +117,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`', function test( t ) {

Check warning on line 120 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -140,7 +140,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.75,1)`', function test( t ) {

Check warning on line 143 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var EPS = require( '@stdlib/constants/float32/eps' );
Expand All @@ -48,39 +48,39 @@

// TESTS //

tape( 'main export is a function', function test( t ) {
tape( 'main export is a function', opts, function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof logitf, 'function', 'main export is a function' );
t.end();
});

tape( 'the function returns `NaN` when provided `NaN`', function test( t ) {
tape( 'the function returns `NaN` when provided `NaN`', opts, function test( t ) {
var y = logitf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnanf( y ), true, 'returns expected value' );
t.end();
});

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

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

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

tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', function test( t ) {
tape( 'the function evaluates the logitf of `x` for the interval `(0,0.25]`', opts, function test( t ) {

Check warning on line 83 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -103,7 +103,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`', function test( t ) {
tape( 'the function evaluates the logitf of `x` for the interval `[0.25,0.49]`', opts, function test( t ) {

Check warning on line 106 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -126,7 +126,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`', function test( t ) {
tape( 'the function evaluates the logitf of `x` for the interval `[0.5,0.75]`', opts, function test( t ) {

Check warning on line 129 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand All @@ -149,7 +149,7 @@
t.end();
});

tape( 'the function evaluates the logitf of `x` for the interval `[0.75,1)`', function test( t ) {
tape( 'the function evaluates the logitf of `x` for the interval `[0.75,1)`', opts, function test( t ) {

Check warning on line 152 in lib/node_modules/@stdlib/math/base/special/logitf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "logitf"
var expected;
var delta;
var tol;
Expand Down
Loading