diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index cd15304a..7f0967ac 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -53,7 +53,8 @@ jobs:
id: tests
run: |
npm test || npm test || npm test
- - uses: act10ns/slack@v1
+ - name: Send status to Slack channel in case of failure
+ uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml
index f5697d4b..35cffea9 100644
--- a/.github/workflows/test_coverage.yml
+++ b/.github/workflows/test_coverage.yml
@@ -51,14 +51,26 @@ jobs:
timeout-minutes: 15
- name: Upload coverage to Codecov
id: upload
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v2
with:
directory: reports/coverage
flags: unittests
fail_ci_if_error: true
+ - name: Extract coverage value and assign to output
+ id: extract-coverage
+ run: |
+ coverage=`cat reports/coverage/lcov-report/index.html | grep "fraction" | grep -oP '\d+/\d+' | printf %s "$(cat)" | jq -R -s -c 'split("\n")'`
+ echo "::set-output name=coverage::$coverage"
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()
+ - name: Send Webhook with status to stdlib backend
+ uses: distributhor/workflow-webhook@v2
+ env:
+ webhook_url: ${{ secrets.STDLIB_COVERAGE_URL }}
+ webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }}
+ data: '{ "coverage": ${{ steps.extract-coverage.outputs.coverage }}, "run_id": "${{ github.run_id }}" }'
+ if: ${{ false }}
diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml
index 0bb1900d..bbe93c1c 100644
--- a/.github/workflows/test_install.yml
+++ b/.github/workflows/test_install.yml
@@ -27,6 +27,7 @@ on:
workflow_run:
workflows: ["Publish Package"]
types: [completed]
+ workflow_dispatch:
# Workflow jobs:
jobs:
@@ -34,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- if: ${{ github.event.workflow_run.conclusion == 'success' }}
+ if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
@@ -45,7 +46,8 @@ jobs:
run: |
npm install --only=prod || npm install --only=prod || npm install --only=prod
timeout-minutes: 15
- - uses: act10ns/slack@v1
+ - name: Send notification to Slack in case of failure
+ uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
diff --git a/base/README.md b/base/README.md
index 64bbd89b..edc7b7ad 100644
--- a/base/README.md
+++ b/base/README.md
@@ -51,14 +51,22 @@ var o = ns;
- [`bufferDataType( buffer )`][@stdlib/ndarray/base/buffer-dtype]: return the data type of an ndarray data buffer.
- [`buffer( dtype, size )`][@stdlib/ndarray/base/buffer]: create a zero-filled contiguous linear ndarray data buffer.
- [`bytesPerElement( dtype )`][@stdlib/ndarray/base/bytes-per-element]: return the number of bytes per element provided an underlying array data type.
+- [`char2dtype( [ch] )`][@stdlib/ndarray/base/char2dtype]: return the data type string associated with a provided single letter character abbreviation.
- [`clampIndex( idx, max )`][@stdlib/ndarray/base/clamp-index]: restrict an index to the interval `[0,max]`.
- [`ndarray( dtype, buffer, shape, strides, offset, order )`][@stdlib/ndarray/base/ctor]: create a multidimensional array.
-- [`dtypeChar( dtype )`][@stdlib/ndarray/base/dtype-char]: return the single letter abbreviation for an underlying array data type.
+- [`dtypeChar( [dtype] )`][@stdlib/ndarray/base/dtype-char]: return the single letter abbreviation for an underlying array data type.
+- [`dtypeDesc( [dtype] )`][@stdlib/ndarray/base/dtype-desc]: return the description for a specified data type.
+- [`dtypeEnum2Str( dtype )`][@stdlib/ndarray/base/dtype-enum2str]: return the data type string associated with an ndarray data type enumeration constant.
+- [`dtypeResolveEnum( dtype )`][@stdlib/ndarray/base/dtype-resolve-enum]: return the enumeration constant associated with a supported ndarray data type value.
+- [`dtypeResolveStr( dtype )`][@stdlib/ndarray/base/dtype-resolve-str]: return the data type string associated with a supported ndarray data type value.
+- [`dtypeStr2Enum( dtype )`][@stdlib/ndarray/base/dtype-str2enum]: return the enumeration constant associated with an ndarray data type string.
+- [`dtype2c( dtype )`][@stdlib/ndarray/base/dtype2c]: return the C data type associated with a provided data type string.
- [`dtypes2signatures( dtypes, nin, nout )`][@stdlib/ndarray/base/dtypes2signatures]: transform a list of array argument data types into a list of signatures.
- [`ind( idx, max, mode )`][@stdlib/ndarray/base/ind]: return an index given an index mode.
- [`ind2sub( shape, strides, offset, order, idx, mode )`][@stdlib/ndarray/base/ind2sub]: convert a linear index to an array of subscripts.
- [`iterationOrder( strides )`][@stdlib/ndarray/base/iteration-order]: given a stride array, determine array iteration order.
- [`maxViewBufferIndex( shape, strides, offset )`][@stdlib/ndarray/base/max-view-buffer-index]: compute the maximum linear index in an underlying data buffer accessible to an array view.
+- [`metaDataProps( meta, dtypes, obj )`][@stdlib/ndarray/base/meta-data-props]: define non-enumerable read-only properties which expose ndarray function meta data.
- [`minViewBufferIndex( shape, strides, offset )`][@stdlib/ndarray/base/min-view-buffer-index]: compute the minimum linear index in an underlying data buffer accessible to an array view.
- [`minmaxViewBufferIndex( shape, strides, offset )`][@stdlib/ndarray/base/minmax-view-buffer-index]: compute the minimum and maximum linear indices in an underlying data buffer which are accessible to an array view.
- [`nonsingletonDimensions( shape )`][@stdlib/ndarray/base/nonsingleton-dimensions]: return the number of non-singleton dimensions.
@@ -144,12 +152,26 @@ console.log( objectKeys( ns ) );
[@stdlib/ndarray/base/bytes-per-element]: https://github.com/stdlib-js/ndarray/tree/main/base/bytes-per-element
+[@stdlib/ndarray/base/char2dtype]: https://github.com/stdlib-js/ndarray/tree/main/base/char2dtype
+
[@stdlib/ndarray/base/clamp-index]: https://github.com/stdlib-js/ndarray/tree/main/base/clamp-index
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
[@stdlib/ndarray/base/dtype-char]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-char
+[@stdlib/ndarray/base/dtype-desc]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-desc
+
+[@stdlib/ndarray/base/dtype-enum2str]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-enum2str
+
+[@stdlib/ndarray/base/dtype-resolve-enum]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-resolve-enum
+
+[@stdlib/ndarray/base/dtype-resolve-str]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-resolve-str
+
+[@stdlib/ndarray/base/dtype-str2enum]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype-str2enum
+
+[@stdlib/ndarray/base/dtype2c]: https://github.com/stdlib-js/ndarray/tree/main/base/dtype2c
+
[@stdlib/ndarray/base/dtypes2signatures]: https://github.com/stdlib-js/ndarray/tree/main/base/dtypes2signatures
[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray/tree/main/base/ind
@@ -160,6 +182,8 @@ console.log( objectKeys( ns ) );
[@stdlib/ndarray/base/max-view-buffer-index]: https://github.com/stdlib-js/ndarray/tree/main/base/max-view-buffer-index
+[@stdlib/ndarray/base/meta-data-props]: https://github.com/stdlib-js/ndarray/tree/main/base/meta-data-props
+
[@stdlib/ndarray/base/min-view-buffer-index]: https://github.com/stdlib-js/ndarray/tree/main/base/min-view-buffer-index
[@stdlib/ndarray/base/minmax-view-buffer-index]: https://github.com/stdlib-js/ndarray/tree/main/base/minmax-view-buffer-index
diff --git a/base/dtype-char/README.md b/base/dtype-char/README.md
index 3d976a70..4644b637 100644
--- a/base/dtype-char/README.md
+++ b/base/dtype-char/README.md
@@ -59,7 +59,7 @@ var ch = dtypeChar( 'foobar' );
// returns null
```
-If not provided a [data type][@stdlib/ndarray/dtypes] string, the function returns an object mapping [data type][@stdlib/ndarray/dtypes] strings to single letter character abbreviations.
+If not provided a [data type][@stdlib/ndarray/dtypes] value, the function returns an object mapping [data type][@stdlib/ndarray/dtypes] strings to single letter character abbreviations.
```javascript
var obj = dtypeChar();
diff --git a/base/dtype-char/docs/repl.txt b/base/dtype-char/docs/repl.txt
index dcff2901..add82a3f 100644
--- a/base/dtype-char/docs/repl.txt
+++ b/base/dtype-char/docs/repl.txt
@@ -3,15 +3,15 @@
Returns the single letter character abbreviation for a specified underlying
array data type.
- If not provided a string data type, the function returns an object mapping
+ If not provided a data type value, the function returns an object mapping
data type strings to single letter character abbreviations.
If provided an unknown/unsupported data type, the function returns `null`.
Parameters
----------
- dtype: string (optional)
- Data type.
+ dtype: any (optional)
+ Data type value.
Returns
-------
diff --git a/base/dtype-char/docs/types/index.d.ts b/base/dtype-char/docs/types/index.d.ts
index dbb6ba14..15e90c3e 100644
--- a/base/dtype-char/docs/types/index.d.ts
+++ b/base/dtype-char/docs/types/index.d.ts
@@ -29,7 +29,7 @@ interface Table {
/**
* Returns the single letter character abbreviation for an underlying array data type.
*
-* @param dtype - data type
+* @param dtype - data type value
* @returns single letter character abbreviation
*
* @example
@@ -39,7 +39,7 @@ interface Table {
* ch = dtypeChar( 'generic' );
* // returns 'o'
*/
-declare function dtypeChar( dtype: string ): string | null;
+declare function dtypeChar( dtype: any ): string | null;
/**
* Returns an object mapping data type strings to single letter character abbreviations.
diff --git a/base/dtype-char/docs/types/test.ts b/base/dtype-char/docs/types/test.ts
index 9a494914..0434bd99 100644
--- a/base/dtype-char/docs/types/test.ts
+++ b/base/dtype-char/docs/types/test.ts
@@ -31,15 +31,3 @@ import dtypeChar = require( './index' );
dtypeChar( 'float64' ); // $ExpectType string | null
dtypeChar( 'generic' ); // $ExpectType string | null
}
-
-// The function does not compile if provided a value other than a string...
-{
- dtypeChar( true ); // $ExpectError
- dtypeChar( false ); // $ExpectError
- dtypeChar( null ); // $ExpectError
- dtypeChar( undefined ); // $ExpectError
- dtypeChar( 5 ); // $ExpectError
- dtypeChar( [] ); // $ExpectError
- dtypeChar( {} ); // $ExpectError
- dtypeChar( ( x: number ): number => x ); // $ExpectError
-}
diff --git a/base/dtype-char/lib/main.js b/base/dtype-char/lib/main.js
index 894cea53..da31e5ce 100644
--- a/base/dtype-char/lib/main.js
+++ b/base/dtype-char/lib/main.js
@@ -20,6 +20,7 @@
// MODULES //
+var resolve = require( './../../../base/dtype-resolve-str' );
var table = require( './table.js' );
@@ -33,7 +34,7 @@ var TABLE;
/**
* Returns the single letter character abbreviation for an underlying array data type.
*
-* @param {string} [dtype] - data type
+* @param {*} [dtype] - data type value
* @returns {(Object|string|null)} single letter character abbreviation(s)
*
* @example
@@ -54,7 +55,7 @@ function dtypeChar( dtype ) {
if ( TABLE === void 0 ) {
TABLE = table();
}
- return TABLE[ dtype ] || null;
+ return TABLE[ resolve( dtype ) ] || null;
}
diff --git a/base/dtype-desc/README.md b/base/dtype-desc/README.md
index e3d3d611..59e41a16 100644
--- a/base/dtype-desc/README.md
+++ b/base/dtype-desc/README.md
@@ -59,7 +59,7 @@ var desc = dtypeDesc( 'foobar' );
// returns null
```
-If not provided a [data type][@stdlib/ndarray/dtypes] string, the function returns an object mapping [data type][@stdlib/ndarray/dtypes] strings to descriptions.
+If not provided a [data type][@stdlib/ndarray/dtypes] value, the function returns an object mapping [data type][@stdlib/ndarray/dtypes] strings to descriptions.
```javascript
var obj = dtypeDesc();
diff --git a/base/dtype-desc/docs/repl.txt b/base/dtype-desc/docs/repl.txt
index 29bb4316..953ccdeb 100644
--- a/base/dtype-desc/docs/repl.txt
+++ b/base/dtype-desc/docs/repl.txt
@@ -2,15 +2,15 @@
{{alias}}( [dtype] )
Returns the description for a specified data type.
- If not provided a string data type, the function returns an object mapping
+ If not provided a data type value, the function returns an object mapping
data type strings to descriptions.
If provided an unknown/unsupported data type, the function returns `null`.
Parameters
----------
- dtype: string (optional)
- Data type.
+ dtype: any (optional)
+ Data type value.
Returns
-------
diff --git a/base/dtype-desc/docs/types/index.d.ts b/base/dtype-desc/docs/types/index.d.ts
index e4e44620..72ecdd90 100644
--- a/base/dtype-desc/docs/types/index.d.ts
+++ b/base/dtype-desc/docs/types/index.d.ts
@@ -29,7 +29,7 @@ interface Table {
/**
* Returns the description for a provided data type.
*
-* @param dtype - data type
+* @param dtype - data type value
* @returns data type description
*
* @example
@@ -39,7 +39,7 @@ interface Table {
* desc = dtypeDesc( 'generic' );
* // returns '...'
*/
-declare function dtypeDesc( dtype: string ): string | null;
+declare function dtypeDesc( dtype: any ): string | null;
/**
* Returns an object mapping data type strings to descriptions.
diff --git a/base/dtype-desc/docs/types/test.ts b/base/dtype-desc/docs/types/test.ts
index eebfa7ae..d83183ed 100644
--- a/base/dtype-desc/docs/types/test.ts
+++ b/base/dtype-desc/docs/types/test.ts
@@ -31,15 +31,3 @@ import dtypeDesc = require( './index' );
dtypeDesc( 'float64' ); // $ExpectType string | null
dtypeDesc( 'generic' ); // $ExpectType string | null
}
-
-// The function does not compile if provided a value other than a string...
-{
- dtypeDesc( true ); // $ExpectError
- dtypeDesc( false ); // $ExpectError
- dtypeDesc( null ); // $ExpectError
- dtypeDesc( undefined ); // $ExpectError
- dtypeDesc( 5 ); // $ExpectError
- dtypeDesc( [] ); // $ExpectError
- dtypeDesc( {} ); // $ExpectError
- dtypeDesc( ( x: number ): number => x ); // $ExpectError
-}
diff --git a/base/dtype-desc/lib/main.js b/base/dtype-desc/lib/main.js
index 1c881fe4..d755c6d6 100644
--- a/base/dtype-desc/lib/main.js
+++ b/base/dtype-desc/lib/main.js
@@ -20,6 +20,7 @@
// MODULES //
+var resolve = require( './../../../base/dtype-resolve-str' );
var table = require( './table.js' );
@@ -54,7 +55,7 @@ function dtypeDesc( dtype ) {
if ( TABLE === void 0 ) {
TABLE = table();
}
- return TABLE[ dtype ] || null;
+ return TABLE[ resolve( dtype ) ] || null;
}
diff --git a/base/dtype-resolve-str/lib/main.js b/base/dtype-resolve-str/lib/main.js
index 13ef05cf..14c2c509 100644
--- a/base/dtype-resolve-str/lib/main.js
+++ b/base/dtype-resolve-str/lib/main.js
@@ -41,7 +41,7 @@ var str2enum = require( './../../../base/dtype-str2enum' );
function resolve( dtype ) {
var t = ( typeof dtype );
if ( t === 'string' ) {
- return ( str2enum( dtype ) ) ? dtype : null;
+ return ( str2enum( dtype ) === null ) ? null : dtype;
}
if ( t === 'number' ) {
return enum2str( dtype );
diff --git a/base/dtype2c/README.md b/base/dtype2c/README.md
index 3054ff73..22387fe9 100644
--- a/base/dtype2c/README.md
+++ b/base/dtype2c/README.md
@@ -20,7 +20,7 @@ limitations under the License.
# dtype2c
-> Return the C data type associated with a provided [data type][@stdlib/ndarray/dtypes] string.
+> Return the C data type associated with a provided [data type][@stdlib/ndarray/dtypes] value.
@@ -42,7 +42,7 @@ var dtype2c = require( '@stdlib/ndarray/base/dtype2c' );
#### dtype2c( dtype )
-Returns the C data type associated with a provided [data type][@stdlib/ndarray/dtypes] string.
+Returns the C data type associated with a provided [data type][@stdlib/ndarray/dtypes] value.
```javascript
var out = dtype2c( 'float64' );
diff --git a/base/dtype2c/docs/repl.txt b/base/dtype2c/docs/repl.txt
index 9b012fce..79e7f606 100644
--- a/base/dtype2c/docs/repl.txt
+++ b/base/dtype2c/docs/repl.txt
@@ -1,13 +1,13 @@
{{alias}}( dtype )
- Returns the C data type associated with a provided data type string.
+ Returns the C data type associated with a provided data type value.
If provided an unknown/unsupported data type, the function returns `null`.
Parameters
----------
- dtype: string
- Data type.
+ dtype: any
+ Data type value.
Returns
-------
diff --git a/base/dtype2c/docs/types/index.d.ts b/base/dtype2c/docs/types/index.d.ts
index 1e5f8c48..ca128396 100644
--- a/base/dtype2c/docs/types/index.d.ts
+++ b/base/dtype2c/docs/types/index.d.ts
@@ -19,9 +19,9 @@
// TypeScript Version: 2.0
/**
-* Returns the C data type associated with a provided data type string.
+* Returns the C data type associated with a provided data type value.
*
-* @param dtype - data type
+* @param dtype - data type value
* @returns C data type (or null)
*
* @example
@@ -31,7 +31,7 @@
* out = dtype2c( 'generic' );
* // returns null
*/
-declare function dtype2c( dtype: string ): string | null;
+declare function dtype2c( dtype: any ): string | null;
// EXPORTS //
diff --git a/base/dtype2c/docs/types/test.ts b/base/dtype2c/docs/types/test.ts
index 3b69d690..a40f09f3 100644
--- a/base/dtype2c/docs/types/test.ts
+++ b/base/dtype2c/docs/types/test.ts
@@ -27,18 +27,6 @@ import dtype2c = require( './index' );
dtype2c( 'generic' ); // $ExpectType string | null
}
-// The function does not compile if provided a value other than a string...
-{
- dtype2c( true ); // $ExpectError
- dtype2c( false ); // $ExpectError
- dtype2c( null ); // $ExpectError
- dtype2c( undefined ); // $ExpectError
- dtype2c( 5 ); // $ExpectError
- dtype2c( [] ); // $ExpectError
- dtype2c( {} ); // $ExpectError
- dtype2c( ( x: number ): number => x ); // $ExpectError
-}
-
// The function does not compile if provided insufficient arguments...
{
dtype2c(); // $ExpectError
diff --git a/base/dtype2c/lib/index.js b/base/dtype2c/lib/index.js
index cdd74442..3162ac30 100644
--- a/base/dtype2c/lib/index.js
+++ b/base/dtype2c/lib/index.js
@@ -19,7 +19,7 @@
'use strict';
/**
-* Return the C data type associated with a provided data type string.
+* Return the C data type associated with a provided data type value.
*
* @module @stdlib/ndarray/base/dtype2c
*
diff --git a/base/dtype2c/lib/main.js b/base/dtype2c/lib/main.js
index 70630591..9cd41ddd 100644
--- a/base/dtype2c/lib/main.js
+++ b/base/dtype2c/lib/main.js
@@ -20,6 +20,7 @@
// MODULES //
+var resolve = require( './../../../base/dtype-resolve-str' );
var TABLE = require( './table.json' );
@@ -28,7 +29,7 @@ var TABLE = require( './table.json' );
/**
* Returns the C data type associated with a provided data type string.
*
-* @param {string} dtype - data type
+* @param {*} dtype - data type value
* @returns {(string|null)} C data type
*
* @example
@@ -39,7 +40,7 @@ var TABLE = require( './table.json' );
* // returns null
*/
function dtype2c( dtype ) {
- return TABLE[ dtype ] || null;
+ return TABLE[ resolve( dtype ) ] || null;
}
diff --git a/base/dtype2c/package.json b/base/dtype2c/package.json
index 1d17f555..d6602620 100644
--- a/base/dtype2c/package.json
+++ b/base/dtype2c/package.json
@@ -1,7 +1,7 @@
{
"name": "@stdlib/ndarray/base/dtype2c",
"version": "0.0.0",
- "description": "Return the C data type associated with a provided data type string.",
+ "description": "Return the C data type associated with a provided data type value.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
diff --git a/base/dtypes2signatures/lib/main.js b/base/dtypes2signatures/lib/main.js
index 0959982b..50d17992 100644
--- a/base/dtypes2signatures/lib/main.js
+++ b/base/dtypes2signatures/lib/main.js
@@ -22,8 +22,7 @@
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
-var resolve = require( './../../../base/dtype-resolve-enum' );
-var enum2str = require( './../../../base/dtype-enum2str' );
+var resolve = require( './../../../base/dtype-resolve-str' );
// MAIN //
@@ -107,7 +106,7 @@ function dtypes2signatures( dtypes, nin, nout ) {
}
}
for ( i = 0; i < len; i++ ) {
- dt = enum2str( resolve( dtypes[ i ] ) );
+ dt = resolve( dtypes[ i ] );
if ( dt === null ) {
dt = dtypes[ i ];
}
diff --git a/base/max-view-buffer-index/lib/main.js b/base/max-view-buffer-index/lib/main.js
index bf666b11..a9f94aab 100644
--- a/base/max-view-buffer-index/lib/main.js
+++ b/base/max-view-buffer-index/lib/main.js
@@ -68,8 +68,11 @@ function maxViewBufferIndex( shape, strides, offset ) {
ndims = shape.length;
idx = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] === 0 ) {
+ return offset;
+ }
if ( strides[ i ] > 0 ) {
- idx += strides[ i ] * (shape[ i ] - 1);
+ idx += strides[ i ] * ( shape[ i ] - 1 );
}
}
return idx;
diff --git a/base/max-view-buffer-index/src/main.c b/base/max-view-buffer-index/src/main.c
index 9bb2a60d..30447423 100644
--- a/base/max-view-buffer-index/src/main.c
+++ b/base/max-view-buffer-index/src/main.c
@@ -46,8 +46,11 @@ int64_t stdlib_ndarray_max_view_buffer_index( int64_t ndims, int64_t *shape, int
idx = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] == 0 ) {
+ return offset;
+ }
if ( strides[ i ] > 0 ) {
- idx += strides[ i ] * (shape[ i ] - 1);
+ idx += strides[ i ] * ( shape[ i ] - 1 );
}
}
return idx;
diff --git a/base/max-view-buffer-index/test/test.js b/base/max-view-buffer-index/test/test.js
index d1a9d2bb..ce1833dc 100644
--- a/base/max-view-buffer-index/test/test.js
+++ b/base/max-view-buffer-index/test/test.js
@@ -126,3 +126,30 @@ tape( 'the function computes the maximum linear index in an underlying array buf
t.end();
});
+
+tape( 'the function returns the provided offset when one or more dimensions is zero', function test( t ) {
+ var strides;
+ var offset;
+ var shape;
+ var idx;
+
+ shape = [ 3, 0 ];
+ strides = [ 2, 1 ];
+ offset = 10;
+ idx = maxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 10, 'returns expected value' );
+
+ shape = [ 0, 2 ];
+ strides = [ -2, 1 ];
+ offset = 14;
+ idx = maxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 14, 'returns expected value' );
+
+ shape = [ 0, 0 ];
+ strides = [ 2, -1 ];
+ offset = 11;
+ idx = maxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 11, 'returns expected value' );
+
+ t.end();
+});
diff --git a/base/min-view-buffer-index/lib/main.js b/base/min-view-buffer-index/lib/main.js
index 9db1a7b3..5841b235 100644
--- a/base/min-view-buffer-index/lib/main.js
+++ b/base/min-view-buffer-index/lib/main.js
@@ -68,8 +68,11 @@ function minViewBufferIndex( shape, strides, offset ) {
ndims = shape.length;
idx = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] === 0 ) {
+ return offset;
+ }
if ( strides[ i ] < 0 ) {
- idx += strides[ i ] * (shape[ i ] - 1); // decrements the index
+ idx += strides[ i ] * ( shape[ i ] - 1 ); // decrements the index
}
}
return idx;
diff --git a/base/min-view-buffer-index/src/main.c b/base/min-view-buffer-index/src/main.c
index 8040d20f..003b8a25 100644
--- a/base/min-view-buffer-index/src/main.c
+++ b/base/min-view-buffer-index/src/main.c
@@ -46,8 +46,11 @@ int64_t stdlib_ndarray_min_view_buffer_index( int64_t ndims, int64_t *shape, int
idx = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] == 0 ) {
+ return offset;
+ }
if ( strides[ i ] < 0 ) {
- idx += strides[ i ] * (shape[ i ] - 1); // decrements the index
+ idx += strides[ i ] * ( shape[ i ] - 1 ); // decrements the index
}
}
return idx;
diff --git a/base/min-view-buffer-index/test/test.js b/base/min-view-buffer-index/test/test.js
index f59b8968..449263f1 100644
--- a/base/min-view-buffer-index/test/test.js
+++ b/base/min-view-buffer-index/test/test.js
@@ -126,3 +126,30 @@ tape( 'the function computes the minimum linear index in an underlying array buf
t.end();
});
+
+tape( 'the function returns the provided offset when one or more dimensions is zero', function test( t ) {
+ var strides;
+ var offset;
+ var shape;
+ var idx;
+
+ shape = [ 3, 0 ];
+ strides = [ 2, 1 ];
+ offset = 10;
+ idx = minViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 10, 'returns expected value' );
+
+ shape = [ 0, 2 ];
+ strides = [ -2, 1 ];
+ offset = 14;
+ idx = minViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 14, 'returns expected value' );
+
+ shape = [ 0, 0 ];
+ strides = [ 2, -1 ];
+ offset = 11;
+ idx = minViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx, 11, 'returns expected value' );
+
+ t.end();
+});
diff --git a/base/minmax-view-buffer-index/lib/assign.js b/base/minmax-view-buffer-index/lib/assign.js
index 77dd5f44..6a3179a3 100644
--- a/base/minmax-view-buffer-index/lib/assign.js
+++ b/base/minmax-view-buffer-index/lib/assign.js
@@ -88,6 +88,11 @@ function minmaxViewBufferIndex( shape, strides, offset, out ) {
min = offset;
max = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] === 0 ) {
+ out[ 0 ] = offset;
+ out[ 1 ] = offset;
+ return out;
+ }
s = strides[ i ];
if ( s > 0 ) {
max += s * ( shape[i]-1 );
diff --git a/base/minmax-view-buffer-index/lib/main.js b/base/minmax-view-buffer-index/lib/main.js
index 24600dd7..457cef1b 100644
--- a/base/minmax-view-buffer-index/lib/main.js
+++ b/base/minmax-view-buffer-index/lib/main.js
@@ -71,6 +71,9 @@ function minmaxViewBufferIndex( shape, strides, offset ) {
min = offset;
max = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] === 0 ) {
+ return [ offset, offset ];
+ }
s = strides[ i ];
if ( s > 0 ) {
max += s * ( shape[i]-1 );
diff --git a/base/minmax-view-buffer-index/src/main.c b/base/minmax-view-buffer-index/src/main.c
index 72daa251..ed95676c 100644
--- a/base/minmax-view-buffer-index/src/main.c
+++ b/base/minmax-view-buffer-index/src/main.c
@@ -56,6 +56,11 @@ int8_t stdlib_ndarray_minmax_view_buffer_index( int64_t ndims, int64_t *shape, i
min = offset;
max = offset;
for ( i = 0; i < ndims; i++ ) {
+ if ( shape[ i ] == 0 ) {
+ out[ 0 ] = offset;
+ out[ 1 ] = offset;
+ return 0;
+ }
s = strides[ i ];
if ( s > 0 ) {
max += s * ( shape[i]-1 );
diff --git a/base/minmax-view-buffer-index/test/test.js b/base/minmax-view-buffer-index/test/test.js
index 982d34d0..55d873e0 100644
--- a/base/minmax-view-buffer-index/test/test.js
+++ b/base/minmax-view-buffer-index/test/test.js
@@ -152,6 +152,36 @@ tape( 'the function computes the minimum and maximum linear indices in an underl
t.end();
});
+tape( 'the function returns the provided offset when one or more dimensions is zero', function test( t ) {
+ var strides;
+ var offset;
+ var shape;
+ var idx;
+
+ shape = [ 3, 0 ];
+ strides = [ 2, 1 ];
+ offset = 10;
+ idx = minmaxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx[ 0 ], 10, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 10, 'returns expected value' );
+
+ shape = [ 0, 2 ];
+ strides = [ -2, 1 ];
+ offset = 14;
+ idx = minmaxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx[ 0 ], 14, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 14, 'returns expected value' );
+
+ shape = [ 0, 0 ];
+ strides = [ 2, -1 ];
+ offset = 11;
+ idx = minmaxViewBufferIndex( shape, strides, offset );
+ t.strictEqual( idx[ 0 ], 11, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 11, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'attached to the main function is a method which supports providing an output object', function test( t ) {
var strides;
var offset;
@@ -247,6 +277,45 @@ tape( 'attached to the main function is a method which supports providing an out
t.end();
});
+tape( 'the function returns the provided offset when one or more dimensions is zero (assign)', function test( t ) {
+ var strides;
+ var offset;
+ var shape;
+ var idx;
+ var out;
+
+ out = [ 0, 0 ];
+ shape = [ 3, 0 ];
+ strides = [ 2, 1 ];
+ offset = 10;
+ idx = minmaxViewBufferIndex.assign( shape, strides, offset, out );
+ t.strictEqual( idx, out, 'returns expected value' );
+ t.strictEqual( idx[ 0 ], 10, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 10, 'returns expected value' );
+
+ out = [ 0, 0 ];
+ shape = [ 3, 0 ];
+ shape = [ 0, 2 ];
+ strides = [ -2, 1 ];
+ offset = 14;
+ idx = minmaxViewBufferIndex.assign( shape, strides, offset, out );
+ t.strictEqual( idx, out, 'returns expected value' );
+ t.strictEqual( idx[ 0 ], 14, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 14, 'returns expected value' );
+
+ out = [ 0, 0 ];
+ shape = [ 3, 0 ];
+ shape = [ 0, 0 ];
+ strides = [ 2, -1 ];
+ offset = 11;
+ idx = minmaxViewBufferIndex.assign( shape, strides, offset, out );
+ t.strictEqual( idx, out, 'returns expected value' );
+ t.strictEqual( idx[ 0 ], 11, 'returns expected value' );
+ t.strictEqual( idx[ 1 ], 11, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function computes the minimum and maximum linear indices in an underlying array buffer which are accessible to an array view (shape[k]=1)', function test( t ) {
var strides;
var offset;
diff --git a/dtypes/docs/types/tsconfig.json b/dtypes/docs/types/tsconfig.json
new file mode 100644
index 00000000..a541d610
--- /dev/null
+++ b/dtypes/docs/types/tsconfig.json
@@ -0,0 +1,39 @@
+{
+ "compilerOptions": {
+ "allowSyntheticDefaultImports": false,
+ "allowUnreachableCode": false,
+ "allowUnusedLabels": false,
+ "alwaysStrict": true,
+ "baseUrl": ".",
+ "charset": "utf8",
+ "forceConsistentCasingInFileNames": true,
+ "keyofStringsOnly": false,
+ "lib": [
+ "es6"
+ ],
+ "locale": "en",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "newLine": "lf",
+ "noEmit": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": false,
+ "noImplicitThis": true,
+ "noStrictGenericChecks": false,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "paths": {},
+ "pretty": true,
+ "strictBindCallApply": true,
+ "strictFunctionTypes": true,
+ "strictNullChecks": true,
+ "suppressExcessPropertyErrors": false,
+ "suppressImplicitAnyIndexErrors": false,
+ "typeRoots": [ "." ],
+ "types": []
+ },
+ "exclude": [
+ "node_modules"
+ ]
+}
diff --git a/dtypes/docs/types/tslint.json b/dtypes/docs/types/tslint.json
new file mode 100644
index 00000000..a0c360d8
--- /dev/null
+++ b/dtypes/docs/types/tslint.json
@@ -0,0 +1,252 @@
+{
+ "extends": "dtslint/dtslint.json",
+ "rules": {
+ "expect": true,
+ "export-just-namespace": true,
+ "no-any-union": true,
+ "no-bad-reference": true,
+ "no-const-enum": true,
+ "no-dead-reference": true,
+ "no-declare-current-package": true,
+ "no-import-default-of-export-equals": true,
+ "no-outside-dependencies": true,
+ "no-padding": true,
+ "no-redundant-undefined": true,
+ "no-relative-import-in-test": false,
+ "no-self-import": true,
+ "no-single-declare-module": true,
+ "no-single-element-tuple-type": true,
+ "no-unnecessary-generics": true,
+ "no-useless-files": true,
+ "prefer-declare-function": true,
+ "strict-export-declare-modifiers": true,
+ "trim-file": true,
+ "unified-signatures": true,
+ "void-return": true,
+
+ "adjacent-overload-signatures": true,
+ "ban-ts-ignore": false,
+ "ban-types": false,
+ "member-access": [ true, "no-public" ],
+ "member-ordering": [ true, "fields-first" ],
+ "no-any": false,
+ "no-empty-interface": true,
+ "no-import-side-effect": true,
+ "no-inferrable-types": true,
+ "no-internal-module": true,
+ "no-magic-numbers": false,
+ "no-namespace": true,
+ "no-non-null-assertion": true,
+ "no-parameter-reassignment": false,
+ "no-reference": true,
+ "no-unnecessary-type-assertion": true,
+ "no-var-requires": true,
+ "only-arrow-functions": false,
+ "prefer-for-of": false,
+ "promise-function-async": false,
+ "typedef": true,
+ "typedef-whitespace": [ true,
+ {
+ "call-signature": "nospace",
+ "index-signature": "nospace",
+ "parameter": "nospace",
+ "property-declaration": "nospace",
+ "variable-declaration": "nospace"
+ },
+ {
+ "call-signature": "onespace",
+ "index-signature": "onespace",
+ "parameter": "onespace",
+ "property-declaration": "onespace",
+ "variable-declaration": "onespace"
+ }
+ ],
+ "unified-signatures": true,
+
+ "await-promise": true,
+ "ban-comma-operator": true,
+ "ban": [ true,
+ {
+ "name": [ "*", "forEach" ],
+ "message": "Use a regular `for` loop instead."
+ }
+ ],
+ "curly": true,
+ "forin": true,
+ "function-constructor": true,
+ "import-blacklist": [ true, "lodash" ],
+ "label-position": true,
+ "no-arg": true,
+ "no-bitwise": false,
+ "no-conditional-assignment": true,
+ "no-console": true,
+ "no-construct": true,
+ "no-debugger": true,
+ "no-duplicate-super": true,
+ "no-duplicate-switch-case": true,
+ "no-duplicate-variable": [ true, "check-parameters" ],
+ "no-dynamic-delete": false,
+ "no-empty": true,
+ "no-eval": true,
+ "no-floating-promises": true,
+ "no-for-in-array": true,
+ "no-implicit-dependencies": false,
+ "no-inferred-empty-object-type": true,
+ "no-invalid-template-strings": true,
+ "no-invalid-this": true,
+ "no-misused-new": true,
+ "no-null-keyword": false,
+ "no-object-literal-type-assertion": true,
+ "no-return-await": true,
+ "no-shadowed-variable": false,
+ "no-sparse-arrays": true,
+ "no-string-literal": false,
+ "no-string-throw": true,
+ "no-submodule-imports": false,
+ "no-switch-case-fall-through": true,
+ "no-this-assignment": [ true,
+ {
+ "allowed-names": [ "^self$" ],
+ "allow-destructuring": true
+ }
+ ],
+ "no-unbound-method": [ true, "ignore-static" ],
+ "no-unnecessary-class": true,
+ "no-unsafe-any": true,
+ "no-unsafe-finally": true,
+ "no-unused-expression": true,
+ "no-use-before-declare": true,
+ "no-var-keyword": true,
+ "no-void-expression": true,
+ "prefer-conditional-expression": false,
+ "prefer-object-spread": false,
+ "radix": true,
+ "restrict-plus-operands": true,
+ "strict-boolean-expressions": false,
+ "strict-type-predicates": true,
+ "switch-default": true,
+ "triple-equals": true,
+ "unnecessary-constructor": true,
+ "use-default-type-parameter": true,
+ "use-isnan": true,
+
+ "cyclomatic-complexity": false,
+ "deprecation": true,
+ "eofline": true,
+ "indent": [ true, "tabs", 4 ],
+ "linebreak-style": [ true, "LF" ],
+ "max-classes-per-file": [ true, 1 ],
+ "max-file-line-count": [ true, 1000 ],
+ "max-line-length": [ true,
+ {
+ "limit": 80,
+ "ignore-pattern": "^import |\\/\\/ |\\/?\\* "
+ }
+ ],
+ "no-default-export": false,
+ "no-default-import": false,
+ "no-duplicate-imports": true,
+ "no-mergeable-namespace": true,
+ "no-require-imports": false,
+ "object-literal-sort-keys": false,
+ "prefer-const": true,
+ "prefer-readonly": true,
+ "trailing-comma": [ false,
+ {
+ "esSpecCompliant": true
+ }
+ ],
+
+ "align": false,
+ "array-type": [ true, "generic" ],
+ "arrow-parens": true,
+ "arrow-return-shorthand": true,
+ "binary-expression-operand-order": true,
+ "callable-types": true,
+ "class-name": true,
+ "comment-format": [ true, "check-space" ],
+ "comment-type": false,
+ "completed-docs": true,
+ "encoding": true,
+ "file-header": false,
+ "file-name-casing": [ true, "snake-case" ],
+ "import-spacing": true,
+ "increment-decrement": true,
+ "interface-name": [ true, "never-prefix" ],
+ "interface-over-type-literal": true,
+ "jsdoc-format": false,
+ "match-default-export-name": false,
+ "newline-before-return": false,
+ "newline-per-chained-call": false,
+ "new-parens": true,
+ "no-angle-bracket-type-assertion": true,
+ "no-boolean-literal-compare": false,
+ "no-consecutive-blank-lines": [ true, 2 ],
+ "no-irregular-whitespace": true,
+ "no-parameter-properties": true,
+ "no-redundant-jsdoc": true,
+ "no-reference-import": true,
+ "no-trailing-whitespace": true,
+ "no-unnecessary-callback-wrapper": true,
+ "no-unnecessary-initializer": true,
+ "no-unnecessary-qualifier": true,
+ "number-literal-format": false,
+ "object-literal-key-quotes": [ true, "always" ],
+ "object-literal-shorthand": [ true, "never" ],
+ "one-line": [ true,
+ "check-catch",
+ "check-finally",
+ "check-else",
+ "check-open-brace",
+ "check-whitespace"
+ ],
+ "one-variable-per-declaration": true,
+ "ordered-imports": [ true,
+ {
+ "grouped-imports": false,
+ "import-sources-order": "any",
+ "named-imports-order": "any",
+ "module-source-path": "full"
+ }
+ ],
+ "prefer-function-over-method": [ true, "allow-public", "allow-protected" ],
+ "prefer-method-signature": true,
+ "prefer-switch": [ true,
+ {
+ "min-cases": 5
+ }
+ ],
+ "prefer-template": false,
+ "prefer-while": true,
+ "quotemark": [ true, "single", "avoid-escape", "avoid-template" ],
+ "return-undefined": false,
+ "semicolon": [ true, "always" ],
+ "space-before-function-paren": [ true,
+ {
+ "anonymous": "always",
+ "named": "never",
+ "asyncArrow": "always",
+ "method": "never",
+ "constructor": "never"
+ }
+ ],
+ "space-within-parens": [ true, 1 ],
+ "switch-final-break": [ true, "always" ],
+ "type-literal-delimiter": [ true,
+ {
+ "singleLine": "always"
+ }
+ ],
+ "unnecessary-bind": true,
+ "variable-name": [ true, "ban-keywords", "check-format" ],
+ "whitespace": [ true,
+ "check-branch",
+ "check-decl",
+ "check-operator",
+ "check-rest-spread",
+ "check-separator",
+ "check-type",
+ "check-preblock"
+ ]
+ }
+}
diff --git a/next-dtype/docs/repl.txt b/next-dtype/docs/repl.txt
index 653d770b..79a7d192 100644
--- a/next-dtype/docs/repl.txt
+++ b/next-dtype/docs/repl.txt
@@ -11,8 +11,8 @@
Parameters
----------
- dtype: string (optional)
- ndarray data type.
+ dtype: any (optional)
+ ndarray data type value.
Returns
-------
diff --git a/next-dtype/docs/types/index.d.ts b/next-dtype/docs/types/index.d.ts
index 0363421f..9f2e4eba 100644
--- a/next-dtype/docs/types/index.d.ts
+++ b/next-dtype/docs/types/index.d.ts
@@ -27,14 +27,14 @@
* - If a data type does not have a next larger data type or the next larger type is not supported, the function returns `-1`.
* - If provided an unrecognized data type, the function returns `null`.
*
-* @param dtype - ndarray data type
+* @param dtype - ndarray data type value
* @returns next larger data type(s) or null
*
* @example
* var dt = nextDataType( 'float32' );
* // returns 'float64'
*/
-declare function nextDataType( dtype?: string ): any;
+declare function nextDataType( dtype?: any ): any;
// EXPORTS //
diff --git a/next-dtype/docs/types/test.ts b/next-dtype/docs/types/test.ts
index 4ce24430..7eda9536 100644
--- a/next-dtype/docs/types/test.ts
+++ b/next-dtype/docs/types/test.ts
@@ -28,16 +28,6 @@ import nextDataType = require( './index' );
nextDataType( 'float' ); // $ExpectType any
}
-// The function does not compile if provided a value other than a string...
-{
- nextDataType( 123 ); // $ExpectError
- nextDataType( true ); // $ExpectError
- nextDataType( false ); // $ExpectError
- nextDataType( null ); // $ExpectError
- nextDataType( {} ); // $ExpectError
- nextDataType( ( x: number ): number => x ); // $ExpectError
-}
-
// The function does not compile if provided more than one argument...
{
nextDataType( 'float32', 123 ); // $ExpectError
diff --git a/next-dtype/lib/main.js b/next-dtype/lib/main.js
index cfe6aad5..ec7a9676 100644
--- a/next-dtype/lib/main.js
+++ b/next-dtype/lib/main.js
@@ -22,6 +22,7 @@
var objectKeys = require( '@stdlib/utils/keys' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
+var resolveStr = require( './../../base/dtype-resolve-str' );
var NEXT_DTYPES = require( './next_dtypes.json' );
@@ -54,7 +55,7 @@ function generateTable() {
/**
* Returns the next larger ndarray data type of the same kind.
*
-* @param {string} [dtype] - ndarray data type
+* @param {*} [dtype] - ndarray data type value
* @returns {(Object|string|integer|null)} next larger data type(s) or null
*
* @example
@@ -65,6 +66,7 @@ function nextDataType( dtype ) {
if ( arguments.length === 0 ) {
return generateTable();
}
+ dtype = resolveStr( dtype );
if ( hasOwnProp( NEXT_DTYPES, dtype ) ) {
return NEXT_DTYPES[ dtype ];
}
diff --git a/promotion-rules/docs/repl.txt b/promotion-rules/docs/repl.txt
index 06f83eef..f11a1e9e 100644
--- a/promotion-rules/docs/repl.txt
+++ b/promotion-rules/docs/repl.txt
@@ -12,11 +12,11 @@
Parameters
----------
- dtype1: string (optional)
- ndarray data type.
+ dtype1: any (optional)
+ ndarray data type value.
- dtype2: string (optional)
- ndarray data type.
+ dtype2: any (optional)
+ ndarray data type value.
Returns
-------
diff --git a/promotion-rules/docs/types/index.d.ts b/promotion-rules/docs/types/index.d.ts
index e8ed0e0d..350fd8bb 100644
--- a/promotion-rules/docs/types/index.d.ts
+++ b/promotion-rules/docs/types/index.d.ts
@@ -29,8 +29,8 @@ interface Table {
/**
* Returns the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.
*
-* @param dtype1 - ndarray data type
-* @param dtype2 - ndarray data type
+* @param dtype1 - ndarray data type value
+* @param dtype2 - ndarray data type value
* @returns promotion rule(s) or null
*
* @example
@@ -45,7 +45,7 @@ interface Table {
* var dt = promotionRules( 'float32', 'foo' );
* // returns null
*/
-declare function promotionRules( dtype1: string, dtype2: string ): number | string | null; // tslint-disable-line max-line-length
+declare function promotionRules( dtype1: any, dtype2: any ): number | string | null; // tslint-disable-line max-line-length
/**
* Returns a type promotion table displaying the ndarray data types with the smallest size and closest "kind" to which ndarray data types can be safely cast.
diff --git a/promotion-rules/docs/types/test.ts b/promotion-rules/docs/types/test.ts
index cb47924e..6f9bb238 100644
--- a/promotion-rules/docs/types/test.ts
+++ b/promotion-rules/docs/types/test.ts
@@ -29,26 +29,6 @@ import promotionRules = require( './index' );
promotionRules( 'float32', 'foo' ); // $ExpectType string | number | null
}
-// The function does not compile if provided a first argument that is not a string...
-{
- promotionRules( 123, 'float64' ); // $ExpectError
- promotionRules( true, 'float64' ); // $ExpectError
- promotionRules( false, 'float64' ); // $ExpectError
- promotionRules( null, 'float64' ); // $ExpectError
- promotionRules( {}, 'float64' ); // $ExpectError
- promotionRules( ( x: number ): number => x, 'float64' ); // $ExpectError
-}
-
-// The function does not compile if provided a second argument that is not a string...
-{
- promotionRules( 'int32', 123 ); // $ExpectError
- promotionRules( 'int32', true ); // $ExpectError
- promotionRules( 'int32', false ); // $ExpectError
- promotionRules( 'int32', null ); // $ExpectError
- promotionRules( 'int32', {} ); // $ExpectError
- promotionRules( 'int32', ( x: number ): number => x ); // $ExpectError
-}
-
// The function does not compile if provided more than one argument...
{
promotionRules( 'float32' ); // $ExpectError
diff --git a/promotion-rules/lib/main.js b/promotion-rules/lib/main.js
index 50345af5..304998a0 100644
--- a/promotion-rules/lib/main.js
+++ b/promotion-rules/lib/main.js
@@ -22,6 +22,7 @@
var objectKeys = require( '@stdlib/utils/keys' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
+var resolve = require( './../../base/dtype-resolve-str' );
var PROMOTION_RULES = require( './promotion_rules.json' );
@@ -66,8 +67,8 @@ function generateFullTable() {
/**
* Returns the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.
*
-* @param {string} [dtype1] - ndarray data type
-* @param {string} [dtype2] - ndarray data type
+* @param {*} [dtype1] - ndarray data type value
+* @param {*} [dtype2] - ndarray data type value
* @returns {(Object|integer|string|null)} promotion rule(s) or null
*
* @example
@@ -91,8 +92,10 @@ function promotionRules( dtype1, dtype2 ) {
if ( arguments.length === 0 ) {
return generateFullTable();
}
+ dtype1 = resolve( dtype1 );
if ( hasOwnProp( PROMOTION_RULES, dtype1 ) ) {
o = PROMOTION_RULES[ dtype1 ];
+ dtype2 = resolve( dtype2 );
if ( hasOwnProp( o, dtype2 ) ) {
return o[ dtype2 ];
}
diff --git a/safe-casts/docs/repl.txt b/safe-casts/docs/repl.txt
index 990a8a13..50605db7 100644
--- a/safe-casts/docs/repl.txt
+++ b/safe-casts/docs/repl.txt
@@ -9,8 +9,8 @@
Parameters
----------
- dtype: string (optional)
- ndarray data type.
+ dtype: any (optional)
+ ndarray data type value.
Returns
-------
diff --git a/safe-casts/docs/types/index.d.ts b/safe-casts/docs/types/index.d.ts
index 5f26b72f..8f9a3c50 100644
--- a/safe-casts/docs/types/index.d.ts
+++ b/safe-casts/docs/types/index.d.ts
@@ -26,14 +26,14 @@
* - If not provided an ndarray data type, the function returns a casting table.
* - If provided an unrecognized ndarray data type, the function returns `null`.
*
-* @param dtype - ndarray data type
+* @param dtype - ndarray data type value
* @returns list of ndarray data types or null
*
* @example
* var list = safeCasts( 'float32' );
* // returns [...]
*/
-declare function safeCasts( dtype?: string ): any;
+declare function safeCasts( dtype?: any ): any;
// EXPORTS //
diff --git a/safe-casts/docs/types/test.ts b/safe-casts/docs/types/test.ts
index 8a502636..5164c726 100644
--- a/safe-casts/docs/types/test.ts
+++ b/safe-casts/docs/types/test.ts
@@ -28,16 +28,6 @@ import safeCasts = require( './index' );
safeCasts( 'float' ); // $ExpectType any
}
-// The function does not compile if provided a value other than a string...
-{
- safeCasts( 123 ); // $ExpectError
- safeCasts( true ); // $ExpectError
- safeCasts( false ); // $ExpectError
- safeCasts( null ); // $ExpectError
- safeCasts( {} ); // $ExpectError
- safeCasts( ( x: number ): number => x ); // $ExpectError
-}
-
// The function does not compile if provided more than one argument...
{
safeCasts( 'float32', 123 ); // $ExpectError
diff --git a/safe-casts/lib/main.js b/safe-casts/lib/main.js
index c5130c82..e323af4c 100644
--- a/safe-casts/lib/main.js
+++ b/safe-casts/lib/main.js
@@ -22,6 +22,7 @@
var objectKeys = require( '@stdlib/utils/keys' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
+var resolve = require( './../../base/dtype-resolve-str' );
var SAFE_CASTS = require( './safe_casts.json' );
@@ -106,7 +107,7 @@ function generateTable() {
/**
* Returns a list of ndarray data types to which a provided ndarray data type can be safely cast.
*
-* @param {string} [dtype] - ndarray data type
+* @param {*} [dtype] - ndarray data type value
* @returns {(Object|StringArray|null)} list of ndarray data types or null
*
* @example
@@ -121,6 +122,7 @@ function safeCasts( dtype ) {
// Lazily generate table...
TABLE = generateTable();
}
+ dtype = resolve( dtype );
if ( hasOwnProp( TABLE, dtype ) ) {
return TABLE[ dtype ].slice();
}
diff --git a/same-kind-casts/docs/repl.txt b/same-kind-casts/docs/repl.txt
index 9a790656..d1bd6898 100644
--- a/same-kind-casts/docs/repl.txt
+++ b/same-kind-casts/docs/repl.txt
@@ -9,8 +9,8 @@
Parameters
----------
- dtype: string (optional)
- ndarray data type.
+ dtype: any (optional)
+ ndarray data type value.
Returns
-------
diff --git a/same-kind-casts/docs/types/index.d.ts b/same-kind-casts/docs/types/index.d.ts
index 5df11fd5..1cb46770 100644
--- a/same-kind-casts/docs/types/index.d.ts
+++ b/same-kind-casts/docs/types/index.d.ts
@@ -26,14 +26,14 @@
* - If not provided an ndarray data type, the function returns a casting table.
* - If provided an unrecognized ndarray data type, the function returns `null`.
*
-* @param dtype - ndarray data type
+* @param dtype - ndarray data type value
* @returns list of ndarray data types or null
*
* @example
* var list = sameKindCasts( 'float32' );
* // returns [...]
*/
-declare function sameKindCasts( dtype?: string ): any;
+declare function sameKindCasts( dtype?: any ): any;
// EXPORTS //
diff --git a/same-kind-casts/docs/types/test.ts b/same-kind-casts/docs/types/test.ts
index e3bae723..3975e818 100644
--- a/same-kind-casts/docs/types/test.ts
+++ b/same-kind-casts/docs/types/test.ts
@@ -28,16 +28,6 @@ import sameKindCasts = require( './index' );
sameKindCasts( 'float' ); // $ExpectType any
}
-// The function does not compile if provided a value other than a string...
-{
- sameKindCasts( 123 ); // $ExpectError
- sameKindCasts( true ); // $ExpectError
- sameKindCasts( false ); // $ExpectError
- sameKindCasts( null ); // $ExpectError
- sameKindCasts( {} ); // $ExpectError
- sameKindCasts( ( x: number ): number => x ); // $ExpectError
-}
-
// The function does not compile if provided more than one argument...
{
sameKindCasts( 'float32', 123 ); // $ExpectError
diff --git a/same-kind-casts/lib/main.js b/same-kind-casts/lib/main.js
index 9bd2c23e..5214c185 100644
--- a/same-kind-casts/lib/main.js
+++ b/same-kind-casts/lib/main.js
@@ -22,6 +22,7 @@
var objectKeys = require( '@stdlib/utils/keys' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
+var resolve = require( './../../base/dtype-resolve-str' );
var SAME_KIND_CASTS = require( './same_kind_casts.json' );
@@ -106,7 +107,7 @@ function generateTable() {
/**
* Returns a list of ndarray data types to which a provided ndarray data type can be safely cast or cast within the same "kind".
*
-* @param {string} [dtype] - ndarray data type
+* @param {*} [dtype] - ndarray data type value
* @returns {(Object|StringArray|null)} list of ndarray data types or null
*
* @example
@@ -121,6 +122,7 @@ function sameKindCasts( dtype ) {
// Lazily generate table...
TABLE = generateTable();
}
+ dtype = resolve( dtype );
if ( hasOwnProp( TABLE, dtype ) ) {
return TABLE[ dtype ].slice();
}