From 499c59ff4ecaa5a66164ece469c372aee99a6281 Mon Sep 17 00:00:00 2001 From: soumajit23 Date: Fri, 1 Mar 2024 12:40:26 +0530 Subject: [PATCH 1/7] refactor(is-cube-number): refactor the `is-cube-number` benchmarks to measure affirmative/negative test values --- .../is-cube-number/benchmark/benchmark.js | 108 ++---------------- 1 file changed, 10 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js index b431f358d28..4b738f047d9 100644 --- a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-new-wrappers, no-empty-function */ +/* eslint-disable no-empty-function */ 'use strict'; @@ -31,13 +31,12 @@ var isCubeNumber = require( './../lib' ); // MAIN // -bench( pkg+'::primitives', function benchmark( b ) { +bench( pkg+'::primitives,true', function benchmark( b ) { var values; var bool; var i; values = [ - '5', 5, 4, 0.5, @@ -45,42 +44,7 @@ bench( pkg+'::primitives', function benchmark( b ) { 0.0, 3.14, -5, - -4, - NaN, - true, - false, - null, - void 0 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = isCubeNumber( 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+'::objects', function benchmark( b ) { - var values; - var bool; - var i; - - values = [ - [], - {}, - function noop() {}, - new Number( 8.0 ), - new Number( 0.5 ), - new Number( NaN ), - new Number( 3.14 ) + -4 ]; b.tic(); @@ -98,21 +62,13 @@ bench( pkg+'::objects', function benchmark( b ) { b.end(); }); -bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { +bench( pkg+'::primitives,false', function benchmark( b ) { var values; var bool; var i; values = [ '5', - 5, - 4, - 3.14, - 0.5, - 1.0, - 0.0, - -5, - -4, NaN, true, false, @@ -122,7 +78,7 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - bool = isCubeNumber.isPrimitive( values[ i % values.length ] ); + bool = isCubeNumber( values[ i % values.length ] ); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } @@ -135,15 +91,12 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isPrimitive', function benchmark( b ) { +bench( pkg+'::objects,true', function benchmark( b ) { var values; var bool; var i; values = [ - [], - {}, - function noop() {}, new Number( 8.0 ), new Number( 0.5 ), new Number( NaN ), @@ -152,44 +105,7 @@ bench( pkg+'::objects:isPrimitive', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - bool = isCubeNumber.isPrimitive( 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+'::primitives:isObject', function benchmark( b ) { - var values; - var bool; - var i; - - values = [ - '5', - 5, - 4, - 3.14, - 0.5, - 1.0, - 0.0, - -5, - -4, - NaN, - true, - false, - null, - void 0 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = isCubeNumber.isObject( values[ i % values.length ] ); + bool = isCubeNumber( values[ i % values.length ] ); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } @@ -202,7 +118,7 @@ bench( pkg+'::primitives:isObject', function benchmark( b ) { b.end(); }); -bench( pkg+'::objects:isObject', function benchmark( b ) { +bench( pkg+'::objects,false', function benchmark( b ) { var values; var bool; var i; @@ -210,16 +126,12 @@ bench( pkg+'::objects:isObject', function benchmark( b ) { values = [ [], {}, - function noop() {}, - new Number( 8.0 ), - new Number( 0.5 ), - new Number( NaN ), - new Number( 3.14 ) + function noop() {} ]; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - bool = isCubeNumber.isObject( values[ i % values.length ] ); + bool = isCubeNumber( values[ i % values.length ] ); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } From cd41b382a7e799e51aa621ef85c6750105ee46f7 Mon Sep 17 00:00:00 2001 From: soumajit23 Date: Sat, 2 Mar 2024 16:25:15 +0530 Subject: [PATCH 2/7] refactor(is-cube-number): put values that result in true for benchmark functions --- .../is-cube-number/benchmark/benchmark.js | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js index 4b738f047d9..c5e67051a3d 100644 --- a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js @@ -37,14 +37,14 @@ bench( pkg+'::primitives,true', function benchmark( b ) { var i; values = [ - 5, - 4, - 0.5, + 8, + 64, 1.0, - 0.0, - 3.14, - -5, - -4 + -27, + -8.0, + 125, + -1000.0, + -8 ]; b.tic(); @@ -73,7 +73,9 @@ bench( pkg+'::primitives,false', function benchmark( b ) { true, false, null, - void 0 + void 0, + -6, + 7.25 ]; b.tic(); @@ -97,10 +99,14 @@ bench( pkg+'::objects,true', function benchmark( b ) { var i; values = [ - new Number( 8.0 ), - new Number( 0.5 ), - new Number( NaN ), - new Number( 3.14 ) + new Number( 8 ), + new Number( 64 ), + new Number( 1.0 ), + new Number( -27 ), + new Number( -8.0 ), + new Number( 125 ), + new Number( -1000.0 ), + new Number( -8 ) ]; b.tic(); @@ -126,7 +132,12 @@ bench( pkg+'::objects,false', function benchmark( b ) { values = [ [], {}, - function noop() {} + function noop() {}, + new Number( 0.5 ), + new Number( NaN ), + new Number( 3.14 ), + new Number( -6 ), + new Number( 7.25 ) ]; b.tic(); From a76ab87ed13c1ade1d571f037ff2791698f2dde7 Mon Sep 17 00:00:00 2001 From: soumajit23 Date: Sat, 2 Mar 2024 17:47:08 +0530 Subject: [PATCH 3/7] refactor(is-cube-number): restored is-primitive and is-object benchmarks --- .../is-cube-number/benchmark/benchmark.js | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js index c5e67051a3d..cecb7d008c0 100644 --- a/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-cube-number/benchmark/benchmark.js @@ -154,3 +154,137 @@ bench( pkg+'::objects,false', function benchmark( b ) { b.pass( 'benchmark finished' ); b.end(); }); + +bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', + 5, + 4, + 3.14, + 0.5, + 1.0, + 0.0, + -5, + -4, + NaN, + true, + false, + null, + void 0 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isCubeNumber.isPrimitive( 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+'::objects:isPrimitive', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + [], + {}, + function noop() {}, + new Number( 8.0 ), + new Number( 0.5 ), + new Number( NaN ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isCubeNumber.isPrimitive( 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+'::primitives:isObject', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', + 5, + 4, + 3.14, + 0.5, + 1.0, + 0.0, + -5, + -4, + NaN, + true, + false, + null, + void 0 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isCubeNumber.isObject( 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+'::objects:isObject', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + [], + {}, + function noop() {}, + new Number( 8.0 ), + new Number( 0.5 ), + new Number( NaN ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isCubeNumber.isObject( 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(); +}); From b3ffdb74e605d715f06ce058afaea8e60af741bd Mon Sep 17 00:00:00 2001 From: soumajit23 Date: Tue, 12 Mar 2024 20:12:04 +0530 Subject: [PATCH 4/7] docs: improve README examples of array/base/assert namespace --- .../@stdlib/array/base/assert/README.md | 147 +++++++++++++++++- .../array/base/assert/examples/index.js | 146 ++++++++++++++++- 2 files changed, 285 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/README.md b/lib/node_modules/@stdlib/array/base/assert/README.md index b2d27de4888..1f63930aa02 100644 --- a/lib/node_modules/@stdlib/array/base/assert/README.md +++ b/lib/node_modules/@stdlib/array/base/assert/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2022 The Stdlib Authors. +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. @@ -81,10 +81,149 @@ The namespace exports the following: ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( '@stdlib/array/base/assert' ); +/* eslint-disable no-unused-vars */ +var cartesianPower = require( '@stdlib/array/cartesian-power' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); + +// Test if two arrays have the same values +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); + +var arr = [1, 2, 3]; + +var power = cartesianPower(arr, 2); // returns Cartesian power of the array + +// Test if an array-like object supports the accessor (get/set) protocol +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); + +var bool = isAccessorArray(new Complex128Array(10)); // returns true + +bool = isAccessorArray(new Complex64Array(10)); // returns true + +bool = isAccessorArray([]); // returns false + +bool = isAccessorArray(new Float64Array(10)); // returns false + +bool = isAccessorArray(new Int32Array(10)); // returns false + +bool = isAccessorArray(new Uint32Array(10)); // returns false + +bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false + +bool = isAccessorArray({ + 'length': 0 +}); + +// Test if an input value is a supported array complex-valued floating-point data type +var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); + +bool = isComplexFloatingPoint('complex128'); // returns true + +bool = isComplexFloatingPoint('complex64'); // returns true + +bool = isComplexFloatingPoint('float32'); // returns false + +bool = isComplexFloatingPoint('float64'); // returns false + +// Test if a value is a complex typed array +var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); + +bool = isComplexTypedArray(new Complex128Array(10)); // returns true + +bool = isComplexTypedArray(new Complex64Array(10)); // returns true + +bool = isComplexTypedArray([]); // returns false + +bool = isComplexTypedArray(new Float64Array(10)); // returns false + +bool = isComplexTypedArray(new Float32Array(10)); // returns false + +bool = isComplexTypedArray({ + 'length': 0 +}); + +// Test if an input value is a supported array data type +var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); + +bool = isDataType('float64'); // returns true + +bool = isDataType('int16'); // returns true + +bool = isDataType('uint8'); // returns true + +bool = isDataType('beep'); // returns false + +// Test if an input value is a supported array floating-point data type +var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); + +bool = isFloatingPoint('float32'); // returns true + +bool = isFloatingPoint('float64'); // returns true + +bool = isFloatingPoint('int16'); // returns false + +bool = isFloatingPoint('uint8'); // returns false + +// Test if an input value is a supported array integer data type +var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); + +bool = isIntegerDataType('int32'); // returns true + +bool = isIntegerDataType('uint16'); // returns true + +bool = isIntegerDataType('float64'); // returns false + +// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type +var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); + +bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true + +bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false + +// Test if an input value is a supported array numeric data type +var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); + +bool = isNumericDataType('int32'); // returns true + +bool = isNumericDataType('uint16'); // returns true + +bool = isNumericDataType('complex128'); // returns true + +bool = isNumericDataType('beep'); // returns false + +// Test if an input value is a supported array real-valued data type +var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); + +bool = isRealDataType('float64'); // returns true + +bool = isRealDataType('complex128'); // returns false + +// Test if an input value is a supported array real-valued floating-point data type +var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); + +bool = isRealFloatingPoint('float32'); // returns true + +bool = isRealFloatingPoint('float64'); // returns true + +bool = isRealFloatingPoint('complex128'); // returns false + +// Determine whether an array data type can be safely cast to another array data type +var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); + +bool = isSafeDataTypeCast('int32', 'uint16'); // returns false + +bool = isSafeDataTypeCast('int16', 'float64'); // returns true + +// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type +var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); + +bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true -console.log( objectKeys( ns ) ); ``` diff --git a/lib/node_modules/@stdlib/array/base/assert/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/examples/index.js index d903e87cb0a..b22104a90fa 100644 --- a/lib/node_modules/@stdlib/array/base/assert/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* 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. @@ -18,7 +18,145 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); +/* eslint-disable no-unused-vars */ +var cartesianPower = require( '@stdlib/array/cartesian-power' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); -console.log( objectKeys( ns ) ); +// Test if two arrays have the same values +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); + +var arr = [1, 2, 3]; + +var power = cartesianPower(arr, 2); // returns Cartesian power of the array + +// Test if an array-like object supports the accessor (get/set) protocol +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); + +var bool = isAccessorArray(new Complex128Array(10)); // returns true + +bool = isAccessorArray(new Complex64Array(10)); // returns true + +bool = isAccessorArray([]); // returns false + +bool = isAccessorArray(new Float64Array(10)); // returns false + +bool = isAccessorArray(new Int32Array(10)); // returns false + +bool = isAccessorArray(new Uint32Array(10)); // returns false + +bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false + +bool = isAccessorArray({ + 'length': 0 +}); + +// Test if an input value is a supported array complex-valued floating-point data type +var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); + +bool = isComplexFloatingPoint('complex128'); // returns true + +bool = isComplexFloatingPoint('complex64'); // returns true + +bool = isComplexFloatingPoint('float32'); // returns false + +bool = isComplexFloatingPoint('float64'); // returns false + +// Test if a value is a complex typed array +var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); + +bool = isComplexTypedArray(new Complex128Array(10)); // returns true + +bool = isComplexTypedArray(new Complex64Array(10)); // returns true + +bool = isComplexTypedArray([]); // returns false + +bool = isComplexTypedArray(new Float64Array(10)); // returns false + +bool = isComplexTypedArray(new Float32Array(10)); // returns false + +bool = isComplexTypedArray({ + 'length': 0 +}); + +// Test if an input value is a supported array data type +var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); + +bool = isDataType('float64'); // returns true + +bool = isDataType('int16'); // returns true + +bool = isDataType('uint8'); // returns true + +bool = isDataType('beep'); // returns false + +// Test if an input value is a supported array floating-point data type +var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); + +bool = isFloatingPoint('float32'); // returns true + +bool = isFloatingPoint('float64'); // returns true + +bool = isFloatingPoint('int16'); // returns false + +bool = isFloatingPoint('uint8'); // returns false + +// Test if an input value is a supported array integer data type +var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); + +bool = isIntegerDataType('int32'); // returns true + +bool = isIntegerDataType('uint16'); // returns true + +bool = isIntegerDataType('float64'); // returns false + +// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type +var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); + +bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true + +bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false + +// Test if an input value is a supported array numeric data type +var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); + +bool = isNumericDataType('int32'); // returns true + +bool = isNumericDataType('uint16'); // returns true + +bool = isNumericDataType('complex128'); // returns true + +bool = isNumericDataType('beep'); // returns false + +// Test if an input value is a supported array real-valued data type +var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); + +bool = isRealDataType('float64'); // returns true + +bool = isRealDataType('complex128'); // returns false + +// Test if an input value is a supported array real-valued floating-point data type +var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); + +bool = isRealFloatingPoint('float32'); // returns true + +bool = isRealFloatingPoint('float64'); // returns true + +bool = isRealFloatingPoint('complex128'); // returns false + +// Determine whether an array data type can be safely cast to another array data type +var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); + +bool = isSafeDataTypeCast('int32', 'uint16'); // returns false + +bool = isSafeDataTypeCast('int16', 'float64'); // returns true + +// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type +var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); + +bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true From 94c8b0fd87792a8a69c169dee3e6ef9f25ef00bc Mon Sep 17 00:00:00 2001 From: soumajit23 Date: Fri, 15 Mar 2024 17:52:31 +0530 Subject: [PATCH 5/7] docs: improve README examples of array/base/assert namespace --- .../@stdlib/array/base/assert/README.md | 144 +++++++++++++++++- .../array/base/assert/examples/index.js | 144 +++++++++++++++++- 2 files changed, 282 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/README.md b/lib/node_modules/@stdlib/array/base/assert/README.md index b2d27de4888..dd0b0b3fd92 100644 --- a/lib/node_modules/@stdlib/array/base/assert/README.md +++ b/lib/node_modules/@stdlib/array/base/assert/README.md @@ -81,10 +81,148 @@ The namespace exports the following: ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( '@stdlib/array/base/assert' ); +/* eslint-disable no-unused-vars */ +var cartesianPower = require( '@stdlib/array/cartesian-power' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); + +// Test if two arrays have the same values +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); + +var arr = [1, 2, 3]; + +var power = cartesianPower(arr, 2); // returns Cartesian power of the array + +// Test if an array-like object supports the accessor (get/set) protocol +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); + +var bool = isAccessorArray(new Complex128Array(10)); // returns true + +bool = isAccessorArray(new Complex64Array(10)); // returns true + +bool = isAccessorArray([]); // returns false + +bool = isAccessorArray(new Float64Array(10)); // returns false + +bool = isAccessorArray(new Int32Array(10)); // returns false + +bool = isAccessorArray(new Uint32Array(10)); // returns false + +bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false + +bool = isAccessorArray({ + 'length': 0 +}); + +// Test if an input value is a supported array complex-valued floating-point data type +var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); + +bool = isComplexFloatingPoint('complex128'); // returns true + +bool = isComplexFloatingPoint('complex64'); // returns true + +bool = isComplexFloatingPoint('float32'); // returns false + +bool = isComplexFloatingPoint('float64'); // returns false + +// Test if a value is a complex typed array +var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); + +bool = isComplexTypedArray(new Complex128Array(10)); // returns true + +bool = isComplexTypedArray(new Complex64Array(10)); // returns true + +bool = isComplexTypedArray([]); // returns false + +bool = isComplexTypedArray(new Float64Array(10)); // returns false + +bool = isComplexTypedArray(new Float32Array(10)); // returns false + +bool = isComplexTypedArray({ + 'length': 0 +}); + +// Test if an input value is a supported array data type +var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); + +bool = isDataType('float64'); // returns true + +bool = isDataType('int16'); // returns true + +bool = isDataType('uint8'); // returns true + +bool = isDataType('beep'); // returns false + +// Test if an input value is a supported array floating-point data type +var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); + +bool = isFloatingPoint('float32'); // returns true + +bool = isFloatingPoint('float64'); // returns true + +bool = isFloatingPoint('int16'); // returns false + +bool = isFloatingPoint('uint8'); // returns false + +// Test if an input value is a supported array integer data type +var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); + +bool = isIntegerDataType('int32'); // returns true + +bool = isIntegerDataType('uint16'); // returns true + +bool = isIntegerDataType('float64'); // returns false + +// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type +var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); + +bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true + +bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false + +// Test if an input value is a supported array numeric data type +var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); + +bool = isNumericDataType('int32'); // returns true + +bool = isNumericDataType('uint16'); // returns true + +bool = isNumericDataType('complex128'); // returns true + +bool = isNumericDataType('beep'); // returns false + +// Test if an input value is a supported array real-valued data type +var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); + +bool = isRealDataType('float64'); // returns true + +bool = isRealDataType('complex128'); // returns false + +// Test if an input value is a supported array real-valued floating-point data type +var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); + +bool = isRealFloatingPoint('float32'); // returns true + +bool = isRealFloatingPoint('float64'); // returns true + +bool = isRealFloatingPoint('complex128'); // returns false + +// Determine whether an array data type can be safely cast to another array data type +var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); + +bool = isSafeDataTypeCast('int32', 'uint16'); // returns false + +bool = isSafeDataTypeCast('int16', 'float64'); // returns true + +// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type +var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); -console.log( objectKeys( ns ) ); +bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true ``` diff --git a/lib/node_modules/@stdlib/array/base/assert/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/examples/index.js index d903e87cb0a..99e0ed906d3 100644 --- a/lib/node_modules/@stdlib/array/base/assert/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/examples/index.js @@ -18,7 +18,145 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); +/* eslint-disable no-unused-vars */ +var cartesianPower = require( '@stdlib/array/cartesian-power' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); -console.log( objectKeys( ns ) ); +// Test if two arrays have the same values +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); + +var arr = [1, 2, 3]; + +var power = cartesianPower(arr, 2); // returns Cartesian power of the array + +// Test if an array-like object supports the accessor (get/set) protocol +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); + +var bool = isAccessorArray(new Complex128Array(10)); // returns true + +bool = isAccessorArray(new Complex64Array(10)); // returns true + +bool = isAccessorArray([]); // returns false + +bool = isAccessorArray(new Float64Array(10)); // returns false + +bool = isAccessorArray(new Int32Array(10)); // returns false + +bool = isAccessorArray(new Uint32Array(10)); // returns false + +bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false + +bool = isAccessorArray({ + 'length': 0 +}); + +// Test if an input value is a supported array complex-valued floating-point data type +var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); + +bool = isComplexFloatingPoint('complex128'); // returns true + +bool = isComplexFloatingPoint('complex64'); // returns true + +bool = isComplexFloatingPoint('float32'); // returns false + +bool = isComplexFloatingPoint('float64'); // returns false + +// Test if a value is a complex typed array +var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); + +bool = isComplexTypedArray(new Complex128Array(10)); // returns true + +bool = isComplexTypedArray(new Complex64Array(10)); // returns true + +bool = isComplexTypedArray([]); // returns false + +bool = isComplexTypedArray(new Float64Array(10)); // returns false + +bool = isComplexTypedArray(new Float32Array(10)); // returns false + +bool = isComplexTypedArray({ + 'length': 0 +}); + +// Test if an input value is a supported array data type +var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); + +bool = isDataType('float64'); // returns true + +bool = isDataType('int16'); // returns true + +bool = isDataType('uint8'); // returns true + +bool = isDataType('beep'); // returns false + +// Test if an input value is a supported array floating-point data type +var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); + +bool = isFloatingPoint('float32'); // returns true + +bool = isFloatingPoint('float64'); // returns true + +bool = isFloatingPoint('int16'); // returns false + +bool = isFloatingPoint('uint8'); // returns false + +// Test if an input value is a supported array integer data type +var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); + +bool = isIntegerDataType('int32'); // returns true + +bool = isIntegerDataType('uint16'); // returns true + +bool = isIntegerDataType('float64'); // returns false + +// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type +var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); + +bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true + +bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false + +// Test if an input value is a supported array numeric data type +var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); + +bool = isNumericDataType('int32'); // returns true + +bool = isNumericDataType('uint16'); // returns true + +bool = isNumericDataType('complex128'); // returns true + +bool = isNumericDataType('beep'); // returns false + +// Test if an input value is a supported array real-valued data type +var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); + +bool = isRealDataType('float64'); // returns true + +bool = isRealDataType('complex128'); // returns false + +// Test if an input value is a supported array real-valued floating-point data type +var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); + +bool = isRealFloatingPoint('float32'); // returns true + +bool = isRealFloatingPoint('float64'); // returns true + +bool = isRealFloatingPoint('complex128'); // returns false + +// Determine whether an array data type can be safely cast to another array data type +var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); + +bool = isSafeDataTypeCast('int32', 'uint16'); // returns false + +bool = isSafeDataTypeCast('int16', 'float64'); // returns true + +// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type +var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); + +bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true From d02ed43a8833402a1bdce6d09cf25505c03f571f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 7 Oct 2024 21:08:41 -0400 Subject: [PATCH 6/7] chore: update examples --- .../@stdlib/array/base/assert/README.md | 173 +++++------------- .../array/base/assert/examples/index.js | 172 +++++------------ 2 files changed, 98 insertions(+), 247 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/README.md b/lib/node_modules/@stdlib/array/base/assert/README.md index 1f63930aa02..9d181345c34 100644 --- a/lib/node_modules/@stdlib/array/base/assert/README.md +++ b/lib/node_modules/@stdlib/array/base/assert/README.md @@ -81,149 +81,74 @@ The namespace exports the following: ```javascript -/* eslint-disable no-unused-vars */ -var cartesianPower = require( '@stdlib/array/cartesian-power' ); -var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); -var Int32Array = require( '@stdlib/array/int32' ); -var Uint32Array = require( '@stdlib/array/uint32' ); -var Float32Array = require( '@stdlib/array/float32' ); +var ns = require( '@stdlib/array/base/assert' ); +var dtype = require( '@stdlib/array/dtype' ); var Float64Array = require( '@stdlib/array/float64' ); -var Complex64Array = require( '@stdlib/array/complex64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); var Complex128Array = require( '@stdlib/array/complex128' ); -// Test if two arrays have the same values -var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); - -var arr = [1, 2, 3]; - -var power = cartesianPower(arr, 2); // returns Cartesian power of the array - -// Test if an array-like object supports the accessor (get/set) protocol -var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); - -var bool = isAccessorArray(new Complex128Array(10)); // returns true - -bool = isAccessorArray(new Complex64Array(10)); // returns true - -bool = isAccessorArray([]); // returns false - -bool = isAccessorArray(new Float64Array(10)); // returns false - -bool = isAccessorArray(new Int32Array(10)); // returns false - -bool = isAccessorArray(new Uint32Array(10)); // returns false - -bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false - -bool = isAccessorArray({ - 'length': 0 -}); - -// Test if an input value is a supported array complex-valued floating-point data type -var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); - -bool = isComplexFloatingPoint('complex128'); // returns true - -bool = isComplexFloatingPoint('complex64'); // returns true - -bool = isComplexFloatingPoint('float32'); // returns false - -bool = isComplexFloatingPoint('float64'); // returns false - -// Test if a value is a complex typed array -var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); - -bool = isComplexTypedArray(new Complex128Array(10)); // returns true - -bool = isComplexTypedArray(new Complex64Array(10)); // returns true - -bool = isComplexTypedArray([]); // returns false - -bool = isComplexTypedArray(new Float64Array(10)); // returns false - -bool = isComplexTypedArray(new Float32Array(10)); // returns false - -bool = isComplexTypedArray({ - 'length': 0 -}); - -// Test if an input value is a supported array data type -var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); - -bool = isDataType('float64'); // returns true - -bool = isDataType('int16'); // returns true - -bool = isDataType('uint8'); // returns true - -bool = isDataType('beep'); // returns false - -// Test if an input value is a supported array floating-point data type -var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); - -bool = isFloatingPoint('float32'); // returns true - -bool = isFloatingPoint('float64'); // returns true - -bool = isFloatingPoint('int16'); // returns false - -bool = isFloatingPoint('uint8'); // returns false - -// Test if an input value is a supported array integer data type -var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); - -bool = isIntegerDataType('int32'); // returns true - -bool = isIntegerDataType('uint16'); // returns true - -bool = isIntegerDataType('float64'); // returns false - -// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type -var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); - -bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true - -bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false - -// Test if an input value is a supported array numeric data type -var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); - -bool = isNumericDataType('int32'); // returns true +// Create various arrays: +var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] ); +var arr2 = new Int32Array( [ 1, 2, 3 ] ); +var arr3 = new Uint8Array( [ 1, 2, 3 ] ); +var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i -bool = isNumericDataType('uint16'); // returns true +// Get data types: +var dt1 = dtype( arr1 ); +var dt2 = dtype( arr2 ); +var dt3 = dtype( arr3 ); +var dt4 = dtype( arr4 ); -bool = isNumericDataType('complex128'); // returns true +// Check data types: +console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) ); +// => 'float64 is floating-point data type: true' -bool = isNumericDataType('beep'); // returns false +console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) ); +// => 'int32 is integer data type: true' -// Test if an input value is a supported array real-valued data type -var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); +console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) ); +// => 'uint8 is unsigned integer data type: true' -bool = isRealDataType('float64'); // returns true +console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) ); +// => 'complex128 is complex floating-point data type: true' -bool = isRealDataType('complex128'); // returns false +// Check if arrays have the same values: +console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) ); +// => 'arr2 and arr3 have same values: true' -// Test if an input value is a supported array real-valued floating-point data type -var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); +console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) ); +// => 'arr1 and arr2 have same values: false' -bool = isRealFloatingPoint('float32'); // returns true +// Check safe data type casts: +console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) ); +// => 'Can safely cast from int32 to float64: true' -bool = isRealFloatingPoint('float64'); // returns true +console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) ); +// => 'Can safely cast from float64 to int32: false' -bool = isRealFloatingPoint('complex128'); // returns false +console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) ); +// => 'Can safely cast from uint8 to int32: true' -// Determine whether an array data type can be safely cast to another array data type -var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); +console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) ); +// => 'Can safely cast from complex128 to float64: false' -bool = isSafeDataTypeCast('int32', 'uint16'); // returns false +// Check if arrays contain specific values: +console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) ); +// => 'arr1 contains 2.2: true' -bool = isSafeDataTypeCast('int16', 'float64'); // returns true +console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) ); +// => 'arr2 contains 2: true' -// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type -var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); +console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) ); +// => 'arr2 contains 2.2: false' -bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true +// Check complex array types: +console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) ); +// => 'arr4 is Complex128Array: true' +console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) ); +// => 'arr4 is complex typed array: true' ``` diff --git a/lib/node_modules/@stdlib/array/base/assert/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/examples/index.js index b22104a90fa..3ba718cecd9 100644 --- a/lib/node_modules/@stdlib/array/base/assert/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/examples/index.js @@ -18,145 +18,71 @@ 'use strict'; -/* eslint-disable no-unused-vars */ -var cartesianPower = require( '@stdlib/array/cartesian-power' ); -var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); -var Int32Array = require( '@stdlib/array/int32' ); -var Uint32Array = require( '@stdlib/array/uint32' ); -var Float32Array = require( '@stdlib/array/float32' ); +var dtype = require( '@stdlib/array/dtype' ); var Float64Array = require( '@stdlib/array/float64' ); -var Complex64Array = require( '@stdlib/array/complex64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); var Complex128Array = require( '@stdlib/array/complex128' ); +var ns = require( './../lib' ); -// Test if two arrays have the same values -var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); - -var arr = [1, 2, 3]; - -var power = cartesianPower(arr, 2); // returns Cartesian power of the array - -// Test if an array-like object supports the accessor (get/set) protocol -var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); - -var bool = isAccessorArray(new Complex128Array(10)); // returns true - -bool = isAccessorArray(new Complex64Array(10)); // returns true - -bool = isAccessorArray([]); // returns false - -bool = isAccessorArray(new Float64Array(10)); // returns false - -bool = isAccessorArray(new Int32Array(10)); // returns false - -bool = isAccessorArray(new Uint32Array(10)); // returns false - -bool = isAccessorArray(new Uint8ClampedArray(10)); // returns false - -bool = isAccessorArray({ - 'length': 0 -}); - -// Test if an input value is a supported array complex-valued floating-point data type -var isComplexFloatingPoint = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); - -bool = isComplexFloatingPoint('complex128'); // returns true - -bool = isComplexFloatingPoint('complex64'); // returns true - -bool = isComplexFloatingPoint('float32'); // returns false - -bool = isComplexFloatingPoint('float64'); // returns false - -// Test if a value is a complex typed array -var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' ); - -bool = isComplexTypedArray(new Complex128Array(10)); // returns true - -bool = isComplexTypedArray(new Complex64Array(10)); // returns true - -bool = isComplexTypedArray([]); // returns false - -bool = isComplexTypedArray(new Float64Array(10)); // returns false - -bool = isComplexTypedArray(new Float32Array(10)); // returns false - -bool = isComplexTypedArray({ - 'length': 0 -}); - -// Test if an input value is a supported array data type -var isDataType = require( '@stdlib/array/base/assert/is-data-type' ); - -bool = isDataType('float64'); // returns true - -bool = isDataType('int16'); // returns true - -bool = isDataType('uint8'); // returns true - -bool = isDataType('beep'); // returns false - -// Test if an input value is a supported array floating-point data type -var isFloatingPoint = require( '@stdlib/array/base/assert/is-floating-point-data-type' ); - -bool = isFloatingPoint('float32'); // returns true - -bool = isFloatingPoint('float64'); // returns true - -bool = isFloatingPoint('int16'); // returns false - -bool = isFloatingPoint('uint8'); // returns false - -// Test if an input value is a supported array integer data type -var isIntegerDataType = require( '@stdlib/array/base/assert/is-integer-data-type' ); - -bool = isIntegerDataType('int32'); // returns true - -bool = isIntegerDataType('uint16'); // returns true - -bool = isIntegerDataType('float64'); // returns false - -// Determine whether an array data type can be safely cast or, for floating-point data types, downcast to another array data type -var isMostlySafeDataTypeCast = require( '@stdlib/array/base/assert/is-mostly-safe-data-type-cast' ); - -bool = isMostlySafeDataTypeCast('float64', 'float32'); // returns true - -bool = isMostlySafeDataTypeCast('float32', 'int16'); // returns false - -// Test if an input value is a supported array numeric data type -var isNumericDataType = require( '@stdlib/array/base/assert/is-numeric-data-type' ); +// Create various arrays: +var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] ); +var arr2 = new Int32Array( [ 1, 2, 3 ] ); +var arr3 = new Uint8Array( [ 1, 2, 3 ] ); +var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i -bool = isNumericDataType('int32'); // returns true +// Get data types: +var dt1 = dtype( arr1 ); +var dt2 = dtype( arr2 ); +var dt3 = dtype( arr3 ); +var dt4 = dtype( arr4 ); -bool = isNumericDataType('uint16'); // returns true +// Check data types: +console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) ); +// => 'float64 is floating-point data type: true' -bool = isNumericDataType('complex128'); // returns true +console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) ); +// => 'int32 is integer data type: true' -bool = isNumericDataType('beep'); // returns false +console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) ); +// => 'uint8 is unsigned integer data type: true' -// Test if an input value is a supported array real-valued data type -var isRealDataType = require( '@stdlib/array/base/assert/is-real-data-type' ); +console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) ); +// => 'complex128 is complex floating-point data type: true' -bool = isRealDataType('float64'); // returns true +// Check if arrays have the same values: +console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) ); +// => 'arr2 and arr3 have same values: true' -bool = isRealDataType('complex128'); // returns false +console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) ); +// => 'arr1 and arr2 have same values: false' -// Test if an input value is a supported array real-valued floating-point data type -var isRealFloatingPoint = require( '@stdlib/array/base/assert/is-real-floating-point-data-type' ); +// Check safe data type casts: +console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) ); +// => 'Can safely cast from int32 to float64: true' -bool = isRealFloatingPoint('float32'); // returns true +console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) ); +// => 'Can safely cast from float64 to int32: false' -bool = isRealFloatingPoint('float64'); // returns true +console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) ); +// => 'Can safely cast from uint8 to int32: true' -bool = isRealFloatingPoint('complex128'); // returns false +console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) ); +// => 'Can safely cast from complex128 to float64: false' -// Determine whether an array data type can be safely cast to another array data type -var isSafeDataTypeCast = require( '@stdlib/array/base/assert/is-safe-data-type-cast' ); +// Check if arrays contain specific values: +console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) ); +// => 'arr1 contains 2.2: true' -bool = isSafeDataTypeCast('int32', 'uint16'); // returns false +console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) ); +// => 'arr2 contains 2: true' -bool = isSafeDataTypeCast('int16', 'float64'); // returns true +console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) ); +// => 'arr2 contains 2.2: false' -// Determine whether an array data type can be safely cast to, or is of the same "kind" as, another array data type -var isSameKindDataTypeCast = require( '@stdlib/array/base/assert/is-same-kind-data-type-cast' ); +// Check complex array types: +console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) ); +// => 'arr4 is Complex128Array: true' -bool = isSameKindDataTypeCast('int32', 'uint16'); // returns true +console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) ); +// => 'arr4 is complex typed array: true' From 9856ceb54a4ff1f3f1f922b4a31f6a2e24a4e867 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 7 Oct 2024 21:10:39 -0400 Subject: [PATCH 7/7] chore: revert copyright year change --- lib/node_modules/@stdlib/array/base/assert/README.md | 2 +- lib/node_modules/@stdlib/array/base/assert/examples/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/README.md b/lib/node_modules/@stdlib/array/base/assert/README.md index 9d181345c34..528a3b7e64c 100644 --- a/lib/node_modules/@stdlib/array/base/assert/README.md +++ b/lib/node_modules/@stdlib/array/base/assert/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +Copyright (c) 2022 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. diff --git a/lib/node_modules/@stdlib/array/base/assert/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/examples/index.js index 3ba718cecd9..971ecff1786 100644 --- a/lib/node_modules/@stdlib/array/base/assert/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2022 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.