-
-
Notifications
You must be signed in to change notification settings - Fork 906
feat: add implementation of stdlib/math/base/special/minmaxabsf
#6290
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
sahil20021008
wants to merge
16
commits into
stdlib-js:develop
Choose a base branch
from
sahil20021008:feature/minmaxabsf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
21e3c87
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 7ab15ee
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 79fa76e
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 a459008
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 e4244db
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 14ff772
feat!: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 f79ffcf
feat!: Committing changes for draft review
sahil20021008 f092b66
Resolve merge conflicts
sahil20021008 160318e
feat: fix manifest.json errors
sahil20021008 eca6eed
fix: resolve lint errors
stdlib-bot 883bae8
feat: fixed copyright dates
sahil20021008 f24b5cc
feat: fix julia benchmark
sahil20021008 a57e629
feat: fix julia benchmark
sahil20021008 18d14d4
feat: fix julia benchmark
sahil20021008 fd84128
feat: addressed review comments
sahil20021008 2c7567e
feat: add implementation of stdlib/math/base/special/minmaxabsf
sahil20021008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
258 changes: 258 additions & 0 deletions
258
lib/node_modules/@stdlib/math/base/special/minmaxabsf/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2025 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. | ||
|
||
--> | ||
|
||
# minmaxabsf | ||
|
||
> Return the minimum and maximum absolute single-precision floating-point numbers. | ||
|
||
<!-- 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 --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var minmaxabsf = require( '@stdlib/math/base/special/minmaxabsf' ); | ||
``` | ||
|
||
#### minmaxabsf( x,y ) | ||
|
||
Returns the minimum and maximum absolute single-precision floating-point values in a single pass. | ||
|
||
```javascript | ||
var v = minmaxabsf( 4.0, 3.0 ); | ||
// returns <Float32Array>[ 3.0, 4.0 ] | ||
|
||
v = minmaxabsf( +0.0, -0.0 ); | ||
// returns <Float32Array>[ 0.0, 0.0 ] | ||
``` | ||
|
||
If any argument is `NaN`, the function returns `Nan` for both the minimum value and the maximum value. | ||
|
||
```javascript | ||
var v = minmaxabsf( 4.2, NaN ); | ||
// returns <Float32Array>[ NaN, NaN ] | ||
|
||
v = minmaxabsf( NaN, 3.14 ); | ||
// returns <Float32Array>[ NaN, NaN ] | ||
``` | ||
|
||
#### minmaxabsf.assign( x, y, out, stride, offset ) | ||
|
||
Returns the minimum and maximum absolute single-precision values in a single pass and assigns the results to a provided output array. | ||
|
||
```javascript | ||
var Float32Array = require( '@stdlib/array/float32' ); | ||
|
||
var out = new Float32Array( 2 ); | ||
|
||
var v = minmaxabsf.assign( 5.0, -1.0, out, 1, 0 ); | ||
// returns <Float32Array>[ 1.0, 5.0 ] | ||
|
||
var bool = ( v === out ); | ||
// returns true | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var minmaxabsf = require( '@stdlib/math/base/special/minmaxabsf' ); | ||
|
||
var x; | ||
var y; | ||
var v; | ||
var i; | ||
|
||
for ( i = 0; i < 100; i++ ) { | ||
x = ( randu()*100.0 ) - 50.0; | ||
y = ( randu()*100.0 ) - 50.0; | ||
v = minmaxabsf( x, y ); | ||
console.log( 'minmaxabsf(%d,%d) = [%d, %d]', x, y, v[0], v[1] ); | ||
} | ||
``` | ||
|
||
</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/minmaxabsf.h" | ||
``` | ||
|
||
#### stdlib_base_minmaxabsf( x, y, min, max ) | ||
|
||
Returns the minimum and maximum absolute single-precision floating-point values in a single pass. | ||
|
||
```c | ||
float min; | ||
float max; | ||
stdlib_base_minmaxabsf( -4.2f, 3.14f, &min, &max ); | ||
// [ 3.14, 4.2 ] | ||
sahil20021008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
stdlib_base_minmaxabsf( 0.0f, -0.0f, &min, &max ); | ||
// [ 0.0, 0.0 ] | ||
sahil20021008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
The function accepts the following arguments: | ||
|
||
- **x**: `[in] float` input value. | ||
- **y**: `[in] float` input value. | ||
- **min**: `[in] *float` output min. | ||
sahil20021008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- **max**: `[in] *float` output max. | ||
sahil20021008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```c | ||
void stdlib_base_minmaxabsf( const float x, const float y, float* min, float* max ); | ||
``` | ||
|
||
</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/minmaxabsf.h" | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
int main(void) { | ||
srand(time(NULL)); // Seed random number generator | ||
|
||
float x1[10], x2[10]; | ||
float min, max; | ||
int i; | ||
|
||
// Generate random floating-point values between -1.0 and 1.0 | ||
for (i = 0; i < 10; i++) { | ||
x1[i] = ((float)rand() / RAND_MAX) * 2.0f - 1.0f; // Random float in [-1,1] | ||
x2[i] = ((float)rand() / RAND_MAX) * 2.0f - 1.0f; // Random float in [-1,1] | ||
|
||
// Introduce NaN values randomly | ||
if (rand() % 10 == 0) x1[i] = NAN; | ||
if (rand() % 10 == 0) x2[i] = NAN; | ||
} | ||
|
||
// Compute min and max values | ||
for (i = 0; i < 10; i++) { | ||
stdlib_base_minmaxabsf(x1[i], x2[i], &min, &max); | ||
printf("x1[%d]: %f, x2[%d]: %f, minmaxf(x1[%d], x2[%d]): (%f, %f)\n", | ||
i, x1[i], i, x2[i], i, i, min, max); | ||
} | ||
|
||
return 0; | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
</section> | ||
|
||
<!-- /.c --> | ||
|
||
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="references"> | ||
|
||
</section> | ||
|
||
<!-- /.references --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</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"> | ||
|
||
<!-- <related-links> --> | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
78 changes: 78 additions & 0 deletions
78
lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 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/randn' ); | ||
var isFloat32Array = require( '@stdlib/assert/is-float32array' ); | ||
var float32Array = require( '@stdlib/array/float32' ); | ||
var pkg = require( './../package.json' ).name; | ||
var minmaxabsf = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var x; | ||
var y; | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
x = ( randu()*1000.0 ) - 500.0; | ||
y = ( randu()*1000.0 ) - 500.0; | ||
z = minmaxabsf( x, y ); | ||
if ( z.length !== 2 ) { | ||
b.fail( 'should have expected length' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isFloat32Array( z ) ) { | ||
b.fail( 'should return an array' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); | ||
|
||
bench( pkg+':assign', function benchmark( b ) { | ||
var x; | ||
var y; | ||
var z; | ||
var i; | ||
|
||
z = new float32Array( 2 ); | ||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
x = ( randu()*1000.0 ) - 500.0; | ||
y = ( randu()*1000.0 ) - 500.0; | ||
z = minmaxabsf.assign( x, y, z, 1, 0 ); | ||
if ( z.length !== 2 ) { | ||
b.fail( 'should have expected length' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isFloat32Array( z ) ) { | ||
b.fail( 'should return an array' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.