Skip to content

Commit c00f27a

Browse files
docs: improve examples of array/base/assert namespace
PR-URL: #1955 Closes: #1545 --------- Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent ec4730b commit c00f27a

File tree

2 files changed

+132
-4
lines changed

2 files changed

+132
-4
lines changed

lib/node_modules/@stdlib/array/base/assert/README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,74 @@ The namespace exports the following:
8383
<!-- eslint no-undef: "error" -->
8484

8585
```javascript
86-
var objectKeys = require( '@stdlib/utils/keys' );
8786
var ns = require( '@stdlib/array/base/assert' );
87+
var dtype = require( '@stdlib/array/dtype' );
88+
var Float64Array = require( '@stdlib/array/float64' );
89+
var Int32Array = require( '@stdlib/array/int32' );
90+
var Uint8Array = require( '@stdlib/array/uint8' );
91+
var Complex128Array = require( '@stdlib/array/complex128' );
8892

89-
console.log( objectKeys( ns ) );
93+
// Create various arrays:
94+
var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] );
95+
var arr2 = new Int32Array( [ 1, 2, 3 ] );
96+
var arr3 = new Uint8Array( [ 1, 2, 3 ] );
97+
var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i
98+
99+
// Get data types:
100+
var dt1 = dtype( arr1 );
101+
var dt2 = dtype( arr2 );
102+
var dt3 = dtype( arr3 );
103+
var dt4 = dtype( arr4 );
104+
105+
// Check data types:
106+
console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) );
107+
// => 'float64 is floating-point data type: true'
108+
109+
console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) );
110+
// => 'int32 is integer data type: true'
111+
112+
console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) );
113+
// => 'uint8 is unsigned integer data type: true'
114+
115+
console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) );
116+
// => 'complex128 is complex floating-point data type: true'
117+
118+
// Check if arrays have the same values:
119+
console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) );
120+
// => 'arr2 and arr3 have same values: true'
121+
122+
console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) );
123+
// => 'arr1 and arr2 have same values: false'
124+
125+
// Check safe data type casts:
126+
console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) );
127+
// => 'Can safely cast from int32 to float64: true'
128+
129+
console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) );
130+
// => 'Can safely cast from float64 to int32: false'
131+
132+
console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) );
133+
// => 'Can safely cast from uint8 to int32: true'
134+
135+
console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) );
136+
// => 'Can safely cast from complex128 to float64: false'
137+
138+
// Check if arrays contain specific values:
139+
console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) );
140+
// => 'arr1 contains 2.2: true'
141+
142+
console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) );
143+
// => 'arr2 contains 2: true'
144+
145+
console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) );
146+
// => 'arr2 contains 2.2: false'
147+
148+
// Check complex array types:
149+
console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) );
150+
// => 'arr4 is Complex128Array: true'
151+
152+
console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) );
153+
// => 'arr4 is complex typed array: true'
90154
```
91155

92156
</section>

lib/node_modules/@stdlib/array/base/assert/examples/index.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,71 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var dtype = require( '@stdlib/array/dtype' );
22+
var Float64Array = require( '@stdlib/array/float64' );
23+
var Int32Array = require( '@stdlib/array/int32' );
24+
var Uint8Array = require( '@stdlib/array/uint8' );
25+
var Complex128Array = require( '@stdlib/array/complex128' );
2226
var ns = require( './../lib' );
2327

24-
console.log( objectKeys( ns ) );
28+
// Create various arrays:
29+
var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] );
30+
var arr2 = new Int32Array( [ 1, 2, 3 ] );
31+
var arr3 = new Uint8Array( [ 1, 2, 3 ] );
32+
var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i
33+
34+
// Get data types:
35+
var dt1 = dtype( arr1 );
36+
var dt2 = dtype( arr2 );
37+
var dt3 = dtype( arr3 );
38+
var dt4 = dtype( arr4 );
39+
40+
// Check data types:
41+
console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) );
42+
// => 'float64 is floating-point data type: true'
43+
44+
console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) );
45+
// => 'int32 is integer data type: true'
46+
47+
console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) );
48+
// => 'uint8 is unsigned integer data type: true'
49+
50+
console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) );
51+
// => 'complex128 is complex floating-point data type: true'
52+
53+
// Check if arrays have the same values:
54+
console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) );
55+
// => 'arr2 and arr3 have same values: true'
56+
57+
console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) );
58+
// => 'arr1 and arr2 have same values: false'
59+
60+
// Check safe data type casts:
61+
console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) );
62+
// => 'Can safely cast from int32 to float64: true'
63+
64+
console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) );
65+
// => 'Can safely cast from float64 to int32: false'
66+
67+
console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) );
68+
// => 'Can safely cast from uint8 to int32: true'
69+
70+
console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) );
71+
// => 'Can safely cast from complex128 to float64: false'
72+
73+
// Check if arrays contain specific values:
74+
console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) );
75+
// => 'arr1 contains 2.2: true'
76+
77+
console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) );
78+
// => 'arr2 contains 2: true'
79+
80+
console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) );
81+
// => 'arr2 contains 2.2: false'
82+
83+
// Check complex array types:
84+
console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) );
85+
// => 'arr4 is Complex128Array: true'
86+
87+
console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) );
88+
// => 'arr4 is complex typed array: true'

0 commit comments

Comments
 (0)