From 59bd897bbd551c3066b98d16ff43b12c6908f576 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 2 Dec 2023 15:08:08 -0800 Subject: [PATCH] feat: add `assert/is-complex128ndarray-like` --- .../is-complex128ndarray-like/README.md | 98 +++++++++++++++++++ .../benchmark/benchmark.js | 97 ++++++++++++++++++ .../is-complex128ndarray-like/docs/repl.txt | 42 ++++++++ .../docs/types/index.d.ts | 44 +++++++++ .../docs/types/test.ts | 33 +++++++ .../examples/index.js | 38 +++++++ .../is-complex128ndarray-like/lib/index.js | 49 ++++++++++ .../is-complex128ndarray-like/lib/main.js | 54 ++++++++++ .../is-complex128ndarray-like/package.json | 76 ++++++++++++++ .../is-complex128ndarray-like/test/test.js | 89 +++++++++++++++++ 10 files changed, 620 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/README.md create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/package.json create mode 100644 lib/node_modules/@stdlib/assert/is-complex128ndarray-like/test/test.js diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/README.md b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/README.md new file mode 100644 index 000000000000..7d6ef2d35dc1 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/README.md @@ -0,0 +1,98 @@ + + +# isComplex128ndarrayLike + +> Test if a value is an [ndarray][@stdlib/ndarray/ctor]-like object containing double-precision complex floating-point numbers. + +
+ +## Usage + +```javascript +var isComplex128ndarrayLike = require( '@stdlib/assert/is-complex128ndarray-like' ); +``` + +#### isComplex128ndarrayLike( value ) + +Tests if a value is an [ndarray][@stdlib/ndarray/ctor]-like object whose underlying data type is `complex128`. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var arr = ndarray( 'complex128', new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +var bool = isComplex128ndarrayLike( arr ); +// returns true +``` + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isComplex128ndarrayLike = require( '@stdlib/assert/is-complex128ndarray-like' ); + +var buffer = new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); +var arr = ndarray( 'complex128', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +var out = isComplex128ndarrayLike( arr ); +// returns true + +out = isComplex128ndarrayLike( [ 1, 2, 3, 4 ] ); +// returns false + +out = isComplex128ndarrayLike( {} ); +// returns false + +out = isComplex128ndarrayLike( null ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/benchmark/benchmark.js new file mode 100644 index 000000000000..5ba3b7febfd6 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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( '@stdlib/assert/is-boolean' ).isPrimitive; +var ndarray = require( '@stdlib/ndarray/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var isComplex128ndarrayLike = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::true', function benchmark( b ) { + var strides; + var offset; + var buffer; + var values; + var shape; + var order; + var bool; + var arr; + var i; + + buffer = new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); + shape = [ 2, 2 ]; + strides = [ 2, 1 ]; + offset = 0; + order = 'row-major'; + + arr = ndarray( 'complex128', buffer, shape, strides, offset, order ); + + values = [ + arr, + arr + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isComplex128ndarrayLike( values[ i%values.length ] ); + 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 = [ + [ 1, 2, 3 ], + null, + 5, + 'beep' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isComplex128ndarrayLike( values[ i%values.length ] ); + 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(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/repl.txt new file mode 100644 index 000000000000..daa538af5902 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( value ) + Tests if a value is an ndarray-like object containing double-precision + complex floating-point numbers. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether a value is an ndarray-like object containing + double-precision complex floating-point numbers. + + Examples + -------- + > var M = {}; + > M.data = new {{alias:@stdlib/array/complex128}}( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); + > M.ndims = 2; + > M.shape = [ 2, 2 ]; + > M.strides = [ 2, 1 ]; + > M.offset = 0; + > M.order = 'row-major'; + > M.dtype = 'complex128'; + > M.length = 4; + > M.flags = {}; + > M.get = function get( i, j ) {}; + > M.set = function set( i, j ) {}; + > var bool = {{alias}}( M ) + true + > bool = {{alias}}( [ 1, 2, 3, 4 ] ) + false + > bool = {{alias}}( 3.14 ) + false + > bool = {{alias}}( {} ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/index.d.ts new file mode 100644 index 000000000000..9137fb36aefa --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/index.d.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 whose underlying data type is `complex128`. +* +* @param v - value to test +* @returns boolean indicating if a value is an ndarray-like object whose underlying data type is `complex128` +* +* @example +* var Complex128Array = require( `@stdlib/array/complex128` ); +* var ndarray = require( `@stdlib/ndarray/ctor` ); +* +* var arr = ndarray( 'complex128', new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* +* var bool = isComplex128ndarrayLike( arr ); +* // returns true +* +* bool = isComplex128ndarrayLike( [] ); +* // returns false +*/ +declare function isComplex128ndarrayLike( v: any ): boolean; + + +// EXPORTS // + +export = isComplex128ndarrayLike; diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/test.ts new file mode 100644 index 000000000000..84a7a63e44f8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/docs/types/test.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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. +*/ + +import isComplex128ndarrayLike = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isComplex128ndarrayLike( [] ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isComplex128ndarrayLike(); // $ExpectError + isComplex128ndarrayLike( 'abc', 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/examples/index.js b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/examples/index.js new file mode 100644 index 000000000000..1352b45ea7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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'; + +var ndarray = require( '@stdlib/ndarray/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isComplex128ndarrayLike = require( './../lib' ); + +var buffer = new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); +var arr = ndarray( 'complex128', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +console.log( isComplex128ndarrayLike( arr ) ); +// => true + +console.log( isComplex128ndarrayLike( [ 1, 2, 3, 4 ] ) ); +// => false + +console.log( isComplex128ndarrayLike( {} ) ); +// => false + +console.log( isComplex128ndarrayLike( null ) ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/index.js b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/index.js new file mode 100644 index 000000000000..c3d859c4312d --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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'; + +/** +* Test if a value is an ndarray-like object whose underlying data type is `complex128`. +* +* @module @stdlib/assert/is-complex128ndarray-like +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var isComplex128ndarrayLike = require( '@stdlib/assert/is-complex128ndarray-like' ); +* +* var buffer = new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); +* +* var arr = ndarray( 'complex128', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* +* var bool = isComplex128ndarrayLike( arr ); +* // returns true +* +* bool = isComplex128ndarrayLike( [] ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/main.js b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/main.js new file mode 100644 index 000000000000..baf5922d55cf --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/lib/main.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); + + +// MAIN // + +/** +* Tests if a value is an ndarray-like object whose underlying data type is `complex128`. +* +* @param {*} v - value to test +* @returns {boolean} boolean indicating if a value is an ndarray-like object whose underlying data type is `complex128` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var buffer = new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ); +* var arr = ndarray( 'complex128', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* +* var bool = isComplex128ndarrayLike( arr ); +* // returns true +* +* bool = isComplex128ndarrayLike( [] ); +* // returns false +*/ +function isComplex128ndarrayLike( v ) { + return ( isndarrayLike( v ) && v.dtype === 'complex128' ); +} + + +// EXPORTS // + +module.exports = isComplex128ndarrayLike; diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/package.json b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/package.json new file mode 100644 index 000000000000..e9fa86690814 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/assert/is-complex128ndarray-like", + "version": "0.0.0", + "description": "Test if a value is an ndarray-like object containing double-precision complex floating-point numbers.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "is", + "isndarray", + "ndarray", + "ndarray-like", + "array", + "nd", + "complex128", + "double", + "double-precision", + "complex128array", + "validate", + "isvalid", + "test", + "type", + "check" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/test/test.js b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/test/test.js new file mode 100644 index 000000000000..12125b5302ac --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-complex128ndarray-like/test/test.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var noop = require( '@stdlib/utils/noop' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isComplex128ndarrayLike = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isComplex128ndarrayLike, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided an ndarray containing double-precision complex floating-point numbers', function test( t ) { + var arr = ndarray( 'complex128', new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + t.equal( isComplex128ndarrayLike( arr ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `true` if provided an ndarray-like object containing double-precision complex floating-point numbers', function test( t ) { + var arr = { + 'data': new Complex128Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'ndims': 2, + 'dtype': 'complex128', + 'length': 4, + 'flags': {}, + 'get': noop, + 'set': noop + }; + + t.equal( isComplex128ndarrayLike( arr ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided an ndarray-like object containing double-precision complex floating-point numbers', function test( t ) { + var values; + var arr; + var i; + + arr = ndarray( 'generic', [ 0, 0, 0, 0, 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + arr, + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isComplex128ndarrayLike( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +});