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 Sep 20, 2024
1 parent b574d74 commit 414fa58
Show file tree
Hide file tree
Showing 12 changed files with 733 additions and 1 deletion.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-09-17)
## Unreleased (2024-09-20)

<section class="packages">

Expand All @@ -20,6 +20,7 @@

##### Features

- [`786e74e`](https://github.com/stdlib-js/stdlib/commit/786e74e1a1eb5ca959ac7150cb6c1a75cd86c843) - add `isndarrayLikeWithDataType` to namespace
- [`5279713`](https://github.com/stdlib-js/stdlib/commit/527971383e70a0e92dbca647dabfef27f294f149) - add `isWebAssemblyMemory` to namespace
- [`e97215f`](https://github.com/stdlib-js/stdlib/commit/e97215fbf9f4d1ec8548086f78ed04a0ec80a43f) - add `hasBtoaSupport` to namespace
- [`80b8061`](https://github.com/stdlib-js/stdlib/commit/80b8061c5888d04dcaa48f0363669ba2606856df) - add `hasAtobSupport` to namespace
Expand Down Expand Up @@ -102,6 +103,28 @@

<!-- /.package -->

<section class="package" id="assert-is-ndarray-like-with--unreleased">

#### [@stdlib/assert/is-ndarray-like-with-](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-ndarray-like-with-)

<details>

<section class="features">

##### Features

- [`755425a`](https://github.com/stdlib-js/stdlib/commit/755425a26f81cc16d2d37d8217efaab339c6416a) - add `assert/is-ndarray-like-with-data-type`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="assert-is-same-accessor-array-unreleased">

#### [@stdlib/assert/is-same-accessor-array](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-accessor-array)
Expand Down Expand Up @@ -216,6 +239,8 @@ A total of 5 people contributed to this release. Thank you to the following cont

<details>

- [`786e74e`](https://github.com/stdlib-js/stdlib/commit/786e74e1a1eb5ca959ac7150cb6c1a75cd86c843) - **feat:** add `isndarrayLikeWithDataType` to namespace _(by Athan Reines)_
- [`755425a`](https://github.com/stdlib-js/stdlib/commit/755425a26f81cc16d2d37d8217efaab339c6416a) - **feat:** add `assert/is-ndarray-like-with-data-type` _(by Athan Reines)_
- [`f387603`](https://github.com/stdlib-js/stdlib/commit/f387603e739f88a38af3263ce6ff675ad903ee8c) - **docs:** consistently use declarative instead of imperative sentences outside of intros _(by Philipp Burckhardt)_
- [`ed44fee`](https://github.com/stdlib-js/stdlib/commit/ed44feecb9eaa5e0849d1a533e5415624d0aa338) - **style:** use imperative in package.json description and end with period _(by Philipp Burckhardt)_
- [`31fd427`](https://github.com/stdlib-js/stdlib/commit/31fd42744ec5d7073041f97c6f72350b8005c0fc) - **style:** remove unwanted empty lines _(by Philipp Burckhardt)_
Expand Down
95 changes: 95 additions & 0 deletions is-ndarray-like-with-data-type/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!--
@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.
-->

# isndarrayLikeWithDataType

> Test if a value is an [ndarray-like object][@stdlib/assert/is-ndarray-like] having a specified [data type][@stdlib/ndarray/dtypes].
<section class="usage">

## Usage

```javascript
var isndarrayLikeWithDataType = require( '@stdlib/assert/is-ndarray-like-with-data-type' );
```

#### isndarrayLikeWithDataType( value, dtype )

Tests if a value is an [ndarray-like object][@stdlib/assert/is-ndarray-like] having a specified [data type][@stdlib/ndarray/dtypes].

```javascript
var ndarray = require( '@stdlib/ndarray/ctor' );

var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
var bool = isndarrayLikeWithDataType( arr, 'generic' );
// returns true
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var ndarray = require( '@stdlib/ndarray/ctor' );
var isndarrayLikeWithDataType = require( '@stdlib/assert/is-ndarray-like-with-data-type' );

var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
var bool = isndarrayLikeWithDataType( arr, 'generic' );
// returns true

bool = isndarrayLikeWithDataType( [ 1, 2, 3, 4 ], 'generic' );
// returns false

bool = isndarrayLikeWithDataType( {}, 'generic' );
// returns false

bool = isndarrayLikeWithDataType( null, 'generic' );
// returns false
```

</section>

<!-- /.examples -->

<!-- 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/assert/is-ndarray-like]: https://github.com/stdlib-js/assert/tree/main/is-ndarray-like

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

</section>

<!-- /.links -->
146 changes: 146 additions & 0 deletions is-ndarray-like-with-data-type/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* @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 isBoolean = require( './../../is-boolean' ).isPrimitive;
var ndarray = require( '@stdlib/ndarray/ctor' );
var noop = require( '@stdlib/utils/noop' );
var pkg = require( './../package.json' ).name;
var isndarrayLikeWithDataType = require( './../lib' );


// MAIN //

bench( pkg+'::true,ndarray', function benchmark( b ) {
var strides;
var offset;
var buffer;
var values;
var shape;
var order;
var bool;
var arr;
var i;

buffer = [ 0, 0, 0, 0 ];
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

arr = ndarray( 'generic', buffer, shape, strides, offset, order );

values = [
arr,
arr,
arr,
arr,
arr
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::true,ndarray_like', function benchmark( b ) {
var values;
var bool;
var arr;
var i;

arr = {
'data': [ 0, 0, 0, 0 ],
'shape': [ 2, 2 ],
'strides': [ 2, 1 ],
'offset': 0,
'order': 'row-major',
'ndims': 2,
'dtype': 'generic',
'length': 4,
'flags': {},
'get': noop,
'set': noop
};

values = [
arr,
arr,
arr,
arr,
arr
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

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

values = [
5,
'beep',
true,
false,
null,
[ 1, 2, 3 ],
{}
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isndarrayLikeWithDataType( values[ i%values.length ], 'generic' );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
44 changes: 44 additions & 0 deletions is-ndarray-like-with-data-type/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

{{alias}}( value, dtype )
Tests if a value is an ndarray-like object having a specified data type.

Parameters
----------
value: any
Value to test.

dtype: any
Data type value.

Returns
-------
bool: boolean
Boolean indicating whether a value is an ndarray-like object having a
specified data type.

Examples
--------
> var M = {};
> M.data = [ 0, 0, 0, 0 ];
> M.ndims = 2;
> M.shape = [ 2, 2 ];
> M.strides = [ 2, 1 ];
> M.offset = 0;
> M.order = 'row-major';
> M.dtype = 'generic';
> M.length = 4;
> M.flags = {};
> M.get = function get( i, j ) {};
> M.set = function set( i, j ) {};
> var bool = {{alias}}( M, 'generic' )
true
> bool = {{alias}}( [ 1, 2, 3, 4 ], 'generic' )
false
> bool = {{alias}}( 3.14, 'generic' )
false
> bool = {{alias}}( {}, 'generic' )
false

See Also
--------

44 changes: 44 additions & 0 deletions is-ndarray-like-with-data-type/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/**
* Tests if a value is an ndarray-like object having a specified data type.
*
* @param v - value to test
* @param dtype - data type
* @returns boolean indicating if a value is an ndarray-like object having a specified data type
*
* @example
* var ndarray = require( '@stdlib/ndarray/ctor' );
*
* var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
*
* var bool = isndarrayLikeWithDataType( arr, 'generic' );
* // returns true
*
* bool = isndarrayLikeWithDataType( [], 'generic' );
* // returns false
*/
declare function isndarrayLikeWithDataType( v: any, dtype: any ): boolean;


// EXPORTS //

export = isndarrayLikeWithDataType;
Loading

0 comments on commit 414fa58

Please sign in to comment.