Skip to content

Commit 4fd6c9e

Browse files
committed
Auto-generated commit
1 parent 48f8d48 commit 4fd6c9e

File tree

12 files changed

+94
-175
lines changed

12 files changed

+94
-175
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2026-03-29)
8+
9+
<section class="commits">
10+
11+
### Commits
12+
13+
<details>
14+
15+
- [`1c769c9`](https://github.com/stdlib-js/stdlib/commit/1c769c983b0a4197ba30c9372568e03af00e9c00) - **test:** use accessors for retrieving ndarray meta data _(by Athan Reines)_
16+
17+
</details>
18+
19+
</section>
20+
21+
<!-- /.commits -->
22+
23+
<section class="contributors">
24+
25+
### Contributors
26+
27+
A total of 1 person contributed to this release. Thank you to this contributor:
28+
29+
- Athan Reines
30+
31+
</section>
32+
33+
<!-- /.contributors -->
34+
35+
</section>
36+
37+
<!-- /.release -->
38+
539
<section class="release" id="v0.2.5">
640

741
## 0.2.5 (2026-02-08)

README.md

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

83-
// Create a 2x2 ndarray:
84-
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
85-
// returns <ndarray>
83+
// Create a 1x2 ndarray:
84+
var x = array( [ [ 1, 2 ] ] );
85+
// returns <ndarray>[ [ 1, 2 ] ]
8686

8787
// Broadcast to a 2x2x2 ndarray:
8888
var y = maybeBroadcastArray( x, [ 2, 2, 2 ] );
89-
// returns <ndarray>
89+
// returns <ndarray>[ [ [ 1, 2 ], [ 1, 2 ] ], [ [ 1, 2 ], [ 1, 2 ] ] ]
9090
```
9191

9292
</section>
@@ -118,30 +118,16 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] );
118118

119119
```javascript
120120
var array = require( '@stdlib/ndarray-array' );
121-
var numel = require( '@stdlib/ndarray-base-numel' );
122-
var ind2sub = require( '@stdlib/ndarray-ind2sub' );
121+
var ndarray2array = require( '@stdlib/ndarray-to-array' );
123122
var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );
124123

125124
// Create a 2x2 array:
126125
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
127-
// returns <ndarray>
126+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
128127

129128
// Broadcast the array to 3x2x2:
130129
var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
131-
// returns <ndarray>
132-
133-
// Retrieve the shape:
134-
var sh = y.shape;
135-
// returns [ 3, 2, 2 ]
136-
137-
// Retrieve the number of elements:
138-
var N = numel( sh );
139-
140-
// Loop through the array elements...
141-
var i;
142-
for ( i = 0; i < N; i++ ) {
143-
console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) );
144-
}
130+
// returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ] ]
145131
```
146132

147133
</section>

dist/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

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 //

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

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/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 //

0 commit comments

Comments
 (0)