Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stdlib-js/ndarray-array
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a355a92
Choose a base ref
...
head repository: stdlib-js/ndarray-array
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc15339
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on May 8, 2025

  1. Transform error messages

    stdlib-bot committed May 8, 2025
    Copy the full SHA
    cc15339 View commit details
Showing with 17 additions and 17 deletions.
  1. +16 −16 lib/main.js
  2. +1 −1 package.json
32 changes: 16 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ var getOrder = require( '@stdlib/ndarray-order' );
var getData = require( '@stdlib/ndarray-data-buffer' );
var arrayShape = require( '@stdlib/array-shape' );
var flatten = require( '@stdlib/array-base-flatten' );
var format = require( '@stdlib/string-format' );
var format = require( '@stdlib/error-tools-fmtprodmsg' );
var isArrayLikeObject = require( './is_array_like_object.js' );
var getDefaults = require( './defaults.js' );
var castBuffer = require( './cast_buffer.js' );
@@ -141,23 +141,23 @@ function array() {
} else {
options = arguments[ 0 ];
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );
throw new TypeError( format( '0hT56', options ) );
}
if ( hasOwnProp( options, 'buffer' ) ) {
buffer = options.buffer;
if ( !isArrayLikeObject( buffer ) ) { // weak test
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 ) );
throw new TypeError( format( '0hT57', 'buffer', buffer ) );
}
}
}
} else {
buffer = arguments[ 0 ];
if ( !isArrayLikeObject( buffer ) ) { // weak test
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 ) );
throw new TypeError( format( '0hT58', buffer ) );
}
options = arguments[ 1 ];
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
throw new TypeError( format( '0hT2V', options ) );
}
// Note: we ignore whether `options` has a `buffer` property
}
@@ -177,23 +177,23 @@ function array() {
if ( hasOwnProp( options, 'casting' ) ) {
opts.casting = options.casting;
if ( !isCastingMode( opts.casting ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );
throw new TypeError( format( '0hT59', 'casting', opts.casting ) );
}
} else {
opts.casting = defaults.casting;
}
if ( hasOwnProp( options, 'flatten' ) ) {
opts.flatten = options.flatten;
if ( !isBoolean( opts.flatten ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );
throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) );
}
} else {
opts.flatten = defaults.flatten;
}
if ( hasOwnProp( options, 'ndmin' ) ) {
opts.ndmin = options.ndmin;
if ( !isNonNegativeInteger( opts.ndmin ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );
throw new TypeError( format( '0hT2t', '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 {
@@ -204,10 +204,10 @@ function array() {
if ( hasOwnProp( options, 'dtype' ) ) {
dtype = options.dtype;
if ( !isDataType( dtype ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );
throw new TypeError( format( '0hTBf', 'dtype', dtype ) );
}
if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {
throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );
throw new Error( format( '0hT5B', opts.casting, btype, dtype ) );
}
} else if ( btype ) { // btype !== void 0
// 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.
@@ -245,7 +245,7 @@ function array() {
order = defaults.order;
}
} else if ( !isOrder( order ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );
throw new TypeError( format( '0hT5C', 'order', order ) );
}
} else {
order = defaults.order;
@@ -268,7 +268,7 @@ function array() {
if ( hasOwnProp( options, 'copy' ) ) {
opts.copy = options.copy;
if ( !isBoolean( opts.copy ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );
throw new TypeError( format( '0hT2o', 'copy', opts.copy ) );
}
} else {
opts.copy = defaults.copy;
@@ -277,7 +277,7 @@ function array() {
if ( hasOwnProp( options, 'shape' ) ) {
shape = options.shape;
if ( !isArrayLikeObject( shape ) ) { // weak test
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );
throw new TypeError( format( '0hT5D', 'shape', shape ) );
}
ndims = shape.length;
len = numel( shape );
@@ -297,7 +297,7 @@ function array() {
shape = [ len ]; // assume a 1-dimensional array (vector)
}
} else {
throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );
throw new Error( format('0hT0X') );
}
// Adjust the array shape to satisfy the minimum number of dimensions...
if ( ndims < opts.ndmin ) {
@@ -307,7 +307,7 @@ function array() {
// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...
if ( FLG ) {
if ( numel( buffer.shape ) !== len ) {
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
throw new RangeError( format('0hT0Y') );
}
if ( btype !== dtype || opts.copy ) {
buffer = copyView( buffer, dtype );
@@ -325,7 +325,7 @@ function array() {
buffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) );
}
if ( buffer.length !== len ) {
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
throw new RangeError( format('0hT0Y') );
}
if ( btype !== dtype || opts.copy ) {
buffer = castBuffer( buffer, len, dtype );
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@
"@stdlib/ndarray-order": "^0.2.2",
"@stdlib/ndarray-shape": "^0.2.2",
"@stdlib/ndarray-strides": "^0.2.2",
"@stdlib/string-format": "^0.2.2",
"@stdlib/error-tools-fmtprodmsg": "^0.2.2",
"@stdlib/types": "^0.4.3",
"@stdlib/error-tools-fmtprodmsg": "^0.2.2"
},