Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Oct 8, 2024
1 parent 3cdcb3a commit d02ed43
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 247 deletions.
173 changes: 49 additions & 124 deletions lib/node_modules/@stdlib/array/base/assert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,149 +81,74 @@ The namespace exports the following:
<!-- eslint no-undef: "error" -->

```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'
```

</section>
Expand Down
172 changes: 49 additions & 123 deletions lib/node_modules/@stdlib/array/base/assert/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit d02ed43

Please sign in to comment.