Skip to content

Commit 693a93d

Browse files
committed
refactor: use accessor utilities
1 parent b545940 commit 693a93d

File tree

1 file changed

+9
-3
lines changed
  • lib/node_modules/@stdlib/ndarray/broadcast-array/lib

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
2424
var isCollection = require( '@stdlib/assert/is-collection' );
2525
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2626
var copy = require( '@stdlib/array/base/copy-indexed' );
27+
var getDType = require( '@stdlib/ndarray/dtype' );
28+
var getShape = require( '@stdlib/ndarray/shape' );
29+
var getStrides = require( '@stdlib/ndarray/strides' );
30+
var getOffset = require( '@stdlib/ndarray/offset' );
31+
var getOrder = require( '@stdlib/ndarray/order' );
32+
var getData = require( '@stdlib/ndarray/data-buffer' );
2733
var format = require( '@stdlib/string/format' );
2834

2935

@@ -105,7 +111,7 @@ function broadcastArray( x, shape ) {
105111
throw new TypeError( format( 'invalid argument. Second argument must be an array of nonnegative integers. Value: `%s`.', shape ) );
106112
}
107113
N = shape.length;
108-
sh = x.shape;
114+
sh = getShape( x );
109115
M = sh.length;
110116
if ( N < M ) {
111117
throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );
@@ -116,7 +122,7 @@ function broadcastArray( x, shape ) {
116122
strides.push( 0 );
117123
}
118124
// Determine the output array strides...
119-
st = x.strides;
125+
st = getStrides( x );
120126
for ( i = N-1; i >= 0; i-- ) {
121127
j = M - N + i;
122128
if ( j < 0 ) {
@@ -141,7 +147,7 @@ function broadcastArray( x, shape ) {
141147
throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );
142148
}
143149
}
144-
return new x.constructor( x.dtype, x.data, copy( shape ), strides, x.offset, x.order, { // eslint-disable-line max-len
150+
return new x.constructor( getDType( x ), getData( x ), copy( shape ), strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len
145151
'readonly': true
146152
});
147153
}

0 commit comments

Comments
 (0)