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 31, 2023
1 parent d4e6efa commit e9a7d5c
Show file tree
Hide file tree
Showing 27 changed files with 366 additions and 62 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions dtypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ limitations under the License.
var dtypes = require( '@stdlib/array/dtypes' );
```

#### dtypes()
#### dtypes( \[kind] )

Returns a list of array data types.

Expand All @@ -49,7 +49,7 @@ var out = dtypes();
// e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
```

The output `array` contains the following data types:
When not provided a data type "kind", the function returns an array containing the following data types:

- `float32`: single-precision floating-point numbers.
- `float64`: double-precision floating-point numbers.
Expand All @@ -64,6 +64,25 @@ The output `array` contains the following data types:
- `uint8`: unsigned 8-bit integers.
- `uint8c`: unsigned clamped 8-bit integers.

To return the subset of data types belonging to a specified data type kind, provide a `kind` argument.

```javascript
var out = dtypes( 'floating_point' );
// returns [...]
```

The function supports the following data type kinds:

- `floating_point`: floating-point data types.
- `real_floating_point`: real-valued floating-point data types.
- `complex_floating_point`: complex-valued floating-point data types.
- `integer`: integer data types.
- `signed_integer`: signed integer data types.
- `unsigned_integer`: unsigned integer data types.
- `real`: real-valued data types.
- `numeric`: numeric data types.
- `all`: all data types.

</section>

<!-- /.usage -->
Expand All @@ -89,7 +108,6 @@ var indexOf = require( '@stdlib/utils/index-of' );
var dtypes = require( '@stdlib/array/dtypes' );

var DTYPES = dtypes();
var bool;

function isdtype( str ) {
if ( indexOf( DTYPES, str ) === -1 ) {
Expand All @@ -98,7 +116,7 @@ function isdtype( str ) {
return true;
}

bool = isdtype( 'float64' );
var bool = isdtype( 'float64' );
// returns true

bool = isdtype( 'int16' );
Expand Down
29 changes: 27 additions & 2 deletions dtypes/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,33 @@ bench( pkg, function benchmark( b ) {
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dtypes();
if ( out.length !== 10 ) {
b.fail( 'should return an array of length 10' );
if ( out.length === 0 ) {
b.fail( 'should return a non-empty array' );
}
}
b.toc();
if ( !isStringArray( out ) ) {
b.fail( 'should return an array of strings' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::kind', function benchmark( b ) {
var values;
var out;
var i;

values = [
'floating_point',
'integer'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dtypes( values[ i%values.length ] );
if ( out.length === 0 ) {
b.fail( 'should return a non-empty array' );
}
}
b.toc();
Expand Down
24 changes: 22 additions & 2 deletions dtypes/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

{{alias}}()
{{alias}}( [kind] )
Returns a list of array data types.

The output array contains the following data types:
When not provided a data type "kind", the function returns an array
containing the following data types:

- float32: single-precision floating-point numbers.
- float64: double-precision floating-point numbers.
Expand All @@ -17,6 +18,23 @@
- uint8: unsigned 8-bit integers.
- uint8c: unsigned clamped 8-bit integers.

The function supports the following data type "kinds":

- floating_point: floating-point data types.
- real_floating_point: real-valued floating-point data types.
- complex_floating_point: complex-valued floating-point data types.
- integer: integer data types.
- signed_integer: signed integer data types.
- unsigned_integer: unsigned integer data types.
- real: real-valued data types.
- numeric: numeric data types.
- all: all data types.

Parameters
----------
kind: string (optional)
Data type kind.

Returns
-------
out: Array<string>
Expand All @@ -26,6 +44,8 @@
--------
> var out = {{alias}}()
<Array>
> out = {{alias}}( 'floating_point' )
<Array>

See Also
--------
Expand Down
9 changes: 7 additions & 2 deletions dtypes/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@

/// <reference types="@stdlib/types"/>

import { DataType } from '@stdlib/types/array';
import { DataType, DataTypeKind } from '@stdlib/types/array';

/**
* Returns a list of array data types.
*
* @param kind - data type kind
* @returns list of array data types
*
* @example
* var list = dtypes();
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
*
* @example
* var list = dtypes( 'floating_point' );
* // returns [...]
*/
declare function dtypes(): Array<DataType>;
declare function dtypes( kind?: DataTypeKind ): Array<DataType>;


// EXPORTS //
Expand Down
6 changes: 3 additions & 3 deletions dtypes/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import dtypes = require( './index' );
// The function returns an array of data types...
{
dtypes(); // $ExpectType DataType[]
dtypes( 'floating_point' ); // $ExpectType DataType[]
}

// The compiler throws an error if the function is provided arguments...
// The compiler throws an error if the function is provided an unsupported number of arguments...
{
dtypes( 1 ); // $ExpectError
dtypes( 1, 2 ); // $ExpectError
dtypes( 'floating_point', 2 ); // $ExpectError
}
3 changes: 1 addition & 2 deletions dtypes/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var indexOf = require( '@stdlib/utils/index-of' );
var dtypes = require( './../lib' );

var DTYPES = dtypes();
var bool;

function isdtype( str ) {
if ( indexOf( DTYPES, str ) === -1 ) {
Expand All @@ -31,7 +30,7 @@ function isdtype( str ) {
return true;
}

bool = isdtype( 'float64' );
var bool = isdtype( 'float64' );
console.log( bool );
// => true

Expand Down
88 changes: 74 additions & 14 deletions dtypes/lib/dtypes.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
[
"float32",
"float64",
"generic",
"int16",
"int32",
"int8",
"uint16",
"uint32",
"uint8",
"uint8c",
"complex64",
"complex128"
]
{
"all": [
"complex64",
"complex128",
"float32",
"float64",
"generic",
"int16",
"int32",
"int8",
"uint16",
"uint32",
"uint8",
"uint8c"
],
"floating_point": [
"complex64",
"complex128",
"float32",
"float64"
],
"real_floating_point": [
"float32",
"float64"
],
"complex_floating_point": [
"complex64",
"complex128"
],
"integer": [
"int16",
"int32",
"int8",
"uint16",
"uint32",
"uint8",
"uint8c"
],
"signed_integer": [
"int16",
"int32",
"int8"
],
"unsigned_integer": [
"uint16",
"uint32",
"uint8",
"uint8c"
],
"real": [
"float32",
"float64",
"int16",
"int32",
"int8",
"uint16",
"uint32",
"uint8",
"uint8c"
],
"numeric": [
"complex64",
"complex128",
"float32",
"float64",
"int16",
"int32",
"int8",
"uint16",
"uint32",
"uint8",
"uint8c"
]
}
12 changes: 11 additions & 1 deletion dtypes/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ var DTYPES = require( './dtypes.json' );
/**
* Returns a list of array data types.
*
* @param {string} [kind] - data type kind
* @returns {StringArray} list of array data types
*
* @example
* var list = dtypes();
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
*
* @example
* var list = dtypes( 'floating_point' );
* // returns [...]
*/
function dtypes() {
return DTYPES.slice();
var out;
if ( arguments.length === 0 ) {
return DTYPES.all.slice();
}
out = DTYPES[ arguments[ 0 ] ];
return ( out ) ? out.slice() : [];
}


Expand Down
Loading

0 comments on commit e9a7d5c

Please sign in to comment.