Skip to content

Commit 1c769c9

Browse files
committed
test: use accessors for retrieving ndarray meta data
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 06b39a8 commit 1c769c9

8 files changed

Lines changed: 55 additions & 170 deletions

File tree

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/README.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ Broadcasts an [ndarray][@stdlib/ndarray/base/ctor] to a specified `shape` if and
4747
```javascript
4848
var array = require( '@stdlib/ndarray/array' );
4949

50-
// Create a 2x2 ndarray:
51-
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
52-
// returns <ndarray>
50+
// Create a 1x2 ndarray:
51+
var x = array( [ [ 1, 2 ] ] );
52+
// returns <ndarray>[ [ 1, 2 ] ]
5353

5454
// Broadcast to a 2x2x2 ndarray:
5555
var y = maybeBroadcastArray( x, [ 2, 2, 2 ] );
56-
// returns <ndarray>
56+
// returns <ndarray>[ [ [ 1, 2 ], [ 1, 2 ] ], [ [ 1, 2 ], [ 1, 2 ] ] ]
5757
```
5858

5959
</section>
@@ -85,30 +85,16 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] );
8585

8686
```javascript
8787
var array = require( '@stdlib/ndarray/array' );
88-
var numel = require( '@stdlib/ndarray/base/numel' );
89-
var ind2sub = require( '@stdlib/ndarray/ind2sub' );
88+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9089
var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' );
9190

9291
// Create a 2x2 array:
9392
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
94-
// returns <ndarray>
93+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
9594

9695
// Broadcast the array to 3x2x2:
9796
var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
98-
// returns <ndarray>
99-
100-
// Retrieve the shape:
101-
var sh = y.shape;
102-
// returns [ 3, 2, 2 ]
103-
104-
// Retrieve the number of elements:
105-
var N = numel( sh );
106-
107-
// Loop through the array elements...
108-
var i;
109-
for ( i = 0; i < N; i++ ) {
110-
console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) );
111-
}
97+
// returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ] ]
11298
```
11399

114100
</section>

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/docs/repl.txt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,9 @@
3939
Examples
4040
--------
4141
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] )
42-
<ndarray>
43-
> var sh = x.shape
44-
[ 2, 2 ]
42+
<ndarray>[ [1,2], [3,4] ]
4543
> var y = {{alias}}( x, [ 3, 2, 2 ] )
46-
<ndarray>
47-
> sh = y.shape
48-
[ 3, 2, 2 ]
49-
> var v = y.get( 0, 0, 0 )
50-
1
51-
> v = y.get( 0, 0, 1 )
52-
2
53-
> v = y.get( 0, 1, 0 )
54-
3
55-
> v = y.get( 0, 1, 1 )
56-
4
57-
> v = y.get( 1, 0, 0 )
58-
1
59-
> v = y.get( 1, 1, 0 )
60-
3
61-
> v = y.get( 2, 0, 0 )
62-
1
63-
> v = y.get( 2, 1, 1 )
64-
4
44+
<ndarray>[ [ [1,2], [3,4] ], [ [1,2], [3,4] ], [ [1,2], [3,4] ] ]
6545

6646
See Also
6747
--------

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/docs/types/index.d.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,22 @@ import { ndarray } from '@stdlib/types/ndarray';
4141
* @returns broadcasted array
4242
*
4343
* @example
44+
* var getShape = require( '@stdlib/ndarray/shape' );
4445
* var array = require( '@stdlib/ndarray/array' );
4546
*
4647
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
47-
* // returns <ndarray>
48+
* // returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
4849
*
49-
* var shx = x.shape;
50+
* var shx = getShape( x );
5051
* // returns [ 2, 2 ]
5152
*
5253
* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
53-
* // returns <ndarray>
54+
* // returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ] ]
5455
*
55-
* var shy = y.shape;
56+
* var shy = getShape( y );
5657
* // returns [ 3, 2, 2 ]
57-
*
58-
* var v = y.get( 0, 0, 0 );
59-
* // returns 1
60-
*
61-
* v = y.get( 0, 0, 1 );
62-
* // returns 2
63-
*
64-
* v = y.get( 1, 0, 0 );
65-
* // returns 1
66-
*
67-
* v = y.get( 1, 1, 0 );
68-
* // returns 3
69-
*
70-
* v = y.get( 2, 0, 0 );
71-
* // returns 1
72-
*
73-
* v = y.get( 2, 1, 1 );
74-
* // returns 4
7558
*/
76-
declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike<number> ): ndarray;
59+
declare function maybeBroadcastArray<T extends ndarray>( arr: T, shape: ArrayLike<number> ): T;
7760

7861

7962
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/docs/types/test.ts

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,23 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable space-in-parens */
20+
1921
/// <reference types="@stdlib/types"/>
2022

21-
import { ndarray } from '@stdlib/types/ndarray';
23+
import zeros = require( '@stdlib/ndarray/zeros' );
2224
import maybeBroadcastArray = require( './index' );
2325

24-
/**
25-
* Mock function to create an ndarray-like object.
26-
*
27-
* @returns ndarray-like object
28-
*/
29-
function array(): ndarray {
30-
const obj: ndarray = {
31-
'byteLength': 80,
32-
'BYTES_PER_ELEMENT': 8,
33-
'data': new Float64Array( 10 ),
34-
'dtype': 'float64',
35-
'flags': {
36-
'ROW_MAJOR_CONTIGUOUS': true,
37-
'COLUMN_MAJOR_CONTIGUOUS': false
38-
},
39-
'length': 10,
40-
'ndims': 1,
41-
'offset': 0,
42-
'order': 'row-major',
43-
'shape': [ 10 ],
44-
'strides': [ 1 ],
45-
'get': (): number => 0,
46-
'set': (): ndarray => obj
47-
};
48-
return obj;
49-
}
50-
5126

5227
// TESTS //
5328

5429
// The function returns an ndarray...
5530
{
56-
const x = array();
31+
const x = zeros( [ 2, 2 ], {
32+
'dtype': 'float64'
33+
});
5734

58-
maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray
35+
maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType float64ndarray
5936
}
6037

6138
// The compiler throws an error if the function is not provided a first argument which is an ndarray...
@@ -72,7 +49,9 @@ function array(): ndarray {
7249

7350
// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers...
7451
{
75-
const x = array();
52+
const x = zeros( [ 2, 2 ], {
53+
'dtype': 'float64'
54+
});
7655

7756
maybeBroadcastArray( x, '5' ); // $ExpectError
7857
maybeBroadcastArray( x, 5 ); // $ExpectError
@@ -86,7 +65,9 @@ function array(): ndarray {
8665

8766
// The compiler throws an error if the function is provided an unsupported number of arguments...
8867
{
89-
const x = array();
68+
const x = zeros( [ 2, 2 ], {
69+
'dtype': 'float64'
70+
});
9071

9172
maybeBroadcastArray(); // $ExpectError
9273
maybeBroadcastArray( x ); // $ExpectError

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/examples/index.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,13 @@
1919
'use strict';
2020

2121
var array = require( '@stdlib/ndarray/array' );
22-
var numel = require( '@stdlib/ndarray/base/numel' );
23-
var ind2sub = require( '@stdlib/ndarray/ind2sub' );
22+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
2423
var maybeBroadcastArray = require( './../lib' );
2524

2625
// Create a 2x2 array:
2726
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
28-
// returns <ndarray>
27+
console.log( ndarray2array( x ) );
2928

3029
// Broadcast the array to 3x2x2:
3130
var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
32-
// returns <ndarray>
33-
34-
// Retrieve the shape:
35-
var sh = y.shape;
36-
// returns [ 3, 2, 2 ]
37-
38-
// Retrieve the number of elements:
39-
var N = numel( sh );
40-
41-
// Loop through the array elements...
42-
var i;
43-
for ( i = 0; i < N; i++ ) {
44-
console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) );
45-
}
31+
console.log( ndarray2array( y ) );

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/lib/index.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,21 @@
2424
* @module @stdlib/ndarray/base/maybe-broadcast-array
2525
*
2626
* @example
27+
* var getShape = require( '@stdlib/ndarray/shape' );
2728
* var array = require( '@stdlib/ndarray/array' );
2829
* var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' );
2930
*
3031
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
31-
* // returns <ndarray>
32+
* // returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
3233
*
33-
* var shx = x.shape;
34+
* var shx = getShape( x );
3435
* // returns [ 2, 2 ]
3536
*
3637
* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
37-
* // returns <ndarray>
38+
* // returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ] ]
3839
*
39-
* var shy = y.shape;
40+
* var shy = getShape( y );
4041
* // returns [ 3, 2, 2 ]
41-
*
42-
* var v = y.get( 0, 0, 0 );
43-
* // returns 1
44-
*
45-
* v = y.get( 0, 0, 1 );
46-
* // returns 2
47-
*
48-
* v = y.get( 1, 0, 0 );
49-
* // returns 1
50-
*
51-
* v = y.get( 1, 1, 0 );
52-
* // returns 3
53-
*
54-
* v = y.get( 2, 0, 0 );
55-
* // returns 1
56-
*
57-
* v = y.get( 2, 1, 1 );
58-
* // returns 4
5942
*/
6043

6144
// MODULES //

lib/node_modules/@stdlib/ndarray/base/maybe-broadcast-array/lib/main.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,22 @@ var getShape = require( '@stdlib/ndarray/base/shape' );
4242
* @returns {ndarray} broadcasted array
4343
*
4444
* @example
45+
* var getShape = require( '@stdlib/ndarray/shape' );
4546
* var array = require( '@stdlib/ndarray/array' );
47+
* var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' );
4648
*
4749
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
48-
* // returns <ndarray>
50+
* // returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
4951
*
50-
* var shx = x.shape;
52+
* var shx = getShape( x );
5153
* // returns [ 2, 2 ]
5254
*
5355
* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
54-
* // returns <ndarray>
56+
* // returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ] ]
5557
*
56-
* var shy = y.shape;
58+
* var shy = getShape( y );
5759
* // returns [ 3, 2, 2 ]
5860
*
59-
* var v = y.get( 0, 0, 0 );
60-
* // returns 1
61-
*
62-
* v = y.get( 0, 0, 1 );
63-
* // returns 2
64-
*
65-
* v = y.get( 1, 0, 0 );
66-
* // returns 1
67-
*
68-
* v = y.get( 1, 1, 0 );
69-
* // returns 3
70-
*
71-
* v = y.get( 2, 0, 0 );
72-
* // returns 1
73-
*
74-
* v = y.get( 2, 1, 1 );
75-
* // returns 4
76-
*
7761
* @example
7862
* var array = require( '@stdlib/ndarray/array' );
7963
*

0 commit comments

Comments
 (0)