Skip to content

Commit 9bfd7f8

Browse files
committed
Auto-generated commit
1 parent 65ae661 commit 9bfd7f8

File tree

6 files changed

+39
-66
lines changed

6 files changed

+39
-66
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ A total of 37 issues were closed in this release:
674674

675675
<details>
676676

677+
- [`da7ea70`](https://github.com/stdlib-js/stdlib/commit/da7ea70b7b2de281c4c1364fe7dca3ef8ca7085c) - **refactor:** support data type instances _(by Athan Reines)_
677678
- [`b1623fe`](https://github.com/stdlib-js/stdlib/commit/b1623fe2c183124b2eb55736b4314329aea2856a) - **feat:** update `ndarray/base` TypeScript declarations [(#9420)](https://github.com/stdlib-js/stdlib/pull/9420) _(by stdlib-bot)_
678679
- [`50367fe`](https://github.com/stdlib-js/stdlib/commit/50367fe8a498ac1e3e80fe688eb5c3df2d57a82d) - **feat:** add `toFlippedud` to namespace _(by Athan Reines)_
679680
- [`e7d3d48`](https://github.com/stdlib-js/stdlib/commit/e7d3d486d1a9fc72f471b845d14f076d4f94ae60) - **feat:** add `toFlippedlr` to namespace _(by Athan Reines)_

base/binary-reduce-strided1d-dispatch/docs/repl.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
- arrays: array containing two input ndarrays, followed by any
3030
additional ndarray arguments.
3131

32-
idtypes: Array<Array<string>>
32+
idtypes: Array<Array<string|DataType>>
3333
List containing lists of supported input array data types for each
3434
input ndarray argument.
3535

36-
odtypes: Array<string>
36+
odtypes: Array<string|DataType>
3737
List of supported output array data types.
3838

3939
policies: Object
@@ -105,9 +105,8 @@
105105
> var ord = 'row-major';
106106
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, oo, ord );
107107
> var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, sx, oo, ord );
108-
> var z = f.apply( x, y );
109-
> var v = z.get()
110-
30.0
108+
> var z = f.apply( x, y )
109+
<ndarray>[ 30.0 ]
111110

112111

113112
{{alias}}.prototype.assign( x, y[, ...args], out[, options] )
@@ -158,11 +157,9 @@
158157
> var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, sx, oo, ord );
159158
> var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': dt } );
160159
> var z = f.assign( x, y, out )
161-
<ndarray>
160+
<ndarray>[ 30.0 ]
162161
> var bool = ( out === z )
163162
true
164-
> var v = out.get()
165-
30.0
166163

167164
See Also
168165
--------

base/binary-reduce-strided1d-dispatch/docs/types/index.d.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ declare class BinaryStrided1dDispatch<T, U> {
153153
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
154154
*
155155
* var z = dot.apply( x, y );
156-
* // returns <ndarray>
157-
*
158-
* var v = z.get();
159-
* // returns -5.0
156+
* // returns <ndarray>[ -5.0 ]
160157
*/
161158
constructor( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies );
162159

@@ -192,10 +189,7 @@ declare class BinaryStrided1dDispatch<T, U> {
192189
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
193190
*
194191
* var z = dot.apply( x, y );
195-
* // returns <ndarray>
196-
*
197-
* var v = z.get();
198-
* // returns -5.0
192+
* // returns <ndarray>[ -5.0 ]
199193
*/
200194
apply( x: InputArray<T>, y: InputArray<T>, ...args: Array<InputArray<T> | Options> ): OutputArray<U>; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how the input ndarrays interact with output data type policy and whether that policy has been overridden by `options.dtype`. In principle, as well, based on the policy, it is possible to know more exactly which `InputArray` types are actually allowed.
201195

@@ -235,10 +229,7 @@ declare class BinaryStrided1dDispatch<T, U> {
235229
* var z = new ndarray( 'generic', zbuf, [], [ 0 ], 0, 'row-major' );
236230
*
237231
* var out = dot.assign( x, y, z );
238-
* // returns <ndarray>
239-
*
240-
* var v = out.get();
241-
* // returns -5.0
232+
* // returns <ndarray>[ -5.0 ]
242233
*
243234
* var bool = ( out === z );
244235
* // returns true
@@ -281,10 +272,7 @@ declare class BinaryStrided1dDispatch<T, U> {
281272
* var z = new ndarray( 'generic', zbuf, [], [ 0 ], 0, 'row-major' );
282273
*
283274
* var out = dot.assign( x, y, z );
284-
* // returns <ndarray>
285-
*
286-
* var v = out.get();
287-
* // returns -5.0
275+
* // returns <ndarray>[ -5.0 ]
288276
*
289277
* var bool = ( out === z );
290278
* // returns true
@@ -329,10 +317,7 @@ interface BinaryStrided1dDispatchConstructor {
329317
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
330318
*
331319
* var z = dot.apply( x, y );
332-
* // returns <ndarray>
333-
*
334-
* var v = z.get();
335-
* // returns -5.0
320+
* // returns <ndarray>[ -5.0 ]
336321
*/
337322
new<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies ): BinaryStrided1dDispatch<T, U>;
338323

@@ -369,10 +354,7 @@ interface BinaryStrided1dDispatchConstructor {
369354
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
370355
*
371356
* var z = dot.apply( x, y );
372-
* // returns <ndarray>
373-
*
374-
* var v = z.get();
375-
* // returns -5.0
357+
* // returns <ndarray>[ -5.0 ]
376358
*/
377359
<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies ): BinaryStrided1dDispatch<T, U>;
378360
}
@@ -410,10 +392,7 @@ interface BinaryStrided1dDispatchConstructor {
410392
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
411393
*
412394
* var z = dot.apply( x, y );
413-
* // returns <ndarray>
414-
*
415-
* var v = z.get();
416-
* // returns -5.0
395+
* // returns <ndarray>[ -5.0 ]
417396
*/
418397
declare var ctor: BinaryStrided1dDispatchConstructor;
419398

base/binary-reduce-strided1d-dispatch/lib/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@
4848
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
4949
*
5050
* var z = dot.apply( x, y );
51-
* // returns <ndarray>
52-
*
53-
* var v = z.get();
54-
* // returns -5.0
51+
* // returns <ndarray>[ -5.0 ]
5552
*/
5653

5754
// MODULES //

base/binary-reduce-strided1d-dispatch/lib/main.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ var isFunctionArray = require( '@stdlib/assert/is-function-array' );
3333
var isDataType = require( './../../../base/assert/is-data-type' );
3434
var isOutputDataTypePolicy = require( './../../../base/assert/is-output-data-type-policy' );
3535
var isInputCastingPolicy = require( './../../../base/assert/is-input-casting-policy' );
36+
var isEqualDataType = require( './../../../base/assert/is-equal-data-type' );
3637
var contains = require( '@stdlib/array/base/assert/contains' );
3738
var binaryReduceStrided1d = require( './../../../base/binary-reduce-strided1d' );
3839
var binaryOutputDataType = require( './../../../base/binary-output-dtype' );
3940
var binaryInputCastingDataType = require( './../../../base/binary-input-casting-dtype' );
4041
var dtypes2enums = require( './../../../base/dtypes2enums' );
42+
var dtypes2strings = require( './../../../base/dtypes2strings' );
43+
var resolveStr = require( './../../../base/dtype-resolve-str' );
4144
var spreadDimensions = require( './../../../base/spread-dimensions' );
4245
var getShape = require( './../../../shape' ); // note: non-base accessor is intentional due to input ndarrays originating in userland
4346
var ndims = require( './../../../ndims' );
@@ -74,10 +77,10 @@ var DEFAULT_ORDER = defaults.get( 'order' );
7477
* @constructor
7578
* @param {Object} table - dispatch table
7679
* @param {Function} table.default - default strided reduction function
77-
* @param {StringArray} [table.types=[]] - one-dimensional list of ndarray data types describing specialized input ndarray argument signatures
80+
* @param {Array} [table.types=[]] - one-dimensional list of ndarray data types describing specialized input ndarray argument signatures
7881
* @param {ArrayLikeObject<Function>} [table.fcns=[]] - list of strided reduction functions which are specific to specialized input ndarray argument signatures
79-
* @param {ArrayLikeObject<StringArray>} idtypes - list containing lists of supported input data types for each input ndarray argument
80-
* @param {StringArray} odtypes - list of supported output data types
82+
* @param {ArrayLikeObject<Array>} idtypes - list containing lists of supported input data types for each input ndarray argument
83+
* @param {Array} odtypes - list of supported output data types
8184
* @param {Object} policies - policies
8285
* @param {string} policies.output - output data type policy
8386
* @param {string} policies.casting - input ndarray casting policy
@@ -112,10 +115,7 @@ var DEFAULT_ORDER = defaults.get( 'order' );
112115
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
113116
*
114117
* var z = dot.apply( x, y );
115-
* // returns <ndarray>
116-
*
117-
* var v = z.get();
118-
* // returns -5.0
118+
* // returns <ndarray>[ -5.0 ]
119119
*/
120120
function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
121121
var dt;
@@ -138,6 +138,7 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
138138
if ( !isCollection( idtypes ) ) {
139139
throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );
140140
}
141+
idtypes = copy( idtypes );
141142
for ( i = 0; i < idtypes.length; i++ ) {
142143
dt = idtypes[ i ];
143144
if (
@@ -147,6 +148,7 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
147148
) {
148149
throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );
149150
}
151+
idtypes[ i ] = dtypes2strings( dt );
150152
}
151153
if (
152154
!isCollection( odtypes ) ||
@@ -155,6 +157,8 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
155157
) {
156158
throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );
157159
}
160+
odtypes = dtypes2strings( odtypes );
161+
158162
if ( !isObject( policies ) ) {
159163
throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', table ) );
160164
}
@@ -226,10 +230,7 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
226230
* var y = new ndarray( 'generic', ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' );
227231
*
228232
* var z = dot.apply( x, y );
229-
* // returns <ndarray>
230-
*
231-
* var v = z.get();
232-
* // returns -5.0
233+
* // returns <ndarray>[ -5.0 ]
233234
*/
234235
setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y ) {
235236
var options;
@@ -264,11 +265,11 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
264265
throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', y ) );
265266
}
266267
xdt = getDType( x );
267-
if ( !contains( this._idtypes[ 0 ], xdt ) ) {
268+
if ( !contains( this._idtypes[ 0 ], resolveStr( xdt ) ) ) {
268269
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( this._idtypes[ 0 ], '", "' ), xdt ) );
269270
}
270271
ydt = getDType( y );
271-
if ( !contains( this._idtypes[ 1 ], ydt ) ) {
272+
if ( !contains( this._idtypes[ 1 ], resolveStr( ydt ) ) ) {
272273
throw new TypeError( format( 'invalid argument. Second argument must have one of the following data types: "%s". Data type: `%s`.', join( this._idtypes[ 1 ], '", "' ), ydt ) );
273274
}
274275
args = [ x, y ];
@@ -278,7 +279,7 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
278279
break;
279280
}
280281
dt = getDType( arr );
281-
if ( !contains( this._idtypes[ i ], dt ) ) {
282+
if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {
282283
throw new TypeError( format( 'invalid argument. Argument %d must have one of the following data types: "%s". Data type: `%s`.', i, join( this._idtypes[ i ], '", "' ), dt ) );
283284
}
284285
// Note: we don't type promote additional ndarray arguments, as they are passed as scalars to the underlying strided reduction function...
@@ -337,15 +338,15 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
337338

338339
// Determine whether we need to cast the input ndarrays...
339340
dt = binaryInputCastingDataType( xdt, ydt, zdt, this._policies.casting );
340-
if ( xdt !== dt ) {
341+
if ( !isEqualDataType( xdt, dt ) ) {
341342
// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
342343
tmp = baseEmpty( dt, shx, ordx );
343344
assign( [ x, tmp ] );
344345
args[ 0 ] = tmp;
345346
xdt = dt;
346347
}
347348
dt = binaryInputCastingDataType( ydt, xdt, zdt, this._policies.casting );
348-
if ( ydt !== dt ) {
349+
if ( !isEqualDataType( ydt, dt ) ) {
349350
// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
350351
tmp = baseEmpty( dt, shy, ordy );
351352
assign( [ y, tmp ] );
@@ -419,10 +420,7 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
419420
* var z = new ndarray( 'generic', zbuf, [], [ 0 ], 0, 'row-major' );
420421
*
421422
* var out = dot.assign( x, y, z );
422-
* // returns <ndarray>
423-
*
424-
* var v = out.get();
425-
* // returns -5.0
423+
* // returns <ndarray>[ -5.0 ]
426424
*
427425
* var bool = ( out === z );
428426
* // returns true
@@ -457,11 +455,11 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'assign', function assign( x, y
457455
}
458456
// Validate the input ndarray data types in order to maintain similar behavior to `apply` above...
459457
xdt = getDType( x );
460-
if ( !contains( this._idtypes[ 0 ], xdt ) ) {
458+
if ( !contains( this._idtypes[ 0 ], resolveStr( xdt ) ) ) {
461459
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( this._idtypes[ 0 ], '", "' ), xdt ) );
462460
}
463461
ydt = getDType( y );
464-
if ( !contains( this._idtypes[ 1 ], ydt ) ) {
462+
if ( !contains( this._idtypes[ 1 ], resolveStr( ydt ) ) ) {
465463
throw new TypeError( format( 'invalid argument. Second argument must have one of the following data types: "%s". Data type: `%s`.', join( this._idtypes[ 1 ], '", "' ), ydt ) );
466464
}
467465
// Verify that both input arrays have the same shape:
@@ -505,7 +503,7 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'assign', function assign( x, y
505503
// Verify that additional ndarray arguments have expected dtypes (note: we intentionally don't validate the output ndarray dtype in order to provide an escape hatch for a user wanting to have an output ndarray having a specific dtype that `apply` does not support; note: we don't type promote additional ndarray arguments, as they are passed as scalars to the underlying strided reduction function)...
506504
for ( i = 2; i < args.length; i++ ) {
507505
dt = getDType( args[ i ] );
508-
if ( !contains( this._idtypes[ i ], dt ) ) {
506+
if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {
509507
throw new TypeError( format( 'invalid argument. Argument %d must have one of the following data types: "%s". Data type: `%s`.', i, join( this._idtypes[ i ], '", "' ), dt ) );
510508
}
511509
}
@@ -525,15 +523,15 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'assign', function assign( x, y
525523
// Determine whether we need to cast the input ndarrays...
526524
zdt = getDType( z );
527525
dt = binaryInputCastingDataType( xdt, ydt, zdt, this._policies.casting );
528-
if ( xdt !== dt ) {
526+
if ( !isEqualDataType( xdt, dt ) ) {
529527
// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
530528
tmp = baseEmpty( dt, shx, getOrder( x ) );
531529
assign( [ x, tmp ] );
532530
args[ 0 ] = tmp;
533531
xdt = dt;
534532
}
535533
dt = binaryInputCastingDataType( ydt, xdt, zdt, this._policies.casting );
536-
if ( ydt !== dt ) {
534+
if ( !isEqualDataType( ydt, dt ) ) {
537535
// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
538536
tmp = baseEmpty( dt, shy, getOrder( y ) );
539537
assign( [ y, tmp ] );

base/binary-reduce-strided1d-dispatch/lib/validate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives;
2727
var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' );
2828
var normalizeIndices = require( './../../../base/to-unique-normalized-indices' );
29+
var resolveStr = require( './../../../base/dtype-resolve-str' );
2930
var join = require( '@stdlib/array/base/join' );
3031
var contains = require( '@stdlib/array/base/assert/contains' );
3132
var format = require( '@stdlib/string/format' );
@@ -85,7 +86,7 @@ function validate( opts, ndims, dtypes, options ) {
8586
}
8687
if ( hasOwnProp( options, 'dtype' ) ) {
8788
opts.dtype = options.dtype;
88-
if ( !contains( dtypes, String( opts.dtype ) ) ) {
89+
if ( !contains( dtypes, resolveStr( opts.dtype ) ) ) {
8990
return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) );
9091
}
9192
}

0 commit comments

Comments
 (0)