Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Dec 15, 2024
1 parent 59851e1 commit 5b1419d
Show file tree
Hide file tree
Showing 22 changed files with 1,278 additions and 0 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

##### Features

- [`14427c7`](https://github.com/stdlib-js/stdlib/commit/14427c79bc62f82b16cbadc9d34749901e48d105) - add `fill`, `map`, and `toReversed` to namespace
- [`a0d6619`](https://github.com/stdlib-js/stdlib/commit/a0d66193409576538d0f16aa89cbaeedec7898be) - add `minSignedIntegerDataType` and `minUnsignedIntegerDataType` to namespace
- [`8b1548f`](https://github.com/stdlib-js/stdlib/commit/8b1548fb45c1ff131f5edac20cb984344a2d28ec) - update namespace TypeScript declarations [(#3190)](https://github.com/stdlib-js/stdlib/pull/3190)

</section>
Expand Down Expand Up @@ -137,6 +139,50 @@

<!-- /.package -->

<section class="package" id="ndarray-base-min-signed-integer-dtype-unreleased">

#### [@stdlib/ndarray/base/min-signed-integer-dtype](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/min-signed-integer-dtype)

<details>

<section class="features">

##### Features

- [`c3bffe5`](https://github.com/stdlib-js/stdlib/commit/c3bffe513318480e2ce4645bb05895df8148ee1e) - add `ndarray/base/min-signed-integer-dtype`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="ndarray-base-min-unsigned-integer-dtype-unreleased">

#### [@stdlib/ndarray/base/min-unsigned-integer-dtype](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/min-unsigned-integer-dtype)

<details>

<section class="features">

##### Features

- [`97e8c1a`](https://github.com/stdlib-js/stdlib/commit/97e8c1aff4f7c1a3b0946d15354a926d82e2120a) - add `ndarray/base/min-unsigned-integer-dtype`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="ndarray-filter-unreleased">

#### [@stdlib/ndarray/filter](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/filter)
Expand Down Expand Up @@ -317,6 +363,10 @@ A total of 3 people contributed to this release. Thank you to the following cont

<details>

- [`14427c7`](https://github.com/stdlib-js/stdlib/commit/14427c79bc62f82b16cbadc9d34749901e48d105) - **feat:** add `fill`, `map`, and `toReversed` to namespace _(by Athan Reines)_
- [`a0d6619`](https://github.com/stdlib-js/stdlib/commit/a0d66193409576538d0f16aa89cbaeedec7898be) - **feat:** add `minSignedIntegerDataType` and `minUnsignedIntegerDataType` to namespace _(by Athan Reines)_
- [`97e8c1a`](https://github.com/stdlib-js/stdlib/commit/97e8c1aff4f7c1a3b0946d15354a926d82e2120a) - **feat:** add `ndarray/base/min-unsigned-integer-dtype` _(by Athan Reines)_
- [`c3bffe5`](https://github.com/stdlib-js/stdlib/commit/c3bffe513318480e2ce4645bb05895df8148ee1e) - **feat:** add `ndarray/base/min-signed-integer-dtype` _(by Athan Reines)_
- [`0d6bf75`](https://github.com/stdlib-js/stdlib/commit/0d6bf755cd3fcefbdf4751bc1f8e011bedefc057) - **refactor:** resolve error constructor and add todos _(by Athan Reines)_
- [`dbfd8f5`](https://github.com/stdlib-js/stdlib/commit/dbfd8f5c81d11be2142ebfc4f2f0bb0316ba7478) - **feat:** add `filterMap` to namespace _(by Athan Reines)_
- [`6ff153f`](https://github.com/stdlib-js/stdlib/commit/6ff153f9023cffac527b3243489e6413e989e940) - **feat:** add `ndarray/filter-map` _(by Athan Reines)_
Expand Down
45 changes: 45 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ setReadOnly( ns, 'emptyLike', require( './../../base/empty-like' ) );
*/
setReadOnly( ns, 'expandDimensions', require( './../../base/expand-dimensions' ) );

/**
* @name fill
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/fill}
*/
setReadOnly( ns, 'fill', require( './../../base/fill' ) );

/**
* @name flag
* @memberof ns
Expand Down Expand Up @@ -391,6 +400,15 @@ setReadOnly( ns, 'ind2sub', require( './../../base/ind2sub' ) );
*/
setReadOnly( ns, 'iterationOrder', require( './../../base/iteration-order' ) );

/**
* @name map
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/map}
*/
setReadOnly( ns, 'map', require( './../../base/map' ) );

/**
* @name maxViewBufferIndex
* @memberof ns
Expand Down Expand Up @@ -427,6 +445,24 @@ setReadOnly( ns, 'maybeBroadcastArrays', require( './../../base/maybe-broadcast-
*/
setReadOnly( ns, 'metaDataProps', require( './../../base/meta-data-props' ) );

/**
* @name minSignedIntegerDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/min-signed-integer-dtype}
*/
setReadOnly( ns, 'minSignedIntegerDataType', require( './../../base/min-signed-integer-dtype' ) );

/**
* @name minUnsignedIntegerDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/min-unsigned-integer-dtype}
*/
setReadOnly( ns, 'minUnsignedIntegerDataType', require( './../../base/min-unsigned-integer-dtype' ) );

/**
* @name minViewBufferIndex
* @memberof ns
Expand Down Expand Up @@ -787,6 +823,15 @@ setReadOnly( ns, 'sub2ind', require( './../../base/sub2ind' ) );
*/
setReadOnly( ns, 'ndarray2array', require( './../../base/to-array' ) );

/**
* @name toReversed
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/to-reversed}
*/
setReadOnly( ns, 'toReversed', require( './../../base/to-reversed' ) );

/**
* @name transpose
* @memberof ns
Expand Down
132 changes: 132 additions & 0 deletions base/min-signed-integer-dtype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# Minimum Data Type

> Determine the minimum ndarray [data type][@stdlib/ndarray/dtypes] for storing a provided signed integer value.
<!-- 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 minSignedIntegerDataType = require( '@stdlib/ndarray/base/min-signed-integer-dtype' );
```

#### minSignedIntegerDataType( value )

Returns the minimum ndarray [data type][@stdlib/ndarray/dtypes] for storing a provided signed integer value.

```javascript
var dt = minSignedIntegerDataType( 9999 );
// returns 'int16'

dt = minSignedIntegerDataType( -3 );
// returns 'int8'

dt = minSignedIntegerDataType( 3 );
// returns 'int8'

dt = minSignedIntegerDataType( 1e100 );
// returns 'float64'
```

</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">

## Notes

- Once a provided integer value exceeds the maximum values of all supported signed integer [data types][@stdlib/ndarray/dtypes], the function defaults to returning `'float64'`.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var exp2 = require( '@stdlib/math/base/special/exp2' );
var minSignedIntegerDataType = require( '@stdlib/ndarray/base/min-signed-integer-dtype' );

// Generate random powers:
var exp = discreteUniform( 100, 0, 40, {
'dtype': 'generic'
});

// Determine the minimum data type for each generated value...
var v;
var i;
for ( i = 0; i < exp.length; i++ ) {
v = exp2( exp[ i ] );
console.log( 'min(%d) => %s', v, minSignedIntegerDataType( v ) );
}
```

</section>

<!-- /.examples -->

<!-- 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">

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes

</section>

<!-- /.links -->
64 changes: 64 additions & 0 deletions base/min-signed-integer-dtype/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var minSignedIntegerDataType = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var N;
var i;

values = [
0,
1,
-128,
128,
99999,
-99999,
1.0e100,
-1.0e100,
-1234567890,
1234567890
];
N = values.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = minSignedIntegerDataType( values[ i%N ] );
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( out ) ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
27 changes: 27 additions & 0 deletions base/min-signed-integer-dtype/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

{{alias}}( value )
Returns the minimum ndarray data type for storing a provided signed integer
value.

Parameters
----------
value: number
Signed integer value.

Returns
-------
dt: string
ndarray data type.

Examples
--------
> var dt = {{alias}}( 3 )
'int8'
> dt = {{alias}}( -3 )
'int8'
> dt = {{alias}}( 1280 )
'int16'

See Also
--------

Loading

0 comments on commit 5b1419d

Please sign in to comment.