Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve README examples of array/base/assert namespace #1846

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 143 additions & 4 deletions lib/node_modules/@stdlib/array/base/assert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -81,10 +81,149 @@ The namespace exports the following:
<!-- eslint no-undef: "error" -->

```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 ) );
```

</section>
Expand Down
146 changes: 142 additions & 4 deletions lib/node_modules/@stdlib/array/base/assert/examples/index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Loading
Loading