Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Mar 22, 2022
1 parent 28f659b commit 424ca33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
25 changes: 13 additions & 12 deletions array/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var createBuffer = require( './../../base/buffer' );
var getType = require( './../../base/buffer-dtype' );
var arrayShape = require( '@stdlib/array/shape' );
var flattenArray = require( '@stdlib/utils/flatten-array' );
var format = require( '@stdlib/string/format' );
var isArrayLikeObject = require( './is_array_like_object.js' );
var defaults = require( './defaults.json' );
var castBuffer = require( './cast_buffer.js' );
Expand Down Expand Up @@ -127,23 +128,23 @@ function array() {
} else {
options = arguments[ 0 ];
if ( !isObject( options ) ) {
throw new TypeError( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `' + options + '`.' );
throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );
}
if ( hasOwnProp( options, 'buffer' ) ) {
buffer = options.buffer;
if ( !isArrayLikeObject( buffer ) ) { // weak test
throw new TypeError( 'invalid option. `buffer` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `' + buffer + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );
}
}
}
} else {
buffer = arguments[ 0 ];
if ( !isArrayLikeObject( buffer ) ) { // weak test
throw new TypeError( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `' + buffer + '`.' );
throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.' , buffer ) );
}
options = arguments[ 1 ];
if ( !isObject( options ) ) {
throw new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
// Note: we ignore whether `options` has a `buffer` property
}
Expand All @@ -163,23 +164,23 @@ function array() {
if ( hasOwnProp( options, 'casting' ) ) {
opts.casting = options.casting;
if ( !isCastingMode( opts.casting ) ) {
throw new TypeError( 'invalid option. `casting` option must be a recognized casting mode. Option: `' + opts.casting + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );
}
} else {
opts.casting = defaults.casting;
}
if ( hasOwnProp( options, 'flatten' ) ) {
opts.flatten = options.flatten;
if ( !isBoolean( opts.flatten ) ) {
throw new TypeError( 'invalid option. `flatten` option must be a boolean. Option: `' + opts.flatten + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );
}
} else {
opts.flatten = defaults.flatten;
}
if ( hasOwnProp( options, 'ndmin' ) ) {
opts.ndmin = options.ndmin;
if ( !isNonNegativeInteger( opts.ndmin ) ) {
throw new TypeError( 'invalid option. `ndmin` option must be a nonnegative integer. Option: `' + opts.ndmin + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );
}
// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)
} else {
Expand All @@ -190,10 +191,10 @@ function array() {
if ( hasOwnProp( options, 'dtype' ) ) {
dtype = options.dtype;
if ( !isDataType( dtype ) ) {
throw new TypeError( 'invalid option. `dtype` option must be a recognized data type. Option: `' + dtype + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );
}
if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {
throw new Error( 'invalid option. Data type cast is not allowed. Casting mode: `' + opts.casting + '`. From: `' + btype + '`. To: `' + dtype + '`.' );
throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );
}
} else if ( btype ) {
// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.
Expand Down Expand Up @@ -231,7 +232,7 @@ function array() {
order = defaults.order;
}
} else if ( !isOrder( order ) ) {
throw new TypeError( 'invalid option. `order` option must be a recognized order. Option: `' + order + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );
}
} else {
order = defaults.order;
Expand All @@ -254,7 +255,7 @@ function array() {
if ( hasOwnProp( options, 'copy' ) ) {
opts.copy = options.copy;
if ( !isBoolean( opts.copy ) ) {
throw new TypeError( 'invalid option. `copy` option must be a boolean. Option: `' + opts.copy + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );
}
} else {
opts.copy = defaults.copy;
Expand All @@ -263,7 +264,7 @@ function array() {
if ( hasOwnProp( options, 'shape' ) ) {
shape = options.shape;
if ( !isArrayLikeObject( shape ) ) { // weak test
throw new TypeError( 'invalid option. `shape` option must be an array-like object containing nonnegative integers. Option: `' + shape + '`.' );
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );
}
ndims = shape.length;
len = numel( shape );
Expand Down
7 changes: 4 additions & 3 deletions sub2ind/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var shape2strides = require( './../../base/shape2strides' );
var getIndex = require( './../../base/sub2ind' );
var format = require( '@stdlib/string/format' );
var defaults = require( './defaults.json' );
var validate = require( './validate.js' );

Expand Down Expand Up @@ -74,7 +75,7 @@ function sub2ind() {

shape = arguments[ 0 ];
if ( !isNonNegativeIntegerArray( shape ) ) {
throw new TypeError( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `' + shape + '`.' );
throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );
}
len = arguments.length;
ndims = shape.length;
Expand All @@ -95,15 +96,15 @@ function sub2ind() {
}
i = 1;
if ( j-i !== ndims ) {
throw new RangeError( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: ' + ndims + '. Number of subscripts: ' + (j-i) + '.' );
throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: %u. Number of subscripts: %u.', ndims, j-i ) );
}
args = new Array( ndims+4 );
args[ 0 ] = shape;
args[ 1 ] = shape2strides( shape, opts.order );
args[ 2 ] = 0; // strides are positive, so offset is always zero
for ( ; i < j; i++ ) {
if ( !isInteger( arguments[ i ] ) ) {
throw new TypeError( 'invalid argument. Subscripts must be integer valued. Argument: ' + i + '. Value: `' + arguments[ i ] + '`.' );
throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: %u. Value: `%s`.', i, arguments[ i ] ) );
}
args[ i+2 ] = arguments[ i ];
}
Expand Down

0 comments on commit 424ca33

Please sign in to comment.